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.
Built from https://develop.svn.wordpress.org/trunk@54961


git-svn-id: http://core.svn.wordpress.org/trunk@54513 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2022-12-13 00:03:15 +00:00
parent 41924d88a3
commit 4ffd8b005e
2 changed files with 27 additions and 23 deletions

View File

@ -2019,43 +2019,47 @@ function get_post_type_labels( $post_type_object ) {
* @since 3.0.0
* @access private
*
* @param object $object A custom-something object.
* @param object $data_object A custom-something object.
* @param array $nohier_vs_hier_defaults Hierarchical vs non-hierarchical default labels.
* @return object Object containing labels for the given custom-something object.
*/
function _get_custom_object_labels( $object, $nohier_vs_hier_defaults ) {
$object->labels = (array) $object->labels;
function _get_custom_object_labels( $data_object, $nohier_vs_hier_defaults ) {
$data_object->labels = (array) $data_object->labels;
if ( isset( $object->label ) && empty( $object->labels['name'] ) ) {
$object->labels['name'] = $object->label;
if ( isset( $data_object->label ) && empty( $data_object->labels['name'] ) ) {
$data_object->labels['name'] = $data_object->label;
}
if ( ! isset( $object->labels['singular_name'] ) && isset( $object->labels['name'] ) ) {
$object->labels['singular_name'] = $object->labels['name'];
if ( ! isset( $data_object->labels['singular_name'] ) && isset( $data_object->labels['name'] ) ) {
$data_object->labels['singular_name'] = $data_object->labels['name'];
}
if ( ! isset( $object->labels['name_admin_bar'] ) ) {
$object->labels['name_admin_bar'] = isset( $object->labels['singular_name'] ) ? $object->labels['singular_name'] : $object->name;
if ( ! isset( $data_object->labels['name_admin_bar'] ) ) {
$data_object->labels['name_admin_bar'] =
isset( $data_object->labels['singular_name'] )
? $data_object->labels['singular_name']
: $data_object->name;
}
if ( ! isset( $object->labels['menu_name'] ) && isset( $object->labels['name'] ) ) {
$object->labels['menu_name'] = $object->labels['name'];
if ( ! isset( $data_object->labels['menu_name'] ) && isset( $data_object->labels['name'] ) ) {
$data_object->labels['menu_name'] = $data_object->labels['name'];
}
if ( ! isset( $object->labels['all_items'] ) && isset( $object->labels['menu_name'] ) ) {
$object->labels['all_items'] = $object->labels['menu_name'];
if ( ! isset( $data_object->labels['all_items'] ) && isset( $data_object->labels['menu_name'] ) ) {
$data_object->labels['all_items'] = $data_object->labels['menu_name'];
}
if ( ! isset( $object->labels['archives'] ) && isset( $object->labels['all_items'] ) ) {
$object->labels['archives'] = $object->labels['all_items'];
if ( ! isset( $data_object->labels['archives'] ) && isset( $data_object->labels['all_items'] ) ) {
$data_object->labels['archives'] = $data_object->labels['all_items'];
}
$defaults = array();
foreach ( $nohier_vs_hier_defaults as $key => $value ) {
$defaults[ $key ] = $object->hierarchical ? $value[1] : $value[0];
$defaults[ $key ] = $data_object->hierarchical ? $value[1] : $value[0];
}
$labels = array_merge( $defaults, $object->labels );
$object->labels = (object) $object->labels;
$labels = array_merge( $defaults, $data_object->labels );
$data_object->labels = (object) $data_object->labels;
return (object) $labels;
}
@ -6323,12 +6327,12 @@ function is_local_attachment( $url ) {
*
* @param string|array $args Arguments for inserting an attachment.
* @param string|false $file Optional. Filename.
* @param int $parent Optional. Parent post ID.
* @param int $parent_post Optional. Parent post ID.
* @param bool $wp_error Optional. Whether to return a WP_Error on failure. Default false.
* @param bool $fire_after_hooks Optional. Whether to fire the after insert hooks. Default true.
* @return int|WP_Error The attachment ID on success. The value 0 or WP_Error on failure.
*/
function wp_insert_attachment( $args, $file = false, $parent = 0, $wp_error = false, $fire_after_hooks = true ) {
function wp_insert_attachment( $args, $file = false, $parent_post = 0, $wp_error = false, $fire_after_hooks = true ) {
$defaults = array(
'file' => $file,
'post_parent' => 0,
@ -6336,8 +6340,8 @@ function wp_insert_attachment( $args, $file = false, $parent = 0, $wp_error = fa
$data = wp_parse_args( $args, $defaults );
if ( ! empty( $parent ) ) {
$data['post_parent'] = $parent;
if ( ! empty( $parent_post ) ) {
$data['post_parent'] = $parent_post;
}
$data['post_type'] = 'attachment';

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.2-alpha-54960';
$wp_version = '6.2-alpha-54961';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.