Skip to content

Commit c32a470

Browse files
committed
Merge branch 'trunk' of https://github.com/WordPress/wordpress-develop into ppiwo/trunk
* 'trunk' of https://github.com/WordPress/wordpress-develop: Twenty Sixteen: Document the `twentysixteen_author_avatar_size` filter. Abilities API: Ensure public method is used in the codebase General: Add comment explaining use of queried object in `feed_links_extra()` instead of global `$post`. Posts, Post Types: Update `get_the_modified_author()` to handle missing global `$post` and add (missing) `$post` arg. General: Improve resilience of `feed_links_extra()` when global `$post` is not set. Twenty Sixteen: Document the `twentysixteen_content_width` filter. Template activation: fix unique slug filtering. Coding Standards: Use Yoda conditions consistently in `wp-includes/formatting.php`.
2 parents 7c52413 + abaf4d3 commit c32a470

File tree

9 files changed

+113
-33
lines changed

9 files changed

+113
-33
lines changed

src/wp-content/themes/twentysixteen/functions.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,13 @@ function twentysixteen_setup() {
246246
* @since Twenty Sixteen 1.0
247247
*/
248248
function twentysixteen_content_width() {
249+
/**
250+
* Filters Twenty Sixteen content width of the theme.
251+
*
252+
* @since Twenty Sixteen 1.0
253+
*
254+
* @param int $content_width Content width in pixels.
255+
*/
249256
$GLOBALS['content_width'] = apply_filters( 'twentysixteen_content_width', 840 );
250257
}
251258
add_action( 'after_setup_theme', 'twentysixteen_content_width', 0 );

src/wp-content/themes/twentysixteen/inc/template-tags.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@
1919
*/
2020
function twentysixteen_entry_meta() {
2121
if ( 'post' === get_post_type() ) {
22+
/**
23+
* Filters the Twenty Sixteen entry meta avatar size.
24+
*
25+
* @since Twenty Sixteen 1.0
26+
*
27+
* @param int $size The avatar height and width size in pixels.
28+
*/
2229
$author_avatar_size = apply_filters( 'twentysixteen_author_avatar_size', 49 );
2330
printf(
2431
'<span class="byline">%1$s<span class="screen-reader-text">%2$s </span><span class="author vcard"><a class="url fn n" href="%3$s">%4$s</a></span></span>',

src/wp-includes/abilities-api/class-wp-abilities-registry.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,7 @@ public function register( string $name, array $args ): ?WP_Ability {
121121

122122
// Validate ability category exists if provided (will be validated as required in WP_Ability).
123123
if ( isset( $args['category'] ) ) {
124-
$category_registry = WP_Ability_Categories_Registry::get_instance();
125-
if ( ! $category_registry->is_registered( $args['category'] ) ) {
124+
if ( ! wp_has_ability_category( $args['category'] ) ) {
126125
_doing_it_wrong(
127126
__METHOD__,
128127
sprintf(

src/wp-includes/author-template.php

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -86,24 +86,31 @@ function the_author( $deprecated = '', $deprecated_echo = true ) {
8686
* Retrieves the author who last edited the current post.
8787
*
8888
* @since 2.8.0
89+
* @since 6.9.0 Added the `$post` parameter. Unknown return value is now explicitly null instead of void.
8990
*
90-
* @return string|void The author's display name, empty string if unknown.
91+
* @param int|WP_Post|null $post Optional. Post ID or post object. Default is global `$post` object.
92+
* @return string|null The author's display name. Empty string if user is unavailable. Null if there was no last editor or the post is invalid.
9193
*/
92-
function get_the_modified_author() {
93-
$last_id = get_post_meta( get_post()->ID, '_edit_last', true );
94-
95-
if ( $last_id ) {
96-
$last_user = get_userdata( $last_id );
94+
function get_the_modified_author( $post = null ) {
95+
$post = get_post( $post );
96+
if ( ! $post ) {
97+
return null;
98+
}
9799

98-
/**
99-
* Filters the display name of the author who last edited the current post.
100-
*
101-
* @since 2.8.0
102-
*
103-
* @param string $display_name The author's display name, empty string if unknown.
104-
*/
105-
return apply_filters( 'the_modified_author', $last_user ? $last_user->display_name : '' );
100+
$last_id = get_post_meta( $post->ID, '_edit_last', true );
101+
if ( ! $last_id ) {
102+
return null;
106103
}
104+
$last_user = get_userdata( $last_id );
105+
106+
/**
107+
* Filters the display name of the author who last edited the current post.
108+
*
109+
* @since 2.8.0
110+
*
111+
* @param string $display_name The author's display name, empty string if user is unavailable.
112+
*/
113+
return apply_filters( 'the_modified_author', $last_user ? $last_user->display_name : '' );
107114
}
108115

109116
/**

src/wp-includes/formatting.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ function _wptexturize_pushpop_element( $text, &$stack, $disabled_elements ) {
446446
function wpautop( $text, $br = true ) {
447447
$pre_tags = array();
448448

449-
if ( trim( $text ) === '' ) {
449+
if ( '' === trim( $text ) ) {
450450
return '';
451451
}
452452

@@ -1181,7 +1181,7 @@ function utf8_uri_encode( $utf8_string, $length = 0, $encode_ascii_characters =
11811181
$unicode .= $encoded_char;
11821182
$unicode_length += $encoded_char_length;
11831183
} else {
1184-
if ( count( $values ) === 0 ) {
1184+
if ( 0 === count( $values ) ) {
11851185
if ( $value < 224 ) {
11861186
$num_octets = 2;
11871187
} elseif ( $value < 240 ) {
@@ -2558,7 +2558,7 @@ function convert_invalid_entities( $content ) {
25582558
* @return string Balanced text.
25592559
*/
25602560
function balanceTags( $text, $force = false ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
2561-
if ( $force || (int) get_option( 'use_balanceTags' ) === 1 ) {
2561+
if ( $force || 1 === (int) get_option( 'use_balanceTags' ) ) {
25622562
return force_balance_tags( $text );
25632563
} else {
25642564
return $text;
@@ -2999,7 +2999,7 @@ function _make_web_ftp_clickable_cb( $matches ) {
29992999

30003000
// Removed trailing [.,;:)] from URL.
30013001
$last_char = substr( $dest, -1 );
3002-
if ( in_array( $last_char, array( '.', ',', ';', ':', ')' ), true ) === true ) {
3002+
if ( in_array( $last_char, array( '.', ',', ';', ':', ')' ), true ) ) {
30033003
$ret = $last_char;
30043004
$dest = substr( $dest, 0, strlen( $dest ) - 1 );
30053005
}
@@ -3326,7 +3326,7 @@ function wp_targeted_link_rel( $text ) {
33263326
_deprecated_function( __FUNCTION__, '6.7.0' );
33273327

33283328
// Don't run (more expensive) regex if no links with targets.
3329-
if ( stripos( $text, 'target' ) === false || stripos( $text, '<a ' ) === false || is_serialized( $text ) ) {
3329+
if ( false === stripos( $text, 'target' ) || false === stripos( $text, '<a ' ) || is_serialized( $text ) ) {
33303330
return $text;
33313331
}
33323332

@@ -3446,7 +3446,7 @@ function wp_remove_targeted_link_rel_filters() {
34463446
function translate_smiley( $matches ) {
34473447
global $wpsmiliestrans;
34483448

3449-
if ( count( $matches ) === 0 ) {
3449+
if ( 0 === count( $matches ) ) {
34503450
return '';
34513451
}
34523452

@@ -3572,7 +3572,7 @@ function is_email( $email, $deprecated = false ) {
35723572
}
35733573

35743574
// Test for an @ character after the first position.
3575-
if ( strpos( $email, '@', 1 ) === false ) {
3575+
if ( false === strpos( $email, '@', 1 ) ) {
35763576
/** This filter is documented in wp-includes/formatting.php */
35773577
return apply_filters( 'is_email', false, $email, 'email_no_at' );
35783578
}
@@ -3786,7 +3786,7 @@ function sanitize_email( $email ) {
37863786
}
37873787

37883788
// Test for an @ character after the first position.
3789-
if ( strpos( $email, '@', 1 ) === false ) {
3789+
if ( false === strpos( $email, '@', 1 ) ) {
37903790
/** This filter is documented in wp-includes/formatting.php */
37913791
return apply_filters( 'sanitize_email', '', $email, 'email_no_at' );
37923792
}
@@ -5362,7 +5362,7 @@ function wp_sprintf_l( $pattern, $args ) {
53625362

53635363
$args = (array) $args;
53645364
$result = array_shift( $args );
5365-
if ( count( $args ) === 1 ) {
5365+
if ( 1 === count( $args ) ) {
53665366
$result .= $l['between_only_two'] . array_shift( $args );
53675367
}
53685368

src/wp-includes/general-template.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3326,9 +3326,13 @@ function feed_links_extra( $args = array() ) {
33263326
*/
33273327
$args = apply_filters( 'feed_links_extra_args', $args );
33283328

3329-
if ( is_singular() ) {
3330-
$id = 0;
3331-
$post = get_post( $id );
3329+
/*
3330+
* The template conditionals are referring to the global query, so the queried object is used rather than
3331+
* depending on a global $post being set.
3332+
*/
3333+
$queried_object = get_queried_object();
3334+
if ( is_singular() && $queried_object instanceof WP_Post ) {
3335+
$post = $queried_object;
33323336

33333337
/** This filter is documented in wp-includes/general-template.php */
33343338
$show_comments_feed = apply_filters( 'feed_links_show_comments_feed', true );
@@ -3348,12 +3352,17 @@ function feed_links_extra( $args = array() ) {
33483352
*/
33493353
$show_post_comments_feed = apply_filters( 'feed_links_extra_show_post_comments_feed', $show_comments_feed );
33503354

3351-
if ( $show_post_comments_feed && ( comments_open() || pings_open() || $post->comment_count > 0 ) ) {
3355+
if ( $show_post_comments_feed && ( comments_open( $post ) || pings_open( $post ) || (int) $post->comment_count > 0 ) ) {
33523356
$title = sprintf(
33533357
$args['singletitle'],
33543358
get_bloginfo( 'name' ),
33553359
$args['separator'],
3356-
the_title_attribute( array( 'echo' => false ) )
3360+
the_title_attribute(
3361+
array(
3362+
'echo' => false,
3363+
'post' => $post,
3364+
)
3365+
)
33573366
);
33583367

33593368
$feed_link = get_post_comments_feed_link( $post->ID );

src/wp-includes/theme-templates.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ function wp_filter_wp_template_unique_post_slug( $override_slug, $slug, $post_id
5050
}
5151

5252
// For wp_template, slugs no longer have to be unique within the same theme.
53-
if ( 'wp_template' !== $post_type ) {
54-
return $override_slug;
53+
if ( 'wp_template' === $post_type ) {
54+
return $slug;
5555
}
5656

5757
if ( ! $override_slug ) {

tests/phpunit/tests/general/feedLinksExtra.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,4 +634,15 @@ public function data_feed_links_extra_should_output_nothing_when_filters_return_
634634
),
635635
);
636636
}
637+
638+
/**
639+
* @ticket 63263
640+
*/
641+
public function test_feed_links_extra_should_work_fail_if_global_post_empty() {
642+
$post_id = self::factory()->post->create();
643+
$this->go_to( get_permalink( $post_id ) );
644+
$GLOBALS['post'] = null;
645+
646+
$this->assertNotEmpty( get_echo( 'feed_links_extra' ) );
647+
}
637648
}

tests/phpunit/tests/user/getTheModifiedAuthor.php

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
3737
public function set_up() {
3838
parent::set_up();
3939

40-
$GLOBALS['post'] = self::$post_id;
40+
$GLOBALS['post'] = get_post( self::$post_id );
4141
}
4242

4343
public function test_get_the_modified_author() {
@@ -56,4 +56,44 @@ public function test_get_the_modified_author_should_return_empty_string_if_user_
5656

5757
$this->assertSame( '', get_the_modified_author() );
5858
}
59+
60+
/**
61+
* @ticket 64104
62+
*/
63+
public function test_get_the_modified_author_when_post_global_does_not_exist() {
64+
$GLOBALS['post'] = null;
65+
$this->assertNull( get_the_modified_author() );
66+
}
67+
68+
/**
69+
* @ticket 64104
70+
*/
71+
public function test_get_the_modified_author_when_invalid_post() {
72+
$this->assertNull( get_the_modified_author( -1 ) );
73+
}
74+
75+
/**
76+
* @ticket 64104
77+
*/
78+
public function test_get_the_modified_author_for_another_post() {
79+
$expected_display_name = 'Test Editor';
80+
81+
$editor_id = self::factory()->user->create(
82+
array(
83+
'role' => 'editor',
84+
'user_login' => 'test_editor',
85+
'display_name' => $expected_display_name,
86+
'description' => 'test_editor',
87+
)
88+
);
89+
90+
$another_post_id = self::factory()->post->create();
91+
92+
$this->assertNull( get_the_modified_author( $another_post_id ) );
93+
$this->assertNull( get_the_modified_author( get_post( $another_post_id ) ) );
94+
95+
add_post_meta( $another_post_id, '_edit_last', $editor_id );
96+
$this->assertSame( $expected_display_name, get_the_modified_author( $another_post_id ) );
97+
$this->assertSame( $expected_display_name, get_the_modified_author( get_post( $another_post_id ) ) );
98+
}
5999
}

0 commit comments

Comments
 (0)