0 ? $course_id : RouteContext::course_id(); if ( $course_id <= 0 || ! Services::gate()->can_view_course( get_current_user_id(), $course_id )->allowed ) { return null; } $post = (int) ( Services::posts()->for_objects( ObjectType::COURSE, array( $course_id ), Switcher::current() )[ $course_id ] ?? 0 ); if ( $post <= 0 ) { return null; } return array( 'title' => Services::posts()->title( $post ), 'url' => Services::posts()->permalink( $post ), ); } public static function markup( string $class_name, int $course_id = 0, string $tag = 'p' ): string { $course = self::of( $course_id ); $tag = in_array( $tag, array( 'p', 'h2', 'h3' ), true ) ? $tag : 'p'; return null === $course ? '' : '<' . $tag . ' class="' . esc_attr( $class_name ) . '">' . esc_html( $course['title'] ) . '' . $tag . '>'; } public static function supertitle( string $html, array $block ): string { unset( $block ); if ( self::$printed || ! is_singular( array( PostTypes::LESSON, PostTypes::QUIZ, PostTypes::COURSE ) ) ) { return $html; } $line = is_singular( PostTypes::COURSE ) ? self::category_line() : self::markup( 'rooster-lms-supertitle', 0, 'h2' ); if ( '' === $line ) { return $html; } self::$printed = true; return Markup::ui_mark( $line, 'course-link' ) . $html; } private static function category_line(): string { $course = Services::course_repo()->id_for_post( (int) get_queried_object_id() ); if ( $course <= 0 || ! Services::gate()->can_view_course( get_current_user_id(), $course )->allowed ) { return ''; } $trail = Services::category_resolver()->trail_for_object( ObjectType::COURSE, $course, Switcher::current() ); $node = array() === $trail ? null : $trail[ count( $trail ) - 1 ]; if ( null === $node || '' === $node->name ) { return ''; } $name = esc_html( $node->name ); return '