mardi 17 mai 2016

Proper way of validating if I'm on the right screen in Wordpress

I'm developing a wordpress plugin and I want to check if i'm on the right screen and I have this approach to it.

class Tome_Places
{
    function __construct( $loader )
    {
        $this->loader = $loader;

        $this->define_admin_hooks();
    }

    private function define_admin_hooks()   
    {
        $this->loader->add_action('in_admin_header', $this, 'current_screen');
    }


    function start_wrapper() {
            global $pagenow, $post_type;

            if ( $pagenow == 'post.php' && $post_type == 'tome_place' )
                echo '<div class="chapter-wrapper">';
    }


    function end_wrapper() {
            global $pagenow, $post_type;

            if ( $pagenow == 'post.php' && $post_type == 'tome_place' )
                echo '</div>';
    }

}

is there any better approach instead of asking in each function if ( $pagenow == 'post.php' && $post_type == 'tome_place' ?

thank you



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire