' . '' . '' . '' . '' . ''; } /** * A topic's page is not a post WordPress can find by its slug (lessons live * in their own table), so WordPress would answer 404. A topic that exists * is a real page: answer 200, which client-side navigation also relies on. * * @param bool $preempt Whether to skip WordPress's own 404 handling. * @param \WP_Query $wp_query Main query. * @return bool */ public static function not_a_404( $preempt, $wp_query ) { if ( $preempt || ! self::is_request() ) { return $preempt; } $data = LearnPage\Data::current(); if ( ! $data['courseId'] || ! $data['topicId'] ) { return $preempt; } status_header( 200 ); $wp_query->is_404 = false; // The topic's slug arrives as the `name` query var, so WordPress treats // the request as a single post and then finds none. Anything that asks // for the queried post (body_class() in core, themes, SEO and community // plugins) reads a property of null and prints PHP warnings into the // page. The page belongs to the course, so make that the queried post. $course = get_post( (int) $data['courseId'] ); if ( $course instanceof \WP_Post ) { $wp_query->queried_object = $course; $wp_query->queried_object_id = (int) $course->ID; } return true; } /** * Mark the page for styling. * * @param string[] $classes Body classes. * @return string[] */ public static function body_class( $classes ) { if ( self::is_request() ) { $classes[] = 'academy-learn-body'; if ( LearnPage\Settings::get()['themeChrome'] ) { $classes[] = 'academy-learn-body--theme'; } } return $classes; } /** * Load the page's stylesheet and script in the head, before the blocks * render, so the layout does not jump. * * @return void */ public static function enqueue_styles() { if ( self::is_request() ) { wp_enqueue_style( 'academy-learn-page-style' ); // Before the head prints the import map, so the page can load the // router when a student moves to another topic. wp_enqueue_script_module( 'academy-learn-page-view-script-module' ); } } /** * The page draws its own full-screen layout; floating widgets pinned to the * window by other plugins sit on top of the lesson otherwise. * * @return void */ public static function dequeue_theme_scripts() { if ( ! self::is_request() ) { return; } wp_dequeue_style( 'storeengine-floating-cart' ); } }