Make WordPress Core

Opened 5 months ago

Closed 3 days ago

#64897 closed task (blessed) (fixed)

Coding Standards fixes for 7.1

Reported by: desrosj Owned by:
Priority: normal Milestone: 7.1
Component: General Version:
Severity: normal Keywords: has-patch
Cc: Focuses: coding-standards

Description

Previously:

Change History (50)

This ticket was mentioned in PR #11952 on WordPress/wordpress-develop by @khokansardar.


3 months ago
#1

  • Keywords has-patch added

Renames abbreviated local variables in wp-admin media and file handling code to follow WordPress Naming Conventions:

  • $ext$extension
  • $ext_type$extension_type
  • $id3data$id3_data

Follow-up to [61224].

@mukesh27 commented on PR #11952:


2 months ago
#2

Mark duplicate of #10780

This ticket was mentioned in PR #12015 on WordPress/wordpress-develop by @mukesh27.


2 months ago
#3

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

## Use of AI Tools
N/A

@mukesh27 commented on PR #12015:


2 months ago
#5

I noticed that the WP_REST_Icons_Controller class is also missing the @since tag. Should we address that in a separate PR?

Yes. See #12024

#6 @wildworks
2 months ago

In 62434:

Docs: Add missing @since tags to WP_Icons_Registry.

Add the missing @since 7.0.0 tags to the properties, constructor, and methods of the WP_Icons_Registry class to document the version in which they were introduced.

Follow-up to [61674].

Props mukesh27, wildworks.
See #64897.

#7 @wildworks
2 months ago

In 62435:

Docs: Add missing @since tags to WP_REST_Icons_Controller.

Add the missing @since 7.0.0 tags to the constructor and methods of the WP_REST_Icons_Controller class to document the version in which they were introduced.

Follow-up to [61674].

Props mukesh27, wildworks.
See #64897.

@wildworks commented on PR #12024:


2 months ago
#8

This PR was committed by r62435.

@wildworks commented on PR #12015:


2 months ago
#9

This PR was committed by r62434.

This ticket was mentioned in PR #10780 on WordPress/wordpress-develop by @huzaifaalmesbah.


2 months ago
#10

This PR updates variable names in wp-admin includes to strictly adhere to WordPress Coding Standards (lowercase with underscores, no unnecessary abbreviations). These changes focus on local variables to avoid backward compatibility issues.

Trac ticket:
https://core.trac.wordpress.org/ticket/64897
https://core.trac.wordpress.org/ticket/64226

### Changes

  • src/wp-admin/includes/post.php: Renamed $id3data to $id3_data in edit_post().
  • src/wp-admin/includes/media.php: Renamed $ext to $extension and $ext_type to $extension_type in media_handle_upload() and media_send_to_editor().
  • src/wp-admin/includes/image-edit.php: Renamed $ext to $extension in wp_image_editor().

### Testing Instructions

  1. Media Upload: Upload image, audio, and video files. Ensure uploads complete successfully and correct icons/metadata are displayed.
  2. Image Editing: Go to Media Library, select an image, click "Edit Image", perform a crop or rotation, and save. Confirm the edit is applied successfully.
  3. General Admin: Edit a post and verify the page loads and saves correctly without any PHP notices or errors.

This ticket was mentioned in PR #12088 on WordPress/wordpress-develop by @Soean.


2 months ago
#11

This pull request makes a minor improvement to the documentation of the update_size method in the WP_Image_Editor_GDclaaa. The change clarifies that the $width and $height parameters can accept either an int or false as their value.

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

This ticket was mentioned in PR #12119 on WordPress/wordpress-develop by @Soean.


2 months ago
#12

This PR removes a unused local variable $all_class_directives from the data_wp_class_processor() function.

Follow-up to r58327.

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

This ticket was mentioned in PR #12144 on WordPress/wordpress-develop by @Soean.


2 months ago
#13

Replace Chr() and Ord() with their canonical lowercase forms chr() and ord().

This is flagged as a case-sensitivity violation by the upcoming PHP 8.6 RFC, which will emit E_DEPRECATED for function references that don't match their declared casing. Fixing it now keeps WordPress ahead of the deprecation.

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

#14 @SergeyBiryukov
8 weeks ago

In 62498:

Coding Standards: Correct casing of chr() and ord() in class-pclzip.php.

This replaces Chr() and Ord() with their canonical lowercase forms chr() and ord().

This is flagged as a case-sensitivity violation by the upcoming PHP 8.6 RFC, which will emit E_DEPRECATED for function references that don't match their declared casing. Fixing it now keeps WordPress ahead of the deprecation.

Props Soean.
See #64897.

#15 @SergeyBiryukov
8 weeks ago

In 62499:

Coding Standards: Remove unused local variable $all_class_directives.

