diff --git a/wp-admin/includes/template.php b/wp-admin/includes/template.php index dd701fa766..168dc3bc07 100644 --- a/wp-admin/includes/template.php +++ b/wp-admin/includes/template.php @@ -691,13 +691,19 @@ function meta_form( $post = null ) { * @param int $limit Number of custom fields to retrieve. Default 30. */ $limit = apply_filters( 'postmeta_form_limit', 30 ); - $sql = "SELECT DISTINCT meta_key - FROM $wpdb->postmeta - WHERE meta_key NOT BETWEEN '_' AND '_z' - HAVING meta_key NOT LIKE %s - ORDER BY meta_key - LIMIT %d"; - $keys = $wpdb->get_col( $wpdb->prepare( $sql, $wpdb->esc_like( '_' ) . '%', $limit ) ); + + $keys = $wpdb->get_col( + $wpdb->prepare( + "SELECT DISTINCT meta_key + FROM $wpdb->postmeta + WHERE meta_key NOT BETWEEN '_' AND '_z' + HAVING meta_key NOT LIKE %s + ORDER BY meta_key + LIMIT %d", + $wpdb->esc_like( '_' ) . '%', + $limit + ) + ); } if ( $keys ) { @@ -784,7 +790,7 @@ function touch_time( $edit = 1, $for_post = 1, $tab_index = 0, $multi = 0 ) { $post = get_post(); if ( $for_post ) { - $edit = ! ( in_array( $post->post_status, array( 'draft', 'pending' ), true ) && ( ! $post->post_date_gmt || '0000-00-00 00:00:00' == $post->post_date_gmt ) ); + $edit = ! ( in_array( $post->post_status, array( 'draft', 'pending' ), true ) && ( ! $post->post_date_gmt || '0000-00-00 00:00:00' === $post->post_date_gmt ) ); } $tab_index_attribute = ''; @@ -896,13 +902,14 @@ function page_template_dropdown( $default = '', $post_type = 'page' ) { */ function parent_dropdown( $default = 0, $parent = 0, $level = 0, $post = null ) { global $wpdb; + $post = get_post( $post ); $items = $wpdb->get_results( $wpdb->prepare( "SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'page' ORDER BY menu_order", $parent ) ); if ( $items ) { foreach ( $items as $item ) { // A page cannot be its own parent. - if ( $post && $post->ID && $item->ID == $post->ID ) { + if ( $post && $post->ID && (int) $item->ID === $post->ID ) { continue; } @@ -932,7 +939,7 @@ function wp_dropdown_roles( $selected = '' ) { foreach ( $editable_roles as $role => $details ) { $name = translate_user_role( $details['name'] ); // Preselect specified role. - if ( $selected == $role ) { + if ( $selected === $role ) { $r .= "\n\t"; } else { $r .= "\n\t"; @@ -1057,7 +1064,7 @@ function add_meta_box( $id, $title, $callback, $screen = null, $context = 'advan } // If a core box was previously added or removed by a plugin, don't add. - if ( 'core' == $priority ) { + if ( 'core' === $priority ) { // If core box previously deleted, don't add. if ( false === $wp_meta_boxes[ $page ][ $a_context ][ $a_priority ][ $id ] ) { return; @@ -1067,7 +1074,7 @@ function add_meta_box( $id, $title, $callback, $screen = null, $context = 'advan * If box was added with default priority, give it core priority to * maintain sort order. */ - if ( 'default' == $a_priority ) { + if ( 'default' === $a_priority ) { $wp_meta_boxes[ $page ][ $a_context ]['core'][ $id ] = $wp_meta_boxes[ $page ][ $a_context ]['default'][ $id ]; unset( $wp_meta_boxes[ $page ][ $a_context ]['default'][ $id ] ); } @@ -1080,13 +1087,14 @@ function add_meta_box( $id, $title, $callback, $screen = null, $context = 'advan * Else, if we're adding to the sorted priority, we don't know the title * or callback. Grab them from the previously added context/priority. */ - } elseif ( 'sorted' == $priority ) { + } elseif ( 'sorted' === $priority ) { $title = $wp_meta_boxes[ $page ][ $a_context ][ $a_priority ][ $id ]['title']; $callback = $wp_meta_boxes[ $page ][ $a_context ][ $a_priority ][ $id ]['callback']; $callback_args = $wp_meta_boxes[ $page ][ $a_context ][ $a_priority ][ $id ]['args']; } + // An ID can be in only one priority and one context. - if ( $priority != $a_priority || $context != $a_context ) { + if ( $priority !== $a_priority || $context !== $a_context ) { unset( $wp_meta_boxes[ $page ][ $a_context ][ $a_priority ][ $id ] ); } } @@ -1227,15 +1235,15 @@ function _get_plugin_from_callback( $callback ) { * * @staticvar bool $already_sorted * - * @param string|WP_Screen $screen Screen identifier. If you have used add_menu_page() or + * @param string|WP_Screen $screen The screen identifier. If you have used add_menu_page() or * add_submenu_page() to create a new screen (and hence screen_id) * make sure your menu slug conforms to the limits of sanitize_key() * otherwise the 'screen' menu may not correctly render on your page. * @param string $context The screen context for which to display meta boxes. - * @param mixed $object Gets passed to the first parameter of the meta box callback function. + * @param mixed $object Gets passed to the meta box callback function as the first parameter. * Often this is the object that's the focus of the current screen, for * example a `WP_Post` or `WP_Comment` object. - * @return int number of meta_boxes + * @return int Number of meta_boxes. */ function do_meta_boxes( $screen, $context, $object ) { global $wp_meta_boxes; @@ -1275,7 +1283,7 @@ function do_meta_boxes( $screen, $context, $object ) { foreach ( array( 'high', 'sorted', 'core', 'default', 'low' ) as $priority ) { if ( isset( $wp_meta_boxes[ $page ][ $context ][ $priority ] ) ) { foreach ( (array) $wp_meta_boxes[ $page ][ $context ][ $priority ] as $box ) { - if ( false == $box || ! $box['title'] ) { + if ( false === $box || ! $box['title'] ) { continue; } @@ -1307,7 +1315,7 @@ function do_meta_boxes( $screen, $context, $object ) { // get_hidden_meta_boxes() doesn't apply in the block editor. $hidden_class = ( ! $screen->is_block_editor() && in_array( $box['id'], $hidden, true ) ) ? ' hide-if-js' : ''; echo '