I'm working on my Plugin & i wanted to declare one of the global wordpress variables which is $current_screen
To Check whether The user is on the target page or some other page, my Approach was like this , but it didn't work out .
class my_Class {
public $current_screen;
public function __construct() {
global $current_screen;
add_action( 'current_screen', array( $this, 'Current_Screen') );
}
public function Current_Screen() {
if ( $current_screen->parent_base == 'slug-page' ) {
// Do Something ...
}
}
}
Unfortunately Nothing Happens but Fatal Error . So Please Guys I Wanna Help . Thanks In Advance .