diff -r c7c34916027a -r 177826044cd9 wp/wp-admin/includes/template.php --- a/wp/wp-admin/includes/template.php Mon Oct 14 18:06:33 2019 +0200 +++ b/wp/wp-admin/includes/template.php Mon Oct 14 18:28:13 2019 +0200 @@ -29,8 +29,8 @@ * $selected_cats must not be an array. Default 0. * @param int $descendants_and_self Optional. ID of the category to output along with its descendants. * Default 0. - * @param array $selected_cats Optional. List of categories to mark as checked. Default false. - * @param array $popular_cats Optional. List of categories to receive the "popular-category" class. + * @param int[] $selected_cats Optional. Array of category IDs to mark as checked. Default false. + * @param int[] $popular_cats Optional. Array of category IDs to receive the "popular-category" class. * Default false. * @param object $walker Optional. Walker object to use to build the output. * Default is a Walker_Category_Checklist instance. @@ -38,14 +38,17 @@ * the top of the list. Default true. */ function wp_category_checklist( $post_id = 0, $descendants_and_self = 0, $selected_cats = false, $popular_cats = false, $walker = null, $checked_ontop = true ) { - wp_terms_checklist( $post_id, array( - 'taxonomy' => 'category', - 'descendants_and_self' => $descendants_and_self, - 'selected_cats' => $selected_cats, - 'popular_cats' => $popular_cats, - 'walker' => $walker, - 'checked_ontop' => $checked_ontop - ) ); + wp_terms_checklist( + $post_id, + array( + 'taxonomy' => 'category', + 'descendants_and_self' => $descendants_and_self, + 'selected_cats' => $selected_cats, + 'popular_cats' => $popular_cats, + 'walker' => $walker, + 'checked_ontop' => $checked_ontop, + ) + ); } /** @@ -62,8 +65,8 @@ * * @type int $descendants_and_self ID of the category to output along with its descendants. * Default 0. - * @type array $selected_cats List of categories to mark as checked. Default false. - * @type array $popular_cats List of categories to receive the "popular-category" class. + * @type int[] $selected_cats Array of category IDs to mark as checked. Default false. + * @type int[] $popular_cats Array of category IDs to receive the "popular-category" class. * Default false. * @type object $walker Walker object to use to build the output. * Default is a Walker_Category_Checklist instance. @@ -75,14 +78,14 @@ * } */ function wp_terms_checklist( $post_id = 0, $args = array() ) { - $defaults = array( + $defaults = array( 'descendants_and_self' => 0, - 'selected_cats' => false, - 'popular_cats' => false, - 'walker' => null, - 'taxonomy' => 'category', - 'checked_ontop' => true, - 'echo' => true, + 'selected_cats' => false, + 'popular_cats' => false, + 'walker' => null, + 'taxonomy' => 'category', + 'checked_ontop' => true, + 'echo' => true, ); /** @@ -105,12 +108,12 @@ $walker = $r['walker']; } - $taxonomy = $r['taxonomy']; + $taxonomy = $r['taxonomy']; $descendants_and_self = (int) $r['descendants_and_self']; $args = array( 'taxonomy' => $taxonomy ); - $tax = get_taxonomy( $taxonomy ); + $tax = get_taxonomy( $taxonomy ); $args['disabled'] = ! current_user_can( $tax->cap->assign_terms ); $args['list_only'] = ! empty( $r['list_only'] ); @@ -125,21 +128,27 @@ if ( is_array( $r['popular_cats'] ) ) { $args['popular_cats'] = $r['popular_cats']; } else { - $args['popular_cats'] = get_terms( $taxonomy, array( - 'fields' => 'ids', - 'orderby' => 'count', - 'order' => 'DESC', - 'number' => 10, - 'hierarchical' => false - ) ); + $args['popular_cats'] = get_terms( + $taxonomy, + array( + 'fields' => 'ids', + 'orderby' => 'count', + 'order' => 'DESC', + 'number' => 10, + 'hierarchical' => false, + ) + ); } if ( $descendants_and_self ) { - $categories = (array) get_terms( $taxonomy, array( - 'child_of' => $descendants_and_self, - 'hierarchical' => 0, - 'hide_empty' => 0 - ) ); - $self = get_term( $descendants_and_self, $taxonomy ); + $categories = (array) get_terms( + $taxonomy, + array( + 'child_of' => $descendants_and_self, + 'hierarchical' => 0, + 'hide_empty' => 0, + ) + ); + $self = get_term( $descendants_and_self, $taxonomy ); array_unshift( $categories, $self ); } else { $categories = (array) get_terms( $taxonomy, array( 'get' => 'all' ) ); @@ -150,12 +159,12 @@ if ( $r['checked_ontop'] ) { // Post process $categories rather than adding an exclude to the get_terms() query to keep the query the same across all posts (for any query cache) $checked_categories = array(); - $keys = array_keys( $categories ); + $keys = array_keys( $categories ); foreach ( $keys as $k ) { - if ( in_array( $categories[$k]->term_id, $args['selected_cats'] ) ) { - $checked_categories[] = $categories[$k]; - unset( $categories[$k] ); + if ( in_array( $categories[ $k ]->term_id, $args['selected_cats'] ) ) { + $checked_categories[] = $categories[ $k ]; + unset( $categories[ $k ] ); } } @@ -191,21 +200,31 @@ function wp_popular_terms_checklist( $taxonomy, $default = 0, $number = 10, $echo = true ) { $post = get_post(); - if ( $post && $post->ID ) - $checked_terms = wp_get_object_terms($post->ID, $taxonomy, array('fields'=>'ids')); - else + if ( $post && $post->ID ) { + $checked_terms = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'ids' ) ); + } else { $checked_terms = array(); + } - $terms = get_terms( $taxonomy, array( 'orderby' => 'count', 'order' => 'DESC', 'number' => $number, 'hierarchical' => false ) ); + $terms = get_terms( + $taxonomy, + array( + 'orderby' => 'count', + 'order' => 'DESC', + 'number' => $number, + 'hierarchical' => false, + ) + ); - $tax = get_taxonomy($taxonomy); + $tax = get_taxonomy( $taxonomy ); $popular_ids = array(); foreach ( (array) $terms as $term ) { $popular_ids[] = $term->term_id; - if ( !$echo ) // Hack for Ajax use. + if ( ! $echo ) { // Hack for Ajax use. continue; - $id = "popular-$taxonomy-$term->term_id"; + } + $id = "popular-$taxonomy-$term->term_id"; $checked = in_array( $term->term_id, $checked_terms ) ? 'checked="checked"' : ''; ?> @@ -246,18 +265,25 @@ $checked_categories[] = $default; } - $categories = get_terms( 'link_category', array( 'orderby' => 'name', 'hide_empty' => 0 ) ); + $categories = get_terms( + 'link_category', + array( + 'orderby' => 'name', + 'hide_empty' => 0, + ) + ); - if ( empty( $categories ) ) + if ( empty( $categories ) ) { return; + } foreach ( $categories as $category ) { $cat_id = $category->term_id; /** This filter is documented in wp-includes/category-template.php */ - $name = esc_html( apply_filters( 'the_category', $category->name, '', '' ) ); + $name = esc_html( apply_filters( 'the_category', $category->name, '', '' ) ); $checked = in_array( $cat_id, $checked_categories ) ? ' checked="checked"' : ''; - echo '"; + echo ''; } } @@ -268,10 +294,11 @@ * * @param WP_Post $post Post object. */ -function get_inline_data($post) { - $post_type_object = get_post_type_object($post->post_type); - if ( ! current_user_can( 'edit_post', $post->ID ) ) +function get_inline_data( $post ) { + $post_type_object = get_post_type_object( $post->post_type ); + if ( ! current_user_can( 'edit_post', $post->ID ) ) { return; + } $title = esc_textarea( trim( $post->post_title ) ); @@ -304,7 +331,7 @@ } $taxonomy_names = get_object_taxonomies( $post->post_type ); - foreach ( $taxonomy_names as $taxonomy_name) { + foreach ( $taxonomy_names as $taxonomy_name ) { $taxonomy = get_taxonomy( $taxonomy_name ); if ( $taxonomy->hierarchical && $taxonomy->show_ui ) { @@ -325,17 +352,19 @@ $terms_to_edit = ''; } - echo '
' + echo '
' . esc_html( str_replace( ',', ', ', $terms_to_edit ) ) . '
'; } } - if ( !$post_type_object->hierarchical ) - echo '
' . (is_sticky($post->ID) ? 'sticky' : '') . '
'; + if ( ! $post_type_object->hierarchical ) { + echo '
' . ( is_sticky( $post->ID ) ? 'sticky' : '' ) . '
'; + } - if ( post_type_supports( $post->post_type, 'post-formats' ) ) + if ( post_type_supports( $post->post_type, 'post-formats' ) ) { echo '
' . esc_html( get_post_format( $post->ID ) ) . '
'; + } /** * Fires after outputting the fields for the inline editor for posts and pages. @@ -379,24 +408,32 @@ * @param string $content The reply-to form content. * @param array $args An array of default args. */ - $content = apply_filters( 'wp_comment_reply', '', array( 'position' => $position, 'checkbox' => $checkbox, 'mode' => $mode ) ); + $content = apply_filters( + 'wp_comment_reply', + '', + array( + 'position' => $position, + 'checkbox' => $checkbox, + 'mode' => $mode, + ) + ); - if ( ! empty($content) ) { + if ( ! empty( $content ) ) { echo $content; return; } if ( ! $wp_list_table ) { if ( $mode == 'single' ) { - $wp_list_table = _get_list_table('WP_Post_Comments_List_Table'); + $wp_list_table = _get_list_table( 'WP_Post_Comments_List_Table' ); } else { - $wp_list_table = _get_list_table('WP_Comments_List_Table'); + $wp_list_table = _get_list_table( 'WP_Comments_List_Table' ); } } -?> + ?>
- +
- +
- + - + ?> - + ?> - - + + - + } + ?>
- - $entry['meta_id'] = (int) $entry['meta_id']; + $entry['meta_id'] = (int) $entry['meta_id']; $delete_nonce = wp_create_nonce( 'delete-meta_' . $entry['meta_id'] ); @@ -577,9 +625,9 @@ $r .= get_submit_button( __( 'Delete' ), 'deletemeta small', "deletemeta[{$entry['meta_id']}]", false, array( 'data-wp-lists' => "delete:the-list:meta-{$entry['meta_id']}::_ajax_nonce=$delete_nonce" ) ); $r .= "\n\t\t"; $r .= get_submit_button( __( 'Update' ), 'updatemeta small', "meta-{$entry['meta_id']}-submit", false, array( 'data-wp-lists' => "add:the-list:meta-{$entry['meta_id']}::_ajax_nonce-add-meta=$update_nonce" ) ); - $r .= ""; + $r .= ''; $r .= wp_nonce_field( 'change-meta', '_ajax_nonce', false, false ); - $r .= ""; + $r .= ''; $r .= "\n\t\t\n\t"; return $r; @@ -621,13 +669,13 @@ * @param int $limit Number of custom fields to retrieve. Default 30. */ $limit = apply_filters( 'postmeta_form_limit', 30 ); - $sql = "SELECT DISTINCT meta_key + $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( $sql, $wpdb->esc_like( '_' ) . '%', $limit ) ); } if ( $keys ) { @@ -636,35 +684,36 @@ } else { $meta_key_input_id = 'metakeyinput'; } -?> -

+ ?> +

- - + +
- + - - + + @@ -674,13 +723,24 @@
- 'newmeta-submit', 'data-wp-lists' => 'add:the-list:newmeta' ) ); ?> + 'newmeta-submit', + 'data-wp-lists' => 'add:the-list:newmeta', + ) + ); + ?>
- +
-post_status, array('draft', 'pending') ) && (!$post->post_date_gmt || '0000-00-00 00:00:00' == $post->post_date_gmt ) ); + if ( $for_post ) { + $edit = ! ( in_array( $post->post_status, array( 'draft', 'pending' ) ) && ( ! $post->post_date_gmt || '0000-00-00 00:00:00' == $post->post_date_gmt ) ); + } $tab_index_attribute = ''; - if ( (int) $tab_index > 0 ) + if ( (int) $tab_index > 0 ) { $tab_index_attribute = " tabindex=\"$tab_index\""; + } // todo: Remove this? // echo '
'; - $time_adj = current_time('timestamp'); - $post_date = ($for_post) ? $post->post_date : get_comment()->comment_date; - $jj = ($edit) ? mysql2date( 'd', $post_date, false ) : gmdate( 'd', $time_adj ); - $mm = ($edit) ? mysql2date( 'm', $post_date, false ) : gmdate( 'm', $time_adj ); - $aa = ($edit) ? mysql2date( 'Y', $post_date, false ) : gmdate( 'Y', $time_adj ); - $hh = ($edit) ? mysql2date( 'H', $post_date, false ) : gmdate( 'H', $time_adj ); - $mn = ($edit) ? mysql2date( 'i', $post_date, false ) : gmdate( 'i', $time_adj ); - $ss = ($edit) ? mysql2date( 's', $post_date, false ) : gmdate( 's', $time_adj ); + $post_date = ( $for_post ) ? $post->post_date : get_comment()->comment_date; + $jj = ( $edit ) ? mysql2date( 'd', $post_date, false ) : current_time( 'd' ); + $mm = ( $edit ) ? mysql2date( 'm', $post_date, false ) : current_time( 'm' ); + $aa = ( $edit ) ? mysql2date( 'Y', $post_date, false ) : current_time( 'Y' ); + $hh = ( $edit ) ? mysql2date( 'H', $post_date, false ) : current_time( 'H' ); + $mn = ( $edit ) ? mysql2date( 'i', $post_date, false ) : current_time( 'i' ); + $ss = ( $edit ) ? mysql2date( 's', $post_date, false ) : current_time( 's' ); - $cur_jj = gmdate( 'd', $time_adj ); - $cur_mm = gmdate( 'm', $time_adj ); - $cur_aa = gmdate( 'Y', $time_adj ); - $cur_hh = gmdate( 'H', $time_adj ); - $cur_mn = gmdate( 'i', $time_adj ); + $cur_jj = current_time( 'd' ); + $cur_mm = current_time( 'm' ); + $cur_aa = current_time( 'Y' ); + $cur_hh = current_time( 'H' ); + $cur_mn = current_time( 'i' ); $month = ''; - $day = ''; - $year = ''; - $hour = ''; + $day = ''; + $year = ''; + $hour = ''; $minute = ''; echo '
'; @@ -748,7 +809,9 @@ echo '
'; - if ( $multi ) return; + if ( $multi ) { + return; + } echo "\n\n"; $map = array( @@ -765,13 +828,13 @@ $cur_timeunit = 'cur_' . $timeunit; echo '' . "\n"; } -?> + ?>

