• Resolved new_B

    (@new_b)


    Hi,

    Thanks for the useful plugin.

    I’m getting the following message:
    REQUIRED: add_contextual_help found in the file inc/theme-options.php. Deprecated since version 3.3. Use get_current_screen()->add_help_tab() instead.

    I’ve tried multiple variations but am having trouble getting it to work.

    Old code:
    add_contextual_help( $theme_page, $help );

    New code:

    get_current_screen()->add_help_tab( array(
       'id' => 'theme_options_help_tab',
       'title' => __('Theme Options Help Tab'),
       'content' => $help,
    ) );

    I’m getting the following error:

    Fatal error: Call to a member function add_help_tab() on a non-object

    Thanks in advance for any help you can provide.

    https://www.ads-software.com/extend/plugins/theme-check/

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter new_B

    (@new_b)

    correction–noticed an extra comma

    New code:

    get_current_screen()->add_help_tab( array(
       'id' => 'theme_options_help_tab',
       'title' => __('Theme Options Help Tab'),
       'content' => $help
    ) );
    Plugin Author Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    What action are you hooking this to?

    The way it works is that you create an admin page, then you can hook to it so that it will do stuff when that page is loaded. Like this:

    add_action('admin_menu', 'example_menu_add');
    function example_menu_add() {
    // add the menu item and screen
    $hook = add_menu_page( 'Whatever', 'Whatever', 'manage_options', 'whatever', 'whatever_admin' );
    add_action( "load-$hook", 'example_menu_load' );
    }

    In the function that is hooked to that load-$hook, I can call get_current_screen() and get back a valid object. But I can’t just call get_current_screen from anywhere, because the screen object might not exist yet. The load-$hook is the hook for my specific screen, and it will get called to create the info for my screen, so then I can be assured that get_current_screen() will return something meaningful.

    Thread Starter new_B

    (@new_b)

    Thanks, Samuel. I have the following:

    /**
     * Add our theme options page to the admin menu, including some help
     * documentation.
     *
     * This function is attached to the admin_menu action hook.
     */
    function abc_theme_options_add_page() {
    
    $theme_page = add_theme_page(
    		__( 'Theme Options', 'abc' ),   // Name of page
    		__( 'Theme Options', 'abc' ),   // Label in menu
    		'edit_theme_options',    // Capability required
    		'theme_options',   // Menu slug, used to uniquely identify the page
    		'abc_theme_options_render_page' // Function that renders the options page
    	);
    
    	if ( ! $theme_page )
    		return;
    
    	$help = '<p>'.__('Some help text').'</p>';
    
    	 get_current_screen()->add_help_tab( array(
    		'id' => 'my_help_tab',
    		'title' => 'My Help Tab',
    		'content' => $help
    	 ));
    
    	//add_contextual_help( $theme_page, $help );
    }
    add_action( 'admin_menu', 'abc_theme_options_add_page' );
    Plugin Author Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    You need to move the function calls that add the help page out into their own function with a different hook. Like this:

    function abc_theme_options_add_page() {
    
    $theme_page = add_theme_page(
    		__( 'Theme Options', 'abc' ),   // Name of page
    		__( 'Theme Options', 'abc' ),   // Label in menu
    		'edit_theme_options',    // Capability required
    		'theme_options',   // Menu slug, used to uniquely identify the page
    		'abc_theme_options_render_page' // Function that renders the options page
    	);
    
    	add_action( "load-$theme_page", 'abc_theme_options_add_help' );
    }
    add_action( 'admin_menu', 'abc_theme_options_add_page' );
    
    function abc_theme_options_add_help() {
    	$help = '<p>'.__('Some help text').'</p>';
    
    	 get_current_screen()->add_help_tab( array(
    		'id' => 'my_help_tab',
    		'title' => 'My Help Tab',
    		'content' => $help
    	 ));
    }
    Plugin Author Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    Edit: The hook should be "load-$theme_page", with a dash, not an underscore like I typo’ed a moment ago.

    Thread Starter new_B

    (@new_b)

    Thanks so much Samuel–much appreciated. Worked like a charm!

    Just used this to update a theme options page as well, thanks Otto!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘add_contextual_help deprecated – need help’ is closed to new replies.