Skip to content

Commit

Permalink
Theme: Make get_my_courses_page_url safe to call
Browse files Browse the repository at this point in the history
Fixes exception where get_my_courses_page_url is undefined.
Move this helper function from the plugin to the theme as it is only used in theme templates.
  • Loading branch information
adamwoodnz committed Aug 13, 2024
1 parent cfb2a66 commit 2f686c3
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 19 deletions.
15 changes: 0 additions & 15 deletions wp-content/plugins/wporg-learn/inc/sensei.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,21 +254,6 @@ class="sensei-date-picker"
}
add_action( 'sensei_reports_overview_before_top_filters', __NAMESPACE__ . '\wporg_learn_add_student_count_to_reports' );

/**
* Get the URL of the "My Courses" page.
*
* @return string The URL of the "My Courses" page.
*/
function get_my_courses_page_url() {
$page_id = Sensei()->settings->get_my_courses_page_id();

if ( ! $page_id ) {
return '';
}

return get_permalink( $page_id );
}

/**
* Redirect requests for the "My Courses" page to the login page and back, if logged out.
*/
Expand Down
6 changes: 4 additions & 2 deletions wp-content/themes/pub/wporg-learn-2024/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
namespace WordPressdotorg\Theme\Learn_2024;

use WP_HTML_Tag_Processor;
use function WPOrg_Learn\Sensei\{get_my_courses_page_url, get_lesson_has_published_course};
use function WPOrg_Learn\Sensei\{get_lesson_has_published_course};
use function WordPressdotorg\Theme\Learn_2024\Template_Helpers\{get_my_courses_page_url};

// Block files
require_once __DIR__ . '/src/card-featured-image-a11y/index.php';
Expand All @@ -20,8 +21,9 @@
require_once __DIR__ . '/src/upcoming-online-workshops/index.php';
require_once __DIR__ . '/inc/block-config.php';
require_once __DIR__ . '/inc/block-hooks.php';
require_once __DIR__ . '/inc/query.php';
require_once __DIR__ . '/inc/head.php';
require_once __DIR__ . '/inc/query.php';
require_once __DIR__ . '/inc/template-helpers.php';

/**
* Actions and filters.
Expand Down
18 changes: 18 additions & 0 deletions wp-content/themes/pub/wporg-learn-2024/inc/template-helpers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace WordPressdotorg\Theme\Learn_2024\Template_Helpers;

/**
* Get the URL of the "My Courses" page.
*
* @return string The URL of the "My Courses" page.
*/
function get_my_courses_page_url() {
if ( function_exists( 'Sensei' ) ) {
$page_id = Sensei()->settings->get_my_courses_page_id();

return $page_id ? get_permalink( $page_id ) : '';
}

return '';
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Inserter: no
*/

use function WPOrg_Learn\Sensei\{get_my_courses_page_url}
use function WordPressdotorg\Theme\Learn_2024\Template_Helpers\{get_my_courses_page_url};
?>

<!-- wp:heading {"level":1} -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @package wporg-learn-2024
*/

use function WPOrg_Learn\Sensei\{get_my_courses_page_url};
use function WordPressdotorg\Theme\Learn_2024\Template_Helpers\{get_my_courses_page_url};

$completed_course = Sensei_Utils::user_completed_course( get_the_ID() );
$current_post = get_post();
Expand Down

0 comments on commit 2f686c3

Please sign in to comment.