Skip to content

Commit 508e9b9

Browse files
Code Modernization: Rename parameters that use reserved keywords in wp-includes/post.php.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names. This commit: * Renames the `$object` parameter to `$data_object` in `_get_custom_object_labels()`. * Renames the `$parent` parameter to `$parent_post` in `wp_insert_attachment()`. Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216], [53220], [53230], [53232], [53236], [53239], [53240], [53242], [53243], [53245], [53246], [53257], [53269], [53270], [53271], [53272], [53273], [53274], [53275], [53276], [53277], [53281], [53283], [53284], [53285], [53287], [53364], [53365], [54927], [54929], [54930], [54931], [54932], [54933], [54938], [54943], [54944], [54945], [54946], [54947], [54948], [54950], [54951], [54952], [54956], [54959], [54960]. Props jrf, aristath, poena, justinahinon, SergeyBiryukov. See #56788. git-svn-id: https://develop.svn.wordpress.org/trunk@54961 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 453161d commit 508e9b9

File tree

1 file changed

+26
-22
lines changed

1 file changed

+26
-22
lines changed

src/wp-includes/post.php

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2019,43 +2019,47 @@ function get_post_type_labels( $post_type_object ) {
20192019
* @since 3.0.0
20202020
* @access private
20212021
*
2022-
* @param object $object A custom-something object.
2022+
* @param object $data_object A custom-something object.
20232023
* @param array $nohier_vs_hier_defaults Hierarchical vs non-hierarchical default labels.
20242024
* @return object Object containing labels for the given custom-something object.
20252025
*/
2026-
function _get_custom_object_labels( $object, $nohier_vs_hier_defaults ) {
2027-
$object->labels = (array) $object->labels;
2026+
function _get_custom_object_labels( $data_object, $nohier_vs_hier_defaults ) {
2027+
$data_object->labels = (array) $data_object->labels;
20282028

2029-
if ( isset( $object->label ) && empty( $object->labels['name'] ) ) {
2030-
$object->labels['name'] = $object->label;
2029+
if ( isset( $data_object->label ) && empty( $data_object->labels['name'] ) ) {
2030+
$data_object->labels['name'] = $data_object->label;
20312031
}
20322032

2033-
if ( ! isset( $object->labels['singular_name'] ) && isset( $object->labels['name'] ) ) {
2034-
$object->labels['singular_name'] = $object->labels['name'];
2033+
if ( ! isset( $data_object->labels['singular_name'] ) && isset( $data_object->labels['name'] ) ) {
2034+
$data_object->labels['singular_name'] = $data_object->labels['name'];
20352035
}
20362036

2037-
if ( ! isset( $object->labels['name_admin_bar'] ) ) {
2038-
$object->labels['name_admin_bar'] = isset( $object->labels['singular_name'] ) ? $object->labels['singular_name'] : $object->name;
2037+
if ( ! isset( $data_object->labels['name_admin_bar'] ) ) {
2038+
$data_object->labels['name_admin_bar'] =
2039+
isset( $data_object->labels['singular_name'] )
2040+
? $data_object->labels['singular_name']
2041+
: $data_object->name;
20392042
}
20402043

2041-
if ( ! isset( $object->labels['menu_name'] ) && isset( $object->labels['name'] ) ) {
2042-
$object->labels['menu_name'] = $object->labels['name'];
2044+
if ( ! isset( $data_object->labels['menu_name'] ) && isset( $data_object->labels['name'] ) ) {
2045+
$data_object->labels['menu_name'] = $data_object->labels['name'];
20432046
}
20442047

2045-
if ( ! isset( $object->labels['all_items'] ) && isset( $object->labels['menu_name'] ) ) {
2046-
$object->labels['all_items'] = $object->labels['menu_name'];
2048+
if ( ! isset( $data_object->labels['all_items'] ) && isset( $data_object->labels['menu_name'] ) ) {
2049+
$data_object->labels['all_items'] = $data_object->labels['menu_name'];
20472050
}
20482051

2049-
if ( ! isset( $object->labels['archives'] ) && isset( $object->labels['all_items'] ) ) {
2050-
$object->labels['archives'] = $object->labels['all_items'];
2052+
if ( ! isset( $data_object->labels['archives'] ) && isset( $data_object->labels['all_items'] ) ) {
2053+
$data_object->labels['archives'] = $data_object->labels['all_items'];
20512054
}
20522055

20532056
$defaults = array();
20542057
foreach ( $nohier_vs_hier_defaults as $key => $value ) {
2055-
$defaults[ $key ] = $object->hierarchical ? $value[1] : $value[0];
2058+
$defaults[ $key ] = $data_object->hierarchical ? $value[1] : $value[0];
20562059
}
2057-
$labels = array_merge( $defaults, $object->labels );
2058-
$object->labels = (object) $object->labels;
2060+
2061+
$labels = array_merge( $defaults, $data_object->labels );
2062+
$data_object->labels = (object) $data_object->labels;
20592063

20602064
return (object) $labels;
20612065
}
@@ -6323,21 +6327,21 @@ function is_local_attachment( $url ) {
63236327
*
63246328
* @param string|array $args Arguments for inserting an attachment.
63256329
* @param string|false $file Optional. Filename.
6326-
* @param int $parent Optional. Parent post ID.
6330+
* @param int $parent_post Optional. Parent post ID.
63276331
* @param bool $wp_error Optional. Whether to return a WP_Error on failure. Default false.
63286332
* @param bool $fire_after_hooks Optional. Whether to fire the after insert hooks. Default true.
63296333
* @return int|WP_Error The attachment ID on success. The value 0 or WP_Error on failure.
63306334
*/
6331-
function wp_insert_attachment( $args, $file = false, $parent = 0, $wp_error = false, $fire_after_hooks = true ) {
6335+
function wp_insert_attachment( $args, $file = false, $parent_post = 0, $wp_error = false, $fire_after_hooks = true ) {
63326336
$defaults = array(
63336337
'file' => $file,
63346338
'post_parent' => 0,
63356339
);
63366340

63376341
$data = wp_parse_args( $args, $defaults );
63386342

6339-
if ( ! empty( $parent ) ) {
6340-
$data['post_parent'] = $parent;
6343+
if ( ! empty( $parent_post ) ) {
6344+
$data['post_parent'] = $parent_post;
63416345
}
63426346

63436347
$data['post_type'] = 'attachment';

0 commit comments

Comments
 (0)