Making WordPress.org

Changeset 11352


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

WordPress.org Learn: sync with GitHub

Props hlashbrooke.

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

Location:
sites/trunk/wordpress.org/public_html/wp-content
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-learn/inc/blocks.php

    r11294 r11352  
    7272 */
    7373function workshop_details_render_callback( $attributes, $content ) {
    74         $post     = get_post();
    75         $topics   = wp_get_post_terms( $post->ID, 'topic', array( 'fields' => 'names' ) );
    76         $level    = wp_get_post_terms( $post->ID, 'level', array( 'fields' => 'names' ) );
    77         $captions = get_post_meta( $post->ID, 'video_caption_language' );
     74        $post      = get_post();
     75        $topic_ids = wp_get_post_terms( $post->ID, 'topic', array( 'fields' => 'ids' ) );
     76        $level     = wp_get_post_terms( $post->ID, 'level', array( 'fields' => 'names' ) );
     77        $captions  = get_post_meta( $post->ID, 'video_caption_language' );
     78
     79        $topic_names = array();
     80        foreach ( $topic_ids as $id ) {
     81                $topic_names[] = get_term( $id )->name;
     82        }
    7883
    7984        $fields = array(
    80                 __( 'Length', 'wporg-learn' )   => get_workshop_duration( $post, 'string' ),
    81                 __( 'Topic', 'wporg-learn' )    => implode( ', ', array_map( 'esc_html', $topics ) ),
    82                 __( 'Level', 'wporg-learn' )    => implode( ', ', array_map( 'esc_html', $level ) ),
    83                 __( 'Language', 'wporg-learn' ) => esc_html( get_locale_name_from_code( $post->video_language, 'native' ) ),
    84                 __( 'Subtitles', 'wporg-learn' ) => implode(
    85                         ', ',
    86                         array_map(
     85                'length' => array(
     86                        'label' => __( 'Length', 'wporg-learn' ),
     87                        'param' => array(),
     88                        'value' => array( get_workshop_duration( $post, 'string' ) ),
     89                ),
     90                'topic' => array(
     91                        'label' => __( 'Topic', 'wporg-learn' ),
     92                        'param' => $topic_ids,
     93                        'value' => $topic_names,
     94                ),
     95                'level' => array(
     96                        'label' => __( 'Level', 'wporg-learn' ),
     97                        'param' => array(),
     98                        'value' => $level,
     99                ),
     100                'language' => array(
     101                        'label' => __( 'Language', 'wporg-learn' ),
     102                        'param' => array( $post->video_language ),
     103                        'value' => array( esc_html( get_locale_name_from_code( $post->video_language, 'native' ) ) ),
     104                ),
     105                'captions' => array(
     106                        'label' => __( 'Subtitles', 'wporg-learn' ),
     107                        'param' => $captions,
     108                        'value' => array_map(
    87109                                function( $caption_lang ) {
    88110                                        return esc_html( get_locale_name_from_code( $caption_lang, 'native' ) );
    89111                                },
    90112                                $captions
    91                         )
    92                 ),
    93         );
    94 
    95         // Remove empty fields.
    96         $fields = array_filter( $fields );
     113                        ),
     114                ),
     115        );
     116
     117        // Remove fields with empty values.
     118        $fields = array_filter( $fields, function( $data ) {
     119                return $data['value'];
     120        } );
    97121
    98122        $lesson_id = get_post_meta( $post->ID, 'linked_lesson_id', true );
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-learn/views/block-workshop-details.php

    r11324 r11352  
    1818        <?php if ( ! empty( $fields ) ) : ?>
    1919                <ul class="workshop-details-list">
    20                         <?php foreach ( $fields as $key => $value ) : ?>
     20                        <?php foreach ( $fields as $key => $field ) : ?>
    2121                                <li>
    22                                         <b><?php echo esc_html( $key ); ?></b>
    23                                         <span><?php echo esc_html( $value ); ?></span>
     22                                        <b><?php echo esc_html( $field['label'] ); ?></b>
     23                                        <span>
     24                                                <?php
     25                                                $i = 0;
     26                                                foreach ( $field['value'] as $field_key => $value ) {
     27                                                        $url = '';
     28                                                        if ( ! empty( $field['param'] ) ) {
     29                                                                $url = trailingslashit( site_url() ) . 'workshops/?' . $key . '=' . $field['param'][ $field_key ];
     30                                                        }
     31
     32                                                        if ( 0 < $i ) {
     33                                                                echo ', ';
     34                                                        }
     35
     36                                                        if ( $url ) {
     37                                                                echo '<a href="' . esc_url( $url ) . '">' . esc_html( $value ) . '</a>';
     38                                                        } else {
     39                                                                echo esc_html( $value );
     40                                                        }
     41                                                        $i++;
     42                                                }
     43                                                ?>
     44                                        </span>
    2445                                </li>
    2546                        <?php endforeach; ?>
  • 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
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-learn-2020/header.php

    r11309 r11352  
    5050                                        <?php get_search_form(); ?>
    5151                                </div>
    52                                 <?php elseif ( is_page() ) : ?>
    53                                 <h1 class="site-title"><a href="<?php echo esc_url( get_the_permalink() ); ?>" rel="home"><?php the_title(); ?></a></h1>
    5452                                <?php else : ?>
    5553                                <p class="site-title">
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-learn-2020/page.php

    r10513 r11352  
    2121                <?php get_template_part( 'template-parts/component', 'breadcrumbs' ); ?>
    2222
     23                <div class="row align-middle between section-heading section-heading--with-space">
     24                        <?php the_title( '<h1 class="section-heading_title h2">', '</h1>' ); ?>
     25                </div>
     26                <hr>
     27
    2328                <div id="main-content">
    2429                        <?php
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-learn-2020/sidebar-lesson-plan.php

    r11322 r11352  
    1515                <ul>
    1616                        <?php
    17                         foreach ( wporg_learn_get_lesson_plan_taxonomy_data( get_the_ID() ) as $detail ) {
     17                        foreach ( wporg_learn_get_lesson_plan_taxonomy_data( get_the_ID(), 'single' ) as $detail ) {
    1818                                if ( ! empty( $detail['value'] ) ) {
    1919                                        include locate_template( 'template-parts/component-taxonomy-item.php' );
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-learn-2020/template-parts/component-taxonomy-item.php

    r10513 r11352  
    1414        <span><?php echo esc_html( $detail['label'] ); ?></span>
    1515        <strong>
    16                 <span><?php echo esc_html( $detail['value'] ); ?></span>
     16                <span>
     17                        <?php //echo esc_html( $detail['value'] ); ?>
     18
     19                        <?php
     20                        $i = 0;
     21                        foreach ( $detail['value'] as $key => $value ) {
     22                                $url = trailingslashit( site_url() ) . 'lesson-plans/?' . $detail['slug'] . '[]=' . $key;
     23
     24                                if ( 0 < $i ) {
     25                                        echo ', ';
     26                                }
     27
     28                                echo '<a href="' . esc_attr( $url ) . '">' . esc_html( $value ) . '</a>';
     29                                $i++;
     30                        }
     31                        ?>
     32                </span>
    1733        </strong>
    1834</li>
Note: See TracChangeset for help on using the changeset viewer.