Make WordPress Core

Opened 3 years ago

Closed 2 years ago

#54728 closed task (blessed) (fixed)

Coding Standards fixes for WP 6.0

Reported by: hellofromtonya's profile hellofromTonya Owned by:
Milestone: 6.0 Priority: normal
Severity: normal Version:
Component: General Keywords: has-patch
Focuses: coding-standards Cc:

Description

Previously:

Attachments (6)

54728.diff (2.7 KB) - added by azouamauriac 2 years ago.
src/wp-admin/user-edit.php
54728.2.diff (3.3 KB) - added by azouamauriac 2 years ago.
src/wp-admin/includes/misc.php WordPress.NamingConventions.ValidVariableName and WordPress.PHP.StrictComparisons.LooseComparison
54728.3.diff (3.2 KB) - added by azouamauriac 2 years ago.
src/wp-admin/includes/image-edit.php WordPress.PHP.StrictComparisons
54728.4.diff (14.2 KB) - added by azouamauriac 2 years ago.
Fix (WordPress.PHP.StrictComparisons.LooseComparison) ; and fix typo RE: https://developer.wordpress.org/coding-standards/inline-documentation-standards/php/#language
54728.5.diff (6.7 KB) - added by azouamauriac 2 years ago.
Fix "WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase" in src/wp-includes/class-wp-http-curl.php src/wp-includes/class-wp-http-streams.php src/wp-includes/category-template.php;
54728.6.diff (50.6 KB) - added by azouamauriac 2 years ago.
Fix "WordPress.PHP.StrictComparisons.LooseComparison" in src/wp-admin/

Download all attachments as: .zip

Change History (67)

#1 @jrf
3 years ago

  • Focuses coding-standards added

This ticket was mentioned in Slack in #core-coding-standards by costdev. View the logs.


3 years ago

#3 @SergeyBiryukov
3 years ago

In 52534:

Coding Standards: Use strict comparison in wp-admin/plugin-install.php.

Follow-up to [11366].

See #54728.

#4 @SergeyBiryukov
3 years ago

In 52538:

Coding Standards: Use strict comparison in wp-admin/revision.php.

Follow-up to [7913], [12751].

See #54728.

#5 @SergeyBiryukov
3 years ago

In 52540:

Coding Standards: Use strict comparison in wp-admin/themes.php.

Follow-up to [15646], [30697].

See #54728.

#6 @SergeyBiryukov
3 years ago

In 52544:

Coding Standards: Correct alignment in get_block_editor_settings().

This fixes an Array double arrow not aligned correctly WPCS warning.

Follow-up to [52054].

See #54728.

#7 @SergeyBiryukov
3 years ago

In 52568:

Coding Standards: Remove an extra variable in get_author_posts_url().

This fixes a Variable "$auth_ID" is not in valid snake_case format WPCS warning by using the existing $author_id variable, and brings consistency with a similar fragment in get_author_feed_link().

Follow-up to [979], [5087], [6364], [6365].

See #54728.

#8 @SergeyBiryukov
3 years ago

In 52581:

Coding Standards: Use strict comparison in wp-admin/includes/class-wp-users-list-table.php.

This mirrors a similar check a few lines below and includes minor code layout fixes for better readability.

Follow-up to [9955], [13931], [14176], [15315], [45407], [50129].

See #54728.

#9 @SergeyBiryukov
3 years ago

In 52583:

Coding Standards: Use strict comparison in wp-admin/includes/class-wp-ms-users-list-table.php.

Follow-up to [16607], [32630], [32757], [47219].

See #54728.

#10 @SergeyBiryukov
3 years ago

In 52584:

Coding Standards: Rename the $val variable to $site for clarity in WP_MS_Users_List_Table::column_blogs().

Follow-up to [12603], [13918], [16607], [32757], [52583].

See #54728.

This ticket was mentioned in PR #2198 on WordPress/wordpress-develop by leskam.


3 years ago
#11

  • Keywords has-patch added

Coding Standards fixes for WP 6.0

Trac ticket: https://core.trac.wordpress.org/ticket/54728

@azouamauriac
2 years ago

src/wp-admin/user-edit.php

