diff --git a/wp-content/plugins/wporg-learn/inc/taxonomy.php b/wp-content/plugins/wporg-learn/inc/taxonomy.php index 2fbea5c4d..d5e2983e5 100644 --- a/wp-content/plugins/wporg-learn/inc/taxonomy.php +++ b/wp-content/plugins/wporg-learn/inc/taxonomy.php @@ -27,6 +27,7 @@ function register() { register_lesson_instruction_type(); register_lesson_level(); register_lesson_plan_series(); + register_lesson_visibility(); register_workshop_series(); register_workshop_type(); register_wp_version(); @@ -260,6 +261,57 @@ function register_lesson_level() { register_taxonomy( 'level', array( 'lesson-plan', 'lesson', 'course' ), $args ); } +/** + * Register the Lesson visibility taxonomy, used to hide lessons from the archive and search views. + */ +function register_lesson_visibility() { + $labels = array( + 'name' => _x( 'Visibility', 'Taxonomy General Name', 'wporg-learn' ), + 'singular_name' => _x( 'Visibility', 'Taxonomy Singular Name', 'wporg-learn' ), + 'menu_name' => __( 'Visibility', 'wporg-learn' ), + 'all_items' => __( 'All Visibilities', 'wporg-learn' ), + 'parent_item' => __( 'Parent Visibility', 'wporg-learn' ), + 'parent_item_colon' => __( 'Parent Visibility:', 'wporg-learn' ), + 'new_item_name' => __( 'New Visibility Name', 'wporg-learn' ), + 'add_new_item' => __( 'Add New Visibility', 'wporg-learn' ), + 'edit_item' => __( 'Edit Visibility', 'wporg-learn' ), + 'update_item' => __( 'Update Visibility', 'wporg-learn' ), + 'view_item' => __( 'View Visibility', 'wporg-learn' ), + 'separate_items_with_commas' => __( 'Separate visibilities with commas', 'wporg-learn' ), + 'add_or_remove_items' => __( 'Add or remove visibilities', 'wporg-learn' ), + 'choose_from_most_used' => __( 'Choose from the most used', 'wporg-learn' ), + 'popular_items' => __( 'Popular Visibilities', 'wporg-learn' ), + 'search_items' => __( 'Search Visibilities', 'wporg-learn' ), + 'not_found' => __( 'No Visibilities Found', 'wporg-learn' ), + 'no_terms' => __( 'No visibilities', 'wporg-learn' ), + 'items_list' => __( 'Visibilities list', 'wporg-learn' ), + 'items_list_navigation' => __( 'Visibilities list navigation', 'wporg-learn' ), + ); + + $args = array( + 'labels' => $labels, + 'hierarchical' => true, + 'public' => true, + 'query_var' => 'wporg_lesson_visibility', // Prevent collisions with query params in the archive filter. + 'show_ui' => true, + 'show_admin_column' => true, + 'show_in_nav_menus' => true, + 'show_tagcloud' => false, + 'show_in_rest' => true, + 'rewrite' => false, + 'capabilities' => array( + 'manage_terms' => 'manage_categories', + 'edit_terms' => 'manage_categories', + 'delete_terms' => 'manage_categories', + 'assign_terms' => 'edit_lessons', + ), + ); + + // Use an existing taxonomy registered with Jetpack Search + // See https://github.com/Automattic/jetpack/blob/36b2d5232e2ec3a1ad14034ab673fddce3acab97/projects/packages/sync/src/modules/class-search.php#L1479 + register_taxonomy( 'show', array( 'lesson' ), $args ); +} + /** * Register the Lesson Plan Series taxonomy. */ diff --git a/wp-content/plugins/wporg-learn/js/lesson-archive-excluded-meta/index.js b/wp-content/plugins/wporg-learn/js/lesson-archive-excluded-meta/index.js index e80c7b70c..aa1cdf026 100644 --- a/wp-content/plugins/wporg-learn/js/lesson-archive-excluded-meta/index.js +++ b/wp-content/plugins/wporg-learn/js/lesson-archive-excluded-meta/index.js @@ -16,7 +16,7 @@ const LessonArchiveExcludedMeta = () => { const [ lessonExcluded, setLessonFeatured ] = useState( postMetaData?._lesson_archive_excluded === EXCLUDED ); return ( - + is_main_query() && ( $query->is_archive( 'lesson' ) || $query->is_search() ) ) { $meta_query = $query->get( 'meta_query', array() ); + $tax_query = $query->get( 'tax_query', array() ); - $exclude_lesson_query = array( + $exclude_lessons_by_post_meta = array( 'relation' => 'OR', array( 'key' => '_lesson_archive_excluded', @@ -71,13 +72,29 @@ function add_excluded_to_lesson_archive_query( $query ) { $meta_query = array( 'relation' => 'AND', $meta_query, - $exclude_lesson_query, + $exclude_lessons_by_post_meta, ); } else { - $meta_query = $exclude_lesson_query; + $meta_query = $exclude_lessons_by_post_meta; + } + + $exclude_lessons_by_taxonomy = array( + 'taxonomy' => 'show', + 'field' => 'slug', + 'terms' => 'hidden', + 'operator' => 'NOT IN', + ); + + // If there's an existing tax query, add the new condition + if ( ! empty( $tax_query ) ) { + $tax_query['relation'] = 'AND'; + $tax_query[] = $exclude_lessons_by_taxonomy; + } else { + $tax_query = array( $exclude_lessons_by_taxonomy ); } $query->set( 'meta_query', $meta_query ); + $query->set( 'tax_query', $tax_query ); } }