This removes an unused variable in WP_Interactivity_API::data_wp_class_processor().

Follow-up to [57563], [61020].

Props Soean.
See #64897.

This ticket was mentioned in PR #12174 on WordPress/wordpress-develop by @Soean.


8 weeks ago
#18

Remove redundant arguments of add_filter(). Arguments match the parameters' default values.

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

#19 @SergeyBiryukov
8 weeks ago

In 62503:

Coding Standards: Remove redundant arguments of add_filter().

The arguments match the parameters' default values.

Follow-up to [61019].

Props Soean.
See #64897.

#21 @SergeyBiryukov
7 weeks ago

In 62517:

Media: Make ::update_size() parameters consistent across image editors.

Includes:

  • Standardizing default values on null vs. false.
  • Updating the documentation to correct parameter types.
  • Adding missing parameter descriptions.

Follow-up to [22094].

Props Soean, mukesh27, SergeyBiryukov.
See #64897.

#23 @westonruter
5 weeks ago

In 62635:

Docs: Modernize and improve specificity of types in WP_Error class.

This brings the WP_Error class to full PHPStan rule level 10 compliance.

Also make use of null coalescing operator where appropriate, and simplify has_errors() method.

Developed in https://github.com/WordPress/wordpress-develop/pull/12405.
Follow-up to r42761, r49115, r49116.

See #64898, #64897.

#24 @SergeyBiryukov
4 weeks ago

In 62699:

Coding Standards: Use in_array() instead of array_search() for existence checks.

Several places in core use array_search() purely to determine whether a value exists in an array, comparing the result against false. In these cases the returned key/position is never used, so in_array() expresses the intent more clearly and avoids computing a return value that is discarded.

This commit replaces those existence-only array_search() calls with in_array(). The strict (true) comparison flag is preserved in every case, so there is no change in behavior.

Props Soean.
See #64897.

This ticket was mentioned in PR #12502 on WordPress/wordpress-develop by @mukesh27.


4 weeks ago
#25

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

## Use of AI Tools

#27 @SergeyBiryukov
4 weeks ago

In 62727:

Coding Standards: Correct HTML tags in a customizer preview error message.

Follow-up to [48609].

Props mukesh27, westonruter.
See #64897.

@SergeyBiryukov commented on PR #12502:


4 weeks ago
#28

Thanks for the PR! Merged in r62727.

This ticket was mentioned in PR #12495 on WordPress/wordpress-develop by @Soean.


4 weeks ago
#29

The str_contains() function was introduced in PHP 8.0 and a polyfill is available in WordPress Core, making the intent of the check clearer than comparing the result of strpos() against false.

Follow-up to [62687]

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

This ticket was mentioned in PR #12417 on WordPress/wordpress-develop by @Soean.


4 weeks ago
#30

Replace $array[ count( $array ) - 1 ] constructs with the array_last() function (added in PHP 8.5, polyfilled in compat.php) for improved readability.

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

This ticket was mentioned in PR #12296 on WordPress/wordpress-develop by @Soean.


4 weeks ago
#31

This change modernizes WP_REST_View_Config_Controller by replacing several isset( $x ) ? $x : $default ternary expressions with the equivalent null coalescing operator (??). The null coalescing operator uses the same isset() semantics — it returns the fallback when the key is either missing or null, so the behavior is identical to the previous code.

Follow-up to [61403]

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

This ticket was mentioned in PR #12602 on WordPress/wordpress-develop by @Soean.


3 weeks ago
#32

## Description
Replaces a handful of verbose isset() guard patterns with the null coalescing operator (??):

// Before
if ( isset( $x ) ) {
    return $x;
} else {
    return $default;
}
    
// After
return $x ?? $default;

Both forms are functionally identical; ?? is shorter and clearer.

## Notes

  • No behavior change; PHP's minimum version already supports ??.

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

@westonruter commented on PR #12417:


3 weeks ago
#33

Nice thing about this is it is resilient against the possibility of not getting the actual last item in the array if the array is not a list, such as if the integer-indexed array becomes sparse: https://3v4l.org/cMG4N#v8.5.8

This ticket was mentioned in PR #12725 on WordPress/wordpress-develop by @westonruter.


12 days ago
#34

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

Correction: This was intended for #64898

@westonruter commented on PR #12725:


11 days ago
#35

@luisherranz Would you please push up commits to this branch that apply your suggestions?

Another option to consider would be to replicate in PHP what JavaScript's String() does. An object becomes [object Object], an array becomes a comma join, and INF and NAN become "Infinity" and "NaN", although I'm not sure if, especially the [object Object] part, would make much sense.

IMO, it would be better to have a warning so that the author would be more readily discover their usage error.

#36 @SergeyBiryukov
10 days ago

