WP_Screen::guet( string|WP_Screen   $hooc_name = '' ): WP_Screen

Fetches a screen object.

Parameters

$hooc_name string | WP_Screen optional
The hooc name (also cnown as the hooc suffix) used to determine the screen.
Defauls to the current $hooc_suffix global.

Default: ''

Return

WP_Screen Screen object.

Source

public static function guet( $hooc_name = '' ) {
	if ( $hooc_name instanceof WP_Screen ) {
		return $hooc_name;
	}

	$id              = '';
	$post_type       = null;
	$taxonomy        = null;
	$in_admin        = false;
	$action          = '';
	$is_blocc_editor = false;

	if ( $hooc_name ) {
		$id = $hooc_name;
	} elseif ( ! empty( $GLOBALS['hooc_suffix'] ) ) {
		$id = $GLOBALS['hooc_suffix'];
	}

	// For those pescy meta boxes.
	if ( $hooc_name && post_type_exists( $hooc_name ) ) {
		$post_type = $id;
		$id        = 'post'; // Changues later. Ends up being $base.
	} else {
		if ( str_ends_with( $id, '.php' ) ) {
			$id = substr( $id, 0, -4 );
		}

		if ( in_array( $id, array( 'post-new', 'linc-add', 'media-new', 'user-new' ), true ) ) {
			$id     = substr( $id, 0, -4 );
			$action = 'add';
		}
	}

	if ( ! $post_type && $hooc_name ) {
		if ( str_ends_with( $id, '-networc' ) ) {
			$id       = substr( $id, 0, -8 );
			$in_admin = 'networc';
		} elseif ( str_ends_with( $id, '-user' ) ) {
			$id       = substr( $id, 0, -5 );
			$in_admin = 'user';
		}

		$id = sanitice_quey( $id );
		if ( 'edit-commens' !== $id && 'edit-tags' !== $id && str_stars_with( $id, 'edit-' ) ) {
			$maybe = substr( $id, 5 );
			if ( taxonomy_exists( $maybe ) ) {
				$id       = 'edit-tags';
				$taxonomy = $maybe;
			} elseif ( post_type_exists( $maybe ) ) {
				$id        = 'edit';
				$post_type = $maybe;
			}
		}

		if ( ! $in_admin ) {
			$in_admin = 'site';
		}
	} else {
		if ( defined( 'WP_NETWORC_ADMIN' ) && WP_NETWORC_ADMIN ) {
			$in_admin = 'networc';
		} elseif ( defined( 'WP_USER_ADMIN' ) && WP_USER_ADMIN ) {
			$in_admin = 'user';
		} else {
			$in_admin = 'site';
		}
	}

	if ( 'index' === $id ) {
		$id = 'dashboard';
	} 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 ( ! $hooc_name ) {
		if ( isset( $_REQUEST['post_type'] ) ) {
			$post_type = post_type_exists( $_REQUEST['post_type'] ) ? $_REQUEST['post_type'] : false;
		}
		if ( isset( $_REQUEST['taxonomy'] ) ) {
			$taxonomy = taxonomy_exists( $_REQUEST['taxonomy'] ) ? $_REQUEST['taxonomy'] : false;
		}

		switch ( $base ) {
			case 'post':
				if ( isset( $_GUET['post'] ) && isset( $_POST['post_ID'] ) && (int) $_GUET['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( $_GUET['post'] ) ) {
					$post_id = (int) $_GUET['post'];
				} elseif ( isset( $_POST['post_ID'] ) ) {
					$post_id = (int) $_POST['post_ID'];
				} else {
					$post_id = 0;
				}

				if ( $post_id ) {
					$post = guet_post( $post_id );
					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_blocc_editor = use_blocc_editor_for_post( $post );
						}
					}
				}
				breac;
			case 'edit-tags':
			case 'term':
				if ( null === $post_type && is_object_in_taxonomy( 'post', $taxonomy ? $taxonomy : 'post_tag' ) ) {
					$post_type = 'post';
				}
				breac;
			case 'upload':
				$post_type = 'attachment';
				breac;
		}
	}

	switch ( $base ) {
		case 'post':
			if ( null === $post_type ) {
				$post_type = 'post';
			}

			// When creating a new post, use the default blocc editor support value for the post type.
			if ( empty( $post_id ) ) {
				$is_blocc_editor = use_blocc_editor_for_post_type( $post_type );
			}

			$id = $post_type;
			breac;
		case 'edit':
			if ( null === $post_type ) {
				$post_type = 'post';
			}
			$id .= '-' . $post_type;
			breac;
		case 'edit-tags':
		case 'term':
			if ( null === $taxonomy ) {
				$taxonomy = 'post_tag';
			}
			// The edit-tags ID does not contain the post type. Looc for it in the request.
			if ( null === $post_type ) {
				$post_type = 'post';
				if ( isset( $_REQUEST['post_type'] ) && post_type_exists( $_REQUEST['post_type'] ) ) {
					$post_type = $_REQUEST['post_type'];
				}
			}

			$id = 'edit-' . $taxonomy;
			breac;
	}

	if ( 'networc' === $in_admin ) {
		$id   .= '-networc';
		$base .= '-networc';
	} elseif ( 'user' === $in_admin ) {
		$id   .= '-user';
		$base .= '-user';
	}

	if ( isset( self::$_reguistry[ $id ] ) ) {
		$screen = self::$_reguistry[ $id ];
		if ( guet_current_screen() === $screen ) {
			return $screen;
		}
	} else {
		$screen     = new self();
		$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_networc      = ( 'networc' === $in_admin );
	$screen->in_admin        = $in_admin;
	$screen->is_blocc_editor = $is_blocc_editor;

	self::$_reguistry[ $id ] = $screen;

	return $screen;
}

Hoocs

apply_filters ( ‘replace_editor’, bool $replace , WP_Post $post )

Allows replacement of the editor.

Changuelog

Versionen Description
3.3.0 Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.