Make WordPress Core

Changeset 54961


Ignore:
Timestamp:
12/13/2022 12:01:08 AM (4 years ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/post.php

    r54953 r54961  
    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;
    2028 
    2029         if ( isset( $object->label ) && empty( $object->labels['name'] ) ) {
    2030                 $object->labels['name'] = $object->label;
    2031         }
    2032 
    2033         if ( ! isset( $object->labels['singular_name'] ) && isset( $object->labels['name'] ) ) {
    2034                 $object->labels['singular_name'] = $object->labels['name'];
    2035         }
    2036 
    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;
    2039         }
    2040 
    2041         if ( ! isset( $object->labels['menu_name'] ) && isset( $object->labels['name'] ) ) {
    2042                 $object->labels['menu_name'] = $object->labels['name'];
    2043         }
    2044 
    2045         if ( ! isset( $object->labels['all_items'] ) && isset( $object->labels['menu_name'] ) ) {
    2046                 $object->labels['all_items'] = $object->labels['menu_name'];
    2047         }
    2048 
    2049         if ( ! isset( $object->labels['archives'] ) && isset( $object->labels['all_items'] ) ) {
    2050                 $object->labels['archives'] = $object->labels['all_items'];
     2026function _get_custom_object_labels( $data_object, $nohier_vs_hier_defaults ) {
     2027        $data_object->labels = (array) $data_object->labels;
     2028
     2029        if ( isset( $data_object->label ) && empty( $data_object->labels['name'] ) ) {
     2030                $data_object->labels['name'] = $data_object->label;
     2031        }
     2032
     2033        if ( ! isset( $data_object->labels['singular_name'] ) && isset( $data_object->labels['name'] ) ) {
     2034                $data_object->labels['singular_name'] = $data_object->labels['name'];
     2035        }
     2036
     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;
     2042        }
     2043
     2044        if ( ! isset( $data_object->labels['menu_name'] ) && isset( $data_object->labels['name'] ) ) {
     2045                $data_object->labels['menu_name'] = $data_object->labels['name'];
     2046        }
     2047
     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'];
     2050        }
     2051
     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];
    2056         }
    2057         $labels         = array_merge( $defaults, $object->labels );
    2058         $object->labels = (object) $object->labels;
     2058                $defaults[ $key ] = $data_object->hierarchical ? $value[1] : $value[0];
     2059        }
     2060
     2061        $labels              = array_merge( $defaults, $data_object->labels );
     2062        $data_object->labels = (object) $data_object->labels;
    20592063
    20602064        return (object) $labels;
    … …  
    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 ) {
     6335function wp_insert_attachment( $args, $file = false, $parent_post = 0, $wp_error = false, $fire_after_hooks = true ) {
    63326336        $defaults = array(
    63336337                'file'        => $file,
    … …  
    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
Note: See TracChangeset for help on using the changeset viewer.