- - + +

-" . esc_html( $template ) . ""; + echo "\n\t'; } } @@ -805,24 +868,25 @@ * @param int $level Optional. Page depth level. Default 0. * @param int|WP_Post $post Post ID or WP_Post object. * - * @return null|false Boolean False if page has no children, otherwise print out html elements + * @return null|false Boolean False if page has no children, otherwise print out html elements. */ 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) ); + $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 && $item->ID == $post->ID ) { continue; + } - $pad = str_repeat( ' ', $level * 3 ); + $pad = str_repeat( ' ', $level * 3 ); $selected = selected( $default, $item->ID, false ); - echo "\n\t"; - parent_dropdown( $default, $item->ID, $level +1 ); + echo "\n\t'; + parent_dropdown( $default, $item->ID, $level + 1 ); } } else { return false; @@ -842,7 +906,7 @@ $editable_roles = array_reverse( get_editable_roles() ); foreach ( $editable_roles as $role => $details ) { - $name = translate_user_role($details['name'] ); + $name = translate_user_role( $details['name'] ); // preselect specified role if ( $selected == $role ) { $r .= "\n\t"; @@ -872,24 +936,26 @@ * * @param int $max_upload_size Allowed upload size. Default 1 MB. */ - $bytes = apply_filters( 'import_upload_size_limit', wp_max_upload_size() ); - $size = size_format( $bytes ); + $bytes = apply_filters( 'import_upload_size_limit', wp_max_upload_size() ); + $size = size_format( $bytes ); $upload_dir = wp_upload_dir(); if ( ! empty( $upload_dir['error'] ) ) : - ?>

-

+

+

+ + ?>

- () + ()

- +
-id; - if ( !isset($wp_meta_boxes) ) + if ( ! isset( $wp_meta_boxes ) ) { $wp_meta_boxes = array(); - if ( !isset($wp_meta_boxes[$page]) ) - $wp_meta_boxes[$page] = array(); - if ( !isset($wp_meta_boxes[$page][$context]) ) - $wp_meta_boxes[$page][$context] = array(); + } + if ( ! isset( $wp_meta_boxes[ $page ] ) ) { + $wp_meta_boxes[ $page ] = array(); + } + if ( ! isset( $wp_meta_boxes[ $page ][ $context ] ) ) { + $wp_meta_boxes[ $page ][ $context ] = array(); + } - foreach ( array_keys($wp_meta_boxes[$page]) as $a_context ) { - foreach ( array('high', 'core', 'default', 'low') as $a_priority ) { - if ( !isset($wp_meta_boxes[$page][$a_context][$a_priority][$id]) ) + foreach ( array_keys( $wp_meta_boxes[ $page ] ) as $a_context ) { + foreach ( array( 'high', 'core', 'default', 'low' ) as $a_priority ) { + if ( ! isset( $wp_meta_boxes[ $page ][ $a_context ][ $a_priority ][ $id ] ) ) { continue; + } // If a core box was previously added or removed by a plugin, don't add. if ( 'core' == $priority ) { // If core box previously deleted, don't add - if ( false === $wp_meta_boxes[$page][$a_context][$a_priority][$id] ) + if ( false === $wp_meta_boxes[ $page ][ $a_context ][ $a_priority ][ $id ] ) { return; + } /* * If box was added with default priority, give it core priority to * maintain sort order. */ 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]); + $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 ] ); } return; } // If no priority given and id already present, use existing priority. - if ( empty($priority) ) { + if ( empty( $priority ) ) { $priority = $a_priority; - /* - * 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. - */ + /* + * 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 ) { - $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']; + $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 ) - unset($wp_meta_boxes[$page][$a_context][$a_priority][$id]); + if ( $priority != $a_priority || $context != $a_context ) { + unset( $wp_meta_boxes[ $page ][ $a_context ][ $a_priority ][ $id ] ); + } } } - if ( empty($priority) ) + if ( empty( $priority ) ) { $priority = 'low'; + } + + if ( ! isset( $wp_meta_boxes[ $page ][ $context ][ $priority ] ) ) { + $wp_meta_boxes[ $page ][ $context ][ $priority ] = array(); + } + + $wp_meta_boxes[ $page ][ $context ][ $priority ][ $id ] = array( + 'id' => $id, + 'title' => $title, + 'callback' => $callback, + 'args' => $callback_args, + ); +} + - if ( !isset($wp_meta_boxes[$page][$context][$priority]) ) - $wp_meta_boxes[$page][$context][$priority] = array(); +/** + * Function that renders a "fake" meta box with an information message, + * shown on the block editor, when an incompatible meta box is found. + * + * @since 5.0.0 + * + * @param mixed $object The data object being rendered on this screen. + * @param array $box { + * Custom formats meta box arguments. + * + * @type string $id Meta box 'id' attribute. + * @type string $title Meta box title. + * @type callable $old_callback The original callback for this meta box. + * @type array $args Extra meta box arguments. + * } + */ +function do_block_editor_incompatible_meta_box( $object, $box ) { + $plugin = _get_plugin_from_callback( $box['old_callback'] ); + $plugins = get_plugins(); + echo '

'; + if ( $plugin ) { + /* translators: %s: the name of the plugin that generated this meta box. */ + printf( __( "This meta box, from the %s plugin, isn't compatible with the block editor." ), "{$plugin['Name']}" ); + } else { + _e( "This meta box isn't compatible with the block editor." ); + } + echo '

'; - $wp_meta_boxes[$page][$context][$priority][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback, 'args' => $callback_args); + if ( empty( $plugins['classic-editor/classic-editor.php'] ) ) { + if ( current_user_can( 'install_plugins' ) ) { + echo '

'; + /* translators: %s: A link to install the Classic Editor plugin. */ + printf( __( 'Please install the Classic Editor plugin to use this meta box.' ), esc_url( self_admin_url( 'plugin-install.php?tab=featured' ) ) ); + echo '

'; + } + } elseif ( is_plugin_inactive( 'classic-editor/classic-editor.php' ) ) { + if ( current_user_can( 'activate_plugins' ) ) { + $activate_url = wp_nonce_url( self_admin_url( 'plugins.php?action=activate&plugin=classic-editor/classic-editor.php' ), 'activate-plugin_classic-editor/classic-editor.php' ); + echo '

'; + /* translators: %s: A link to activate the Classic Editor plugin. */ + printf( __( 'Please activate the Classic Editor plugin to use this meta box.' ), esc_url( $activate_url ) ); + echo '

'; + } + } elseif ( $object instanceof WP_Post ) { + $edit_url = add_query_arg( + array( + 'classic-editor' => '', + 'classic-editor__forget' => '', + ), + get_edit_post_link( $object ) + ); + echo '

'; + /* translators: %s: A link to use the Classic Editor plugin. */ + printf( __( 'Please open the classic editor to use this meta box.' ), esc_url( $edit_url ) ); + echo '

'; + } } /** - * Meta-Box template function + * Internal helper function to find the plugin from a meta box callback. + * + * @since 5.0.0 + * + * @access private + * + * @param callable $callback The callback function to check. + * @return array|null The plugin that the callback belongs to, or null if it doesn't belong to a plugin. + */ +function _get_plugin_from_callback( $callback ) { + try { + if ( is_array( $callback ) ) { + $reflection = new ReflectionMethod( $callback[0], $callback[1] ); + } elseif ( is_string( $callback ) && false !== strpos( $callback, '::' ) ) { + $reflection = new ReflectionMethod( $callback ); + } else { + $reflection = new ReflectionFunction( $callback ); + } + } catch ( ReflectionException $exception ) { + // We could not properly reflect on the callable, so we abort here. + return null; + } + + // Don't show an error if it's an internal PHP function. + if ( ! $reflection->isInternal() ) { + + // Only show errors if the meta box was registered by a plugin. + $filename = wp_normalize_path( $reflection->getFileName() ); + $plugin_dir = wp_normalize_path( WP_PLUGIN_DIR ); + if ( strpos( $filename, $plugin_dir ) === 0 ) { + $filename = str_replace( $plugin_dir, '', $filename ); + $filename = preg_replace( '|^/([^/]*/).*$|', '\\1', $filename ); + + $plugins = get_plugins(); + foreach ( $plugins as $name => $plugin ) { + if ( strpos( $name, $filename ) === 0 ) { + return $plugin; + } + } + } + } + + return null; +} + +/** + * Meta-Box template function. * * @since 2.5.0 * @@ -1011,18 +1195,21 @@ * 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 box context - * @param mixed $object gets passed to the box callback function as first parameter + * @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. + * 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 */ function do_meta_boxes( $screen, $context, $object ) { global $wp_meta_boxes; static $already_sorted = false; - if ( empty( $screen ) ) + if ( empty( $screen ) ) { $screen = get_current_screen(); - elseif ( is_string( $screen ) ) + } elseif ( is_string( $screen ) ) { $screen = convert_to_screen( $screen ); + } $page = $screen->id; @@ -1047,20 +1234,47 @@ if ( isset( $wp_meta_boxes[ $page ][ $context ] ) ) { foreach ( array( 'high', 'sorted', 'core', 'default', 'low' ) as $priority ) { - if ( isset( $wp_meta_boxes[ $page ][ $context ][ $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; + } + + $block_compatible = true; + if ( is_array( $box['args'] ) ) { + // If a meta box is just here for back compat, don't show it in the block editor. + if ( $screen->is_block_editor() && isset( $box['args']['__back_compat_meta_box'] ) && $box['args']['__back_compat_meta_box'] ) { + continue; + } + + if ( isset( $box['args']['__block_editor_compatible_meta_box'] ) ) { + $block_compatible = (bool) $box['args']['__block_editor_compatible_meta_box']; + unset( $box['args']['__block_editor_compatible_meta_box'] ); + } + + // If the meta box is declared as incompatible with the block editor, override the callback function. + if ( ! $block_compatible && $screen->is_block_editor() ) { + $box['old_callback'] = $box['callback']; + $box['callback'] = 'do_block_editor_incompatible_meta_box'; + } + + if ( isset( $box['args']['__back_compat_meta_box'] ) ) { + $block_compatible = $block_compatible || (bool) $box['args']['__back_compat_meta_box']; + unset( $box['args']['__back_compat_meta_box'] ); + } + } + $i++; - $hidden_class = in_array($box['id'], $hidden) ? ' hide-if-js' : ''; - echo '
' . "\n"; + // get_hidden_meta_boxes() doesn't apply in the block editor. + $hidden_class = ( ! $screen->is_block_editor() && in_array( $box['id'], $hidden ) ) ? ' hide-if-js' : ''; + echo '
' . "\n"; if ( 'dashboard_browser_nag' != $box['id'] ) { - $widget_title = $box[ 'title' ]; + $widget_title = $box['title']; - if ( is_array( $box[ 'args' ] ) && isset( $box[ 'args' ][ '__widget_basename' ] ) ) { - $widget_title = $box[ 'args' ][ '__widget_basename' ]; + if ( is_array( $box['args'] ) && isset( $box['args']['__widget_basename'] ) ) { + $widget_title = $box['args']['__widget_basename']; // Do not pass this parameter to the user callback function. - unset( $box[ 'args' ][ '__widget_basename' ] ); + unset( $box['args']['__widget_basename'] ); } echo ''; } - echo "

{$box['title']}

\n"; + echo '

'; + if ( 'dashboard_php_nag' === $box['id'] ) { + echo ''; + echo '' . __( 'Warning:' ) . ' '; + } + echo "{$box['title']}"; + echo "

\n"; echo '
' . "\n"; - call_user_func($box['callback'], $object, $box); + + if ( WP_DEBUG && ! $block_compatible && 'edit' === $screen->parent_base && ! $screen->is_block_editor() && ! isset( $_GET['meta-box-loader'] ) ) { + $plugin = _get_plugin_from_callback( $box['callback'] ); + if ( $plugin ) { + ?> +
+

+ {$plugin['Name']}" ); + ?> +

+
+ \n"; echo "
\n"; } @@ -1078,7 +1315,7 @@ } } - echo "
"; + echo '
'; return $i; @@ -1121,19 +1358,23 @@ $page = $screen->id; - if ( !isset($wp_meta_boxes) ) + if ( ! isset( $wp_meta_boxes ) ) { $wp_meta_boxes = array(); - if ( !isset($wp_meta_boxes[$page]) ) - $wp_meta_boxes[$page] = array(); - if ( !isset($wp_meta_boxes[$page][$context]) ) - $wp_meta_boxes[$page][$context] = array(); + } + if ( ! isset( $wp_meta_boxes[ $page ] ) ) { + $wp_meta_boxes[ $page ] = array(); + } + if ( ! isset( $wp_meta_boxes[ $page ][ $context ] ) ) { + $wp_meta_boxes[ $page ][ $context ] = array(); + } - foreach ( array('high', 'core', 'default', 'low') as $priority ) - $wp_meta_boxes[$page][$context][$priority][$id] = false; + foreach ( array( 'high', 'core', 'default', 'low' ) as $priority ) { + $wp_meta_boxes[ $page ][ $context ][ $priority ][ $id ] = false; + } } /** - * Meta Box Accordion Template Function + * Meta Box Accordion Template Function. * * Largely made up of abstracted code from do_meta_boxes(), this * function serves to build meta boxes as list items for display as @@ -1153,10 +1394,11 @@ wp_enqueue_script( 'accordion' ); - if ( empty( $screen ) ) + if ( empty( $screen ) ) { $screen = get_current_screen(); - elseif ( is_string( $screen ) ) + } elseif ( is_string( $screen ) ) { $screen = convert_to_screen( $screen ); + } $page = $screen->id; @@ -1165,15 +1407,16 @@