diff -r c7c34916027a -r 177826044cd9 wp/wp-admin/includes/class-wp-screen.php --- a/wp/wp-admin/includes/class-wp-screen.php Mon Oct 14 18:06:33 2019 +0200 +++ b/wp/wp-admin/includes/class-wp-screen.php Mon Oct 14 18:28:13 2019 +0200 @@ -108,6 +108,7 @@ /** * The taxonomy associated with the screen, if any. * The 'edit-tags.php?taxonomy=category' screen has a taxonomy of 'category'. + * * @since 3.3.0 * @var string */ @@ -129,7 +130,7 @@ */ private $_help_sidebar = ''; - /** + /** * The accessible hidden headings and text associated with the screen, if any. * * @since 4.4.0 @@ -140,8 +141,6 @@ /** * Stores old string-based help. * - * @static - * * @var array */ private static $_old_compat_help = array(); @@ -159,8 +158,6 @@ * * @since 3.3.0 * - * @static - * * @var array */ private static $_registry = array(); @@ -182,16 +179,22 @@ private $_screen_settings; /** + * Whether the screen is using the block editor. + * + * @since 5.0.0 + * @var bool + */ + public $is_block_editor = false; + + /** * Fetches a screen object. * * @since 3.3.0 * - * @static - * * @global string $hook_suffix * * @param string|WP_Screen $hook_name Optional. The hook name (also known as the hook suffix) used to determine the screen. - * Defaults to the current $hook_suffix global. + * Defaults to the current $hook_suffix global. * @return WP_Screen Screen object. */ public static function get( $hook_name = '' ) { @@ -199,35 +202,38 @@ return $hook_name; } - $post_type = $taxonomy = null; - $in_admin = false; - $action = ''; + $post_type = $taxonomy = null; + $in_admin = false; + $action = ''; + $is_block_editor = false; - if ( $hook_name ) + if ( $hook_name ) { $id = $hook_name; - else + } else { $id = $GLOBALS['hook_suffix']; + } // For those pesky meta boxes. if ( $hook_name && post_type_exists( $hook_name ) ) { $post_type = $id; - $id = 'post'; // changes later. ends up being $base. + $id = 'post'; // changes later. ends up being $base. } else { - if ( '.php' == substr( $id, -4 ) ) + if ( '.php' == substr( $id, -4 ) ) { $id = substr( $id, 0, -4 ); + } if ( 'post-new' == $id || 'link-add' == $id || 'media-new' == $id || 'user-new' == $id ) { - $id = substr( $id, 0, -4 ); + $id = substr( $id, 0, -4 ); $action = 'add'; } } if ( ! $post_type && $hook_name ) { if ( '-network' == substr( $id, -8 ) ) { - $id = substr( $id, 0, -8 ); + $id = substr( $id, 0, -8 ); $in_admin = 'network'; } elseif ( '-user' == substr( $id, -5 ) ) { - $id = substr( $id, 0, -5 ); + $id = substr( $id, 0, -5 ); $in_admin = 'user'; } @@ -235,58 +241,75 @@ if ( 'edit-comments' != $id && 'edit-tags' != $id && 'edit-' == substr( $id, 0, 5 ) ) { $maybe = substr( $id, 5 ); if ( taxonomy_exists( $maybe ) ) { - $id = 'edit-tags'; + $id = 'edit-tags'; $taxonomy = $maybe; } elseif ( post_type_exists( $maybe ) ) { - $id = 'edit'; + $id = 'edit'; $post_type = $maybe; } } - if ( ! $in_admin ) + if ( ! $in_admin ) { $in_admin = 'site'; + } } else { - if ( defined( 'WP_NETWORK_ADMIN' ) && WP_NETWORK_ADMIN ) + if ( defined( 'WP_NETWORK_ADMIN' ) && WP_NETWORK_ADMIN ) { $in_admin = 'network'; - elseif ( defined( 'WP_USER_ADMIN' ) && WP_USER_ADMIN ) + } elseif ( defined( 'WP_USER_ADMIN' ) && WP_USER_ADMIN ) { $in_admin = 'user'; - else + } else { $in_admin = 'site'; + } } - if ( 'index' == $id ) + if ( 'index' == $id ) { $id = 'dashboard'; - elseif ( 'front' == $id ) + } elseif ( 'front' == $id ) { $in_admin = false; + } $base = $id; // If this is the current screen, see if we can be more accurate for post types and taxonomies. if ( ! $hook_name ) { - if ( isset( $_REQUEST['post_type'] ) ) + if ( isset( $_REQUEST['post_type'] ) ) { $post_type = post_type_exists( $_REQUEST['post_type'] ) ? $_REQUEST['post_type'] : false; - if ( isset( $_REQUEST['taxonomy'] ) ) + } + if ( isset( $_REQUEST['taxonomy'] ) ) { $taxonomy = taxonomy_exists( $_REQUEST['taxonomy'] ) ? $_REQUEST['taxonomy'] : false; + } switch ( $base ) { - case 'post' : - if ( isset( $_GET['post'] ) ) + case 'post': + if ( isset( $_GET['post'] ) && isset( $_POST['post_ID'] ) && (int) $_GET['post'] !== (int) $_POST['post_ID'] ) { + wp_die( __( 'A post ID mismatch has been detected.' ), __( 'Sorry, you are not allowed to edit this item.' ), 400 ); + } elseif ( isset( $_GET['post'] ) ) { $post_id = (int) $_GET['post']; - elseif ( isset( $_POST['post_ID'] ) ) + } elseif ( isset( $_POST['post_ID'] ) ) { $post_id = (int) $_POST['post_ID']; - else + } else { $post_id = 0; + } if ( $post_id ) { $post = get_post( $post_id ); - if ( $post ) + if ( $post ) { $post_type = $post->post_type; + + /** This filter is documented in wp-admin/post.php */ + $replace_editor = apply_filters( 'replace_editor', false, $post ); + + if ( ! $replace_editor ) { + $is_block_editor = use_block_editor_for_post( $post ); + } + } } break; - case 'edit-tags' : - case 'term' : - if ( null === $post_type && is_object_in_taxonomy( 'post', $taxonomy ? $taxonomy : 'post_tag' ) ) + case 'edit-tags': + case 'term': + if ( null === $post_type && is_object_in_taxonomy( 'post', $taxonomy ? $taxonomy : 'post_tag' ) ) { $post_type = 'post'; + } break; case 'upload': $post_type = 'attachment'; @@ -295,25 +318,35 @@ } switch ( $base ) { - case 'post' : - if ( null === $post_type ) + case 'post': + if ( null === $post_type ) { $post_type = 'post'; + } + + // When creating a new post, use the default block editor support value for the post type. + if ( empty( $post_id ) ) { + $is_block_editor = use_block_editor_for_post_type( $post_type ); + } + $id = $post_type; break; - case 'edit' : - if ( null === $post_type ) + case 'edit': + if ( null === $post_type ) { $post_type = 'post'; + } $id .= '-' . $post_type; break; - case 'edit-tags' : - case 'term' : - if ( null === $taxonomy ) + case 'edit-tags': + case 'term': + if ( null === $taxonomy ) { $taxonomy = 'post_tag'; + } // The edit-tags ID does not contain the post type. Look for it in the request. if ( null === $post_type ) { $post_type = 'post'; - if ( isset( $_REQUEST['post_type'] ) && post_type_exists( $_REQUEST['post_type'] ) ) + if ( isset( $_REQUEST['post_type'] ) && post_type_exists( $_REQUEST['post_type'] ) ) { $post_type = $_REQUEST['post_type']; + } } $id = 'edit-' . $taxonomy; @@ -330,20 +363,22 @@ if ( isset( self::$_registry[ $id ] ) ) { $screen = self::$_registry[ $id ]; - if ( $screen === get_current_screen() ) + if ( $screen === get_current_screen() ) { return $screen; + } } else { - $screen = new WP_Screen(); - $screen->id = $id; + $screen = new WP_Screen(); + $screen->id = $id; } - $screen->base = $base; - $screen->action = $action; - $screen->post_type = (string) $post_type; - $screen->taxonomy = (string) $taxonomy; - $screen->is_user = ( 'user' == $in_admin ); - $screen->is_network = ( 'network' == $in_admin ); - $screen->in_admin = $in_admin; + $screen->base = $base; + $screen->action = $action; + $screen->post_type = (string) $post_type; + $screen->taxonomy = (string) $taxonomy; + $screen->is_user = ( 'user' == $in_admin ); + $screen->is_network = ( 'network' == $in_admin ); + $screen->in_admin = $in_admin; + $screen->is_block_editor = $is_block_editor; self::$_registry[ $id ] = $screen; @@ -363,8 +398,8 @@ public function set_current_screen() { global $current_screen, $taxnow, $typenow; $current_screen = $this; - $taxnow = $this->taxonomy; - $typenow = $this->post_type; + $taxnow = $this->taxonomy; + $typenow = $this->post_type; /** * Fires after the current screen has been set. @@ -393,19 +428,34 @@ * @return bool True if the screen is in the indicated admin, false otherwise. */ public function in_admin( $admin = null ) { - if ( empty( $admin ) ) + if ( empty( $admin ) ) { return (bool) $this->in_admin; + } return ( $admin == $this->in_admin ); } /** + * Sets or returns whether the block editor is loading on the current screen. + * + * @since 5.0.0 + * + * @param bool $set Optional. Sets whether the block editor is loading on the current screen or not. + * @return bool True if the block editor is being loaded, false otherwise. + */ + public function is_block_editor( $set = null ) { + if ( $set !== null ) { + $this->is_block_editor = (bool) $set; + } + + return $this->is_block_editor; + } + + /** * Sets the old string-based contextual help for the screen for backward compatibility. * * @since 3.3.0 * - * @static - * * @param WP_Screen $screen A screen object. * @param string $help Help text. */ @@ -422,9 +472,9 @@ * @param string $parent_file The parent file of the screen. Typically the $parent_file global. */ public function set_parentage( $parent_file ) { - $this->parent_file = $parent_file; + $this->parent_file = $parent_file; list( $this->parent_base ) = explode( '?', $parent_file ); - $this->parent_base = str_replace( '.php', '', $this->parent_base ); + $this->parent_base = str_replace( '.php', '', $this->parent_base ); } /** @@ -482,11 +532,13 @@ * @return string The option value if set, null otherwise. */ public function get_option( $option, $key = false ) { - if ( ! isset( $this->_options[ $option ] ) ) + if ( ! isset( $this->_options[ $option ] ) ) { return null; + } if ( $key ) { - if ( isset( $this->_options[ $option ][ $key ] ) ) + if ( isset( $this->_options[ $option ][ $key ] ) ) { return $this->_options[ $option ][ $key ]; + } return null; } return $this->_options[ $option ]; @@ -533,8 +585,9 @@ * @return array Help tab arguments. */ public function get_help_tab( $id ) { - if ( ! isset( $this->_help_tabs[ $id ] ) ) + if ( ! isset( $this->_help_tabs[ $id ] ) ) { return null; + } return $this->_help_tabs[ $id ]; } @@ -563,13 +616,14 @@ 'callback' => false, 'priority' => 10, ); - $args = wp_parse_args( $args, $defaults ); + $args = wp_parse_args( $args, $defaults ); $args['id'] = sanitize_html_class( $args['id'] ); // Ensure we have an ID and title. - if ( ! $args['id'] || ! $args['title'] ) + if ( ! $args['id'] || ! $args['title'] ) { return; + } // Allows for overriding an existing tab with that ID. $this->_help_tabs[ $args['id'] ] = $args; @@ -635,7 +689,7 @@ return $this->columns; } - /** + /** * Get the accessible hidden headings and text used in the screen. * * @since 4.4.0 @@ -685,7 +739,7 @@ 'heading_pagination' => __( 'Items list navigation' ), 'heading_list' => __( 'Items list' ), ); - $content = wp_parse_args( $content, $defaults ); + $content = wp_parse_args( $content, $defaults ); $this->_screen_reader_content = $content; } @@ -734,7 +788,6 @@ * @param string $old_help Help text that appears on the screen. * @param string $screen_id Screen ID. * @param WP_Screen $this Current WP_Screen instance. - * */ $old_help = apply_filters( 'contextual_help', $old_help, $this->id, $this ); @@ -751,29 +804,33 @@ * @param string $old_help_default Default contextual help text. */ $default_help = apply_filters( 'default_contextual_help', '' ); - if ( $default_help ) + if ( $default_help ) { $old_help = '
' . $default_help . '
'; + } } if ( $old_help ) { - $this->add_help_tab( array( - 'id' => 'old-contextual-help', - 'title' => __('Overview'), - 'content' => $old_help, - ) ); + $this->add_help_tab( + array( + 'id' => 'old-contextual-help', + 'title' => __( 'Overview' ), + 'content' => $old_help, + ) + ); } $help_sidebar = $this->get_help_sidebar(); $help_class = 'hidden'; - if ( ! $help_sidebar ) + if ( ! $help_sidebar ) { $help_class .= ' no-sidebar'; + } // Time to render! ?>