diff -r c7c34916027a -r 177826044cd9 wp/wp-includes/link-template.php --- a/wp/wp-includes/link-template.php Mon Oct 14 18:06:33 2019 +0200 +++ b/wp/wp-includes/link-template.php Mon Oct 14 18:28:13 2019 +0200 @@ -44,12 +44,13 @@ * for use in the filter. Default empty string. * @return string The URL with the trailing slash appended or stripped. */ -function user_trailingslashit($string, $type_of_url = '') { +function user_trailingslashit( $string, $type_of_url = '' ) { global $wp_rewrite; - if ( $wp_rewrite->use_trailing_slashes ) - $string = trailingslashit($string); - else - $string = untrailingslashit($string); + if ( $wp_rewrite->use_trailing_slashes ) { + $string = trailingslashit( $string ); + } else { + $string = untrailingslashit( $string ); + } /** * Filters the trailing-slashed string, depending on whether the site is set to use trailing slashes. @@ -79,7 +80,7 @@ switch ( strtolower( $mode ) ) { case 'title': $title = sanitize_title( $post->post_title ) . '-' . $post->ID; - echo ''; + echo ''; break; case 'id': default: @@ -123,31 +124,33 @@ '%hour%', '%minute%', '%second%', - $leavename? '' : '%postname%', + $leavename ? '' : '%postname%', '%post_id%', '%category%', '%author%', - $leavename? '' : '%pagename%', + $leavename ? '' : '%pagename%', ); if ( is_object( $post ) && isset( $post->filter ) && 'sample' == $post->filter ) { $sample = true; } else { - $post = get_post( $post ); + $post = get_post( $post ); $sample = false; } - if ( empty($post->ID) ) + if ( empty( $post->ID ) ) { return false; - - if ( $post->post_type == 'page' ) - return get_page_link($post, $leavename, $sample); - elseif ( $post->post_type == 'attachment' ) + } + + if ( $post->post_type == 'page' ) { + return get_page_link( $post, $leavename, $sample ); + } elseif ( $post->post_type == 'attachment' ) { return get_attachment_link( $post, $leavename ); - elseif ( in_array($post->post_type, get_post_types( array('_builtin' => false) ) ) ) - return get_post_permalink($post, $leavename, $sample); - - $permalink = get_option('permalink_structure'); + } elseif ( in_array( $post->post_type, get_post_types( array( '_builtin' => false ) ) ) ) { + return get_post_permalink( $post, $leavename, $sample ); + } + + $permalink = get_option( 'permalink_structure' ); /** * Filters the permalink structure for a post before token replacement occurs. @@ -162,16 +165,19 @@ */ $permalink = apply_filters( 'pre_post_link', $permalink, $post, $leavename ); - if ( '' != $permalink && !in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft', 'future' ) ) ) { - $unixtime = strtotime($post->post_date); + if ( '' != $permalink && ! in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft', 'future' ) ) ) { + $unixtime = strtotime( $post->post_date ); $category = ''; - if ( strpos($permalink, '%category%') !== false ) { - $cats = get_the_category($post->ID); + if ( strpos( $permalink, '%category%' ) !== false ) { + $cats = get_the_category( $post->ID ); if ( $cats ) { - $cats = wp_list_sort( $cats, array( - 'term_id' => 'ASC', - ) ); + $cats = wp_list_sort( + $cats, + array( + 'term_id' => 'ASC', + ) + ); /** * Filters the category that gets used in the %category% permalink token. @@ -185,13 +191,14 @@ $category_object = apply_filters( 'post_link_category', $cats[0], $cats, $post ); $category_object = get_term( $category_object, 'category' ); - $category = $category_object->slug; - if ( $parent = $category_object->parent ) - $category = get_category_parents($parent, false, '/', true) . $category; + $category = $category_object->slug; + if ( $category_object->parent ) { + $category = get_category_parents( $category_object->parent, false, '/', true ) . $category; + } } // show default category in permalinks, without // having to assign it explicitly - if ( empty($category) ) { + if ( empty( $category ) ) { $default_category = get_term( get_option( 'default_category' ), 'category' ); if ( $default_category && ! is_wp_error( $default_category ) ) { $category = $default_category->slug; @@ -200,12 +207,12 @@ } $author = ''; - if ( strpos($permalink, '%author%') !== false ) { - $authordata = get_userdata($post->post_author); - $author = $authordata->user_nicename; + if ( strpos( $permalink, '%author%' ) !== false ) { + $authordata = get_userdata( $post->post_author ); + $author = $authordata->user_nicename; } - $date = explode(" ",date('Y m d H i s', $unixtime)); + $date = explode( ' ', date( 'Y m d H i s', $unixtime ) ); $rewritereplace = array( $date[0], @@ -220,10 +227,10 @@ $author, $post->post_name, ); - $permalink = home_url( str_replace($rewritecode, $rewritereplace, $permalink) ); - $permalink = user_trailingslashit($permalink, 'single'); + $permalink = home_url( str_replace( $rewritecode, $rewritereplace, $permalink ) ); + $permalink = user_trailingslashit( $permalink, 'single' ); } else { // if they're not using the fancy permalink option - $permalink = home_url('?p=' . $post->ID); + $permalink = home_url( '?p=' . $post->ID ); } /** @@ -255,34 +262,42 @@ function get_post_permalink( $id = 0, $leavename = false, $sample = false ) { global $wp_rewrite; - $post = get_post($id); - - if ( is_wp_error( $post ) ) + $post = get_post( $id ); + + if ( is_wp_error( $post ) ) { return $post; - - $post_link = $wp_rewrite->get_extra_permastruct($post->post_type); + } + + $post_link = $wp_rewrite->get_extra_permastruct( $post->post_type ); $slug = $post->post_name; $draft_or_pending = get_post_status( $post ) && in_array( get_post_status( $post ), array( 'draft', 'pending', 'auto-draft', 'future' ) ); - $post_type = get_post_type_object($post->post_type); + $post_type = get_post_type_object( $post->post_type ); if ( $post_type->hierarchical ) { $slug = get_page_uri( $post ); } - if ( !empty($post_link) && ( !$draft_or_pending || $sample ) ) { + if ( ! empty( $post_link ) && ( ! $draft_or_pending || $sample ) ) { if ( ! $leavename ) { - $post_link = str_replace("%$post->post_type%", $slug, $post_link); + $post_link = str_replace( "%$post->post_type%", $slug, $post_link ); } - $post_link = home_url( user_trailingslashit($post_link) ); + $post_link = home_url( user_trailingslashit( $post_link ) ); } else { - if ( $post_type->query_var && ( isset($post->post_status) && !$draft_or_pending ) ) - $post_link = add_query_arg($post_type->query_var, $slug, ''); - else - $post_link = add_query_arg(array('post_type' => $post->post_type, 'p' => $post->ID), ''); - $post_link = home_url($post_link); + if ( $post_type->query_var && ( isset( $post->post_status ) && ! $draft_or_pending ) ) { + $post_link = add_query_arg( $post_type->query_var, $slug, '' ); + } else { + $post_link = add_query_arg( + array( + 'post_type' => $post->post_type, + 'p' => $post->ID, + ), + '' + ); + } + $post_link = home_url( $post_link ); } /** @@ -314,10 +329,11 @@ function get_page_link( $post = false, $leavename = false, $sample = false ) { $post = get_post( $post ); - if ( 'page' == get_option( 'show_on_front' ) && $post->ID == get_option( 'page_on_front' ) ) - $link = home_url('/'); - else + if ( 'page' == get_option( 'show_on_front' ) && $post->ID == get_option( 'page_on_front' ) ) { + $link = home_url( '/' ); + } else { $link = _get_page_link( $post, $leavename, $sample ); + } /** * Filters the permalink for a page. @@ -356,13 +372,13 @@ $link = $wp_rewrite->get_page_permastruct(); - if ( !empty($link) && ( ( isset($post->post_status) && !$draft_or_pending ) || $sample ) ) { + if ( ! empty( $link ) && ( ( isset( $post->post_status ) && ! $draft_or_pending ) || $sample ) ) { if ( ! $leavename ) { - $link = str_replace('%pagename%', get_page_uri( $post ), $link); + $link = str_replace( '%pagename%', get_page_uri( $post ), $link ); } - $link = home_url($link); - $link = user_trailingslashit($link, 'page'); + $link = home_url( $link ); + $link = user_trailingslashit( $link, 'page' ); } else { $link = home_url( '?page_id=' . $post->ID ); } @@ -396,34 +412,39 @@ $link = false; - $post = get_post( $post ); + $post = get_post( $post ); $parent = ( $post->post_parent > 0 && $post->post_parent != $post->ID ) ? get_post( $post->post_parent ) : false; if ( $parent && ! in_array( $parent->post_type, get_post_types() ) ) { $parent = false; } if ( $wp_rewrite->using_permalinks() && $parent ) { - if ( 'page' == $parent->post_type ) + if ( 'page' == $parent->post_type ) { $parentlink = _get_page_link( $post->post_parent ); // Ignores page_on_front - else + } else { $parentlink = get_permalink( $post->post_parent ); - - if ( is_numeric($post->post_name) || false !== strpos(get_option('permalink_structure'), '%category%') ) + } + + if ( is_numeric( $post->post_name ) || false !== strpos( get_option( 'permalink_structure' ), '%category%' ) ) { $name = 'attachment/' . $post->post_name; // // is paged so we use the explicit attachment marker - else + } else { $name = $post->post_name; - - if ( strpos($parentlink, '?') === false ) - $link = user_trailingslashit( trailingslashit($parentlink) . '%postname%' ); - - if ( ! $leavename ) + } + + if ( strpos( $parentlink, '?' ) === false ) { + $link = user_trailingslashit( trailingslashit( $parentlink ) . '%postname%' ); + } + + if ( ! $leavename ) { $link = str_replace( '%postname%', $name, $link ); + } } elseif ( $wp_rewrite->using_permalinks() && ! $leavename ) { $link = home_url( user_trailingslashit( $post->post_name ) ); } - if ( ! $link ) + if ( ! $link ) { $link = home_url( '/?attachment_id=' . $post->ID ); + } /** * Filters the permalink for an attachment. @@ -448,11 +469,12 @@ */ function get_year_link( $year ) { global $wp_rewrite; - if ( !$year ) - $year = gmdate('Y', current_time('timestamp')); + if ( ! $year ) { + $year = current_time( 'Y' ); + } $yearlink = $wp_rewrite->get_year_permastruct(); - if ( !empty($yearlink) ) { - $yearlink = str_replace('%year%', $year, $yearlink); + if ( ! empty( $yearlink ) ) { + $yearlink = str_replace( '%year%', $year, $yearlink ); $yearlink = home_url( user_trailingslashit( $yearlink, 'year' ) ); } else { $yearlink = home_url( '?m=' . $year ); @@ -480,16 +502,18 @@ * @param bool|int $month False for current month. Integer of month. * @return string The permalink for the specified month and year archive. */ -function get_month_link($year, $month) { +function get_month_link( $year, $month ) { global $wp_rewrite; - if ( !$year ) - $year = gmdate('Y', current_time('timestamp')); - if ( !$month ) - $month = gmdate('m', current_time('timestamp')); + if ( ! $year ) { + $year = current_time( 'Y' ); + } + if ( ! $month ) { + $month = current_time( 'm' ); + } $monthlink = $wp_rewrite->get_month_permastruct(); - if ( !empty($monthlink) ) { - $monthlink = str_replace('%year%', $year, $monthlink); - $monthlink = str_replace('%monthnum%', zeroise(intval($month), 2), $monthlink); + if ( ! empty( $monthlink ) ) { + $monthlink = str_replace( '%year%', $year, $monthlink ); + $monthlink = str_replace( '%monthnum%', zeroise( intval( $month ), 2 ), $monthlink ); $monthlink = home_url( user_trailingslashit( $monthlink, 'month' ) ); } else { $monthlink = home_url( '?m=' . $year . zeroise( $month, 2 ) ); @@ -519,20 +543,23 @@ * @param bool|int $day False for current day. Integer of day. * @return string The permalink for the specified day, month, and year archive. */ -function get_day_link($year, $month, $day) { +function get_day_link( $year, $month, $day ) { global $wp_rewrite; - if ( !$year ) - $year = gmdate('Y', current_time('timestamp')); - if ( !$month ) - $month = gmdate('m', current_time('timestamp')); - if ( !$day ) - $day = gmdate('j', current_time('timestamp')); + if ( ! $year ) { + $year = current_time( 'Y' ); + } + if ( ! $month ) { + $month = current_time( 'm' ); + } + if ( ! $day ) { + $day = current_time( 'j' ); + } $daylink = $wp_rewrite->get_day_permastruct(); - if ( !empty($daylink) ) { - $daylink = str_replace('%year%', $year, $daylink); - $daylink = str_replace('%monthnum%', zeroise(intval($month), 2), $daylink); - $daylink = str_replace('%day%', zeroise(intval($day), 2), $daylink); + if ( ! empty( $daylink ) ) { + $daylink = str_replace( '%year%', $year, $daylink ); + $daylink = str_replace( '%monthnum%', zeroise( intval( $month ), 2 ), $daylink ); + $daylink = str_replace( '%day%', zeroise( intval( $day ), 2 ), $daylink ); $daylink = home_url( user_trailingslashit( $daylink, 'day' ) ); } else { $daylink = home_url( '?m=' . $year . zeroise( $month, 2 ) . zeroise( $day, 2 ) ); @@ -589,25 +616,28 @@ $permalink = $wp_rewrite->get_feed_permastruct(); if ( '' != $permalink ) { - if ( false !== strpos($feed, 'comments_') ) { - $feed = str_replace('comments_', '', $feed); + if ( false !== strpos( $feed, 'comments_' ) ) { + $feed = str_replace( 'comments_', '', $feed ); $permalink = $wp_rewrite->get_comment_feed_permastruct(); } - if ( get_default_feed() == $feed ) + if ( get_default_feed() == $feed ) { $feed = ''; - - $permalink = str_replace('%feed%', $feed, $permalink); - $permalink = preg_replace('#/+#', '/', "/$permalink"); - $output = home_url( user_trailingslashit($permalink, 'feed') ); + } + + $permalink = str_replace( '%feed%', $feed, $permalink ); + $permalink = preg_replace( '#/+#', '/', "/$permalink" ); + $output = home_url( user_trailingslashit( $permalink, 'feed' ) ); } else { - if ( empty($feed) ) + if ( empty( $feed ) ) { $feed = get_default_feed(); - - if ( false !== strpos($feed, 'comments_') ) - $feed = str_replace('comments_', 'comments-', $feed); - - $output = home_url("?feed={$feed}"); + } + + if ( false !== strpos( $feed, 'comments_' ) ) { + $feed = str_replace( 'comments_', 'comments-', $feed ); + } + + $output = home_url( "?feed={$feed}" ); } /** @@ -633,40 +663,62 @@ function get_post_comments_feed_link( $post_id = 0, $feed = '' ) { $post_id = absint( $post_id ); - if ( ! $post_id ) + if ( ! $post_id ) { $post_id = get_the_ID(); - - if ( empty( $feed ) ) + } + + if ( empty( $feed ) ) { $feed = get_default_feed(); - - $post = get_post( $post_id ); + } + + $post = get_post( $post_id ); $unattached = 'attachment' === $post->post_type && 0 === (int) $post->post_parent; - if ( '' != get_option('permalink_structure') ) { - if ( 'page' == get_option('show_on_front') && $post_id == get_option('page_on_front') ) + if ( '' != get_option( 'permalink_structure' ) ) { + if ( 'page' == get_option( 'show_on_front' ) && $post_id == get_option( 'page_on_front' ) ) { $url = _get_page_link( $post_id ); - else - $url = get_permalink($post_id); + } else { + $url = get_permalink( $post_id ); + } if ( $unattached ) { - $url = home_url( '/feed/' ); + $url = home_url( '/feed/' ); if ( $feed !== get_default_feed() ) { $url .= "$feed/"; } $url = add_query_arg( 'attachment_id', $post_id, $url ); } else { - $url = trailingslashit($url) . 'feed'; - if ( $feed != get_default_feed() ) + $url = trailingslashit( $url ) . 'feed'; + if ( $feed != get_default_feed() ) { $url .= "/$feed"; - $url = user_trailingslashit($url, 'single_feed'); + } + $url = user_trailingslashit( $url, 'single_feed' ); } } else { if ( $unattached ) { - $url = add_query_arg( array( 'feed' => $feed, 'attachment_id' => $post_id ), home_url( '/' ) ); + $url = add_query_arg( + array( + 'feed' => $feed, + 'attachment_id' => $post_id, + ), + home_url( '/' ) + ); } elseif ( 'page' == $post->post_type ) { - $url = add_query_arg( array( 'feed' => $feed, 'page_id' => $post_id ), home_url( '/' ) ); + $url = add_query_arg( + array( + 'feed' => $feed, + 'page_id' => $post_id, + ), + home_url( '/' ) + ); } else { - $url = add_query_arg( array( 'feed' => $feed, 'p' => $post_id ), home_url( '/' ) ); + $url = add_query_arg( + array( + 'feed' => $feed, + 'p' => $post_id, + ), + home_url( '/' ) + ); } } @@ -696,7 +748,7 @@ function post_comments_feed_link( $link_text = '', $post_id = '', $feed = '' ) { $url = get_post_comments_feed_link( $post_id, $feed ); if ( empty( $link_text ) ) { - $link_text = __('Comments Feed'); + $link_text = __( 'Comments Feed' ); } $link = '' . $link_text . ''; @@ -725,22 +777,24 @@ * @return string Link to the feed for the author specified by $author_id. */ function get_author_feed_link( $author_id, $feed = '' ) { - $author_id = (int) $author_id; - $permalink_structure = get_option('permalink_structure'); - - if ( empty($feed) ) + $author_id = (int) $author_id; + $permalink_structure = get_option( 'permalink_structure' ); + + if ( empty( $feed ) ) { $feed = get_default_feed(); + } if ( '' == $permalink_structure ) { - $link = home_url("?feed=$feed&author=" . $author_id); + $link = home_url( "?feed=$feed&author=" . $author_id ); } else { - $link = get_author_posts_url($author_id); - if ( $feed == get_default_feed() ) + $link = get_author_posts_url( $author_id ); + if ( $feed == get_default_feed() ) { $feed_link = 'feed'; - else + } else { $feed_link = "feed/$feed"; - - $link = trailingslashit($link) . user_trailingslashit($feed_link, 'feed'); + } + + $link = trailingslashit( $link ) . user_trailingslashit( $feed_link, 'feed' ); } /** @@ -786,34 +840,36 @@ * @return string|false Link to the feed for the term specified by $term_id and $taxonomy. */ function get_term_feed_link( $term_id, $taxonomy = 'category', $feed = '' ) { - $term_id = ( int ) $term_id; - - $term = get_term( $term_id, $taxonomy ); - - if ( empty( $term ) || is_wp_error( $term ) ) + $term_id = (int) $term_id; + + $term = get_term( $term_id, $taxonomy ); + + if ( empty( $term ) || is_wp_error( $term ) ) { return false; - - if ( empty( $feed ) ) + } + + if ( empty( $feed ) ) { $feed = get_default_feed(); + } $permalink_structure = get_option( 'permalink_structure' ); if ( '' == $permalink_structure ) { if ( 'category' == $taxonomy ) { - $link = home_url("?feed=$feed&cat=$term_id"); - } - elseif ( 'post_tag' == $taxonomy ) { - $link = home_url("?feed=$feed&tag=$term->slug"); + $link = home_url( "?feed=$feed&cat=$term_id" ); + } elseif ( 'post_tag' == $taxonomy ) { + $link = home_url( "?feed=$feed&tag=$term->slug" ); } else { - $t = get_taxonomy( $taxonomy ); - $link = home_url("?feed=$feed&$t->query_var=$term->slug"); + $t = get_taxonomy( $taxonomy ); + $link = home_url( "?feed=$feed&$t->query_var=$term->slug" ); } } else { $link = get_term_link( $term_id, $term->taxonomy ); - if ( $feed == get_default_feed() ) + if ( $feed == get_default_feed() ) { $feed_link = 'feed'; - else + } else { $feed_link = "feed/$feed"; + } $link = trailingslashit( $link ) . user_trailingslashit( $feed_link, 'feed' ); } @@ -979,19 +1035,22 @@ * @return string|void HTML content. */ function edit_term_link( $link = '', $before = '', $after = '', $term = null, $echo = true ) { - if ( is_null( $term ) ) + if ( is_null( $term ) ) { $term = get_queried_object(); - - if ( ! $term ) + } + + if ( ! $term ) { return; + } $tax = get_taxonomy( $term->taxonomy ); if ( ! current_user_can( 'edit_term', $term->term_id ) ) { return; } - if ( empty( $link ) ) - $link = __('Edit This'); + if ( empty( $link ) ) { + $link = __( 'Edit This' ); + } $link = '' . $link . ''; @@ -1005,10 +1064,11 @@ */ $link = $before . apply_filters( 'edit_term_link', $link, $term->term_id ) . $after; - if ( $echo ) + if ( $echo ) { echo $link; - else + } else { return $link; + } } /** @@ -1024,20 +1084,21 @@ function get_search_link( $query = '' ) { global $wp_rewrite; - if ( empty($query) ) + if ( empty( $query ) ) { $search = get_search_query( false ); - else - $search = stripslashes($query); + } else { + $search = stripslashes( $query ); + } $permastruct = $wp_rewrite->get_search_permastruct(); if ( empty( $permastruct ) ) { - $link = home_url('?s=' . urlencode($search) ); + $link = home_url( '?s=' . urlencode( $search ) ); } else { - $search = urlencode($search); - $search = str_replace('%2F', '/', $search); // %2F(/) is not valid within a URL, send it un-encoded. - $link = str_replace( '%search%', $search, $permastruct ); - $link = home_url( user_trailingslashit( $link, 'search' ) ); + $search = urlencode( $search ); + $search = str_replace( '%2F', '/', $search ); // %2F(/) is not valid within a URL, send it un-encoded. + $link = str_replace( '%search%', $search, $permastruct ); + $link = home_url( user_trailingslashit( $link, 'search' ) ); } /** @@ -1062,19 +1123,20 @@ * @param string $feed Optional. Feed type. Default empty. * @return string The search results feed permalink. */ -function get_search_feed_link($search_query = '', $feed = '') { +function get_search_feed_link( $search_query = '', $feed = '' ) { global $wp_rewrite; - $link = get_search_link($search_query); - - if ( empty($feed) ) + $link = get_search_link( $search_query ); + + if ( empty( $feed ) ) { $feed = get_default_feed(); + } $permastruct = $wp_rewrite->get_search_permastruct(); - if ( empty($permastruct) ) { - $link = add_query_arg('feed', $feed, $link); + if ( empty( $permastruct ) ) { + $link = add_query_arg( 'feed', $feed, $link ); } else { - $link = trailingslashit($link); + $link = trailingslashit( $link ); $link .= "feed/$feed/"; } @@ -1101,20 +1163,22 @@ * @param string $feed Optional. Feed type. Default empty. * @return string The comments feed search results permalink. */ -function get_search_comments_feed_link($search_query = '', $feed = '') { +function get_search_comments_feed_link( $search_query = '', $feed = '' ) { global $wp_rewrite; - if ( empty($feed) ) + if ( empty( $feed ) ) { $feed = get_default_feed(); - - $link = get_search_feed_link($search_query, $feed); + } + + $link = get_search_feed_link( $search_query, $feed ); $permastruct = $wp_rewrite->get_search_permastruct(); - if ( empty($permastruct) ) - $link = add_query_arg('feed', 'comments-' . $feed, $link); - else - $link = add_query_arg('withcomments', 1, $link); + if ( empty( $permastruct ) ) { + $link = add_query_arg( 'feed', 'comments-' . $feed, $link ); + } else { + $link = add_query_arg( 'withcomments', 1, $link ); + } /** This filter is documented in wp-includes/link-template.php */ return apply_filters( 'search_feed_link', $link, $feed, 'comments' ); @@ -1133,12 +1197,13 @@ */ function get_post_type_archive_link( $post_type ) { global $wp_rewrite; - if ( ! $post_type_obj = get_post_type_object( $post_type ) ) + if ( ! $post_type_obj = get_post_type_object( $post_type ) ) { return false; + } if ( 'post' === $post_type ) { - $show_on_front = get_option( 'show_on_front' ); - $page_for_posts = get_option( 'page_for_posts' ); + $show_on_front = get_option( 'show_on_front' ); + $page_for_posts = get_option( 'page_for_posts' ); if ( 'page' == $show_on_front && $page_for_posts ) { $link = get_permalink( $page_for_posts ); @@ -1149,15 +1214,17 @@ return apply_filters( 'post_type_archive_link', $link, $post_type ); } - if ( ! $post_type_obj->has_archive ) + if ( ! $post_type_obj->has_archive ) { return false; + } if ( get_option( 'permalink_structure' ) && is_array( $post_type_obj->rewrite ) ) { $struct = ( true === $post_type_obj->has_archive ) ? $post_type_obj->rewrite['slug'] : $post_type_obj->has_archive; - if ( $post_type_obj->rewrite['with_front'] ) + if ( $post_type_obj->rewrite['with_front'] ) { $struct = $wp_rewrite->front . $struct; - else + } else { $struct = $wp_rewrite->root . $struct; + } $link = home_url( user_trailingslashit( $struct, 'post_type_archive' ) ); } else { $link = home_url( '?post_type=' . $post_type ); @@ -1185,18 +1252,21 @@ */ function get_post_type_archive_feed_link( $post_type, $feed = '' ) { $default_feed = get_default_feed(); - if ( empty( $feed ) ) + if ( empty( $feed ) ) { $feed = $default_feed; - - if ( ! $link = get_post_type_archive_link( $post_type ) ) + } + + if ( ! $link = get_post_type_archive_link( $post_type ) ) { return false; + } $post_type_obj = get_post_type_object( $post_type ); if ( get_option( 'permalink_structure' ) && is_array( $post_type_obj->rewrite ) && $post_type_obj->rewrite['feeds'] ) { - $link = trailingslashit( $link ); + $link = trailingslashit( $link ); $link .= 'feed/'; - if ( $feed != $default_feed ) + if ( $feed != $default_feed ) { $link .= "$feed/"; + } } else { $link = add_query_arg( 'feed', $feed, $link ); } @@ -1239,7 +1309,7 @@ } $query_args['preview'] = 'true'; - $preview_link = add_query_arg( $query_args, $preview_link ); + $preview_link = add_query_arg( $query_args, $preview_link ); } /** @@ -1268,22 +1338,26 @@ * not allow an editing UI. */ function get_edit_post_link( $id = 0, $context = 'display' ) { - if ( ! $post = get_post( $id ) ) + if ( ! $post = get_post( $id ) ) { return; - - if ( 'revision' === $post->post_type ) + } + + if ( 'revision' === $post->post_type ) { $action = ''; - elseif ( 'display' == $context ) + } elseif ( 'display' == $context ) { $action = '&action=edit'; - else + } else { $action = '&action=edit'; + } $post_type_object = get_post_type_object( $post->post_type ); - if ( !$post_type_object ) + if ( ! $post_type_object ) { return; - - if ( !current_user_can( 'edit_post', $post->ID ) ) + } + + if ( ! current_user_can( 'edit_post', $post->ID ) ) { return; + } if ( $post_type_object->_edit_link ) { $link = admin_url( sprintf( $post_type_object->_edit_link . $action, $post->ID ) ); @@ -1356,20 +1430,24 @@ * @return string|void The delete post link URL for the given post. */ function get_delete_post_link( $id = 0, $deprecated = '', $force_delete = false ) { - if ( ! empty( $deprecated ) ) + if ( ! empty( $deprecated ) ) { _deprecated_argument( __FUNCTION__, '3.0.0' ); - - if ( !$post = get_post( $id ) ) + } + + if ( ! $post = get_post( $id ) ) { return; + } $post_type_object = get_post_type_object( $post->post_type ); - if ( !$post_type_object ) + if ( ! $post_type_object ) { return; - - if ( !current_user_can( 'delete_post', $post->ID ) ) + } + + if ( ! current_user_can( 'delete_post', $post->ID ) ) { return; - - $action = ( $force_delete || !EMPTY_TRASH_DAYS ) ? 'delete' : 'trash'; + } + + $action = ( $force_delete || ! EMPTY_TRASH_DAYS ) ? 'delete' : 'trash'; $delete_link = add_query_arg( 'action', $action, admin_url( sprintf( $post_type_object->_edit_link, $post->ID ) ) ); @@ -1396,10 +1474,11 @@ function get_edit_comment_link( $comment_id = 0 ) { $comment = get_comment( $comment_id ); - if ( !current_user_can( 'edit_comment', $comment->comment_ID ) ) + if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) ) { return; - - $location = admin_url('comment.php?action=editcomment&c=') . $comment->comment_ID; + } + + $location = admin_url( 'comment.php?action=editcomment&c=' ) . $comment->comment_ID; /** * Filters the comment edit link. @@ -1456,10 +1535,11 @@ function get_edit_bookmark_link( $link = 0 ) { $link = get_bookmark( $link ); - if ( !current_user_can('manage_links') ) + if ( ! current_user_can( 'manage_links' ) ) { return; - - $location = admin_url('link.php?action=edit&link_id=') . $link->link_id; + } + + $location = admin_url( 'link.php?action=edit&link_id=' ) . $link->link_id; /** * Filters the bookmark edit link. @@ -1483,13 +1563,15 @@ * @param int $bookmark Optional. Bookmark ID. Default is the current bookmark. */ function edit_bookmark_link( $link = '', $before = '', $after = '', $bookmark = null ) { - $bookmark = get_bookmark($bookmark); - - if ( !current_user_can('manage_links') ) + $bookmark = get_bookmark( $bookmark ); + + if ( ! current_user_can( 'manage_links' ) ) { return; - - if ( empty($link) ) - $link = __('Edit This'); + } + + if ( empty( $link ) ) { + $link = __( 'Edit This' ); + } $link = '' . $link . ''; @@ -1513,21 +1595,25 @@ * @return string URL to edit user page or empty string. */ function get_edit_user_link( $user_id = null ) { - if ( ! $user_id ) + if ( ! $user_id ) { $user_id = get_current_user_id(); - - if ( empty( $user_id ) || ! current_user_can( 'edit_user', $user_id ) ) + } + + if ( empty( $user_id ) || ! current_user_can( 'edit_user', $user_id ) ) { return ''; + } $user = get_userdata( $user_id ); - if ( ! $user ) + if ( ! $user ) { return ''; - - if ( get_current_user_id() == $user->ID ) + } + + if ( get_current_user_id() == $user->ID ) { $link = get_edit_profile_url( $user->ID ); - else + } else { $link = add_query_arg( 'user_id', $user->ID, self_admin_url( 'user-edit.php' ) ); + } /** * Filters the user edit link. @@ -1591,58 +1677,61 @@ function get_adjacent_post( $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) { global $wpdb; - if ( ( ! $post = get_post() ) || ! taxonomy_exists( $taxonomy ) ) + if ( ( ! $post = get_post() ) || ! taxonomy_exists( $taxonomy ) ) { return null; + } $current_post_date = $post->post_date; - $join = ''; - $where = ''; + $join = ''; + $where = ''; $adjacent = $previous ? 'previous' : 'next'; + if ( ! empty( $excluded_terms ) && ! is_array( $excluded_terms ) ) { + // Back-compat, $excluded_terms used to be $excluded_categories with IDs separated by " and ". + if ( false !== strpos( $excluded_terms, ' and ' ) ) { + _deprecated_argument( __FUNCTION__, '3.3.0', sprintf( __( 'Use commas instead of %s to separate excluded terms.' ), "'and'" ) ); + $excluded_terms = explode( ' and ', $excluded_terms ); + } else { + $excluded_terms = explode( ',', $excluded_terms ); + } + + $excluded_terms = array_map( 'intval', $excluded_terms ); + } + + /** + * Filters the IDs of terms excluded from adjacent post queries. + * + * The dynamic portion of the hook name, `$adjacent`, refers to the type + * of adjacency, 'next' or 'previous'. + * + * @since 4.4.0 + * + * @param array $excluded_terms Array of excluded term IDs. + */ + $excluded_terms = apply_filters( "get_{$adjacent}_post_excluded_terms", $excluded_terms ); + if ( $in_same_term || ! empty( $excluded_terms ) ) { - if ( ! empty( $excluded_terms ) && ! is_array( $excluded_terms ) ) { - // back-compat, $excluded_terms used to be $excluded_terms with IDs separated by " and " - if ( false !== strpos( $excluded_terms, ' and ' ) ) { - _deprecated_argument( __FUNCTION__, '3.3.0', sprintf( __( 'Use commas instead of %s to separate excluded terms.' ), "'and'" ) ); - $excluded_terms = explode( ' and ', $excluded_terms ); - } else { - $excluded_terms = explode( ',', $excluded_terms ); + if ( $in_same_term ) { + $join .= " INNER JOIN $wpdb->term_relationships AS tr ON p.ID = tr.object_id INNER JOIN $wpdb->term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id"; + $where .= $wpdb->prepare( 'AND tt.taxonomy = %s', $taxonomy ); + + if ( ! is_object_in_taxonomy( $post->post_type, $taxonomy ) ) { + return ''; } - - $excluded_terms = array_map( 'intval', $excluded_terms ); - } - - if ( $in_same_term ) { - $join .= " INNER JOIN $wpdb->term_relationships AS tr ON p.ID = tr.object_id INNER JOIN $wpdb->term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id"; - $where .= $wpdb->prepare( "AND tt.taxonomy = %s", $taxonomy ); - - if ( ! is_object_in_taxonomy( $post->post_type, $taxonomy ) ) - return ''; $term_array = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'ids' ) ); // Remove any exclusions from the term array to include. $term_array = array_diff( $term_array, (array) $excluded_terms ); $term_array = array_map( 'intval', $term_array ); - if ( ! $term_array || is_wp_error( $term_array ) ) + if ( ! $term_array || is_wp_error( $term_array ) ) { return ''; - - $where .= " AND tt.term_id IN (" . implode( ',', $term_array ) . ")"; + } + + $where .= ' AND tt.term_id IN (' . implode( ',', $term_array ) . ')'; } - /** - * Filters the IDs of terms excluded from adjacent post queries. - * - * The dynamic portion of the hook name, `$adjacent`, refers to the type - * of adjacency, 'next' or 'previous'. - * - * @since 4.4.0 - * - * @param string $excluded_terms Array of excluded term IDs. - */ - $excluded_terms = apply_filters( "get_{$adjacent}_post_excluded_terms", $excluded_terms ); - if ( ! empty( $excluded_terms ) ) { $where .= " AND p.ID NOT IN ( SELECT tr.object_id FROM $wpdb->term_relationships tr LEFT JOIN $wpdb->term_taxonomy tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id) WHERE tt.term_id IN (" . implode( ',', array_map( 'intval', $excluded_terms ) ) . ') )'; } @@ -1665,20 +1754,20 @@ * current user has the 'read_private_posts' cap. */ $private_states = get_post_stati( array( 'private' => true ) ); - $where .= " AND ( p.post_status = 'publish'"; + $where .= " AND ( p.post_status = 'publish'"; foreach ( (array) $private_states as $state ) { if ( current_user_can( $read_private_cap ) ) { - $where .= $wpdb->prepare( " OR p.post_status = %s", $state ); + $where .= $wpdb->prepare( ' OR p.post_status = %s', $state ); } else { - $where .= $wpdb->prepare( " OR (p.post_author = %d AND p.post_status = %s)", $user_id, $state ); + $where .= $wpdb->prepare( ' OR (p.post_author = %d AND p.post_status = %s)', $user_id, $state ); } } - $where .= " )"; + $where .= ' )'; } else { $where .= " AND p.post_status = 'publish'"; } - $op = $previous ? '<' : '>'; + $op = $previous ? '<' : '>'; $order = $previous ? 'DESC' : 'ASC'; /** @@ -1729,25 +1818,28 @@ * @param WP_Post $post WP_Post object. * @param string $order Sort order. 'DESC' for previous post, 'ASC' for next. */ - $sort = apply_filters( "get_{$adjacent}_post_sort", "ORDER BY p.post_date $order LIMIT 1", $post, $order ); - - $query = "SELECT p.ID FROM $wpdb->posts AS p $join $where $sort"; + $sort = apply_filters( "get_{$adjacent}_post_sort", "ORDER BY p.post_date $order LIMIT 1", $post, $order ); + + $query = "SELECT p.ID FROM $wpdb->posts AS p $join $where $sort"; $query_key = 'adjacent_post_' . md5( $query ); - $result = wp_cache_get( $query_key, 'counts' ); + $result = wp_cache_get( $query_key, 'counts' ); if ( false !== $result ) { - if ( $result ) + if ( $result ) { $result = get_post( $result ); + } return $result; } $result = $wpdb->get_var( $query ); - if ( null === $result ) + if ( null === $result ) { $result = ''; + } wp_cache_set( $query_key, $result, 'counts' ); - if ( $result ) + if ( $result ) { $result = get_post( $result ); + } return $result; } @@ -1767,25 +1859,33 @@ * @return string|void The adjacent post relational link URL. */ function get_adjacent_post_rel_link( $title = '%title', $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) { - if ( $previous && is_attachment() && $post = get_post() ) + if ( $previous && is_attachment() && $post = get_post() ) { $post = get_post( $post->post_parent ); - else + } else { $post = get_adjacent_post( $in_same_term, $excluded_terms, $previous, $taxonomy ); - - if ( empty( $post ) ) + } + + if ( empty( $post ) ) { return; - - $post_title = the_title_attribute( array( 'echo' => false, 'post' => $post ) ); - - if ( empty( $post_title ) ) + } + + $post_title = the_title_attribute( + array( + 'echo' => false, + 'post' => $post, + ) + ); + + if ( empty( $post_title ) ) { $post_title = $previous ? __( 'Previous Post' ) : __( 'Next Post' ); + } $date = mysql2date( get_option( 'date_format' ), $post->post_date ); $title = str_replace( '%title', $post_title, $title ); $title = str_replace( '%date', $date, $title ); - $link = $previous ? "\n"; @@ -1886,43 +1986,49 @@ */ function get_boundary_post( $in_same_term = false, $excluded_terms = '', $start = true, $taxonomy = 'category' ) { $post = get_post(); - if ( ! $post || ! is_single() || is_attachment() || ! taxonomy_exists( $taxonomy ) ) + if ( ! $post || ! is_single() || is_attachment() || ! taxonomy_exists( $taxonomy ) ) { return null; + } $query_args = array( - 'posts_per_page' => 1, - 'order' => $start ? 'ASC' : 'DESC', + 'posts_per_page' => 1, + 'order' => $start ? 'ASC' : 'DESC', 'update_post_term_cache' => false, - 'update_post_meta_cache' => false + 'update_post_meta_cache' => false, ); $term_array = array(); if ( ! is_array( $excluded_terms ) ) { - if ( ! empty( $excluded_terms ) ) + if ( ! empty( $excluded_terms ) ) { $excluded_terms = explode( ',', $excluded_terms ); - else + } else { $excluded_terms = array(); + } } if ( $in_same_term || ! empty( $excluded_terms ) ) { - if ( $in_same_term ) + if ( $in_same_term ) { $term_array = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'ids' ) ); + } if ( ! empty( $excluded_terms ) ) { $excluded_terms = array_map( 'intval', $excluded_terms ); $excluded_terms = array_diff( $excluded_terms, $term_array ); $inverse_terms = array(); - foreach ( $excluded_terms as $excluded_term ) + foreach ( $excluded_terms as $excluded_term ) { $inverse_terms[] = $excluded_term * -1; + } $excluded_terms = $inverse_terms; } - $query_args[ 'tax_query' ] = array( array( - 'taxonomy' => $taxonomy, - 'terms' => array_merge( $term_array, $excluded_terms ) - ) ); + $query_args['tax_query'] = array( + array( + 'taxonomy' => $taxonomy, + 'terms' => array_merge( $term_array, $excluded_terms ), + ), + ); } return get_posts( $query_args ); @@ -1990,7 +2096,7 @@ * @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'. */ function next_post_link( $format = '%link »', $link = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) { - echo get_next_post_link( $format, $link, $in_same_term, $excluded_terms, $taxonomy ); + echo get_next_post_link( $format, $link, $in_same_term, $excluded_terms, $taxonomy ); } /** @@ -2009,26 +2115,28 @@ * @return string The link URL of the previous or next post in relation to the current post. */ function get_adjacent_post_link( $format, $link, $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) { - if ( $previous && is_attachment() ) + if ( $previous && is_attachment() ) { $post = get_post( get_post()->post_parent ); - else + } else { $post = get_adjacent_post( $in_same_term, $excluded_terms, $previous, $taxonomy ); + } if ( ! $post ) { $output = ''; } else { $title = $post->post_title; - if ( empty( $post->post_title ) ) + if ( empty( $post->post_title ) ) { $title = $previous ? __( 'Previous Post' ) : __( 'Next Post' ); + } /** This filter is documented in wp-includes/post-template.php */ $title = apply_filters( 'the_title', $title, $post->ID ); $date = mysql2date( get_option( 'date_format' ), $post->post_date ); - $rel = $previous ? 'prev' : 'next'; - - $string = ''; + $rel = $previous ? 'prev' : 'next'; + + $string = ''; $inlink = str_replace( '%title', $title, $link ); $inlink = str_replace( '%date', $date, $inlink ); $inlink = $string . $inlink . ''; @@ -2081,26 +2189,26 @@ * * @global WP_Rewrite $wp_rewrite * - * @param int $pagenum Optional. Page ID. Default 1. + * @param int $pagenum Optional. Page number. Default 1. * @param bool $escape Optional. Whether to escape the URL for display, with esc_url(). Defaults to true. - * Otherwise, prepares the URL with esc_url_raw(). + * Otherwise, prepares the URL with esc_url_raw(). * @return string The link URL for the given page number. */ -function get_pagenum_link($pagenum = 1, $escape = true ) { +function get_pagenum_link( $pagenum = 1, $escape = true ) { global $wp_rewrite; $pagenum = (int) $pagenum; $request = remove_query_arg( 'paged' ); - $home_root = parse_url(home_url()); - $home_root = ( isset($home_root['path']) ) ? $home_root['path'] : ''; + $home_root = parse_url( home_url() ); + $home_root = ( isset( $home_root['path'] ) ) ? $home_root['path'] : ''; $home_root = preg_quote( $home_root, '|' ); - $request = preg_replace('|^'. $home_root . '|i', '', $request); - $request = preg_replace('|^/+|', '', $request); - - if ( !$wp_rewrite->using_permalinks() || is_admin() ) { + $request = preg_replace( '|^' . $home_root . '|i', '', $request ); + $request = preg_replace( '|^/+|', '', $request ); + + if ( ! $wp_rewrite->using_permalinks() || is_admin() ) { $base = trailingslashit( get_bloginfo( 'url' ) ); if ( $pagenum > 1 ) { @@ -2112,24 +2220,25 @@ $qs_regex = '|\?.*?$|'; preg_match( $qs_regex, $request, $qs_match ); - if ( !empty( $qs_match[0] ) ) { + if ( ! empty( $qs_match[0] ) ) { $query_string = $qs_match[0]; - $request = preg_replace( $qs_regex, '', $request ); + $request = preg_replace( $qs_regex, '', $request ); } else { $query_string = ''; } - $request = preg_replace( "|$wp_rewrite->pagination_base/\d+/?$|", '', $request); - $request = preg_replace( '|^' . preg_quote( $wp_rewrite->index, '|' ) . '|i', '', $request); - $request = ltrim($request, '/'); + $request = preg_replace( "|$wp_rewrite->pagination_base/\d+/?$|", '', $request ); + $request = preg_replace( '|^' . preg_quote( $wp_rewrite->index, '|' ) . '|i', '', $request ); + $request = ltrim( $request, '/' ); $base = trailingslashit( get_bloginfo( 'url' ) ); - if ( $wp_rewrite->using_index_permalinks() && ( $pagenum > 1 || '' != $request ) ) + if ( $wp_rewrite->using_index_permalinks() && ( $pagenum > 1 || '' != $request ) ) { $base .= $wp_rewrite->index . '/'; + } if ( $pagenum > 1 ) { - $request = ( ( !empty( $request ) ) ? trailingslashit( $request ) : $request ) . user_trailingslashit( $wp_rewrite->pagination_base . "/" . $pagenum, 'paged' ); + $request = ( ( ! empty( $request ) ) ? trailingslashit( $request ) : $request ) . user_trailingslashit( $wp_rewrite->pagination_base . '/' . $pagenum, 'paged' ); } $result = $base . $request . $query_string; @@ -2139,15 +2248,18 @@ * Filters the page number link for the current request. * * @since 2.5.0 + * @since 5.2.0 Added the `$pagenum` argument. * - * @param string $result The page number link. + * @param string $result The page number link. + * @param int $pagenum The page number. */ - $result = apply_filters( 'get_pagenum_link', $result ); - - if ( $escape ) + $result = apply_filters( 'get_pagenum_link', $result, $pagenum ); + + if ( $escape ) { return esc_url( $result ); - else + } else { return esc_url_raw( $result ); + } } /** @@ -2162,15 +2274,17 @@ * @param int $max_page Optional. Max pages. Default 0. * @return string|void The link URL for next posts page. */ -function get_next_posts_page_link($max_page = 0) { +function get_next_posts_page_link( $max_page = 0 ) { global $paged; - if ( !is_single() ) { - if ( !$paged ) + if ( ! is_single() ) { + if ( ! $paged ) { $paged = 1; - $nextpage = intval($paged) + 1; - if ( !$max_page || $max_page >= $nextpage ) - return get_pagenum_link($nextpage); + } + $nextpage = intval( $paged ) + 1; + if ( ! $max_page || $max_page >= $nextpage ) { + return get_pagenum_link( $nextpage ); + } } } @@ -2186,10 +2300,11 @@ function next_posts( $max_page = 0, $echo = true ) { $output = esc_url( get_next_posts_page_link( $max_page ) ); - if ( $echo ) + if ( $echo ) { echo $output; - else + } else { return $output; + } } /** @@ -2207,18 +2322,21 @@ function get_next_posts_link( $label = null, $max_page = 0 ) { global $paged, $wp_query; - if ( !$max_page ) + if ( ! $max_page ) { $max_page = $wp_query->max_num_pages; - - if ( !$paged ) + } + + if ( ! $paged ) { $paged = 1; - - $nextpage = intval($paged) + 1; - - if ( null === $label ) + } + + $nextpage = intval( $paged ) + 1; + + if ( null === $label ) { $label = __( 'Next Page »' ); - - if ( !is_single() && ( $nextpage <= $max_page ) ) { + } + + if ( ! is_single() && ( $nextpage <= $max_page ) ) { /** * Filters the anchor tag attributes for the next posts page link. * @@ -2228,7 +2346,7 @@ */ $attr = apply_filters( 'next_posts_link_attributes', '' ); - return '" . preg_replace('/&([^#])(?![a-z]{1,8};)/i', '&$1', $label) . ''; + return '" . preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&$1', $label ) . ''; } } @@ -2260,11 +2378,12 @@ function get_previous_posts_page_link() { global $paged; - if ( !is_single() ) { - $nextpage = intval($paged) - 1; - if ( $nextpage < 1 ) + if ( ! is_single() ) { + $nextpage = intval( $paged ) - 1; + if ( $nextpage < 1 ) { $nextpage = 1; - return get_pagenum_link($nextpage); + } + return get_pagenum_link( $nextpage ); } } @@ -2279,10 +2398,11 @@ function previous_posts( $echo = true ) { $output = esc_url( get_previous_posts_page_link() ); - if ( $echo ) + if ( $echo ) { echo $output; - else + } else { return $output; + } } /** @@ -2298,10 +2418,11 @@ function get_previous_posts_link( $label = null ) { global $paged; - if ( null === $label ) + if ( null === $label ) { $label = __( '« Previous Page' ); - - if ( !is_single() && $paged > 1 ) { + } + + if ( ! is_single() && $paged > 1 ) { /** * Filters the anchor tag attributes for the previous posts page link. * @@ -2310,7 +2431,7 @@ * @param string $attributes Attributes for the anchor tag. */ $attr = apply_filters( 'previous_posts_link_attributes', '' ); - return '". preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&$1', $label ) .''; + return '" . preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&$1', $label ) . ''; } } @@ -2348,26 +2469,26 @@ $return = ''; - if ( !is_singular() ) { + if ( ! is_singular() ) { $defaults = array( - 'sep' => ' — ', - 'prelabel' => __('« Previous Page'), - 'nxtlabel' => __('Next Page »'), + 'sep' => ' — ', + 'prelabel' => __( '« Previous Page' ), + 'nxtlabel' => __( 'Next Page »' ), ); - $args = wp_parse_args( $args, $defaults ); + $args = wp_parse_args( $args, $defaults ); $max_num_pages = $wp_query->max_num_pages; - $paged = get_query_var('paged'); + $paged = get_query_var( 'paged' ); //only have sep if there's both prev and next results - if ($paged < 2 || $paged >= $max_num_pages) { + if ( $paged < 2 || $paged >= $max_num_pages ) { $args['sep'] = ''; } if ( $max_num_pages > 1 ) { - $return = get_previous_posts_link($args['prelabel']); - $return .= preg_replace('/&([^#])(?![a-z]{1,8};)/i', '&$1', $args['sep']); - $return .= get_next_posts_link($args['nxtlabel']); + $return = get_previous_posts_link( $args['prelabel'] ); + $return .= preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&$1', $args['sep'] ); + $return .= get_next_posts_link( $args['nxtlabel'] ); } } return $return; @@ -2384,8 +2505,8 @@ * @param string $nxtlabel Optional Label for next pages. Default empty. */ function posts_nav_link( $sep = '', $prelabel = '', $nxtlabel = '' ) { - $args = array_filter( compact('sep', 'prelabel', 'nxtlabel') ); - echo get_posts_nav_link($args); + $args = array_filter( compact( 'sep', 'prelabel', 'nxtlabel' ) ); + echo get_posts_nav_link( $args ); } /** @@ -2407,14 +2528,17 @@ * @return string Markup for post links. */ function get_the_post_navigation( $args = array() ) { - $args = wp_parse_args( $args, array( - 'prev_text' => '%title', - 'next_text' => '%title', - 'in_same_term' => false, - 'excluded_terms' => '', - 'taxonomy' => 'category', - 'screen_reader_text' => __( 'Post navigation' ), - ) ); + $args = wp_parse_args( + $args, + array( + 'prev_text' => '%title', + 'next_text' => '%title', + 'in_same_term' => false, + 'excluded_terms' => '', + 'taxonomy' => 'category', + 'screen_reader_text' => __( 'Post navigation' ), + ) + ); $navigation = ''; @@ -2478,11 +2602,14 @@ // Don't print empty markup if there's only one page. if ( $GLOBALS['wp_query']->max_num_pages > 1 ) { - $args = wp_parse_args( $args, array( - 'prev_text' => __( 'Older posts' ), - 'next_text' => __( 'Newer posts' ), - 'screen_reader_text' => __( 'Posts navigation' ), - ) ); + $args = wp_parse_args( + $args, + array( + 'prev_text' => __( 'Older posts' ), + 'next_text' => __( 'Newer posts' ), + 'screen_reader_text' => __( 'Posts navigation' ), + ) + ); $next_link = get_previous_posts_link( $args['next_text'] ); $prev_link = get_next_posts_link( $args['prev_text'] ); @@ -2531,12 +2658,15 @@ // Don't print empty markup if there's only one page. if ( $GLOBALS['wp_query']->max_num_pages > 1 ) { - $args = wp_parse_args( $args, array( - 'mid_size' => 1, - 'prev_text' => _x( 'Previous', 'previous set of posts' ), - 'next_text' => _x( 'Next', 'next set of posts' ), - 'screen_reader_text' => __( 'Posts navigation' ), - ) ); + $args = wp_parse_args( + $args, + array( + 'mid_size' => 1, + 'prev_text' => _x( 'Previous', 'previous set of posts' ), + 'next_text' => _x( 'Next', 'next set of posts' ), + 'screen_reader_text' => __( 'Posts navigation' ), + ) + ); // Make sure we get a string back. Plain is the next best thing. if ( isset( $args['type'] ) && 'array' == $args['type'] ) { @@ -2629,18 +2759,20 @@ $result = get_permalink(); - if ( 'newest' == get_option('default_comments_page') ) { + if ( 'newest' == get_option( 'default_comments_page' ) ) { if ( $pagenum != $max_page ) { - if ( $wp_rewrite->using_permalinks() ) - $result = user_trailingslashit( trailingslashit($result) . $wp_rewrite->comments_pagination_base . '-' . $pagenum, 'commentpaged'); - else + if ( $wp_rewrite->using_permalinks() ) { + $result = user_trailingslashit( trailingslashit( $result ) . $wp_rewrite->comments_pagination_base . '-' . $pagenum, 'commentpaged' ); + } else { $result = add_query_arg( 'cpage', $pagenum, $result ); + } } } elseif ( $pagenum > 1 ) { - if ( $wp_rewrite->using_permalinks() ) - $result = user_trailingslashit( trailingslashit($result) . $wp_rewrite->comments_pagination_base . '-' . $pagenum, 'commentpaged'); - else + if ( $wp_rewrite->using_permalinks() ) { + $result = user_trailingslashit( trailingslashit( $result ) . $wp_rewrite->comments_pagination_base . '-' . $pagenum, 'commentpaged' ); + } else { $result = add_query_arg( 'cpage', $pagenum, $result ); + } } $result .= '#comments'; @@ -2669,28 +2801,33 @@ function get_next_comments_link( $label = '', $max_page = 0 ) { global $wp_query; - if ( ! is_singular() ) + if ( ! is_singular() ) { return; - - $page = get_query_var('cpage'); + } + + $page = get_query_var( 'cpage' ); if ( ! $page ) { $page = 1; } - $nextpage = intval($page) + 1; - - if ( empty($max_page) ) + $nextpage = intval( $page ) + 1; + + if ( empty( $max_page ) ) { $max_page = $wp_query->max_num_comment_pages; - - if ( empty($max_page) ) + } + + if ( empty( $max_page ) ) { $max_page = get_comment_pages_count(); - - if ( $nextpage > $max_page ) + } + + if ( $nextpage > $max_page ) { return; - - if ( empty($label) ) - $label = __('Newer Comments »'); + } + + if ( empty( $label ) ) { + $label = __( 'Newer Comments »' ); + } /** * Filters the anchor tag attributes for the next comments page link. @@ -2699,7 +2836,7 @@ * * @param string $attributes Attributes for the anchor tag. */ - return ''. preg_replace('/&([^#])(?![a-z]{1,8};)/i', '&$1', $label) .''; + return '' . preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&$1', $label ) . ''; } /** @@ -2723,18 +2860,21 @@ * @return string|void HTML-formatted link for the previous page of comments. */ function get_previous_comments_link( $label = '' ) { - if ( ! is_singular() ) + if ( ! is_singular() ) { + return; + } + + $page = get_query_var( 'cpage' ); + + if ( intval( $page ) <= 1 ) { return; - - $page = get_query_var('cpage'); - - if ( intval($page) <= 1 ) - return; - - $prevpage = intval($page) - 1; - - if ( empty($label) ) - $label = __('« Older Comments'); + } + + $prevpage = intval( $page ) - 1; + + if ( empty( $label ) ) { + $label = __( '« Older Comments' ); + } /** * Filters the anchor tag attributes for the previous comments page link. @@ -2743,7 +2883,7 @@ * * @param string $attributes Attributes for the anchor tag. */ - return '' . preg_replace('/&([^#])(?![a-z]{1,8};)/i', '&$1', $label) .''; + return '' . preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&$1', $label ) . ''; } /** @@ -2766,36 +2906,41 @@ * @global WP_Rewrite $wp_rewrite * * @param string|array $args Optional args. See paginate_links(). Default empty array. - * @return string|void Markup for pagination links. + * @return string|array|void Markup for comment page links or array of comment page links. */ function paginate_comments_links( $args = array() ) { global $wp_rewrite; - if ( ! is_singular() ) + if ( ! is_singular() ) { return; - - $page = get_query_var('cpage'); - if ( !$page ) + } + + $page = get_query_var( 'cpage' ); + if ( ! $page ) { $page = 1; + } $max_page = get_comment_pages_count(); $defaults = array( - 'base' => add_query_arg( 'cpage', '%#%' ), - 'format' => '', - 'total' => $max_page, - 'current' => $page, - 'echo' => true, - 'add_fragment' => '#comments' + 'base' => add_query_arg( 'cpage', '%#%' ), + 'format' => '', + 'total' => $max_page, + 'current' => $page, + 'echo' => true, + 'type' => 'plain', + 'add_fragment' => '#comments', ); - if ( $wp_rewrite->using_permalinks() ) - $defaults['base'] = user_trailingslashit(trailingslashit(get_permalink()) . $wp_rewrite->comments_pagination_base . '-%#%', 'commentpaged'); - - $args = wp_parse_args( $args, $defaults ); + if ( $wp_rewrite->using_permalinks() ) { + $defaults['base'] = user_trailingslashit( trailingslashit( get_permalink() ) . $wp_rewrite->comments_pagination_base . '-%#%', 'commentpaged' ); + } + + $args = wp_parse_args( $args, $defaults ); $page_links = paginate_links( $args ); - if ( $args['echo'] ) + if ( $args['echo'] && 'array' !== $args['type'] ) { echo $page_links; - else + } else { return $page_links; + } } /** @@ -2819,11 +2964,14 @@ // Are there comments to navigate through? if ( get_comment_pages_count() > 1 ) { - $args = wp_parse_args( $args, array( - 'prev_text' => __( 'Older comments' ), - 'next_text' => __( 'Newer comments' ), - 'screen_reader_text' => __( 'Comments navigation' ), - ) ); + $args = wp_parse_args( + $args, + array( + 'prev_text' => __( 'Older comments' ), + 'next_text' => __( 'Newer comments' ), + 'screen_reader_text' => __( 'Comments navigation' ), + ) + ); $prev_link = get_previous_comments_link( $args['prev_text'] ); $next_link = get_next_comments_link( $args['next_text'] ); @@ -2868,10 +3016,13 @@ * @return string Markup for pagination links. */ function get_the_comments_pagination( $args = array() ) { - $navigation = ''; - $args = wp_parse_args( $args, array( - 'screen_reader_text' => __( 'Comments navigation' ), - ) ); + $navigation = ''; + $args = wp_parse_args( + $args, + array( + 'screen_reader_text' => __( 'Comments navigation' ), + ) + ); $args['echo'] = false; // Make sure we get a string back. Plain is the next best thing. @@ -2939,7 +3090,7 @@ $orig_scheme = $scheme; - if ( empty( $blog_id ) || !is_multisite() ) { + if ( empty( $blog_id ) || ! is_multisite() ) { $url = get_option( 'home' ); } else { switch_to_blog( $blog_id ); @@ -2948,16 +3099,18 @@ } if ( ! in_array( $scheme, array( 'http', 'https', 'relative' ) ) ) { - if ( is_ssl() && ! is_admin() && 'wp-login.php' !== $pagenow ) + if ( is_ssl() && ! is_admin() && 'wp-login.php' !== $pagenow ) { $scheme = 'https'; - else + } else { $scheme = parse_url( $url, PHP_URL_SCHEME ); + } } $url = set_url_scheme( $url, $scheme ); - if ( $path && is_string( $path ) ) + if ( $path && is_string( $path ) ) { $url .= '/' . ltrim( $path, '/' ); + } /** * Filters the home URL. @@ -3009,7 +3162,7 @@ * @return string Site URL link with optional path appended. */ function get_site_url( $blog_id = null, $path = '', $scheme = null ) { - if ( empty( $blog_id ) || !is_multisite() ) { + if ( empty( $blog_id ) || ! is_multisite() ) { $url = get_option( 'siteurl' ); } else { switch_to_blog( $blog_id ); @@ -3019,8 +3172,9 @@ $url = set_url_scheme( $url, $scheme ); - if ( $path && is_string( $path ) ) + if ( $path && is_string( $path ) ) { $url .= '/' . ltrim( $path, '/' ); + } /** * Filters the site URL. @@ -3063,10 +3217,11 @@ * @return string Admin URL link with optional path appended. */ function get_admin_url( $blog_id = null, $path = '', $scheme = 'admin' ) { - $url = get_site_url($blog_id, 'wp-admin/', $scheme); - - if ( $path && is_string( $path ) ) + $url = get_site_url( $blog_id, 'wp-admin/', $scheme ); + + if ( $path && is_string( $path ) ) { $url .= ltrim( $path, '/' ); + } /** * Filters the admin area URL. @@ -3093,8 +3248,9 @@ function includes_url( $path = '', $scheme = null ) { $url = site_url( '/' . WPINC . '/', $scheme ); - if ( $path && is_string( $path ) ) - $url .= ltrim($path, '/'); + if ( $path && is_string( $path ) ) { + $url .= ltrim( $path, '/' ); + } /** * Filters the URL to the includes directory. @@ -3119,8 +3275,9 @@ function content_url( $path = '' ) { $url = set_url_scheme( WP_CONTENT_URL ); - if ( $path && is_string( $path ) ) - $url .= '/' . ltrim($path, '/'); + if ( $path && is_string( $path ) ) { + $url .= '/' . ltrim( $path, '/' ); + } /** * Filters the URL to the content directory. @@ -3131,7 +3288,7 @@ * @param string $path Path relative to the URL to the content directory. Blank string * if no path is specified. */ - return apply_filters( 'content_url', $url, $path); + return apply_filters( 'content_url', $url, $path ); } /** @@ -3150,26 +3307,28 @@ */ function plugins_url( $path = '', $plugin = '' ) { - $path = wp_normalize_path( $path ); - $plugin = wp_normalize_path( $plugin ); + $path = wp_normalize_path( $path ); + $plugin = wp_normalize_path( $plugin ); $mu_plugin_dir = wp_normalize_path( WPMU_PLUGIN_DIR ); - if ( !empty($plugin) && 0 === strpos($plugin, $mu_plugin_dir) ) + if ( ! empty( $plugin ) && 0 === strpos( $plugin, $mu_plugin_dir ) ) { $url = WPMU_PLUGIN_URL; - else + } else { $url = WP_PLUGIN_URL; - + } $url = set_url_scheme( $url ); - if ( !empty($plugin) && is_string($plugin) ) { - $folder = dirname(plugin_basename($plugin)); - if ( '.' != $folder ) - $url .= '/' . ltrim($folder, '/'); + if ( ! empty( $plugin ) && is_string( $plugin ) ) { + $folder = dirname( plugin_basename( $plugin ) ); + if ( '.' != $folder ) { + $url .= '/' . ltrim( $folder, '/' ); + } } - if ( $path && is_string( $path ) ) - $url .= '/' . ltrim($path, '/'); + if ( $path && is_string( $path ) ) { + $url .= '/' . ltrim( $path, '/' ); + } /** * Filters the URL to the plugins directory. @@ -3202,18 +3361,21 @@ * @return string Site URL link with optional path appended. */ function network_site_url( $path = '', $scheme = null ) { - if ( ! is_multisite() ) - return site_url($path, $scheme); + if ( ! is_multisite() ) { + return site_url( $path, $scheme ); + } $current_network = get_network(); - if ( 'relative' == $scheme ) + if ( 'relative' == $scheme ) { $url = $current_network->path; - else + } else { $url = set_url_scheme( 'http://' . $current_network->domain . $current_network->path, $scheme ); - - if ( $path && is_string( $path ) ) + } + + if ( $path && is_string( $path ) ) { $url .= ltrim( $path, '/' ); + } /** * Filters the network site URL. @@ -3244,22 +3406,26 @@ * @return string Home URL link with optional path appended. */ function network_home_url( $path = '', $scheme = null ) { - if ( ! is_multisite() ) - return home_url($path, $scheme); + if ( ! is_multisite() ) { + return home_url( $path, $scheme ); + } $current_network = get_network(); - $orig_scheme = $scheme; - - if ( ! in_array( $scheme, array( 'http', 'https', 'relative' ) ) ) + $orig_scheme = $scheme; + + if ( ! in_array( $scheme, array( 'http', 'https', 'relative' ) ) ) { $scheme = is_ssl() && ! is_admin() ? 'https' : 'http'; - - if ( 'relative' == $scheme ) + } + + if ( 'relative' == $scheme ) { $url = $current_network->path; - else + } else { $url = set_url_scheme( 'http://' . $current_network->domain . $current_network->path, $scheme ); - - if ( $path && is_string( $path ) ) + } + + if ( $path && is_string( $path ) ) { $url .= ltrim( $path, '/' ); + } /** * Filters the network home URL. @@ -3272,7 +3438,7 @@ * @param string|null $orig_scheme Scheme to give the URL context. Accepts 'http', 'https', * 'relative' or null. */ - return apply_filters( 'network_home_url', $url, $path, $orig_scheme); + return apply_filters( 'network_home_url', $url, $path, $orig_scheme ); } /** @@ -3286,13 +3452,15 @@ * @return string Admin URL link with optional path appended. */ function network_admin_url( $path = '', $scheme = 'admin' ) { - if ( ! is_multisite() ) + if ( ! is_multisite() ) { return admin_url( $path, $scheme ); - - $url = network_site_url('wp-admin/network/', $scheme); - - if ( $path && is_string( $path ) ) - $url .= ltrim($path, '/'); + } + + $url = network_site_url( 'wp-admin/network/', $scheme ); + + if ( $path && is_string( $path ) ) { + $url .= ltrim( $path, '/' ); + } /** * Filters the network admin URL. @@ -3317,10 +3485,11 @@ * @return string Admin URL link with optional path appended. */ function user_admin_url( $path = '', $scheme = 'admin' ) { - $url = network_site_url('wp-admin/user/', $scheme); - - if ( $path && is_string( $path ) ) - $url .= ltrim($path, '/'); + $url = network_site_url( 'wp-admin/user/', $scheme ); + + if ( $path && is_string( $path ) ) { + $url .= ltrim( $path, '/' ); + } /** * Filters the user admin URL for the current user. @@ -3388,13 +3557,15 @@ } $url = trim( $url ); - if ( substr( $url, 0, 2 ) === '//' ) + if ( substr( $url, 0, 2 ) === '//' ) { $url = 'http:' . $url; + } if ( 'relative' == $scheme ) { $url = ltrim( preg_replace( '#^\w+://[^/]*#', '', $url ) ); - if ( $url !== '' && $url[0] === '/' ) - $url = '/' . ltrim($url , "/ \t\n\r\0\x0B" ); + if ( $url !== '' && $url[0] === '/' ) { + $url = '/' . ltrim( $url, "/ \t\n\r\0\x0B" ); + } } else { $url = preg_replace( '#^\w+://#', $scheme . '://', $url ); } @@ -3432,20 +3603,21 @@ $user_id = $user_id ? (int) $user_id : get_current_user_id(); $blogs = get_blogs_of_user( $user_id ); - if ( is_multisite() && ! user_can( $user_id, 'manage_network' ) && empty($blogs) ) { + if ( is_multisite() && ! user_can( $user_id, 'manage_network' ) && empty( $blogs ) ) { $url = user_admin_url( $path, $scheme ); } elseif ( ! is_multisite() ) { $url = admin_url( $path, $scheme ); } else { $current_blog = get_current_blog_id(); - if ( $current_blog && ( user_can( $user_id, 'manage_network' ) || in_array( $current_blog, array_keys( $blogs ) ) ) ) { + if ( $current_blog && ( user_can( $user_id, 'manage_network' ) || in_array( $current_blog, array_keys( $blogs ) ) ) ) { $url = admin_url( $path, $scheme ); } else { $active = get_active_blog_for_user( $user_id ); - if ( $active ) + if ( $active ) { $url = get_admin_url( $active->blog_id, $path, $scheme ); - else + } else { $url = user_admin_url( $path, $scheme ); + } } } @@ -3460,7 +3632,7 @@ * @param string $scheme Scheme to give the URL context. Accepts 'http', 'https', 'login', * 'login_post', 'admin', 'relative' or null. */ - return apply_filters( 'user_dashboard_url', $url, $user_id, $path, $scheme); + return apply_filters( 'user_dashboard_url', $url, $user_id, $path, $scheme ); } /** @@ -3476,12 +3648,13 @@ function get_edit_profile_url( $user_id = 0, $scheme = 'admin' ) { $user_id = $user_id ? (int) $user_id : get_current_user_id(); - if ( is_user_admin() ) + if ( is_user_admin() ) { $url = user_admin_url( 'profile.php', $scheme ); - elseif ( is_network_admin() ) + } elseif ( is_network_admin() ) { $url = network_admin_url( 'profile.php', $scheme ); - else + } else { $url = get_dashboard_url( $user_id, 'profile.php', $scheme ); + } /** * Filters the URL for a user's profile editor. @@ -3493,7 +3666,7 @@ * @param string $scheme Scheme to give the URL context. Accepts 'http', 'https', 'login', * 'login_post', 'admin', 'relative' or null. */ - return apply_filters( 'edit_profile_url', $url, $user_id, $scheme); + return apply_filters( 'edit_profile_url', $url, $user_id, $scheme ); } /** @@ -3553,7 +3726,7 @@ * Outputs rel=canonical for singular queries. * * @since 2.9.0 - * @since 4.6.0 Adjusted to use wp_get_canonical_url(). + * @since 4.6.0 Adjusted to use `wp_get_canonical_url()`. */ function rel_canonical() { if ( ! is_singular() ) { @@ -3582,7 +3755,7 @@ * via the {@see 'pre_get_shortlink'} filter or filter the output via the {@see 'get_shortlink'} * filter. * - * @since 3.0.0. + * @since 3.0.0 * * @param int $id Optional. A post or site id. Default is 0, which means the current post or site. * @param string $context Optional. Whether the id is a 'site' id, 'post' id, or 'media' id. If 'post', @@ -3616,11 +3789,12 @@ $post_id = 0; if ( 'query' == $context && is_singular() ) { $post_id = get_queried_object_id(); - $post = get_post( $post_id ); + $post = get_post( $post_id ); } elseif ( 'post' == $context ) { $post = get_post( $id ); - if ( ! empty( $post->ID ) ) + if ( ! empty( $post->ID ) ) { $post_id = $post->ID; + } } $shortlink = ''; @@ -3659,8 +3833,9 @@ function wp_shortlink_wp_head() { $shortlink = wp_get_shortlink( 0, 'query' ); - if ( empty( $shortlink ) ) + if ( empty( $shortlink ) ) { return; + } echo "\n"; } @@ -3673,15 +3848,17 @@ * @since 3.0.0 */ function wp_shortlink_header() { - if ( headers_sent() ) + if ( headers_sent() ) { return; - - $shortlink = wp_get_shortlink(0, 'query'); - - if ( empty($shortlink) ) + } + + $shortlink = wp_get_shortlink( 0, 'query' ); + + if ( empty( $shortlink ) ) { return; - - header('Link: <' . $shortlink . '>; rel=shortlink', false); + } + + header( 'Link: <' . $shortlink . '>; rel=shortlink', false ); } /** @@ -3701,15 +3878,17 @@ function the_shortlink( $text = '', $title = '', $before = '', $after = '' ) { $post = get_post(); - if ( empty( $text ) ) - $text = __('This is the short link.'); - - if ( empty( $title ) ) + if ( empty( $text ) ) { + $text = __( 'This is the short link.' ); + } + + if ( empty( $title ) ) { $title = the_title_attribute( array( 'echo' => false ) ); + } $shortlink = wp_get_shortlink( $post->ID ); - if ( !empty( $shortlink ) ) { + if ( ! empty( $shortlink ) ) { $link = '' . $text . ''; /** @@ -3760,6 +3939,29 @@ return $args['url']; } + +/** + * Check if this comment type allows avatars to be retrieved. + * + * @since 5.1.0 + * + * @param string $comment_type Comment type to check. + * @return bool Whether the comment type is allowed for retrieving avatars. + */ +function is_avatar_comment_type( $comment_type ) { + /** + * Filters the list of allowed comment types for retrieving avatars. + * + * @since 3.0.0 + * + * @param array $types An array of content types. Default only contains 'comment'. + */ + $allowed_comment_types = apply_filters( 'get_avatar_comment_types', array( 'comment' ) ); + + return in_array( $comment_type, (array) $allowed_comment_types, true ); +} + + /** * Retrieves default data about the avatar. * @@ -3797,17 +3999,20 @@ * } */ function get_avatar_data( $id_or_email, $args = null ) { - $args = wp_parse_args( $args, array( - 'size' => 96, - 'height' => null, - 'width' => null, - 'default' => get_option( 'avatar_default', 'mystery' ), - 'force_default' => false, - 'rating' => get_option( 'avatar_rating' ), - 'scheme' => null, - 'processed_args' => null, // if used, should be a reference - 'extra_attr' => '', - ) ); + $args = wp_parse_args( + $args, + array( + 'size' => 96, + 'height' => null, + 'width' => null, + 'default' => get_option( 'avatar_default', 'mystery' ), + 'force_default' => false, + 'rating' => get_option( 'avatar_rating' ), + 'scheme' => null, + 'processed_args' => null, // if used, should be a reference + 'extra_attr' => '', + ) + ); if ( is_numeric( $args['size'] ) ) { $args['size'] = absint( $args['size'] ); @@ -3841,12 +4046,12 @@ } switch ( $args['default'] ) { - case 'mm' : - case 'mystery' : - case 'mysteryman' : + case 'mm': + case 'mystery': + case 'mysteryman': $args['default'] = 'mm'; break; - case 'gravatar_default' : + case 'gravatar_default': $args['default'] = false; break; } @@ -3872,13 +4077,13 @@ */ $args = apply_filters( 'pre_get_avatar_data', $args, $id_or_email ); - if ( isset( $args['url'] ) && ! is_null( $args['url'] ) ) { + if ( isset( $args['url'] ) ) { /** This filter is documented in wp-includes/link-template.php */ return apply_filters( 'get_avatar_data', $args, $id_or_email ); } $email_hash = ''; - $user = $email = false; + $user = $email = false; if ( is_object( $id_or_email ) && isset( $id_or_email->comment_ID ) ) { $id_or_email = get_comment( $id_or_email ); @@ -3902,15 +4107,7 @@ // Post Object $user = get_user_by( 'id', (int) $id_or_email->post_author ); } elseif ( $id_or_email instanceof WP_Comment ) { - /** - * Filters the list of allowed comment types for retrieving avatars. - * - * @since 3.0.0 - * - * @param array $types An array of content types. Default only contains 'comment'. - */ - $allowed_comment_types = apply_filters( 'get_avatar_comment_types', array( 'comment' ) ); - if ( ! empty( $id_or_email->comment_type ) && ! in_array( $id_or_email->comment_type, (array) $allowed_comment_types ) ) { + if ( ! is_avatar_comment_type( get_comment_type( $id_or_email ) ) ) { $args['url'] = false; /** This filter is documented in wp-includes/link-template.php */ return apply_filters( 'get_avatar_data', $args, $id_or_email ); @@ -3936,7 +4133,7 @@ if ( $email_hash ) { $args['found_avatar'] = true; - $gravatar_server = hexdec( $email_hash[0] ) % 3; + $gravatar_server = hexdec( $email_hash[0] ) % 3; } else { $gravatar_server = rand( 0, 2 ); }