Changeset 10169 for sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-learn-2020/functions.php
- Timestamp:
- 08/13/2020 11:43:14 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-learn-2020/functions.php
r10166 r10169 29 29 */ 30 30 function 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' ) ); 32 32 wp_enqueue_script( 'wporg-navigation', get_template_directory_uri() . '/js/navigation.js', array(), filemtime( __DIR__ . '/js/navigation.js' ), true ); 33 34 33 } 35 34 add_action( 'wp_enqueue_scripts', 'wporg_learn_scripts' ); … … 51 50 */ 52 51 function 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' ) ); 54 53 } 55 54 … … 57 56 * Get the lesson plans associated to a taxonomy 58 57 * 59 * @param string $slugs Comma separated list of taxonomy terms 58 * @param string $slugs Comma separated list of taxonomy terms. 60 59 * @package WPBBP 61 60 */ … … 113 112 $cat = wporg_get_filter_category(); 114 113 115 if ( empty( $cat ) ) {114 if ( empty( $cat ) ) { 116 115 return wporg_get_default_cat()->slug; 117 116 } … … 124 123 * Get the values associated to the page/post 125 124 * 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. 128 127 * @return string 129 128 */ 130 function get_taxonomy_values( $id, $tax_slug ) {131 $terms = wp_get_post_terms( $id, $tax_slug, array( 'fields' => 'names' ) );129 function get_taxonomy_values( $id, $tax_slug ) { 130 $terms = wp_get_post_terms( $id, $tax_slug, array( 'fields' => 'names' ) ); 132 131 return implode( ', ', $terms ); 133 132 } … … 137 136 * Returns the taxonomies associated to a lesson or workshop 138 137 * 139 * @param string $id Id of the post 138 * @param string $id Id of the post. 140 139 * @return string 141 140 */ 142 141 function 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 ); 165 164 } 166 165 … … 198 197 */ 199 198 function 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 ); 201 200 } 202 201 … … 206 205 * @return array 207 206 */ 208 function wporg_get_workshops( $options = NULL) {207 function wporg_get_workshops( $options = null ) { 209 208 $args = array( 210 209 'post_type' => 'wporg_workshop', 211 210 ); 212 211 213 if ( ! is_null( $options ) ) {212 if ( ! is_null( $options ) ) { 214 213 $args = array_merge( $args, $options ); 215 214 … … 243 242 } 244 243 245 /** 244 /** 246 245 * 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 */ 251 250 function 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.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)