Make WordPress Core

Ticket #45112: 45112.2.diff

File 45112.2.diff, 14.4 KB (added by ocean90, 7 years ago)
  • src/wp-admin/edit-form-advanced.php

     
    226226require_once( ABSPATH . 'wp-admin/includes/meta-boxes.php' );
    227227
    228228
    229 $publish_callback_args = null;
     229$publish_callback_args = array( '__back_compat_meta_box' => true );
    230230if ( post_type_supports($post_type, 'revisions') && 'auto-draft' != $post->post_status ) {
    231231        $revisions = wp_get_post_revisions( $post_ID );
    232232
     
    233233        // We should aim to show the revisions meta box only when there are revisions.
    234234        if ( count( $revisions ) > 1 ) {
    235235                reset( $revisions ); // Reset pointer for key()
    236                 $publish_callback_args = array( 'revisions_count' => count( $revisions ), 'revision_id' => key( $revisions ) );
    237                 add_meta_box('revisionsdiv', __('Revisions'), 'post_revisions_meta_box', null, 'normal', 'core');
     236                $publish_callback_args = array( 'revisions_count' => count( $revisions ), 'revision_id' => key( $revisions ), '__back_compat_meta_box' => true );
     237                add_meta_box('revisionsdiv', __('Revisions'), 'post_revisions_meta_box', null, 'normal', 'core', array( '__back_compat_meta_box' => true ) );
    238238        }
    239239}
    240240
     
    241241if ( 'attachment' == $post_type ) {
    242242        wp_enqueue_script( 'image-edit' );
    243243        wp_enqueue_style( 'imgareaselect' );
    244         add_meta_box( 'submitdiv', __('Save'), 'attachment_submit_meta_box', null, 'side', 'core' );
     244        add_meta_box( 'submitdiv', __('Save'), 'attachment_submit_meta_box', null, 'side', 'core', array( '__back_compat_meta_box' => true ) );
    245245        add_action( 'edit_form_after_title', 'edit_form_image_editor' );
    246246
    247247        if ( wp_attachment_is( 'audio', $post ) ) {
    248                 add_meta_box( 'attachment-id3', __( 'Metadata' ), 'attachment_id3_data_meta_box', null, 'normal', 'core' );
     248                add_meta_box( 'attachment-id3', __( 'Metadata' ), 'attachment_id3_data_meta_box', null, 'normal', 'core', array( '__back_compat_meta_box' => true ) );
    249249        }
    250250} else {
    251251        add_meta_box( 'submitdiv', __( 'Publish' ), 'post_submit_meta_box', null, 'side', 'core', $publish_callback_args );
     
    252252}
    253253
    254254if ( current_theme_supports( 'post-formats' ) && post_type_supports( $post_type, 'post-formats' ) )
    255         add_meta_box( 'formatdiv', _x( 'Format', 'post format' ), 'post_format_meta_box', null, 'side', 'core' );
     255        add_meta_box( 'formatdiv', _x( 'Format', 'post format' ), 'post_format_meta_box', null, 'side', 'core', array( '__back_compat_meta_box' => true ) );
    256256
    257257// all taxonomies
    258258foreach ( get_object_taxonomies( $post ) as $tax_name ) {
     
    267267        else
    268268                $tax_meta_box_id = $tax_name . 'div';
    269269
    270         add_meta_box( $tax_meta_box_id, $label, $taxonomy->meta_box_cb, null, 'side', 'core', array( 'taxonomy' => $tax_name ) );
     270        add_meta_box( $tax_meta_box_id, $label, $taxonomy->meta_box_cb, null, 'side', 'core', array( 'taxonomy' => $tax_name, '__back_compat_meta_box' => true ) );
    271271}
    272272
    273273if ( post_type_supports( $post_type, 'page-attributes' ) || count( get_page_templates( $post ) ) > 0 ) {
    274         add_meta_box( 'pageparentdiv', $post_type_object->labels->attributes, 'page_attributes_meta_box', null, 'side', 'core' );
     274        add_meta_box( 'pageparentdiv', $post_type_object->labels->attributes, 'page_attributes_meta_box', null, 'side', 'core', array( '__back_compat_meta_box' => true ) );
    275275}
    276276
    277277if ( $thumbnail_support && current_user_can( 'upload_files' ) )
    278         add_meta_box('postimagediv', esc_html( $post_type_object->labels->featured_image ), 'post_thumbnail_meta_box', null, 'side', 'low');
     278        add_meta_box('postimagediv', esc_html( $post_type_object->labels->featured_image ), 'post_thumbnail_meta_box', null, 'side', 'low', array( '__back_compat_meta_box' => true ) );
    279279
    280280if ( post_type_supports($post_type, 'excerpt') )
    281         add_meta_box('postexcerpt', __('Excerpt'), 'post_excerpt_meta_box', null, 'normal', 'core');
     281        add_meta_box('postexcerpt', __('Excerpt'), 'post_excerpt_meta_box', null, 'normal', 'core', array( '__back_compat_meta_box' => true ) );
    282282
    283283if ( post_type_supports($post_type, 'trackbacks') )
    284         add_meta_box('trackbacksdiv', __('Send Trackbacks'), 'post_trackback_meta_box', null, 'normal', 'core');
     284        add_meta_box('trackbacksdiv', __('Send Trackbacks'), 'post_trackback_meta_box', null, 'normal', 'core', array( '__back_compat_meta_box' => true ) );
    285285
    286286if ( post_type_supports($post_type, 'custom-fields') )
    287         add_meta_box('postcustom', __('Custom Fields'), 'post_custom_meta_box', null, 'normal', 'core');
     287        add_meta_box('postcustom', __('Custom Fields'), 'post_custom_meta_box', null, 'normal', 'core', array( '__back_compat_meta_box' => true ) );
    288288
    289289/**
    290290 * Fires in the middle of built-in meta box registration.
     
    299299// Allow the Discussion meta box to show up if the post type supports comments,
    300300// or if comments or pings are open.
    301301if ( comments_open( $post ) || pings_open( $post ) || post_type_supports( $post_type, 'comments' ) ) {
    302         add_meta_box( 'commentstatusdiv', __( 'Discussion' ), 'post_comment_status_meta_box', null, 'normal', 'core' );
     302        add_meta_box( 'commentstatusdiv', __( 'Discussion' ), 'post_comment_status_meta_box', null, 'normal', 'core', array( '__back_compat_meta_box' => true ) );
    303303}
    304304
    305305$stati = get_post_stati( array( 'public' => true ) );
     
    312312        // If the post type support comments, or the post has comments, allow the
    313313        // Comments meta box.
    314314        if ( comments_open( $post ) || pings_open( $post ) || $post->comment_count > 0 || post_type_supports( $post_type, 'comments' ) ) {
    315                 add_meta_box( 'commentsdiv', __( 'Comments' ), 'post_comment_meta_box', null, 'normal', 'core' );
     315                add_meta_box( 'commentsdiv', __( 'Comments' ), 'post_comment_meta_box', null, 'normal', 'core', array( '__back_compat_meta_box' => true ) );
    316316        }
    317317}
    318318
    319319if ( ! ( 'pending' == get_post_status( $post ) && ! current_user_can( $post_type_object->cap->publish_posts ) ) )
    320         add_meta_box('slugdiv', __('Slug'), 'post_slug_meta_box', null, 'normal', 'core');
     320        add_meta_box('slugdiv', __('Slug'), 'post_slug_meta_box', null, 'normal', 'core', array( '__back_compat_meta_box' => true ) );
    321321
    322322if ( post_type_supports( $post_type, 'author' ) && current_user_can( $post_type_object->cap->edit_others_posts ) ) {
    323         add_meta_box( 'authordiv', __( 'Author' ), 'post_author_meta_box', null, 'normal', 'core' );
     323        add_meta_box( 'authordiv', __( 'Author' ), 'post_author_meta_box', null, 'normal', 'core', array( '__back_compat_meta_box' => true ) );
    324324}
    325325
    326326/**
  • src/wp-admin/includes/post.php

     
    18901890                return false;
    18911891        }
    18921892
     1893        // We're in the meta box loader, so don't use the block editor.
     1894        if ( isset( $_GET['meta-box-loader'] ) ) {
     1895                return false;
     1896        }
     1897
    18931898        $use_block_editor = use_block_editor_for_post_type( $post->post_type );
    18941899
    18951900        /**
     
    20172022
    20182023        return $blocks;
    20192024}
     2025
     2026/**
     2027 * Renders the meta boxes forms.
     2028 *
     2029 * @since 5.0.0
     2030 */
     2031function the_block_editor_metaboxes() {
     2032        global $post, $current_screen, $wp_meta_boxes;
     2033
     2034        // Handle meta box state.
     2035        $_original_meta_boxes = $wp_meta_boxes;
     2036
     2037        /**
     2038         * Fires right before the meta boxes are rendered.
     2039         *
     2040         * This allows for the filtering of meta box data, that should already be
     2041         * present by this point. Do not use as a means of adding meta box data.
     2042         *
     2043         * By default gutenberg_filter_meta_boxes() is hooked in and can be
     2044         * unhooked to restore core meta boxes.
     2045         *
     2046         * @since 5.0.0
     2047         *
     2048         * @param array $wp_meta_boxes Global meta box state.
     2049         */
     2050        $wp_meta_boxes = apply_filters( 'filter_block_editor_meta_boxes', $wp_meta_boxes );
     2051        $locations     = array( 'side', 'normal', 'advanced' );
     2052        $priorities    = array( 'high', 'sorted', 'core', 'default', 'low' );
     2053
     2054        // Render meta boxes.
     2055        ?>
     2056        <form class="metabox-base-form">
     2057        <?php the_block_editor_meta_box_post_form_hidden_fields( $post ); ?>
     2058        </form>
     2059        <?php foreach ( $locations as $location ) : ?>
     2060                <form class="metabox-location-<?php echo esc_attr( $location ); ?>">
     2061                        <div id="poststuff" class="sidebar-open">
     2062                                <div id="postbox-container-2" class="postbox-container">
     2063                                        <?php
     2064                                        do_meta_boxes(
     2065                                                $current_screen,
     2066                                                $location,
     2067                                                $post
     2068                                        );
     2069                                        ?>
     2070                                </div>
     2071                        </div>
     2072                </form>
     2073        <?php endforeach; ?>
     2074        <?php
     2075
     2076        $meta_boxes_per_location = array();
     2077        foreach ( $locations as $location ) {
     2078                $meta_boxes_per_location[ $location ] = array();
     2079                foreach ( $priorities as $priority ) {
     2080                        if ( isset( $wp_meta_boxes[ $current_screen->id ][ $location ][ $priority ] ) ) {
     2081                                $meta_boxes = (array) $wp_meta_boxes[ $current_screen->id ][ $location ][ $priority ];
     2082                                foreach ( $meta_boxes as $meta_box ) {
     2083                                        if ( false === $meta_box || ! $meta_box['title'] ) {
     2084                                                continue;
     2085                                        }
     2086
     2087                                        $meta_boxes_per_location[ $location ][] = array(
     2088                                                'id'    => $meta_box['id'],
     2089                                                'title' => $meta_box['title'],
     2090                                        );
     2091                                }
     2092                        }
     2093                }
     2094        }
     2095
     2096        /**
     2097         * Sadly we probably can not add this data directly into editor settings.
     2098         *
     2099         * Some meta boxes need admin_head to fire for meta box registry.
     2100         * admin_head fires after admin_enqueue_scripts, which is where we create our
     2101         * editor instance.
     2102         */
     2103        $script = 'window._wpLoadBlockEditor.then( function() {
     2104                wp.data.dispatch( \'core/edit-post\' ).setAvailableMetaBoxesPerLocation( ' . wp_json_encode( $meta_boxes_per_location ) . ' );
     2105        } );';
     2106
     2107        wp_add_inline_script( 'wp-edit-post', $script );
     2108
     2109        /**
     2110         * When `wp-edit-post` is output in the `<head>`, the inline script needs to be manually printed. Otherwise,
     2111         * metaboxes will not display because inline scripts for `wp-edit-post` will not be printed again after this point.
     2112         */
     2113        if ( wp_script_is( 'wp-edit-post', 'done' ) ) {
     2114                printf( "<script type='text/javascript'>\n%s\n</script>\n", trim( $script ) );
     2115        }
     2116
     2117        // Reset meta box data.
     2118        $wp_meta_boxes = $_original_meta_boxes;
     2119}
     2120
     2121/**
     2122 * Renders the hidden form required for the meta boxes form.
     2123 *
     2124 * @since 5.0.0
     2125 *
     2126 * @param WP_Post $post Current post object.
     2127 */
     2128function the_block_editor_meta_box_post_form_hidden_fields( $post ) {
     2129        $form_extra = '';
     2130        if ( 'auto-draft' === $post->post_status ) {
     2131                $form_extra .= "<input type='hidden' id='auto_draft' name='auto_draft' value='1' />";
     2132        }
     2133        $form_action  = 'editpost';
     2134        $nonce_action = 'update-post_' . $post->ID;
     2135        $form_extra  .= "<input type='hidden' id='post_ID' name='post_ID' value='" . esc_attr( $post->ID ) . "' />";
     2136        $referer      = wp_get_referer();
     2137        $current_user = wp_get_current_user();
     2138        $user_id      = $current_user->ID;
     2139        wp_nonce_field( $nonce_action );
     2140        ?>
     2141        <input type="hidden" id="user-id" name="user_ID" value="<?php echo (int) $user_id; ?>" />
     2142        <input type="hidden" id="hiddenaction" name="action" value="<?php echo esc_attr( $form_action ); ?>" />
     2143        <input type="hidden" id="originalaction" name="originalaction" value="<?php echo esc_attr( $form_action ); ?>" />
     2144        <input type="hidden" id="post_type" name="post_type" value="<?php echo esc_attr( $post->post_type ); ?>" />
     2145        <input type="hidden" id="original_post_status" name="original_post_status" value="<?php echo esc_attr( $post->post_status ); ?>" />
     2146        <input type="hidden" id="referredby" name="referredby" value="<?php echo $referer ? esc_url( $referer ) : ''; ?>" />
     2147        <!-- These fields are not part of the standard post form. Used to redirect back to this page on save. -->
     2148        <input type="hidden" name="gutenberg_meta_boxes" value="gutenberg_meta_boxes" />
     2149
     2150        <?php
     2151        if ( 'draft' !== get_post_status( $post ) ) {
     2152                wp_original_referer_field( true, 'previous' );
     2153        }
     2154        echo $form_extra;
     2155        wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false );
     2156        wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
     2157        // Permalink title nonce.
     2158        wp_nonce_field( 'samplepermalink', 'samplepermalinknonce', false );
     2159}
  • src/wp-admin/includes/template.php

     
    10511051                                foreach ( (array) $wp_meta_boxes[ $page ][ $context ][ $priority ] as $box ) {
    10521052                                        if ( false == $box || ! $box['title'] )
    10531053                                                continue;
     1054
     1055                                        // Don't show boxes that are just here for back compat.
     1056                                        if ( isset( $_GET['meta-box-loader'] ) && isset( $box['args']['__back_compat_meta_box'] ) && $box['args']['__back_compat_meta_box'] ) {
     1057                                                continue;
     1058                                        }
     1059
     1060                                        $block_compatible = true;
     1061                                        if ( isset( $box['args']['__block_editor_compatible_meta_box'] ) ) {
     1062                                                $block_compatible = (bool) $box['args']['__block_editor_compatible_meta_box'];
     1063                                                unset( $box['args']['__block_editor_compatible_meta_box'] );
     1064                                        }
     1065
     1066                                        if ( isset( $box['args']['__back_compat_meta_box'] ) ) {
     1067                                                $block_compatible |= (bool) $box['args']['__back_compat_meta_box'];
     1068                                                unset( $box['args']['__back_compat_meta_box'] );
     1069                                        }
     1070
    10541071                                        $i++;
    10551072                                        $hidden_class = in_array($box['id'], $hidden) ? ' hide-if-js' : '';
    10561073                                        echo '<div id="' . $box['id'] . '" class="postbox ' . postbox_classes($box['id'], $page) . $hidden_class . '" ' . '>' . "\n";
     
    10701087                                        }
    10711088                                        echo "<h2 class='hndle'><span>{$box['title']}</span></h2>\n";
    10721089                                        echo '<div class="inside">' . "\n";
     1090
     1091                                        if ( WP_DEBUG && ! isset( $_GET['meta-box-loader'] ) ) {
     1092                                                if ( is_array( $box['callback'] ) ) {
     1093                                                        $reflection = new ReflectionMethod( $box['callback'][0], $box['callback'][1] );
     1094                                                } else {
     1095                                                        $reflection = new ReflectionFunction( $box['callback'] );
     1096                                                }
     1097
     1098                                                if ( $reflection->isInternal() ) {
     1099                                                        return;
     1100                                                }
     1101
     1102                                                $filename = $reflection->getFileName();
     1103                                                if ( strpos( $filename, WP_PLUGIN_DIR ) !== 0 ) {
     1104                                                        return;
     1105                                                }
     1106
     1107                                                $filename = str_replace( WP_PLUGIN_DIR, '', $filename );
     1108                                                $filename = preg_replace( '|^/([^/]*/).*$|', '\\1', $filename );
     1109
     1110                                                $plugins = get_plugins();
     1111                                                foreach ( $plugins as $name => $plugin ) {
     1112                                                        if ( strpos( $name, $filename ) === 0 ) {
     1113                                                                ?>
     1114                                                                        <div class="error inline">
     1115                                                                                <p>
     1116                                                                                        <?php
     1117                                                                                                /* translators: %s: the name of the plugin that generated this meta box. */
     1118                                                                                                printf( __( "This meta box, from the %s plugin, isn't compatible with the block editor." ), "<strong>{$plugin['Name']}</strong>" );
     1119                                                                                        ?>
     1120                                                                                </p>
     1121                                                                        </div>
     1122                                                                <?php
     1123                                                        }
     1124                                                }
     1125                                        }
     1126
    10731127                                        call_user_func($box['callback'], $object, $box);
    10741128                                        echo "</div>\n";
    10751129                                        echo "</div>\n";