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 ' - + - + ?> - + ?>- | + | + |
---|
+ ?> +
- | + | + | |
---|---|---|---|
- + | + + @@ -674,13 +723,24 @@|||
- 'newmeta-submit', 'data-wp-lists' => 'add:the-list:newmeta' ) ); ?>
+ 'newmeta-submit',
+ 'data-wp-lists' => 'add:the-list:newmeta',
+ )
+ );
+ ?>
-
+
|
-
-" . 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'] ) ) : - ?> - + +'; + 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 '+ {$plugin['Name']}" ); + ?> +
+` tags). @@ -1422,12 +1691,12 @@ 'setting' => $setting, 'code' => $code, 'message' => $message, - 'type' => $type + 'type' => $type, ); } /** - * Fetch settings errors registered by add_settings_error() + * Fetch settings errors registered by add_settings_error(). * * Checks the $wp_settings_errors array for any errors declared during the current * pageload and returns them. @@ -1445,9 +1714,9 @@ * * @global array $wp_settings_errors Storage array of errors registered during this pageload * - * @param string $setting Optional slug title of a specific setting who's errors you want. + * @param string $setting Optional slug title of a specific setting whose errors you want. * @param boolean $sanitize Whether to re-sanitize the setting value before returning errors. - * @return array Array of settings errors + * @return array Array of settings errors. */ function get_settings_errors( $setting = '', $sanitize = false ) { global $wp_settings_errors; @@ -1457,8 +1726,9 @@ * This allows the $sanitize_callback from register_setting() to run, adding * any settings errors you want to show by default. */ - if ( $sanitize ) + if ( $sanitize ) { sanitize_option( $setting, get_option( $setting ) ); + } // If settings were passed back from options.php then use them. if ( isset( $_GET['settings-updated'] ) && $_GET['settings-updated'] && get_transient( 'settings_errors' ) ) { @@ -1475,8 +1745,9 @@ if ( $setting ) { $setting_errors = array(); foreach ( (array) $wp_settings_errors as $key => $details ) { - if ( $setting == $details['setting'] ) - $setting_errors[] = $wp_settings_errors[$key]; + if ( $setting == $details['setting'] ) { + $setting_errors[] = $wp_settings_errors[ $key ]; + } } return $setting_errors; } @@ -1506,28 +1777,30 @@ * * @since 3.0.0 * - * @param string $setting Optional slug title of a specific setting who's errors you want. + * @param string $setting Optional slug title of a specific setting whose errors you want. * @param bool $sanitize Whether to re-sanitize the setting value before returning errors. * @param bool $hide_on_update If set to true errors will not be shown if the settings page has * already been submitted. */ function settings_errors( $setting = '', $sanitize = false, $hide_on_update = false ) { - if ( $hide_on_update && ! empty( $_GET['settings-updated'] ) ) + if ( $hide_on_update && ! empty( $_GET['settings-updated'] ) ) { return; + } $settings_errors = get_settings_errors( $setting, $sanitize ); - if ( empty( $settings_errors ) ) + if ( empty( $settings_errors ) ) { return; + } $output = ''; foreach ( $settings_errors as $key => $details ) { - $css_id = 'setting-error-' . $details['code']; + $css_id = 'setting-error-' . $details['code']; $css_class = $details['type'] . ' settings-error notice is-dismissible'; - $output .= "
{$details['message']}
"; - $output .= "{$details['message']}
"; + $output .= "