#12 @SergeyBiryukov
2 years ago

In 52684:

Coding Standards: Rename $r variable to $args for clarity in walk_nav_menu_tree().

Follow-up to [14248], [32612], [45667].

Props uzumymw.
See #54728.

#14 @SergeyBiryukov
2 years ago

In 52685:

Coding Standards: Rename $r variable to $args for clarity in walk_page_tree().

Follow-up to [9830], [32617], [45667], [52684].

See #54728.

#15 @SergeyBiryukov
2 years ago

In 52687:

Coding Standards: Use strict comparison in wp-admin/user-edit.php.

Follow-up to [2872], [13941], [12722], [14043], [14802], [23364], [42688].

Props azouamauriac.
See #54728.

#16 @SergeyBiryukov
2 years ago

In 52689:

Coding Standards: Rename the $profileuser variable to $profile_user in wp-admin/user-edit.php.

This brings the naming more in line with other variables like $current_user.

Follow-up to [2872].

See #54728.

@azouamauriac
2 years ago

src/wp-admin/includes/misc.php WordPress.NamingConventions.ValidVariableName and WordPress.PHP.StrictComparisons.LooseComparison

@azouamauriac
2 years ago

src/wp-admin/includes/image-edit.php WordPress.PHP.StrictComparisons

#17 @SergeyBiryukov
2 years ago

In 52706:

Cache API: Reorder object cache functions and methods for consistency.

The original order was alphabetical, which became less obvious as newer functions got added, resulting in a somewhat random order.

This commits aims to organize the functions and related WP_Object_Cache methods in a more predictable order:

  • wp_cache_init()
  • wp_cache_add()
  • wp_cache_add_multiple()
  • wp_cache_replace()
  • wp_cache_set()
  • wp_cache_set_multiple()
  • wp_cache_get()
  • wp_cache_get_multiple()
  • wp_cache_delete()
  • wp_cache_delete_multiple()
  • wp_cache_incr()
  • wp_cache_decr()
  • wp_cache_flush()
  • wp_cache_close()
  • wp_cache_add_global_groups()
  • wp_cache_add_non_persistent_groups()
  • wp_cache_switch_to_blog()
  • wp_cache_reset()

Follow-up to [3011], [6543], [7986], [13066], [18580], [21403], [47938], [52700], [52703-52705].

See #54728, #54574.

@azouamauriac
2 years ago

Fix (WordPress.PHP.StrictComparisons.LooseComparison) ; and fix typo RE: https://developer.wordpress.org/coding-standards/inline-documentation-standards/php/#language

#18 follow-up: @azouamauriac
2 years ago

Hello @SergeyBiryukov find a lot of "Use placeholders and $wpdb->prepare(); found array_keys (WordPress.DB.PreparedSQL.NotPrepared)" should i fix them?

#19 in reply to: ↑ 18 @SergeyBiryukov
2 years ago

Replying to azouamauriac:

find a lot of "Use placeholders and $wpdb->prepare(); found array_keys (WordPress.DB.PreparedSQL.NotPrepared)" should i fix them?

Yes, please!

#20 @SergeyBiryukov
2 years ago

In 52717:

Coding Standards: Remove unnecessary try/catch block in wp_get_webp_info().

This appears to be redundant, as none of the functions used inside the block throw an exception.

Follow-up to [50810].

See #54728.

#21 follow-up: @SergeyBiryukov
2 years ago

In 52721:

Coding Standards: Fix WPCS issues in wp-admin/includes/misc.php.

  • Use strict comparison in various conditions.
  • Fix a Variable "$system_webServer_node" is not in valid snake_case format WPCS warning.

Includes minor code layout fixes for better readability.

Follow-up to [10607], [11350], [22253], [26137].

Props azouamauriac, SergeyBiryukov.
See #54728.

#22 in reply to: ↑ 21 ; follow-up: @azouamauriac
2 years ago

Hello @SergeyBiryukov thanks for your great job. I have one concern, I thought that as "web server" is two words; RE: https://www.dictionary.com/browse/web-server, https://en.wikipedia.org/wiki/Web_server; we should use it like this "$system_web_server_node"
to respect coding standard https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/#naming-conventions. But I saw you put it in one word in the commit, is there a raison for that? please enlighten me.

