mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-09-01 14:40:19 +00:00
Coding Standards: Restore more descriptive variable names in a few class methods.
When various methods parameters in child classes were renamed to `$item` to match the parent class for PHP 8 named parameter support, most of the methods restored the more descriptive, specific name at the beginning for better readability, with several exceptions for methods consisting only of a few lines. To avoid confusion about why some methods do that and some don't, this commit aims to bring more consistency to the code, specifically in list tables' `::column_default()` methods. Follow-up to [51728], [51737], [51786]. See #58831. git-svn-id: https://develop.svn.wordpress.org/trunk@56586 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -59,7 +59,8 @@ class Walker_CategoryDropdown extends Walker {
|
||||
public function start_el( &$output, $data_object, $depth = 0, $args = array(), $current_object_id = 0 ) {
|
||||
// Restores the more descriptive, specific name for use within this method.
|
||||
$category = $data_object;
|
||||
$pad = str_repeat( ' ', $depth * 3 );
|
||||
|
||||
$pad = str_repeat( ' ', $depth * 3 );
|
||||
|
||||
/** This filter is documented in wp-includes/category-template.php */
|
||||
$cat_name = apply_filters( 'list_cats', $category->name, $category );
|
||||
|
||||
@@ -62,7 +62,8 @@ class Walker_PageDropdown extends Walker {
|
||||
public function start_el( &$output, $data_object, $depth = 0, $args = array(), $current_object_id = 0 ) {
|
||||
// Restores the more descriptive, specific name for use within this method.
|
||||
$page = $data_object;
|
||||
$pad = str_repeat( ' ', $depth * 3 );
|
||||
|
||||
$pad = str_repeat( ' ', $depth * 3 );
|
||||
|
||||
if ( ! isset( $args['value_field'] ) || ! isset( $page->{$args['value_field']} ) ) {
|
||||
$args['value_field'] = 'ID';
|
||||
|
||||
@@ -104,7 +104,8 @@ class Walker_Page extends Walker {
|
||||
*/
|
||||
public function start_el( &$output, $data_object, $depth = 0, $args = array(), $current_object_id = 0 ) {
|
||||
// Restores the more descriptive, specific name for use within this method.
|
||||
$page = $data_object;
|
||||
$page = $data_object;
|
||||
|
||||
$current_page_id = $current_object_id;
|
||||
|
||||
if ( isset( $args['item_spacing'] ) && 'preserve' === $args['item_spacing'] ) {
|
||||
|
||||
@@ -731,7 +731,8 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller {
|
||||
*/
|
||||
public function prepare_item_for_response( $item, $request ) {
|
||||
// Restores the more descriptive, specific name for use within this method.
|
||||
$post = $item;
|
||||
$post = $item;
|
||||
|
||||
$response = parent::prepare_item_for_response( $post, $request );
|
||||
$fields = $this->get_fields_for_response( $request );
|
||||
$data = $response->get_data();
|
||||
|
||||
@@ -409,10 +409,10 @@ class WP_REST_Autosaves_Controller extends WP_REST_Revisions_Controller {
|
||||
*/
|
||||
public function prepare_item_for_response( $item, $request ) {
|
||||
// Restores the more descriptive, specific name for use within this method.
|
||||
$post = $item;
|
||||
$response = $this->revisions_controller->prepare_item_for_response( $post, $request );
|
||||
$post = $item;
|
||||
|
||||
$fields = $this->get_fields_for_response( $request );
|
||||
$response = $this->revisions_controller->prepare_item_for_response( $post, $request );
|
||||
$fields = $this->get_fields_for_response( $request );
|
||||
|
||||
if ( in_array( 'preview_link', $fields, true ) ) {
|
||||
$parent_id = wp_is_post_autosave( $post );
|
||||
|
||||
@@ -246,8 +246,9 @@ class WP_REST_Block_Types_Controller extends WP_REST_Controller {
|
||||
public function prepare_item_for_response( $item, $request ) {
|
||||
// Restores the more descriptive, specific name for use within this method.
|
||||
$block_type = $item;
|
||||
$fields = $this->get_fields_for_response( $request );
|
||||
$data = array();
|
||||
|
||||
$fields = $this->get_fields_for_response( $request );
|
||||
$data = array();
|
||||
|
||||
if ( rest_is_field_included( 'attributes', $fields ) ) {
|
||||
$data['attributes'] = $block_type->get_attributes();
|
||||
|
||||
@@ -1039,8 +1039,9 @@ class WP_REST_Comments_Controller extends WP_REST_Controller {
|
||||
public function prepare_item_for_response( $item, $request ) {
|
||||
// Restores the more descriptive, specific name for use within this method.
|
||||
$comment = $item;
|
||||
$fields = $this->get_fields_for_response( $request );
|
||||
$data = array();
|
||||
|
||||
$fields = $this->get_fields_for_response( $request );
|
||||
$data = array();
|
||||
|
||||
if ( in_array( 'id', $fields, true ) ) {
|
||||
$data['id'] = (int) $comment->comment_ID;
|
||||
|
||||
@@ -367,8 +367,8 @@ class WP_REST_Global_Styles_Controller extends WP_REST_Controller {
|
||||
}
|
||||
|
||||
// Base fields for every post.
|
||||
$data = array();
|
||||
$fields = $this->get_fields_for_response( $request );
|
||||
$data = array();
|
||||
|
||||
if ( rest_is_field_included( 'id', $fields ) ) {
|
||||
$data['id'] = $post->ID;
|
||||
@@ -603,8 +603,8 @@ class WP_REST_Global_Styles_Controller extends WP_REST_Controller {
|
||||
}
|
||||
|
||||
$theme = WP_Theme_JSON_Resolver::get_merged_data( 'theme' );
|
||||
$data = array();
|
||||
$fields = $this->get_fields_for_response( $request );
|
||||
$data = array();
|
||||
|
||||
if ( rest_is_field_included( 'settings', $fields ) ) {
|
||||
$data['settings'] = $theme->get_settings();
|
||||
|
||||
@@ -168,7 +168,8 @@ class WP_REST_Menu_Locations_Controller extends WP_REST_Controller {
|
||||
*/
|
||||
public function prepare_item_for_response( $item, $request ) {
|
||||
// Restores the more descriptive, specific name for use within this method.
|
||||
$location = $item;
|
||||
$location = $item;
|
||||
|
||||
$locations = get_nav_menu_locations();
|
||||
$menu = isset( $locations[ $location->name ] ) ? $locations[ $location->name ] : 0;
|
||||
|
||||
|
||||
@@ -193,7 +193,8 @@ class WP_REST_Pattern_Directory_Controller extends WP_REST_Controller {
|
||||
*/
|
||||
public function prepare_item_for_response( $item, $request ) {
|
||||
// Restores the more descriptive, specific name for use within this method.
|
||||
$raw_pattern = $item;
|
||||
$raw_pattern = $item;
|
||||
|
||||
$prepared_pattern = array(
|
||||
'id' => absint( $raw_pattern->id ),
|
||||
'title' => sanitize_text_field( $raw_pattern->title->rendered ),
|
||||
|
||||
@@ -222,6 +222,7 @@ class WP_REST_Post_Statuses_Controller extends WP_REST_Controller {
|
||||
public function prepare_item_for_response( $item, $request ) {
|
||||
// Restores the more descriptive, specific name for use within this method.
|
||||
$status = $item;
|
||||
|
||||
$fields = $this->get_fields_for_response( $request );
|
||||
$data = array();
|
||||
|
||||
|
||||
@@ -176,7 +176,8 @@ class WP_REST_Post_Types_Controller extends WP_REST_Controller {
|
||||
*/
|
||||
public function prepare_item_for_response( $item, $request ) {
|
||||
// Restores the more descriptive, specific name for use within this method.
|
||||
$post_type = $item;
|
||||
$post_type = $item;
|
||||
|
||||
$taxonomies = wp_list_filter( get_object_taxonomies( $post_type->name, 'objects' ), array( 'show_in_rest' => true ) );
|
||||
$taxonomies = wp_list_pluck( $taxonomies, 'name' );
|
||||
$base = ! empty( $post_type->rest_base ) ? $post_type->rest_base : $post_type->name;
|
||||
|
||||
@@ -1748,7 +1748,8 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
||||
*/
|
||||
public function prepare_item_for_response( $item, $request ) {
|
||||
// Restores the more descriptive, specific name for use within this method.
|
||||
$post = $item;
|
||||
$post = $item;
|
||||
|
||||
$GLOBALS['post'] = $post;
|
||||
|
||||
setup_postdata( $post );
|
||||
|
||||
@@ -547,7 +547,8 @@ class WP_REST_Revisions_Controller extends WP_REST_Controller {
|
||||
*/
|
||||
public function prepare_item_for_response( $item, $request ) {
|
||||
// Restores the more descriptive, specific name for use within this method.
|
||||
$post = $item;
|
||||
$post = $item;
|
||||
|
||||
$GLOBALS['post'] = $post;
|
||||
|
||||
setup_postdata( $post );
|
||||
|
||||
@@ -195,6 +195,7 @@ class WP_REST_Search_Controller extends WP_REST_Controller {
|
||||
public function prepare_item_for_response( $item, $request ) {
|
||||
// Restores the more descriptive, specific name for use within this method.
|
||||
$item_id = $item;
|
||||
|
||||
$handler = $this->get_search_handler( $request );
|
||||
if ( is_wp_error( $handler ) ) {
|
||||
return new WP_REST_Response();
|
||||
|
||||
@@ -320,8 +320,9 @@ class WP_REST_Sidebars_Controller extends WP_REST_Controller {
|
||||
|
||||
// Restores the more descriptive, specific name for use within this method.
|
||||
$raw_sidebar = $item;
|
||||
$id = $raw_sidebar['id'];
|
||||
$sidebar = array( 'id' => $id );
|
||||
|
||||
$id = $raw_sidebar['id'];
|
||||
$sidebar = array( 'id' => $id );
|
||||
|
||||
if ( isset( $wp_registered_sidebars[ $id ] ) ) {
|
||||
$registered_sidebar = $wp_registered_sidebars[ $id ];
|
||||
|
||||
@@ -209,7 +209,8 @@ class WP_REST_Taxonomies_Controller extends WP_REST_Controller {
|
||||
public function prepare_item_for_response( $item, $request ) {
|
||||
// Restores the more descriptive, specific name for use within this method.
|
||||
$taxonomy = $item;
|
||||
$base = ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name;
|
||||
|
||||
$base = ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name;
|
||||
|
||||
$fields = $this->get_fields_for_response( $request );
|
||||
$data = array();
|
||||
|
||||
@@ -231,9 +231,10 @@ class WP_REST_Themes_Controller extends WP_REST_Controller {
|
||||
*/
|
||||
public function prepare_item_for_response( $item, $request ) {
|
||||
// Restores the more descriptive, specific name for use within this method.
|
||||
$theme = $item;
|
||||
$data = array();
|
||||
$theme = $item;
|
||||
|
||||
$fields = $this->get_fields_for_response( $request );
|
||||
$data = array();
|
||||
|
||||
if ( rest_is_field_included( 'stylesheet', $fields ) ) {
|
||||
$data['stylesheet'] = $theme->get_stylesheet();
|
||||
|
||||
@@ -984,9 +984,10 @@ class WP_REST_Users_Controller extends WP_REST_Controller {
|
||||
*/
|
||||
public function prepare_item_for_response( $item, $request ) {
|
||||
// Restores the more descriptive, specific name for use within this method.
|
||||
$user = $item;
|
||||
$data = array();
|
||||
$user = $item;
|
||||
|
||||
$fields = $this->get_fields_for_response( $request );
|
||||
$data = array();
|
||||
|
||||
if ( in_array( 'id', $fields, true ) ) {
|
||||
$data['id'] = $user->ID;
|
||||
|
||||
@@ -297,8 +297,9 @@ class WP_REST_Widget_Types_Controller extends WP_REST_Controller {
|
||||
public function prepare_item_for_response( $item, $request ) {
|
||||
// Restores the more descriptive, specific name for use within this method.
|
||||
$widget_type = $item;
|
||||
$fields = $this->get_fields_for_response( $request );
|
||||
$data = array(
|
||||
|
||||
$fields = $this->get_fields_for_response( $request );
|
||||
$data = array(
|
||||
'id' => $widget_type['id'],
|
||||
);
|
||||
|
||||
|
||||
@@ -60,7 +60,8 @@ class WP_Sitemaps_Taxonomies extends WP_Sitemaps_Provider {
|
||||
*/
|
||||
public function get_url_list( $page_num, $object_subtype = '' ) {
|
||||
// Restores the more descriptive, specific name for use within this method.
|
||||
$taxonomy = $object_subtype;
|
||||
$taxonomy = $object_subtype;
|
||||
|
||||
$supported_types = $this->get_object_subtypes();
|
||||
|
||||
// Bail early if the queried taxonomy is not supported.
|
||||
|
||||
Reference in New Issue
Block a user