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