Fix WordPress Plugin wp-db-backup Missing Context Help

Problem: context help in dashboard -> tools -> backup, is empty or missing

Situation:

  • After upgrading WordPress to version >= 3.3
  • WordPress plugin wp-db-backup version 2.2.3 (current as of Mar, 2013)

Symptoms:

  • Context help tab on the backup page is missing or empty
  • With WP_DEBUG enabled you see
    Notice: add_contextual_help is deprecated since version 3.3! Use get_current_screen()->add_help_tab() instead.”

The Hack:

  • File: /…/plugins/wp-db-backup/wp-db-backup.php
  • Replace the function admin_menu(), near line 604, in  with the following:
    function admin_menu() {
        $_page_hook = add_management_page(__('Backup','wp-db-backup'), __('Backup','wp-db-backup'), 'import', $this->basename, array(&$this, 'backup_menu')); // $_page_hook = "tools_page_wp-db-backup"
        # add_action( $action_name_tag, $callback_function_to_add [, $priority=10 [, $num_accepted_args=1 ]] );
        add_action('load-' . $_page_hook, array(&$this, 'admin_load'));
        # start of dwb flail to fix missing context help tab, and prevent dashboard debug Notice:
        # "add_contextual_help is deprecated since version 3.3! Use get_current_screen()->add_help_tab() instead."
        # wp docs suggest $screen = get_current_screen();  DOES NOT WORK FROM WITHIN THIS CLASS $screen_obj is NULL
        # add_action( $action_name_tag, $callback_function_to_add [, $priority=10 [, $num_accepted_args=1 ]] );
        # in wp >= 3.3, might also be possible with static method WP_Screen::add_old_compat_help( $screen, $help )
        #echo "<pre>[".basename(__FILE__)."](".__LINE__.') get_class_methods (\'WP_Screen\') : '; var_dump( get_class_methods ('WP_Screen') ); echo "</pre>"; exit;
        if ( method_exists( 'WP_Screen', 'get') ) {
        #if ( class_exists( 'WP_Screen', false ) ) {    # also works
            $screen_obj = WP_Screen::get($_page_hook);
            $screen_obj->add_help_tab( array(
             'id' => $this->basename,                        //unique id for the tab
             'title' => 'Backup',                                //unique visible title for the tab
             'content' => $this->help_menu(),        //actual help text
             'callback' => false                                //optional function to callback
            ) );
        } # end of dwb flail
        elseif ( function_exists('add_contextual_help') ) {        // fallback to wp < 3.3
            $text = $this->help_menu();
            add_contextual_help($_page_hook, $text);
        }
    }

Please comment, whether you have success or not. Thank you.

Leave a comment

Your email address will not be published. Required fields are marked *

1 + 9 =