Making WordPress.org


Ignore:
Timestamp:
08/13/2020 11:43:14 PM (6 years ago)
Author:
coreymckrill
Message:

WordPress.org Learn: Sync with GitHub

https://github.com/WordPress/learn/compare/1accd3db38a60230689bdc157f9e82081d35d163...38e7793fd20434d72ca898988d017ba2009fb677

File:
1 edited

Legend:

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

    r10166 r10169  
    2929 */
    3030function wporg_learn_scripts() {
    31         wp_enqueue_style( 'wporg-style', get_theme_file_uri( '/css/style.css' ), [ 'dashicons', 'open-sans' ], filemtime( __DIR__ . '/css/style.css' ) );
     31        wp_enqueue_style( 'wporg-style', get_theme_file_uri( '/css/style.css' ), array( 'dashicons', 'open-sans' ), filemtime( __DIR__ . '/css/style.css' ) );
    3232        wp_enqueue_script( 'wporg-navigation', get_template_directory_uri() . '/js/navigation.js', array(), filemtime( __DIR__ . '/js/navigation.js' ), true );
    33 
    3433}
    3534add_action( 'wp_enqueue_scripts', 'wporg_learn_scripts' );
     
    5150 */
    5251function wporg_get_tax_slugs_from_workshop() {
    53         return wp_get_post_terms( get_the_ID(), 'lesson_group',  array( 'fields' => 'slugs' ) );
     52        return wp_get_post_terms( get_the_ID(), 'lesson_group', array( 'fields' => 'slugs' ) );
    5453}
    5554
     
    5756 * Get the lesson plans associated to a taxonomy
    5857 *
    59  * @param string $slugs Comma separated list of taxonomy terms
     58 * @param string $slugs Comma separated list of taxonomy terms.
    6059 * @package WPBBP
    6160 */
     
    113112        $cat = wporg_get_filter_category();
    114113
    115         if( empty( $cat ) ) {
     114        if ( empty( $cat ) ) {
    116115                return wporg_get_default_cat()->slug;
    117116        }
     
    124123 * Get the values associated to the page/post
    125124 *
    126  * @param string $id Id of the post
    127  * @param string $tax_slug The slug for the custom taxonomy
     125 * @param string $id Id of the post.
     126 * @param string $tax_slug The slug for the custom taxonomy.
    128127 * @return string
    129128 */
    130 function get_taxonomy_values( $id, $tax_slug ){
    131         $terms = wp_get_post_terms( $id, $tax_slug, array( 'fields' => 'names' )  );
     129function get_taxonomy_values( $id, $tax_slug ) {
     130        $terms = wp_get_post_terms( $id, $tax_slug, array( 'fields' => 'names' ) );
    132131        return implode( ', ', $terms );
    133132}
     
    137136 * Returns the taxonomies associated to a lesson or workshop
    138137 *
    139  * @param string $id Id of the post
     138 * @param string $id Id of the post.
    140139 * @return string
    141140 */
    142141function wporg_get_custom_taxonomies( $id ) {
    143         return [
    144                 [
    145                         'icon' => 'clock',
    146                         'label' => 'Length:',
    147                         'values' => get_taxonomy_values( $id, 'duration' )
    148                 ],
    149                 [
    150                         'icon' => 'admin-users',
    151                         'label' => 'Audience:',
    152                         'values' => get_taxonomy_values( $id, 'audience' )
    153                 ],
    154                 [
    155                         'icon' => 'dashboard',
    156                         'label' => 'Level:',
    157                         'values' => get_taxonomy_values( $id, 'level' )
    158                 ],
    159                 [
    160                         'icon' => 'welcome-learn-more',
    161                         'label' => 'Type of Instruction:',
    162                         'values' => get_taxonomy_values( $id, 'instruction_type' )
    163                 ]
    164         ];
     142        return array(
     143                array(
     144                        'icon'   => 'clock',
     145                        'label'  => 'Length:',
     146                        'values' => get_taxonomy_values( $id, 'duration' ),
     147                ),
     148                array(
     149                        'icon'   => 'admin-users',
     150                        'label'  => 'Audience:',
     151                        'values' => get_taxonomy_values( $id, 'audience' ),
     152                ),
     153                array(
     154                        'icon'   => 'dashboard',
     155                        'label'  => 'Level:',
     156                        'values' => get_taxonomy_values( $id, 'level' ),
     157                ),
     158                array(
     159                        'icon'   => 'welcome-learn-more',
     160                        'label'  => 'Type of Instruction:',
     161                        'values' => get_taxonomy_values( $id, 'instruction_type' ),
     162                ),
     163        );
    165164}
    166165
     
    198197 */
    199198function wporg_get_download_slides_url() {
    200 return get_post_meta( get_the_ID(), 'download_lesson_plan_slides_url', true );
     199        return get_post_meta( get_the_ID(), 'download_lesson_plan_slides_url', true );
    201200}
    202201
     
    206205 * @return array
    207206 */
    208 function wporg_get_workshops( $options = NULL ) {
     207function wporg_get_workshops( $options = null ) {
    209208        $args = array(
    210209                'post_type' => 'wporg_workshop',
    211210        );
    212211
    213         if( ! is_null( $options ) ) {
     212        if ( ! is_null( $options ) ) {
    214213                $args = array_merge( $args, $options );
    215214
     
    243242}
    244243
    245 /**             
     244/**
    246245 * Display a featured image, falling back to the VideoPress thumbnail if no featured image was explicitly set.
    247  *         
    248  * @param $post The Workshop post for which we want the thumbnail.
    249  * @param $size The image size: 'medium', 'full'.
    250  */     
     246 *
     247 * @param WP_Post $post The Workshop post for which we want the thumbnail.
     248 * @param string  $size The image size: 'medium', 'full'.
     249 */
    251250function wporg_get_post_thumbnail( $post, $size = 'post-thumbnail' ) {
    252     $thumbnail = get_the_post_thumbnail( $post, $size );
    253     if ( $thumbnail ) {
    254         return $thumbnail;
    255     } else {
    256         $post = get_post( $post );
    257         foreach ( get_post_meta( $post->ID, '', true ) as $key => $value ) {
    258             if ( substr( $key, 0, 8 ) === '_oembed_' && preg_match( '#https://video.wordpress.com/embed/(\w+)#', $value[0], $match ) ) {
    259                 $video = videopress_get_video_details( $match[1] );
    260                 if ( !is_wp_error( $video ) && isset( $video->poster ) ) {
    261                     return '<img class="attachment-' . esc_attr( $size ) . ' wp-post-image" src=' . esc_url( $video->poster ) . ' loading="lazy" />';
    262                 }
    263             }
    264         }
    265     }
    266 }
    267 
     251        $thumbnail = get_the_post_thumbnail( $post, $size );
     252        if ( $thumbnail ) {
     253                return $thumbnail;
     254        } else {
     255                $post = get_post( $post );
     256                foreach ( get_post_meta( $post->ID, '', true ) as $key => $value ) {
     257                        if ( substr( $key, 0, 8 ) === '_oembed_' && preg_match( '#https://video.wordpress.com/embed/(\w+)#', $value[0], $match ) ) {
     258                                $video = videopress_get_video_details( $match[1] );
     259                                if ( ! is_wp_error( $video ) && isset( $video->poster ) ) {
     260                                        return '<img class="attachment-' . esc_attr( $size ) . ' wp-post-image" src=' . esc_url( $video->poster ) . ' loading="lazy" alt="" />';
     261                                }
     262                        }
     263                }
     264        }
     265}
     266
Note: See TracChangeset for help on using the changeset viewer.