From 762140cc6b1ce46cd8c6833fc21ff32457adbc13 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 10 Feb 2020 19:07:06 +0000 Subject: [PATCH] Twenty Nineteen: Add the missing `inc/helper-functions.php` file. Follow-up to [47214]. Props kjellr, jffng. Fixes #45984. Built from https://develop.svn.wordpress.org/trunk@47242 git-svn-id: http://core.svn.wordpress.org/trunk@47042 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../twentynineteen/inc/helper-functions.php | 163 ++++++++++++++++++ wp-includes/version.php | 2 +- 2 files changed, 164 insertions(+), 1 deletion(-) create mode 100644 wp-content/themes/twentynineteen/inc/helper-functions.php diff --git a/wp-content/themes/twentynineteen/inc/helper-functions.php b/wp-content/themes/twentynineteen/inc/helper-functions.php new file mode 100644 index 0000000000..bea7099718 --- /dev/null +++ b/wp-content/themes/twentynineteen/inc/helper-functions.php @@ -0,0 +1,163 @@ +user_id > 0 ) { + $user = get_userdata( $comment->user_id ); + $post = get_post( $comment->comment_post_ID ); + if ( ! empty( $user ) && ! empty( $post ) ) { + return $comment->user_id === $post->post_author; + } + } + return false; +} + +/** + * Returns information about the current post's discussion, with cache support. + */ +function twentynineteen_get_discussion_data() { + static $discussion, $post_id; + + $current_post_id = get_the_ID(); + if ( $current_post_id === $post_id ) { + return $discussion; /* If we have discussion information for post ID, return cached object */ + } else { + $post_id = $current_post_id; + } + + $comments = get_comments( + array( + 'post_id' => $current_post_id, + 'orderby' => 'comment_date_gmt', + 'order' => get_option( 'comment_order', 'asc' ), /* Respect comment order from Settings ยป Discussion. */ + 'status' => 'approve', + 'number' => 20, /* Only retrieve the last 20 comments, as the end goal is just 6 unique authors */ + ) + ); + + $authors = array(); + foreach ( $comments as $comment ) { + $authors[] = ( (int) $comment->user_id > 0 ) ? (int) $comment->user_id : $comment->comment_author_email; + } + + $authors = array_unique( $authors ); + $discussion = (object) array( + 'authors' => array_slice( $authors, 0, 6 ), /* Six unique authors commenting on the post. */ + 'responses' => get_comments_number( $current_post_id ), /* Number of responses. */ + ); + + return $discussion; +} + +/** + * Converts HSL to HEX colors. + */ +function twentynineteen_hsl_hex( $h, $s, $l, $to_hex = true ) { + + $h /= 360; + $s /= 100; + $l /= 100; + + $r = $l; + $g = $l; + $b = $l; + $v = ( $l <= 0.5 ) ? ( $l * ( 1.0 + $s ) ) : ( $l + $s - $l * $s ); + if ( $v > 0 ) { + $m; + $sv; + $sextant; + $fract; + $vsf; + $mid1; + $mid2; + + $m = $l + $l - $v; + $sv = ( $v - $m ) / $v; + $h *= 6.0; + $sextant = floor( $h ); + $fract = $h - $sextant; + $vsf = $v * $sv * $fract; + $mid1 = $m + $vsf; + $mid2 = $v - $vsf; + + switch ( $sextant ) { + case 0: + $r = $v; + $g = $mid1; + $b = $m; + break; + case 1: + $r = $mid2; + $g = $v; + $b = $m; + break; + case 2: + $r = $m; + $g = $v; + $b = $mid1; + break; + case 3: + $r = $m; + $g = $mid2; + $b = $v; + break; + case 4: + $r = $mid1; + $g = $m; + $b = $v; + break; + case 5: + $r = $v; + $g = $m; + $b = $mid2; + break; + } + } + $r = round( $r * 255, 0 ); + $g = round( $g * 255, 0 ); + $b = round( $b * 255, 0 ); + + if ( $to_hex ) { + + $r = ( $r < 15 ) ? '0' . dechex( $r ) : dechex( $r ); + $g = ( $g < 15 ) ? '0' . dechex( $g ) : dechex( $g ); + $b = ( $b < 15 ) ? '0' . dechex( $b ) : dechex( $b ); + + return "#$r$g$b"; + + } + + return "rgb($r, $g, $b)"; +} diff --git a/wp-includes/version.php b/wp-includes/version.php index a180f7d158..8958bcfe82 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.4-alpha-47241'; +$wp_version = '5.4-alpha-47242'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.