Ticket #45984: 45984.diff
File 45984.diff, 11.7 KB (added by , 16 months ago) |
---|
-
src/wp-content/themes/twentynineteen/functions.php
diff --git a/src/wp-content/themes/twentynineteen/functions.php b/src/wp-content/themes/twentynineteen/functions.php index 9d9c2c3a04..793ce58ed0 100644
a b require get_template_directory() . '/classes/class-twentynineteen-walker-comment 309 309 */ 310 310 require get_template_directory() . '/inc/template-functions.php'; 311 311 312 /** 313 * Common theme functions. 314 */ 315 require get_template_directory() . '/inc/helper-functions.php'; 316 312 317 /** 313 318 * SVG Icons related functions. 314 319 */ -
src/wp-content/themes/twentynineteen/inc/helper-functions.php
diff --git a/src/wp-content/themes/twentynineteen/inc/helper-functions.php b/src/wp-content/themes/twentynineteen/inc/helper-functions.php index 12e1f94c0b..f7fcebbbb5 100644
a b 5 5 * 6 6 * @package WordPress 7 7 * @subpackage Twenty_Nineteen 8 * @since 8 * @since 9 9 */ 10 10 11 11 /** -
src/wp-content/themes/twentynineteen/inc/icon-functions.php
diff --git a/src/wp-content/themes/twentynineteen/inc/icon-functions.php b/src/wp-content/themes/twentynineteen/inc/icon-functions.php index abd7c86bba..666a905158 100644
a b function twentynineteen_nav_menu_social_icons( $item_output, $item, $depth, $arg 50 50 return $item_output; 51 51 } 52 52 add_filter( 'walker_nav_menu_start_el', 'twentynineteen_nav_menu_social_icons', 10, 4 ); 53 54 /** 55 * Add a dropdown icon to top-level menu items. 56 * 57 * @param string $output Nav menu item start element. 58 * @param object $item Nav menu item. 59 * @param int $depth Depth. 60 * @param object $args Nav menu args. 61 * @return string Nav menu item start element. 62 * Add a dropdown icon to top-level menu items 63 */ 64 function twentynineteen_add_dropdown_icons( $output, $item, $depth, $args ) { 65 66 // Only add class to 'top level' items on the 'primary' menu. 67 if ( ! isset( $args->theme_location ) || 'menu-1' !== $args->theme_location ) { 68 return $output; 69 } 70 71 if ( in_array( 'mobile-parent-nav-menu-item', $item->classes, true ) && isset( $item->original_id ) ) { 72 // Inject the keyboard_arrow_left SVG inside the parent nav menu item, and let the item link to the parent item. 73 // @todo Only do this for nested submenus? If on a first-level submenu, then really the link could be "#" since the desire is to remove the target entirely. 74 $link = sprintf( 75 '<button class="menu-item-link-return" tabindex="-1">%s', 76 twentynineteen_get_icon_svg( 'chevron_left', 24 ) 77 ); 78 79 // replace opening <a> with <button> 80 $output = preg_replace( 81 '/<a\s.*?>/', 82 $link, 83 $output, 84 1 // Limit. 85 ); 86 87 // replace closing </a> with </button> 88 $output = preg_replace( 89 '#</a>#i', 90 '</button>', 91 $output, 92 1 // Limit. 93 ); 94 95 } elseif ( in_array( 'menu-item-has-children', $item->classes, true ) ) { 96 97 // Add SVG icon to parent items. 98 $icon = twentynineteen_get_icon_svg( 'keyboard_arrow_down', 24 ); 99 100 $output .= sprintf( 101 '<button class="submenu-expand" tabindex="-1">%s</button>', 102 $icon 103 ); 104 } 105 106 return $output; 107 } 108 add_filter( 'walker_nav_menu_start_el', 'twentynineteen_add_dropdown_icons', 10, 4 ); -
src/wp-content/themes/twentynineteen/inc/template-functions.php
diff --git a/src/wp-content/themes/twentynineteen/inc/template-functions.php b/src/wp-content/themes/twentynineteen/inc/template-functions.php index 6a38224e65..96308595f0 100644
a b function twentynineteen_get_the_archive_title() { 95 95 } 96 96 add_filter( 'get_the_archive_title', 'twentynineteen_get_the_archive_title' ); 97 97 98 /**99 * Determines if post thumbnail can be displayed.100 */101 function twentynineteen_can_show_post_thumbnail() {102 return apply_filters( 'twentynineteen_can_show_post_thumbnail', ! post_password_required() && ! is_attachment() && has_post_thumbnail() );103 }104 105 /**106 * Returns true if image filters are enabled on the theme options.107 */108 function twentynineteen_image_filters_enabled() {109 return 0 !== get_theme_mod( 'image_filter', 1 );110 }111 112 98 /** 113 99 * Add custom sizes attribute to responsive image functionality for post thumbnails. 114 100 * … … function twentynineteen_post_thumbnail_sizes_attr( $attr ) { 131 117 } 132 118 add_filter( 'wp_get_attachment_image_attributes', 'twentynineteen_post_thumbnail_sizes_attr', 10, 1 ); 133 119 134 /**135 * Returns the size for avatars used in the theme.136 */137 function twentynineteen_get_avatar_size() {138 return 60;139 }140 141 /**142 * Returns true if comment is by author of the post.143 *144 * @see get_comment_class()145 */146 function twentynineteen_is_comment_by_post_author( $comment = null ) {147 if ( is_object( $comment ) && $comment->user_id > 0 ) {148 $user = get_userdata( $comment->user_id );149 $post = get_post( $comment->comment_post_ID );150 if ( ! empty( $user ) && ! empty( $post ) ) {151 return $comment->user_id === $post->post_author;152 }153 }154 return false;155 }156 157 /**158 * Returns information about the current post's discussion, with cache support.159 */160 function twentynineteen_get_discussion_data() {161 static $discussion, $post_id;162 163 $current_post_id = get_the_ID();164 if ( $current_post_id === $post_id ) {165 return $discussion; /* If we have discussion information for post ID, return cached object */166 } else {167 $post_id = $current_post_id;168 }169 170 $comments = get_comments(171 array(172 'post_id' => $current_post_id,173 'orderby' => 'comment_date_gmt',174 'order' => get_option( 'comment_order', 'asc' ), /* Respect comment order from Settings » Discussion. */175 'status' => 'approve',176 'number' => 20, /* Only retrieve the last 20 comments, as the end goal is just 6 unique authors */177 )178 );179 180 $authors = array();181 foreach ( $comments as $comment ) {182 $authors[] = ( (int) $comment->user_id > 0 ) ? (int) $comment->user_id : $comment->comment_author_email;183 }184 185 $authors = array_unique( $authors );186 $discussion = (object) array(187 'authors' => array_slice( $authors, 0, 6 ), /* Six unique authors commenting on the post. */188 'responses' => get_comments_number( $current_post_id ), /* Number of responses. */189 );190 191 return $discussion;192 }193 194 120 /** 195 121 * Add an extra menu to our nav for our priority+ navigation to use 196 122 * … … function twentynineteen_add_mobile_parent_nav_menu_items( $sorted_menu_items, $a 339 265 return $amended_menu_items; 340 266 } 341 267 add_filter( 'wp_nav_menu_objects', 'twentynineteen_add_mobile_parent_nav_menu_items', 10, 2 ); 342 343 /**344 * Convert HSL to HEX colors345 */346 function twentynineteen_hsl_hex( $h, $s, $l, $to_hex = true ) {347 348 $h /= 360;349 $s /= 100;350 $l /= 100;351 352 $r = $l;353 $g = $l;354 $b = $l;355 $v = ( $l <= 0.5 ) ? ( $l * ( 1.0 + $s ) ) : ( $l + $s - $l * $s );356 if ( $v > 0 ) {357 $m;358 $sv;359 $sextant;360 $fract;361 $vsf;362 $mid1;363 $mid2;364 365 $m = $l + $l - $v;366 $sv = ( $v - $m ) / $v;367 $h *= 6.0;368 $sextant = floor( $h );369 $fract = $h - $sextant;370 $vsf = $v * $sv * $fract;371 $mid1 = $m + $vsf;372 $mid2 = $v - $vsf;373 374 switch ( $sextant ) {375 case 0:376 $r = $v;377 $g = $mid1;378 $b = $m;379 break;380 case 1:381 $r = $mid2;382 $g = $v;383 $b = $m;384 break;385 case 2:386 $r = $m;387 $g = $v;388 $b = $mid1;389 break;390 case 3:391 $r = $m;392 $g = $mid2;393 $b = $v;394 break;395 case 4:396 $r = $mid1;397 $g = $m;398 $b = $v;399 break;400 case 5:401 $r = $v;402 $g = $m;403 $b = $mid2;404 break;405 }406 }407 $r = round( $r * 255, 0 );408 $g = round( $g * 255, 0 );409 $b = round( $b * 255, 0 );410 411 if ( $to_hex ) {412 413 $r = ( $r < 15 ) ? '0' . dechex( $r ) : dechex( $r );414 $g = ( $g < 15 ) ? '0' . dechex( $g ) : dechex( $g );415 $b = ( $b < 15 ) ? '0' . dechex( $b ) : dechex( $b );416 417 return "#$r$g$b";418 419 }420 421 return "rgb($r, $g, $b)";422 } -
new file src/wp-content/themes/twentynineteen/inc/helper-functions.php
diff --git a/src/wp-content/themes/twentynineteen/inc/helper-functions.php b/src/wp-content/themes/twentynineteen/inc/helper-functions.php new file mode 100644 index 0000000000..12e1f94c0b
- + 1 <?php 2 3 /** 4 * Common Functions for Theme. 5 * 6 * @package WordPress 7 * @subpackage Twenty_Nineteen 8 * @since 9 */ 10 11 /** 12 * Determines if post thumbnail can be displayed. 13 */ 14 function twentynineteen_can_show_post_thumbnail() { 15 return apply_filters( 'twentynineteen_can_show_post_thumbnail', ! post_password_required() && ! is_attachment() && has_post_thumbnail() ); 16 } 17 18 /** 19 * Returns true if image filters are enabled on the theme options. 20 */ 21 function twentynineteen_image_filters_enabled() { 22 return 0 !== get_theme_mod( 'image_filter', 1 ); 23 } 24 25 /** 26 * Returns the size for avatars used in the theme. 27 */ 28 function twentynineteen_get_avatar_size() { 29 return 60; 30 } 31 32 33 /** 34 * Returns true if comment is by author of the post. 35 * 36 * @see get_comment_class() 37 */ 38 function twentynineteen_is_comment_by_post_author( $comment = null ) { 39 if ( is_object( $comment ) && $comment->user_id > 0 ) { 40 $user = get_userdata( $comment->user_id ); 41 $post = get_post( $comment->comment_post_ID ); 42 if ( ! empty( $user ) && ! empty( $post ) ) { 43 return $comment->user_id === $post->post_author; 44 } 45 } 46 return false; 47 } 48 49 /** 50 * Returns information about the current post's discussion, with cache support. 51 */ 52 function twentynineteen_get_discussion_data() { 53 static $discussion, $post_id; 54 55 $current_post_id = get_the_ID(); 56 if ( $current_post_id === $post_id ) { 57 return $discussion; /* If we have discussion information for post ID, return cached object */ 58 } else { 59 $post_id = $current_post_id; 60 } 61 62 $comments = get_comments( 63 array( 64 'post_id' => $current_post_id, 65 'orderby' => 'comment_date_gmt', 66 'order' => get_option( 'comment_order', 'asc' ), /* Respect comment order from Settings » Discussion. */ 67 'status' => 'approve', 68 'number' => 20, /* Only retrieve the last 20 comments, as the end goal is just 6 unique authors */ 69 ) 70 ); 71 72 $authors = array(); 73 foreach ( $comments as $comment ) { 74 $authors[] = ( (int) $comment->user_id > 0 ) ? (int) $comment->user_id : $comment->comment_author_email; 75 } 76 77 $authors = array_unique( $authors ); 78 $discussion = (object) array( 79 'authors' => array_slice( $authors, 0, 6 ), /* Six unique authors commenting on the post. */ 80 'responses' => get_comments_number( $current_post_id ), /* Number of responses. */ 81 ); 82 83 return $discussion; 84 } 85 86 /** 87 * Convert HSL to HEX colors 88 */ 89 function twentynineteen_hsl_hex( $h, $s, $l, $to_hex = true ) { 90 91 $h /= 360; 92 $s /= 100; 93 $l /= 100; 94 95 $r = $l; 96 $g = $l; 97 $b = $l; 98 $v = ( $l <= 0.5 ) ? ( $l * ( 1.0 + $s ) ) : ( $l + $s - $l * $s ); 99 if ( $v > 0 ) { 100 $m; 101 $sv; 102 $sextant; 103 $fract; 104 $vsf; 105 $mid1; 106 $mid2; 107 108 $m = $l + $l - $v; 109 $sv = ( $v - $m ) / $v; 110 $h *= 6.0; 111 $sextant = floor( $h ); 112 $fract = $h - $sextant; 113 $vsf = $v * $sv * $fract; 114 $mid1 = $m + $vsf; 115 $mid2 = $v - $vsf; 116 117 switch ( $sextant ) { 118 case 0: 119 $r = $v; 120 $g = $mid1; 121 $b = $m; 122 break; 123 case 1: 124 $r = $mid2; 125 $g = $v; 126 $b = $m; 127 break; 128 case 2: 129 $r = $m; 130 $g = $v; 131 $b = $mid1; 132 break; 133 case 3: 134 $r = $m; 135 $g = $mid2; 136 $b = $v; 137 break; 138 case 4: 139 $r = $mid1; 140 $g = $m; 141 $b = $v; 142 break; 143 case 5: 144 $r = $v; 145 $g = $m; 146 $b = $mid2; 147 break; 148 } 149 } 150 $r = round( $r * 255, 0 ); 151 $g = round( $g * 255, 0 ); 152 $b = round( $b * 255, 0 ); 153 154 if ( $to_hex ) { 155 156 $r = ( $r < 15 ) ? '0' . dechex( $r ) : dechex( $r ); 157 $g = ( $g < 15 ) ? '0' . dechex( $g ) : dechex( $g ); 158 $b = ( $b < 15 ) ? '0' . dechex( $b ) : dechex( $b ); 159 160 return "#$r$g$b"; 161 162 } 163 164 return "rgb($r, $g, $b)"; 165 }