- Timestamp:
- 12/17/2018 09:51:43 PM (6 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/5.0 merged: 43941
- Property svn:mergeinfo changed
-
trunk/src/wp-admin/includes/post.php
r44260 r44280 2260 2260 } 2261 2261 2262 // If a meta box doesn't work in the block editor, don't show it in the block editor.2263 if ( isset( $meta_box['args']['__block_editor_compatible_meta_box'] ) && ! $meta_box['args']['__block_editor_compatible_meta_box'] ) {2264 continue;2265 }2266 2267 2262 $meta_boxes_per_location[ $location ][] = array( 2268 2263 'id' => $meta_box['id'], -
trunk/src/wp-admin/includes/template.php
r44244 r44280 1080 1080 } 1081 1081 1082 /** 1083 * Displays the meta boxes which are registered against the given screen and context. 1082 1083 /** 1084 * Function that renders a "fake" meta box with an information message, 1085 * shown on the block editor, when an incompatible meta box is found. 1086 * 1087 * @since 5.0.0 1088 * 1089 * @param mixed $object The data object being rendered on this screen. 1090 * @param array $box { 1091 * Custom formats meta box arguments. 1092 * 1093 * @type string $id Meta box 'id' attribute. 1094 * @type string $title Meta box title. 1095 * @type callable $old_callback The original callback for this meta box. 1096 * @type array $args Extra meta box arguments. 1097 * } 1098 */ 1099 function do_block_editor_incompatible_meta_box( $object, $box ) { 1100 $plugin = _get_plugin_from_callback( $box['old_callback'] ); 1101 $plugins = get_plugins(); 1102 echo '<p>'; 1103 if ( $plugin ) { 1104 /* translators: %s: the name of the plugin that generated this meta box. */ 1105 printf( __( "This meta box, from the %s plugin, isn't compatible with the block editor." ), "<strong>{$plugin['Name']}</strong>" ); 1106 } else { 1107 _e( "This meta box isn't compatible with the block editor." ); 1108 } 1109 echo '</p>'; 1110 1111 if ( empty( $plugins['classic-editor/classic-editor.php'] ) ) { 1112 if ( current_user_can( 'install_plugins' ) ) { 1113 echo '<p>'; 1114 /* translators: %s: A link to install the Classic Editor plugin. */ 1115 printf( __( 'Please install the <a href="%s">Classic Editor plugin</a> to use this meta box.' ), esc_url( self_admin_url( 'plugin-install.php?tab=featured' ) ) ); 1116 echo '</p>'; 1117 } 1118 } elseif ( is_plugin_inactive( 'classic-editor/classic-editor.php' ) ) { 1119 if ( current_user_can( 'activate_plugins' ) ) { 1120 $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' ); 1121 echo '<p>'; 1122 /* translators: %s: A link to activate the Classic Editor plugin. */ 1123 printf( __( 'Please activate the <a href="%s">Classic Editor plugin</a> to use this meta box.' ), esc_url( $activate_url ) ); 1124 echo '</p>'; 1125 } 1126 } elseif ( $object instanceof WP_Post ) { 1127 $edit_url = add_query_arg( 'classic-editor', '', get_edit_post_link( $object ) ); 1128 echo '<p>'; 1129 /* translators: %s: A link to use the Classic Editor plugin. */ 1130 printf( __( 'Please open the <a href="%s">classic editor</a> to use this meta box.' ), esc_url( $edit_url ) ); 1131 echo '</p>'; 1132 } 1133 } 1134 1135 /** 1136 * Internal helper function to find the plugin from a meta box callback. 1137 * 1138 * @since 5.0.0 1139 * 1140 * @access private 1141 * 1142 * @param callable $callback The callback function to check. 1143 * @return array|null The plugin that the callback belongs to, or null if it doesn't belong to a plugin. 1144 */ 1145 function _get_plugin_from_callback( $callback ) { 1146 try { 1147 if ( is_array( $callback ) ) { 1148 $reflection = new ReflectionMethod( $callback[0], $callback[1] ); 1149 } elseif ( is_string( $callback ) && false !== strpos( $callback, '::' ) ) { 1150 $reflection = new ReflectionMethod( $callback ); 1151 } else { 1152 $reflection = new ReflectionFunction( $callback ); 1153 } 1154 } catch ( ReflectionException $exception ) { 1155 // We could not properly reflect on the callable, so we abort here. 1156 return null; 1157 } 1158 1159 // Don't show an error if it's an internal PHP function. 1160 if ( ! $reflection->isInternal() ) { 1161 1162 // Only show errors if the meta box was registered by a plugin. 1163 $filename = wp_normalize_path( $reflection->getFileName() ); 1164 $plugin_dir = wp_normalize_path( WP_PLUGIN_DIR ); 1165 if ( strpos( $filename, $plugin_dir ) === 0 ) { 1166 $filename = str_replace( $plugin_dir, '', $filename ); 1167 $filename = preg_replace( '|^/([^/]*/).*$|', '\\1', $filename ); 1168 1169 $plugins = get_plugins(); 1170 foreach ( $plugins as $name => $plugin ) { 1171 if ( strpos( $name, $filename ) === 0 ) { 1172 return $plugin; 1173 } 1174 } 1175 } 1176 } 1177 1178 return null; 1179 } 1180 1181 /** 1182 * Meta-Box template function. 1084 1183 * 1085 1184 * @since 2.5.0 … … 1145 1244 } 1146 1245 1147 // If a meta box doesn't work in the block editor, don't show it in the block editor.1148 if ( $screen->is_block_editor() && isset( $box['args']['__block_editor_compatible_meta_box'] ) && ! $box['args']['__block_editor_compatible_meta_box'] ) {1149 continue;1150 }1151 1152 1246 if ( isset( $box['args']['__block_editor_compatible_meta_box'] ) ) { 1153 1247 $block_compatible = (bool) $box['args']['__block_editor_compatible_meta_box']; 1154 1248 unset( $box['args']['__block_editor_compatible_meta_box'] ); 1249 } 1250 1251 // If the meta box is declared as incompatible with the block editor, override the callback function. 1252 if ( ! $block_compatible && $screen->is_block_editor() ) { 1253 $box['old_callback'] = $box['callback']; 1254 $box['callback'] = 'do_block_editor_incompatible_meta_box'; 1155 1255 } 1156 1256 … … 1189 1289 1190 1290 if ( WP_DEBUG && ! $block_compatible && 'edit' === $screen->parent_base && ! $screen->is_block_editor() && ! isset( $_GET['meta-box-loader'] ) ) { 1191 if ( is_array( $box['callback'] ) ) { 1192 $reflection = new ReflectionMethod( $box['callback'][0], $box['callback'][1] ); 1193 } elseif ( false !== strpos( $box['callback'], '::' ) ) { 1194 $reflection = new ReflectionMethod( $box['callback'] ); 1195 } else { 1196 $reflection = new ReflectionFunction( $box['callback'] ); 1197 } 1198 1199 // Don't show an error if it's an internal PHP function. 1200 if ( ! $reflection->isInternal() ) { 1201 1202 // Only show errors if the meta box was registered by a plugin. 1203 $filename = $reflection->getFileName(); 1204 if ( strpos( $filename, WP_PLUGIN_DIR ) === 0 ) { 1205 $filename = str_replace( WP_PLUGIN_DIR, '', $filename ); 1206 $filename = preg_replace( '|^/([^/]*/).*$|', '\\1', $filename ); 1207 1208 $plugins = get_plugins(); 1209 foreach ( $plugins as $name => $plugin ) { 1210 if ( strpos( $name, $filename ) === 0 ) { 1211 ?> 1212 <div class="error inline"> 1213 <p> 1214 <?php 1215 /* translators: %s: the name of the plugin that generated this meta box. */ 1216 printf( __( "This meta box, from the %s plugin, isn't compatible with the block editor." ), "<strong>{$plugin['Name']}</strong>" ); 1217 ?> 1218 </p> 1219 </div> 1220 <?php 1221 } 1222 } 1223 } 1291 $plugin = _get_plugin_from_callback( $box['callback'] ); 1292 if ( $plugin ) { 1293 ?> 1294 <div class="error inline"> 1295 <p> 1296 <?php 1297 /* translators: %s: the name of the plugin that generated this meta box. */ 1298 printf( __( "This meta box, from the %s plugin, isn't compatible with the block editor." ), "<strong>{$plugin['Name']}</strong>" ); 1299 ?> 1300 </p> 1301 </div> 1302 <?php 1224 1303 } 1225 1304 }
Note: See TracChangeset
for help on using the changeset viewer.