check for the current screen
i'm working on my core theme plugin, i created a theme options in theme admin page, normally to avoid nonces errors, i must separate the sections with tabbed navigation, so i successfully did it , the idea was to set one section as default when the user enter the theme options page, when i tried to do , the only way to do it is to check on the current screen either with get_current_screen()
function or the global variable $current_screen
, unfortunately with the classes oop i couldn't achieve it with success .
that's my code .
class myClass {
protected $curScreen;
public function load_Hooks() {
if ( is_admin() ) {
add_action( 'admin_init', array( $this, 'admin_Settins_Pages' ) );
}
global $current_screen;
$this-curScreen = $current_screen;
}
public function admin_Settins_Pages() {
global $current_screen;
if ( $this-curScreen-parent_base == 'parent-page-slug' || isset( $_GET['tab'] ) $_GET['tab'] == 'head_options' ) {
add_settings_section( 'handle-id', 'Head Options', array( $this, 'head_section_callback' ), 'parent-page-slug' );
}
}
public function head_section_callback() {
// Do Something ...
}
}
if ( class_exists('myClass') ) {
$instClass = new myClass();
$instClass-load_Hooks();
}
- when i use the function
get_current_screen()
i fall in fatal error ( call to undefined function). - when i use the global variable
$current_screen
i fall in notice error ( trying to call property of non-object).
so please guys, i'm in need for solution, i hope someone can help me work it out. thanks in advance.
Topic screen-options settings-api errors plugins Wordpress
Category Web