| [ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Common theme functions 4 * 5 * @package WordPress 6 * @subpackage Twenty_Nineteen 7 * @since Twenty Nineteen 1.5 8 */ 9 10 /** 11 * Determines if post thumbnail can be displayed. 12 */ 13 function twentynineteen_can_show_post_thumbnail() { 14 $show_post_thumbnail = ! post_password_required() && ! is_attachment() && has_post_thumbnail(); 15 16 /** 17 * Filters whether to show post thumbnail. 18 * 19 * @since Twenty Nineteen 1.0 20 * 21 * @param bool $show_post_thumbnail Whether to show post thumbnail. 22 */ 23 return apply_filters( 'twentynineteen_can_show_post_thumbnail', $show_post_thumbnail ); 24 } 25 26 /** 27 * Returns true if image filters are enabled on the theme options. 28 */ 29 function twentynineteen_image_filters_enabled() { 30 return 0 !== get_theme_mod( 'image_filter', 1 ); 31 } 32 33 /** 34 * Returns the size for avatars used in the theme. 35 */ 36 function twentynineteen_get_avatar_size() { 37 return 60; 38 } 39 40 /** 41 * Returns true if comment is by author of the post. 42 * 43 * @see get_comment_class() 44 * 45 * @param WP_Comment|null $comment The comment object to check. Defaults to the current comment. 46 * @return bool True if the comment is by the author of the post, false otherwise. 47 */ 48 function twentynineteen_is_comment_by_post_author( $comment = null ) { 49 if ( is_object( $comment ) && $comment->user_id > 0 ) { 50 $user = get_userdata( $comment->user_id ); 51 $post = get_post( $comment->comment_post_ID ); 52 if ( ! empty( $user ) && ! empty( $post ) ) { 53 return $comment->user_id === $post->post_author; 54 } 55 } 56 return false; 57 } 58 59 /** 60 * Returns information about the current post's discussion, with cache support. 61 */ 62 function twentynineteen_get_discussion_data() { 63 static $discussion, $post_id; 64 65 $current_post_id = get_the_ID(); 66 if ( $current_post_id === $post_id ) { 67 return $discussion; /* If we have discussion information for post ID, return cached object */ 68 } else { 69 $post_id = $current_post_id; 70 } 71 72 $comments = get_comments( 73 array( 74 'post_id' => $current_post_id, 75 'orderby' => 'comment_date_gmt', 76 'order' => get_option( 'comment_order', 'asc' ), /* Respect comment order from Settings ยป Discussion. */ 77 'status' => 'approve', 78 'number' => 20, /* Only retrieve the last 20 comments, as the end goal is just 6 unique authors */ 79 ) 80 ); 81 82 $authors = array(); 83 foreach ( $comments as $comment ) { 84 $authors[] = ( (int) $comment->user_id > 0 ) ? (int) $comment->user_id : $comment->comment_author_email; 85 } 86 87 $authors = array_unique( $authors ); 88 $discussion = (object) array( 89 'authors' => array_slice( $authors, 0, 6 ), /* Six unique authors commenting on the post. */ 90 'responses' => get_comments_number( $current_post_id ), /* Number of responses. */ 91 ); 92 93 return $discussion; 94 } 95 96 /** 97 * Converts HSL to HEX or RGB colors. 98 * 99 * @param float $h The hue component (0-360). 100 * @param float $s The saturation component (0-100). 101 * @param float $l The lightness component (0-100). 102 * @param bool $to_hex Whether to convert to HEX format (true) or RGB (false). Default true. 103 */ 104 function twentynineteen_hsl_hex( $h, $s, $l, $to_hex = true ) { 105 106 $h /= 360; 107 $s /= 100; 108 $l /= 100; 109 110 $r = $l; 111 $g = $l; 112 $b = $l; 113 $v = ( $l <= 0.5 ) ? ( $l * ( 1.0 + $s ) ) : ( $l + $s - $l * $s ); 114 115 if ( $v > 0 ) { 116 $m = $l + $l - $v; 117 $sv = ( $v - $m ) / $v; 118 $h *= 6.0; 119 $sextant = floor( $h ); 120 $fract = $h - $sextant; 121 $vsf = $v * $sv * $fract; 122 $mid1 = $m + $vsf; 123 $mid2 = $v - $vsf; 124 125 switch ( $sextant ) { 126 case 0: 127 $r = $v; 128 $g = $mid1; 129 $b = $m; 130 break; 131 case 1: 132 $r = $mid2; 133 $g = $v; 134 $b = $m; 135 break; 136 case 2: 137 $r = $m; 138 $g = $v; 139 $b = $mid1; 140 break; 141 case 3: 142 $r = $m; 143 $g = $mid2; 144 $b = $v; 145 break; 146 case 4: 147 $r = $mid1; 148 $g = $m; 149 $b = $v; 150 break; 151 case 5: 152 $r = $v; 153 $g = $m; 154 $b = $mid2; 155 break; 156 } 157 } 158 159 $r = round( $r * 255, 0 ); 160 $g = round( $g * 255, 0 ); 161 $b = round( $b * 255, 0 ); 162 163 if ( $to_hex ) { 164 165 $r = ( $r < 15 ) ? '0' . dechex( $r ) : dechex( $r ); 166 $g = ( $g < 15 ) ? '0' . dechex( $g ) : dechex( $g ); 167 $b = ( $b < 15 ) ? '0' . dechex( $b ) : dechex( $b ); 168 169 return "#$r$g$b"; 170 171 } 172 173 return "rgb($r, $g, $b)"; 174 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated : Thu Jul 2 08:20:12 2026 | Cross-referenced by PHPXref |