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