From 20110f63aac507e2b64bb2b6270471957dec8ca3 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Thu, 26 Dec 2024 23:55:05 +0000 Subject: [PATCH 1/5] Coding Standards: Use strict comparison in `get_active_blog_for_user()`. Follow-up to [https://mu.trac.wordpress.org/changeset/804 mu:804], [https://mu.trac.wordpress.org/changeset/1918 mu:1918]. Props debarghyabanerjee, aristath, poena, afercia, SergeyBiryukov. See #62279, #62283. git-svn-id: https://develop.svn.wordpress.org/trunk@59562 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/ms-functions.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/wp-includes/ms-functions.php b/src/wp-includes/ms-functions.php index 9f1889fda6b36..fdbcc6fb78e83 100644 --- a/src/wp-includes/ms-functions.php +++ b/src/wp-includes/ms-functions.php @@ -71,18 +71,23 @@ function get_active_blog_for_user( $user_id ) { } } - if ( ( ! is_object( $primary ) ) || ( 1 == $primary->archived || 1 == $primary->spam || 1 == $primary->deleted ) ) { + if ( ( ! is_object( $primary ) ) + || ( '1' === $primary->archived || '1' === $primary->spam || '1' === $primary->deleted ) + ) { $blogs = get_blogs_of_user( $user_id, true ); // If a user's primary blog is shut down, check their other blogs. $ret = false; if ( is_array( $blogs ) && count( $blogs ) > 0 ) { foreach ( (array) $blogs as $blog_id => $blog ) { - if ( get_current_network_id() != $blog->site_id ) { + if ( get_current_network_id() !== $blog->site_id ) { continue; } + $details = get_site( $blog_id ); - if ( is_object( $details ) && 0 == $details->archived && 0 == $details->spam && 0 == $details->deleted ) { + if ( is_object( $details ) + && '0' === $details->archived && '0' === $details->spam && '0' === $details->deleted + ) { $ret = $details; - if ( get_user_meta( $user_id, 'primary_blog', true ) != $blog_id ) { + if ( (int) get_user_meta( $user_id, 'primary_blog', true ) !== $blog_id ) { update_user_meta( $user_id, 'primary_blog', $blog_id ); } if ( ! get_user_meta( $user_id, 'source_domain', true ) ) { From 779ed48a034c60a65cd1ac7ab35262e496e39c99 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Fri, 27 Dec 2024 23:00:41 +0000 Subject: [PATCH 2/5] Coding Standards: Use strict comparison in `is_user_spammy()`. Follow-up to [https://mu.trac.wordpress.org/changeset/1640 mu:1640]. Props debarghyabanerjee, aristath, poena, afercia, SergeyBiryukov. See #62279, #62283. git-svn-id: https://develop.svn.wordpress.org/trunk@59563 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/ms-functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/ms-functions.php b/src/wp-includes/ms-functions.php index fdbcc6fb78e83..e0ae1a0315f17 100644 --- a/src/wp-includes/ms-functions.php +++ b/src/wp-includes/ms-functions.php @@ -2304,7 +2304,7 @@ function is_user_spammy( $user = null ) { } } - return $user && isset( $user->spam ) && 1 == $user->spam; + return $user && isset( $user->spam ) && '1' === $user->spam; } /** From 4a6b12bea7761ec8f9037685aad3104285e15b21 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sat, 28 Dec 2024 22:08:19 +0000 Subject: [PATCH 3/5] Options, Meta APIs: Ensure `after_section` is printed for sections without any fields. This brings consistency with the `before_section` HTML content, which did get printed in `do_settings_sections()` regardless of whether the settings section has any fields attached. Follow-up to [8855], [21742], [54247]. Props alpipego, SergeyBiryukov. Fixes #62746. git-svn-id: https://develop.svn.wordpress.org/trunk@59564 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/template.php | 9 ++++--- .../phpunit/tests/admin/includesTemplate.php | 24 +++++++++++++++++++ 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/wp-admin/includes/template.php b/src/wp-admin/includes/template.php index 3bff8bc279b5f..a0d07696d3019 100644 --- a/src/wp-admin/includes/template.php +++ b/src/wp-admin/includes/template.php @@ -1784,12 +1784,11 @@ function do_settings_sections( $page ) { call_user_func( $section['callback'], $section ); } - if ( ! isset( $wp_settings_fields ) || ! isset( $wp_settings_fields[ $page ] ) || ! isset( $wp_settings_fields[ $page ][ $section['id'] ] ) ) { - continue; + if ( isset( $wp_settings_fields[ $page ][ $section['id'] ] ) ) { + echo ''; + do_settings_fields( $page, $section['id'] ); + echo ''; } - echo ''; - do_settings_fields( $page, $section['id'] ); - echo ''; if ( '' !== $section['after_section'] ) { echo wp_kses_post( $section['after_section'] ); diff --git a/tests/phpunit/tests/admin/includesTemplate.php b/tests/phpunit/tests/admin/includesTemplate.php index f24a046933922..66e3befd5f07b 100644 --- a/tests/phpunit/tests/admin/includesTemplate.php +++ b/tests/phpunit/tests/admin/includesTemplate.php @@ -240,6 +240,30 @@ public function test_add_settings_section_with_extra_args( $extra_args, $expecte $this->assertStringContainsString( $expected_after_section_html, $output, 'Test page output does not contain the custom markup to be placed after the section.' ); } + /** + * @ticket 62746 + * + * @param array $extra_args Extra arguments to pass to function `add_settings_section()`. + * @param array $expected_section_data Expected set of section data. + * @param string $expected_before_section_html Expected HTML markup to be rendered before the settings section. + * @param string $expected_after_section_html Expected HTML markup to be rendered after the settings section. + * + * @covers ::add_settings_section + * @covers ::do_settings_sections + * + * @dataProvider data_extra_args_for_add_settings_section + */ + public function test_add_settings_section_without_any_fields( $extra_args, $expected_section_data, $expected_before_section_html, $expected_after_section_html ) { + add_settings_section( 'test-section', 'Section title', '__return_false', 'test-page', $extra_args ); + + ob_start(); + do_settings_sections( 'test-page' ); + $output = ob_get_clean(); + + $this->assertStringContainsString( $expected_before_section_html, $output, 'Test page output does not contain the custom markup to be placed before the section.' ); + $this->assertStringContainsString( $expected_after_section_html, $output, 'Test page output does not contain the custom markup to be placed after the section.' ); + } + /** * Data provider for `test_add_settings_section_with_extra_args()`. * From 4e1752dee97eb3454c7a6da9176b8890d7c371a8 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sun, 29 Dec 2024 21:52:34 +0000 Subject: [PATCH 4/5] Coding Standards: Use strict comparison in `sanitize_post()`. Follow-up to [12062]. Props aristath, poena, afercia, SergeyBiryukov. See #62279. git-svn-id: https://develop.svn.wordpress.org/trunk@59565 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/post.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index eb90e762f5663..cadc929457979 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -2823,7 +2823,7 @@ function is_sticky( $post_id = 0 ) { function sanitize_post( $post, $context = 'display' ) { if ( is_object( $post ) ) { // Check if post already filtered for this context. - if ( isset( $post->filter ) && $context == $post->filter ) { + if ( isset( $post->filter ) && $context === $post->filter ) { return $post; } if ( ! isset( $post->ID ) ) { @@ -2835,7 +2835,7 @@ function sanitize_post( $post, $context = 'display' ) { $post->filter = $context; } elseif ( is_array( $post ) ) { // Check if post already filtered for this context. - if ( isset( $post['filter'] ) && $context == $post['filter'] ) { + if ( isset( $post['filter'] ) && $context === $post['filter'] ) { return $post; } if ( ! isset( $post['ID'] ) ) { From 2ba84334c9d412956322544564c1a8e32fb56363 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 30 Dec 2024 09:30:14 +0000 Subject: [PATCH 5/5] Coding Standards: Use strict comparison in `get_post_ancestors()`. Follow-up to [7074], [15758], [21559], [21953]. Props aristath, poena, afercia, SergeyBiryukov. See #62279. git-svn-id: https://develop.svn.wordpress.org/trunk@59566 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/post.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index cadc929457979..dfdd41ed5ef93 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -1135,7 +1135,7 @@ function get_post( $post = null, $output = OBJECT, $filter = 'raw' ) { function get_post_ancestors( $post ) { $post = get_post( $post ); - if ( ! $post || empty( $post->post_parent ) || $post->post_parent == $post->ID ) { + if ( ! $post || empty( $post->post_parent ) || $post->post_parent === $post->ID ) { return array(); } @@ -1146,7 +1146,9 @@ function get_post_ancestors( $post ) { while ( $ancestor = get_post( $id ) ) { // Loop detection: If the ancestor has been seen before, break. - if ( empty( $ancestor->post_parent ) || ( $ancestor->post_parent == $post->ID ) || in_array( $ancestor->post_parent, $ancestors, true ) ) { + if ( empty( $ancestor->post_parent ) || $ancestor->post_parent === $post->ID + || in_array( $ancestor->post_parent, $ancestors, true ) + ) { break; }