In 62895:

Code Modernization: Use the null coalescing operator for isset() return checks.

This commit replaces a handful of verbose isset() guard patterns with the null coalescing operator (??):

<?php
// Before
if ( isset( $x ) ) {
    return $x;
} else {
    return $default;
}
    
// After
return $x ?? $default;

Both forms are functionally identical; ?? is shorter and clearer.

Developed in https://github.com/WordPress/wordpress-develop/pull/12602.

Follow-up to [61463], [61470], [62870].

Props Soean, westonruter.
See #64897.

@SergeyBiryukov commented on PR #12602:


10 days ago
#37

Thanks for the PR! Merged in r62895.

@westonruter commented on PR #12725:


9 days ago
#38

This is a bit unexpected to me , but it also is the behavior in trunk, which I just realized.

@luisherranz I think I got it. How about 0d8e02388419a7fc21e9d08c96ef6f61f6483ec4?

#39 @SergeyBiryukov
9 days ago

In 62949:

Code Modernization: Use null coalescing operator instead of ternaries.

This change modernizes WP_REST_View_Config_Controller by replacing several isset( $x ) ? $x : $default ternary expressions with the equivalent null coalescing operator (??). The null coalescing operator uses the same isset() semantics — it returns the fallback when the key is either missing or null, so the behavior is identical to the previous code.

Developed in https://github.com/WordPress/wordpress-develop/pull/12296.

Follow-up to [61403], [62547].

Props Soean.
See #64897.

@SergeyBiryukov commented on PR #12296:


9 days ago
#40

Thanks for the PR! Merged in r62949.

@luisherranz commented on PR #12725:


9 days ago
#41

@luisherranz I think I got it. How about https://github.com/WordPress/wordpress-develop/commit/0d8e02388419a7fc21e9d08c96ef6f61f6483ec4?

Looks great! I'll prepare the fix to sync it in Gutenberg, thank you very much! 🙂

@luisherranz commented on PR #12725:


8 days ago
#42

Gutenberg PR for the syntax backport here:

#43 @SergeyBiryukov
8 days ago

In 62956:

Coding Standards: Use array_last() to get the last array element.

This commit replaces $array[ count( $array ) - 1 ] constructs with the array_last() function (added in PHP 8.5 and polyfilled as of WordPress 6.9) for improved readability.

Follow-up to [60672].

Props Soean, westonruter.
See #64897.

#45 @SergeyBiryukov
7 days ago

In 62964:

HTML API: Use str_contains() instead of strpos() in WP_HTML_Tag_Processor.

The str_contains() function was introduced in PHP 8.0 and a polyfill is available in WordPress Core, making the intent of the check clearer than comparing the result of strpos() against false.

Follow-up to [62687].

Props Soean, mukesh27, westonruter.
See #64897.

@SergeyBiryukov commented on PR #12495:


6 days ago
#46

Thanks for the PR! Merged in r62964.

This ticket was mentioned in PR #12858 on WordPress/wordpress-develop by @Soean.


3 days ago
#47

## Description

composer run format currently reports two Generic.Formatting.MultipleStatementAlignment warnings. This PR applies the auto-fixes so that a clean checkout of trunk passes without pending changes.

## Warnings

FILE: src/wp-admin/includes/class-wp-users-list-table.php
 638 | WARNING | [x] Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

FILE: src/wp-includes/pluggable.php
2379 | WARNING | [x] Equals sign not aligned correctly; expected 1 space but found 2 spaces

## When were these introduced?

Both were introduced during the 7.1 development cycle, so no released version of WordPress is affected.

File Introduced in Ticket
src/wp-admin/includes/class-wp-users-list-table.php r62838 – *Administration: Use post title column as table header in post lists* (2026-07-23) #32892
src/wp-includes/pluggable.php r62590 – *Notifications: Remove the username from the new user notification email* (2026-06-30) #63085

In r62838 the new $tag assignment was added directly above an existing $row .= assignment without aligning the block. In r62590 the line above $message was removed, leaving $message with the alignment padding of a block that no longer exists.

These are whitespace-only changes, so no functional testing is required.

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

#48 @SergeyBiryukov
3 days ago

In 63027:

Coding Standards: Correct alignment of assignment operators.

This resolves a WPCS warning:

Equals sign not aligned with surrounding assignments

Follow-up to [62590], [62838].

Props Soean.
See #64897.

@SergeyBiryukov commented on PR #12858:


3 days ago
#49

Thanks for the PR! Merged in r63027.

#50 @desrosj
3 days ago

  • Resolutionfixed
  • Status newclosed

With 7.1 RC1 due out any minute, I'm going to close this one out.

#65818 has been opened for the 7.2 release cycle.

Note: See TracTickets for help on using tickets.