Replying to SergeyBiryukov:

In 52721:

Coding Standards: Fix WPCS issues in wp-admin/includes/misc.php.

  • Use strict comparison in various conditions.
  • Fix a Variable "$system_webServer_node" is not in valid snake_case format WPCS warning.

Includes minor code layout fixes for better readability.

Follow-up to [10607], [11350], [22253], [26137].

Props azouamauriac, SergeyBiryukov.
See #54728.

#23 in reply to: ↑ 22 @SergeyBiryukov
2 years ago

Replying to azouamauriac:

I have one concern, I thought that as "web server" is two words; RE: https://www.dictionary.com/browse/web-server, https://en.wikipedia.org/wiki/Web_server; we should use it like this "$system_web_server_node"

Thanks for the note! It just seemed a bit too long for a variable name :) It refers to the system.webServer XML node, where webServer reads as a single word to me. On second thought, I guess you're right and that camelCase should be replaced with two words. I have no objections to changing it.

#24 @SergeyBiryukov
2 years ago

In 52732:

Coding Standards: Rename some variables in iis7_add_rewrite_rule() for consistency.

Follow-up to [52721].

Props azouamauriac.
See #54728.

@azouamauriac
2 years ago

Fix "WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase" in src/wp-includes/class-wp-http-curl.php src/wp-includes/class-wp-http-streams.php src/wp-includes/category-template.php;

#25 @davidbaumwald
2 years ago

In 52840:

Coding Standards: Fix minor alignment issue in wp_ajax_install_theme().

Follow-up to [52819].

See #54728.

#26 @peterwilsoncc
2 years ago

In 52945:

Registration/Login: Coding standards fixes for wp-login.php.

Props alkesh7, Presskopp, audrasjb.
Fixes #54746.
See #54728.

#28 @SergeyBiryukov
2 years ago

In 52957:

Coding Standards: Use esc_url() instead of esc_attr() for some URLs.

Follow-up to [2063], [2182], [4656], [6952], [9098], [11109], [11204], [17887], [22505],

Props kebbet.
See #54728.

#31 @SergeyBiryukov
2 years ago

In 52958:

Coding Standards: Rename the $cat_ID argument to $cat_id in get_the_category_by_ID().

This fixes a Variable "$cat_ID" is not in valid snake_case format WPCS warning.

Props azouamauriac.
See #54728.

SergeyBiryukov commented on PR #2434:


2 years ago
#32

Thanks for the PR! Per discussions in Trac tickets #22436, #44916, and some others, it looks like we don't generally escape HTML in post titles, as they get sanitized by KSES. I agree we should escape the URL though.

#33 @SergeyBiryukov
2 years ago

In 52960:

Coding Standards: Rename the $bodyStarted variable to $body_started in WP_Http_Streams::request().

This fixes a Variable "$bodyStarted" is not in valid snake_case format WPCS warning.

Follow-up to [17555], [51825], [51929], [51940].

Props azouamauriac.
See #54728.

#34 @SergeyBiryukov
2 years ago

In 52961:

Coding Standards: Rename the $requestPath variable to $request_path in WP_Http_Streams::request().

This fixes a Variable "$requestPath" is not in valid snake_case format WPCS warning.

Follow-up to [8516], [51825], [51929], [51940], [52960].

Props azouamauriac.
See #54728.

#35 @SergeyBiryukov
2 years ago

In 52962:

Coding Standards: Rename the $strHeaders variable to $headers in WP_Http_Streams::request().

This fixes a Variable "$strHeaders" is not in valid snake_case format WPCS warning.

Follow-up to [8516], [51825], [51929], [51940], [52960], [52961].

Props azouamauriac.
See #54728.

#36 @SergeyBiryukov
2 years ago

In 52963:

Coding Standards: Rename the $headerValue variable to $header_value in WP_Http_Streams::request().

This fixes a Variable "$headerValue" is not in valid snake_case format WPCS warning.

Follow-up to [8516], [51825], [51929], [51940], [52960], [52961], [52962].

