From 2f686c3a3525f2dcf4c8e01e39c878e1de754f8e Mon Sep 17 00:00:00 2001 From: Adam Wood <1017872+adamwoodnz@users.noreply.github.com> Date: Wed, 14 Aug 2024 10:44:57 +1200 Subject: [PATCH] Theme: Make get_my_courses_page_url safe to call 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. --- wp-content/plugins/wporg-learn/inc/sensei.php | 15 --------------- .../themes/pub/wporg-learn-2024/functions.php | 6 ++++-- .../wporg-learn-2024/inc/template-helpers.php | 18 ++++++++++++++++++ .../page-learning-pathways-content.php | 2 +- .../patterns/sidebar-course.php | 2 +- 5 files changed, 24 insertions(+), 19 deletions(-) create mode 100644 wp-content/themes/pub/wporg-learn-2024/inc/template-helpers.php diff --git a/wp-content/plugins/wporg-learn/inc/sensei.php b/wp-content/plugins/wporg-learn/inc/sensei.php index 416cf219b..1c6dd56a8 100644 --- a/wp-content/plugins/wporg-learn/inc/sensei.php +++ b/wp-content/plugins/wporg-learn/inc/sensei.php @@ -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. */ diff --git a/wp-content/themes/pub/wporg-learn-2024/functions.php b/wp-content/themes/pub/wporg-learn-2024/functions.php index c2788dfe9..cac7ce2c7 100644 --- a/wp-content/themes/pub/wporg-learn-2024/functions.php +++ b/wp-content/themes/pub/wporg-learn-2024/functions.php @@ -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'; @@ -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. diff --git a/wp-content/themes/pub/wporg-learn-2024/inc/template-helpers.php b/wp-content/themes/pub/wporg-learn-2024/inc/template-helpers.php new file mode 100644 index 000000000..78cdf04f8 --- /dev/null +++ b/wp-content/themes/pub/wporg-learn-2024/inc/template-helpers.php @@ -0,0 +1,18 @@ +settings->get_my_courses_page_id(); + + return $page_id ? get_permalink( $page_id ) : ''; + } + + return ''; +} diff --git a/wp-content/themes/pub/wporg-learn-2024/patterns/page-learning-pathways-content.php b/wp-content/themes/pub/wporg-learn-2024/patterns/page-learning-pathways-content.php index d5df6980b..c63e27c69 100644 --- a/wp-content/themes/pub/wporg-learn-2024/patterns/page-learning-pathways-content.php +++ b/wp-content/themes/pub/wporg-learn-2024/patterns/page-learning-pathways-content.php @@ -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}; ?> diff --git a/wp-content/themes/pub/wporg-learn-2024/patterns/sidebar-course.php b/wp-content/themes/pub/wporg-learn-2024/patterns/sidebar-course.php index 52080c0ae..b9653e56a 100644 --- a/wp-content/themes/pub/wporg-learn-2024/patterns/sidebar-course.php +++ b/wp-content/themes/pub/wporg-learn-2024/patterns/sidebar-course.php @@ -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();