Ticket #45112: 45112.diff
| File 45112.diff, 14.5 KB (added by , 7 years ago) |
|---|
-
src/wp-admin/edit-form-advanced.php
diff --git a/src/wp-admin/edit-form-advanced.php b/src/wp-admin/edit-form-advanced.php index 2400521804..9e8da8588d 100644
a b $post_type_object = get_post_type_object($post_type); 226 226 require_once( ABSPATH . 'wp-admin/includes/meta-boxes.php' ); 227 227 228 228 229 $publish_callback_args = null;229 $publish_callback_args = array( '__back_compat_meta_box' => true ); 230 230 if ( post_type_supports($post_type, 'revisions') && 'auto-draft' != $post->post_status ) { 231 231 $revisions = wp_get_post_revisions( $post_ID ); 232 232 233 233 // We should aim to show the revisions meta box only when there are revisions. 234 234 if ( count( $revisions ) > 1 ) { 235 235 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 ) ); 238 238 } 239 239 } 240 240 241 241 if ( 'attachment' == $post_type ) { 242 242 wp_enqueue_script( 'image-edit' ); 243 243 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 ) ); 245 245 add_action( 'edit_form_after_title', 'edit_form_image_editor' ); 246 246 247 247 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 ) ); 249 249 } 250 250 } else { 251 251 add_meta_box( 'submitdiv', __( 'Publish' ), 'post_submit_meta_box', null, 'side', 'core', $publish_callback_args ); 252 252 } 253 253 254 254 if ( 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 ) ); 256 256 257 257 // all taxonomies 258 258 foreach ( get_object_taxonomies( $post ) as $tax_name ) { … … foreach ( get_object_taxonomies( $post ) as $tax_name ) { 267 267 else 268 268 $tax_meta_box_id = $tax_name . 'div'; 269 269 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 ) ); 271 271 } 272 272 273 273 if ( 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 ) ); 275 275 } 276 276 277 277 if ( $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 ) ); 279 279 280 280 if ( 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 ) ); 282 282 283 283 if ( 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 ) ); 285 285 286 286 if ( 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 ) ); 288 288 289 289 /** 290 290 * Fires in the middle of built-in meta box registration. … … do_action( 'dbx_post_advanced', $post ); 299 299 // Allow the Discussion meta box to show up if the post type supports comments, 300 300 // or if comments or pings are open. 301 301 if ( 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 ) ); 303 303 } 304 304 305 305 $stati = get_post_stati( array( 'public' => true ) ); … … if ( in_array( get_post_status( $post ), $stati ) ) { 312 312 // If the post type support comments, or the post has comments, allow the 313 313 // Comments meta box. 314 314 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 ) ); 316 316 } 317 317 } 318 318 319 319 if ( ! ( '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 ) ); 321 321 322 322 if ( 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 ) ); 324 324 } 325 325 326 326 /** -
src/wp-admin/includes/post.php
diff --git a/src/wp-admin/includes/post.php b/src/wp-admin/includes/post.php index c644ae3391..713eb39864 100644
a b function use_block_editor_for_post( $post ) { 1890 1890 return false; 1891 1891 } 1892 1892 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 1893 1898 $use_block_editor = use_block_editor_for_post_type( $post->post_type ); 1894 1899 1895 1900 /** … … function get_block_editor_server_block_settings() { 2017 2022 2018 2023 return $blocks; 2019 2024 } 2025 2026 /** 2027 * Renders the meta boxes forms. 2028 * 2029 * @since 5.0.0 2030 */ 2031 function 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 $meta_boxes = (array) $wp_meta_boxes[ $current_screen->id ][ $location ][ $priority ]; 2081 foreach ( $meta_boxes as $meta_box ) { 2082 if ( ! empty( $meta_box['title'] ) ) { 2083 $meta_boxes_per_location[ $location ][] = array( 2084 'id' => $meta_box['id'], 2085 'title' => $meta_box['title'], 2086 ); 2087 } 2088 } 2089 } 2090 } 2091 2092 /** 2093 * Sadly we probably can not add this data directly into editor settings. 2094 * 2095 * Some meta boxes need admin_head to fire for meta box registry. 2096 * admin_head fires after admin_enqueue_scripts, which is where we create our 2097 * editor instance. 2098 */ 2099 $script = 'window._wpLoadBlockEditor.then( function() { 2100 wp.data.dispatch( \'core/edit-post\' ).setAvailableMetaBoxesPerLocation( ' . wp_json_encode( $meta_boxes_per_location ) . ' ); 2101 } );'; 2102 2103 wp_add_inline_script( 'wp-edit-post', $script ); 2104 2105 /** 2106 * When `wp-edit-post` is output in the `<head>`, the inline script needs to be manually printed. Otherwise, 2107 * metaboxes will not display because inline scripts for `wp-edit-post` will not be printed again after this point. 2108 */ 2109 if ( wp_script_is( 'wp-edit-post', 'done' ) ) { 2110 printf( "<script type='text/javascript'>\n%s\n</script>\n", trim( $script ) ); 2111 } 2112 2113 // Reset meta box data. 2114 $wp_meta_boxes = $_original_meta_boxes; 2115 } 2116 2117 /** 2118 * Renders the hidden form required for the meta boxes form. 2119 * 2120 * @since 5.0.0 2121 * 2122 * @param WP_Post $post Current post object. 2123 */ 2124 function the_block_editor_meta_box_post_form_hidden_fields( $post ) { 2125 $form_extra = ''; 2126 if ( 'auto-draft' === $post->post_status ) { 2127 $form_extra .= "<input type='hidden' id='auto_draft' name='auto_draft' value='1' />"; 2128 } 2129 $form_action = 'editpost'; 2130 $nonce_action = 'update-post_' . $post->ID; 2131 $form_extra .= "<input type='hidden' id='post_ID' name='post_ID' value='" . esc_attr( $post->ID ) . "' />"; 2132 $referer = wp_get_referer(); 2133 $current_user = wp_get_current_user(); 2134 $user_id = $current_user->ID; 2135 wp_nonce_field( $nonce_action ); 2136 ?> 2137 <input type="hidden" id="user-id" name="user_ID" value="<?php echo (int) $user_id; ?>" /> 2138 <input type="hidden" id="hiddenaction" name="action" value="<?php echo esc_attr( $form_action ); ?>" /> 2139 <input type="hidden" id="originalaction" name="originalaction" value="<?php echo esc_attr( $form_action ); ?>" /> 2140 <input type="hidden" id="post_type" name="post_type" value="<?php echo esc_attr( $post->post_type ); ?>" /> 2141 <input type="hidden" id="original_post_status" name="original_post_status" value="<?php echo esc_attr( $post->post_status ); ?>" /> 2142 <input type="hidden" id="referredby" name="referredby" value="<?php echo $referer ? esc_url( $referer ) : ''; ?>" /> 2143 <!-- These fields are not part of the standard post form. Used to redirect back to this page on save. --> 2144 <input type="hidden" name="gutenberg_meta_boxes" value="gutenberg_meta_boxes" /> 2145 2146 <?php 2147 if ( 'draft' !== get_post_status( $post ) ) { 2148 wp_original_referer_field( true, 'previous' ); 2149 } 2150 echo $form_extra; 2151 wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false ); 2152 wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); 2153 // Permalink title nonce. 2154 wp_nonce_field( 'samplepermalink', 'samplepermalinknonce', false ); 2155 } -
src/wp-admin/includes/template.php
diff --git a/src/wp-admin/includes/template.php b/src/wp-admin/includes/template.php index ca1121da82..2a32cbaf88 100644
a b function do_meta_boxes( $screen, $context, $object ) { 1051 1051 foreach ( (array) $wp_meta_boxes[ $page ][ $context ][ $priority ] as $box ) { 1052 1052 if ( false == $box || ! $box['title'] ) 1053 1053 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 1054 1071 $i++; 1055 1072 $hidden_class = in_array($box['id'], $hidden) ? ' hide-if-js' : ''; 1056 1073 echo '<div id="' . $box['id'] . '" class="postbox ' . postbox_classes($box['id'], $page) . $hidden_class . '" ' . '>' . "\n"; … … function do_meta_boxes( $screen, $context, $object ) { 1070 1087 } 1071 1088 echo "<h2 class='hndle'><span>{$box['title']}</span></h2>\n"; 1072 1089 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 1073 1127 call_user_func($box['callback'], $object, $box); 1074 1128 echo "</div>\n"; 1075 1129 echo "</div>\n";