Props azouamauriac.
See #54728.

#37 @SergeyBiryukov
2 years ago

In 52964:

Coding Standards: Rename the $strResponse variable to $response in WP_Http_Streams::request().

This fixes a Variable "$strResponse" is not in valid snake_case format WPCS warning.

For consistency, this commit also renames the WP_Http::processResponse() argument to $response.

Follow-up to [8516], [51825], [51929], [51940], [52025], [52960], [52961], [52962], [52963].

Props azouamauriac.
See #54728.

#38 @SergeyBiryukov
2 years ago

In 52965:

Coding Standards: Rename the $theBody variable to $body in WP_Http_Curl::request().

This fixes a Variable "$theBody" is not in valid snake_case format WPCS warning.

Follow-up to [8516], [51825], [51929], [51931], [51940], [52025], [52960], [52961], [52962], [52963], [52964].

Props azouamauriac.
See #54728.

#39 @SergeyBiryukov
2 years ago

In 52966:

Coding Standards: Use strict comparison in wp-includes/class-wp-http-curl.php.

Follow-up to [17692], [25303], [29968].

See #54728.

kebbet commented on PR #2434:


2 years ago
#40

Thank you for your review @SergeyBiryukov. PR is updated now.

#41 @SergeyBiryukov
2 years ago

In 52967:

Coding Standards: Escape the comment post URL in _wp_dashboard_recent_comments_row().

Follow-up to [6705].

Props kebbet.
See #54728.

This ticket was mentioned in PR #2435 on WordPress/wordpress-develop by kebbet.


2 years ago
#43

Trac ticket:
A new set of imporovements. :)
https://core.trac.wordpress.org/ticket/54728

#44 @SergeyBiryukov
2 years ago

In 52972:

Coding Standards: Simplify some long conditions in wp-includes/class-wp-term-query.php.

This aims to improve readability and make the logic easier to parse at a glance.

Follow-up to [40293], [52970].

See #55352, #54728.

#45 @SergeyBiryukov
2 years ago

In 52973:

Coding Standards: Wrap the $this->request property in wp-includes/class-wp-*-query.php.

This aims to improve readability by fitting the values on a single screen to avoid horizontal scrolling.

See #54728.

#46 @SergeyBiryukov
2 years ago

In 52974:

Coding Standards: Remove a one-time $pieces variable in wp-includes/class-wp-*-query.php.

Use the existing $clauses variable instead for consistency.

See #54728.

#47 follow-up: @jrf
2 years ago

@SergeyBiryukov I'm not a fan of some of the recent changes.

Splitting long queries into separate parts and joining them using implode() makes the code less readable.

If you want to improve those, you can either use multi-line strings or use sprintf(), which both make for more readable code.

Example:

<?php
// Original code:
$old_request   = "SELECT $found_rows $distinct $fields FROM {$wpdb->posts} $join WHERE 1=1 $where $groupby $orderby $limits";

// More readable than implode:
$old_request   = "
    SELECT $found_rows $distinct $fields
    FROM {$wpdb->posts}
    $join
    WHERE 1=1 $where
    $groupby
    $orderby
    $limits";

// Alternative:
$old_request   = "sprintf(
    'SELECT %s %s %s FROM %s %s WHERE 1=1 %s %s %s %s',
    $found_rows,
    $distinct,
    $fields,
    $wpdb->posts,
    $join,
    $where,
    $groupby,
    $orderby,
    $limits
);

As for the changes from array() to compact(): this is a BC-break which should be reverted.
You are changing the array which is passed to the filters from a numerically indexed array to an associative array and any code which is hooked into those filters which was approaching the array using numeric indexes will now be broken.

See: https://3v4l.org/gUWOB

#48 in reply to: ↑ 47 @SergeyBiryukov
2 years ago

Replying to jrf:

As for the changes from array() to compact(): this is a BC-break which should be reverted.
You are changing the array which is passed to the filters from a numerically indexed array to an associative array and any code which is hooked into those filters which was approaching the array using numeric indexes will now be broken.

See: https://3v4l.org/gUWOB

Thanks for reviewing the changes and noting this!

I will address the first suggestion shortly.

