What is the right way to issue commands in wp-admin? My plugin imports data from a set of RSS feeds via a cron job. Thats all working good. I've set up a custom settings page to change parameters, and wanted to add an "Update Now" button so the user could force a manual refresh. I need a few other commands as well.

What is the "wordpress way" to add and handle these commands?

I tried adding a url http://example.com/wp-admin/options-general.php?page=myplugin&action=update to the options page, then

if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'update') { doUpdate(); }

but i get an error showing $wp has not been initialised. I tried including the wp-load.php and the wp-settings.php but it didn't help.

Error message is Fatal error: Call to a member function add_rewrite_tag() on a non-object in /wordpress/wp-includes/rewrite.php on line 51

The lines causing the problem in doUpdate() are

    if (taxonomy_exists($name)) {

    $slug  = str_replace(' ', '_', $title);
             'labels'            => array( 'name' => __(ucwords($title)) ),
             'public'            => true,
             'show_ui'           => self::SHOW_UI,
             'show_in_nav_menus' => true,
             'show_admin_column' => true,
             'hierarchical'      => false,
             'query_var'         => $slug,
             'rewrite'           => array( 'slug' => __($slug) ),

What am I doing wrong? How can I allow the user to perform an action from an admin settings pane?

  • This sounds roughly correct but please post more code. The problem must be in the implementation. And post the complete unedited error message. – s_ha_dum Mar 15 '13 at 4:19

Always wait for init or wp_loaded, so you know all needed functions and classes are available.

add_action( 'wp_loaded', 'plugin_prefix_start' );

function plugin_prefix_start()
    if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'update') 
  • aagh! of course! thanks for the patient answer to my silly question. Its working beautifully now (after wasting hours trying to figure out why it wasn't). – Steve Mar 16 '13 at 0:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.