get_current_screen is a very helpful WordPress perform; sadly, it’s not all the time obtainable relying on how early you might want it

This doesn’t imply there aren’t other ways to detect what display we’re on, although. It simply takes some artistic conditionals given what each WordPress and PHP present.

When You Can’t Get the Present Display screen

There are a couple of caveats to this technique (as-in in could not work for each case), however it’s one thing price contemplating ought to it’s essential to hook into the WordPress life cycle.

For instance, let’s say it’s essential to do one thing the the display the place you edit the publish however it’s a must to do it at a time throughout which the get_current_screen object isn’t obtainable.

What then?

Why not have a look at the URL and/or the question string variables obtainable in PHP after which use one of many filter_input capabilities to examine and see. Living proof:

add_action('admin_init', perform () {
    if (0 < intval(filter_input(INPUT_GET, 'publish'))) {
        // TODO ...
    }
});

From right here, you understand you’re engaged on a publish or a customized publish kind and also you’re ensuring that it’s legitimate since you’re verifying the ID is bigger than 0.

Once more, this will not work in all circumstances, however it’s actually one possibility that now we have at our disposal when different API capabilities aren’t but prepared.