For second one, however, unless I'm missing something, [52974] did not replace array() with compact(), but only relocated the compact() call while removing the redundant array() at the same time. All of these arrays were associative before the change, not numerically indexed.

As far as I can tell, there is no functional difference between this:

$array = compact( array( 'a', 'b' ) );

and this:

$array = compact( 'a', 'b' );

https://3v4l.org/5WRUs seems to confirm that.

#49 @jrf
2 years ago

For second one, however, unless I'm missing something, [52974] did not replace array() with compact(), but only relocated the compact() call while removing the redundant array() at the same time. All of these arrays were associative before the change, not numerically indexed.

@SergeyBiryukov Ah! I completely overlooked that those filters had a compact() within the filter call. My bad! (though still good to verify this was the case for all of them)

#50 @SergeyBiryukov
2 years ago

In 52977:

Coding Standards: Use multi-line strings for the $this->request property in wp-includes/class-wp-*-query.php.

This further improves the readability by replacing implode() calls with string interpolation.

Follow-up to [52973].

Props jrf.
See #54728.

@azouamauriac
2 years ago

Fix "WordPress.PHP.StrictComparisons.LooseComparison" in src/wp-admin/

#51 follow-up: @knutsp
2 years ago

<?php
1 === $_GET['test'] 

will never evaluate to true, as $_REQUEST values are all strings. Keep the loose comparison.

#52 in reply to: ↑ 51 @jrf
2 years ago

Replying to knutsp:

<?php
1 === $_GET['test'] 

will never evaluate to true, as $_REQUEST values are all strings. Keep the loose comparison.

Or do a strict comparison, but compare against the right type, i.e. '1' === $_GET['test'] ;-)

#53 @SergeyBiryukov
2 years ago

In 53175:

Query: Restore late compact() call for SQL clauses in wp-includes/class-wp-*-query.php.

This addresses a backward compatibility break where posts_groupby and other filters were applied, but their results were subsequently discarded and earlier values were used instead.

Follow-up to [52974].

Props nextend_ramona.
See #54728, #meta6273.

#54 @SergeyBiryukov
2 years ago

In 53183:

Coding Standards: Rename the $object variable to $attachment in several files.

This brings some consistency with a similar fragment in Custom_Image_Heade::step_2_manage_upload(), WP_Site_Icon::insert_attachment(), media_handle_upload(), and clarifies the type of the data.

Follow-up to [52946], [53137].

See #55327, #54728.

#55 @SergeyBiryukov
2 years ago

In 53195:

Coding Standards: Use more descriptive variable names in add_menu_classes().

Follow-up to [9578], [53193], [53194].

See #54728.

#56 @SergeyBiryukov
2 years ago

In 53196:

Coding Standards: Correct the $items_count variable in add_menu_classes().

Follow-up to [53195].

See #54728.

#57 @SergeyBiryukov
2 years ago

In 53197:

Coding Standards: Correct alignment in various files.

This fixes an Array double arrow not aligned correctly WPCS warning.

Follow-up to [53075], [53084], [53091], [53094], [53155], [53129].

See #54728.

#58 @SergeyBiryukov
2 years ago

In 53199:

Coding Standards: Simplify long conditions in xfn_check().

Add some comments for clarity.

Follow-up to [2051], [4990], [53198].

See #54728.

#59 @SergeyBiryukov
2 years ago

In 53322:

Coding Standards: Remove extra alignment level in the data provider for wp_validate_boolean() tests.

Follow-up to [46159], [46224], [52775], [52776], [52777].

See #54725, #54728.

#60 @audrasjb
2 years ago

In 53325:

Coding standards: Remove extra spaces in docblocks of the Walker_PageDropdown class.

Follow-up to [51779].

See #54728.

#61 @costdev
2 years ago

  • Resolution set to fixed
  • Status changed from new to closed

With 6.0 RC1 tomorrow and since coding standards updates usually touch code, I'm going to close this out.

If there are any more changes required between now and the final 6.0 release, this can be referenced and reopened if necessary with dev-reviewed.

#55647 is open for continuation during the 6.1 cycle.

Note: See TracTickets for help on using tickets.