Making WordPress.org


Ignore:
Timestamp:
12/02/2021 12:59:04 AM (4 years ago)
Author:
tellyworth
Message:

WordPress.org Learn: sync with GitHub

Props hlashbrooke.

https://github.com/WordPress/learn/compare/fa76b2cdf5c9b979585f3142d62949ae4c0ca91d...4b476da0d46f52c39505379eeb202561bf0d37db

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-learn-2020/functions.php

    r11336 r11352  
    166166
    167167/**
    168  * Get the values associated to the page/post
     168 * Get the values associated to the page/post formatted as a string
    169169 *
    170170 * @param string $post_id Id of the post.
     
    180180
    181181/**
     182 * Get the values associated to the page/post formatted as an array
     183 *
     184 * @param string $post_id Id of the post.
     185 * @param string $tax_slug The slug for the custom taxonomy.
     186 *
     187 * @return array
     188 */
     189function wporg_learn_get_taxonomy_terms_array( $post_id, $tax_slug ) {
     190    $term_ids = wp_get_post_terms( $post_id, $tax_slug, array( 'fields' => 'ids' ) );
     191
     192    $terms = array();
     193    foreach ( $term_ids as $id ) {
     194        $terms[ $id ] = get_term( $id )->name;
     195    }
     196
     197    return $terms;
     198}
     199
     200/**
     201 * Get the values associated to the page/post according to the context
     202 *
     203 * @param  int    $post_id  ID of the post.
     204 * @param  string $tax_slug The slug for the custom taxonomy.
     205 * @param  string $context  The context for display.
     206 *
     207 * @return array|string
     208 */
     209function wporg_learn_get_taxonomy_terms( $post_id, $tax_slug, $context ) {
     210    switch ( $context ) {
     211        case 'archive':
     212            return wporg_learn_get_taxonomy_terms_string( $post_id, $tax_slug );
     213            break;
     214        case 'single':
     215            return wporg_learn_get_taxonomy_terms_array( $post_id, $tax_slug );
     216            break;
     217    }
     218}
     219
     220/**
    182221 * Returns the taxonomies associated to a lesson or workshop
    183222 *
     
    186225 * @return array
    187226 */
    188 function wporg_learn_get_lesson_plan_taxonomy_data( $post_id ) {
     227function wporg_learn_get_lesson_plan_taxonomy_data( $post_id, $context ) {
    189228    return array(
    190229        array(
    191230            'icon'  => 'clock',
     231            'slug'  => 'duration',
    192232            'label' => wporg_label_with_colon( get_taxonomy_labels( get_taxonomy( 'duration' ) )->singular_name ),
    193             'value' => wporg_learn_get_taxonomy_terms_string( $post_id, 'duration' ),
     233            'value' => wporg_learn_get_taxonomy_terms( $post_id, 'duration', $context ),
    194234        ),
    195235        array(
    196236            'icon'  => 'admin-users',
     237            'slug'  => 'audience',
    197238            'label' => wporg_label_with_colon( get_taxonomy_labels( get_taxonomy( 'audience' ) )->singular_name ),
    198             'value' => wporg_learn_get_taxonomy_terms_string( $post_id, 'audience' ),
     239            'value' => wporg_learn_get_taxonomy_terms( $post_id, 'audience', $context ),
    199240        ),
    200241        array(
    201242            'icon'  => 'dashboard',
     243            'slug'  => 'level',
    202244            'label' => wporg_label_with_colon( get_taxonomy_labels( get_taxonomy( 'level' ) )->singular_name ),
    203             'value' => wporg_learn_get_taxonomy_terms_string( $post_id, 'level' ),
     245            'value' => wporg_learn_get_taxonomy_terms( $post_id, 'level', $context ),
    204246        ),
    205247        array(
    206248            'icon'  => 'welcome-learn-more',
     249            'slug'  => 'type',
    207250            'label' => wporg_label_with_colon( get_taxonomy_labels( get_taxonomy( 'instruction_type' ) )->singular_name ),
    208             'value' => wporg_learn_get_taxonomy_terms_string( $post_id, 'instruction_type' ),
     251            'value' => wporg_learn_get_taxonomy_terms( $post_id, 'instruction_type', $context ),
    209252        ),
    210253    );
     
    301344    if ( $query->is_main_query() && $query->is_search() ) {
    302345        $public_post_types = array_keys( get_post_types( array( 'public' => true ) ) );
    303         $omit_from_search = array( 'attachment', 'lesson', 'quiz', 'sensei_message', 'meeting' );
     346        $omit_from_search = array( 'attachment', 'page', 'lesson', 'quiz', 'sensei_message', 'meeting' );
    304347        $searchable_post_types = array_diff( $public_post_types, $omit_from_search );
     348
     349        // Only show featured courses, but don't limit other post types
     350        $query->set(
     351            'meta_query',
     352            array(
     353                'relation' => 'OR',
     354                array(
     355                    'key'   => '_course_featured',
     356                    'value' => 'featured',
     357                ),
     358                array(
     359                    'key'      => '_course_featured',
     360                    'compare'  => 'NOT EXISTS',
     361                ),
     362            )
     363        );
    305364
    306365        $query->set( 'post_type', $searchable_post_types );
     
    564623
    565624        case 'lesson-plan':
    566             $args['meta'] = wporg_learn_get_lesson_plan_taxonomy_data( $post_id );
     625            $args['meta'] = wporg_learn_get_lesson_plan_taxonomy_data( $post_id, 'archive' );
    567626            break;
    568627
Note: See TracChangeset for help on using the changeset viewer.