Sometimes we may need to determine if the current block editor is used to edit the full site or a particular single post/page. While these two are similar, they have mechanisms that are different and you may need to detect which one is currently in use. For example, the editor has different data stores on each of these screens.
The following function will return site
if it’s a full-site editing or post
if it’s a single post/page editing.
function zwp_get_editor_screen()
{
$filename = isset($_SERVER["SCRIPT_FILENAME"])
? sanitize_file_name(
basename(
wp_unslash(
$_SERVER["SCRIPT_FILENAME"]
),
'.php'
)
)
: null;
if ('post' === $filename || 'post-new' === $filename) {
return 'post';
}
return 'site';
}