Forums

[resolved] error when deactivating custom plugin (6 posts)

  1. philbert_mcpleb
    Member
    Posted 2 weeks ago #

    I am writing a small plugin to manage some downloads, currently i am still setting up the basics but have run into a problem.

    When i try to deactivate the plugin i get the error below

    Warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'WP_download_manager::deactivate' was given in /home/philbert/web-published/devbert/test1/wp-includes/plugin.php on line 339

    the same deactivation function and hook is used in another or my plugins and works without issue. does anyone have any ideas?

    thanks

  2. MikeChallis
    Member
    Posted 2 weeks ago #

    It would be hard to comment on unseen code. Do you have a code sample?

  3. philbert_mcpleb
    Member
    Posted 2 weeks ago #

    here are the functions that activate and deactivate the plugin.

    register_activation_hook(__File__, array('WP_download_manager', 'activate'));
    register_deactivation_hook(__File__, array('WP_download_manager', 'deactivate'));
    //add actions for the types of pages to display
    add_action('admin_menu', 'WP_download_manager_admin');
    
    	function activate()
    		{
    		//stuff plugin should do on activation goes here
    		$data = array('title' => "WPDM_option");
    		if ( ! get_option('WPDM_option'))
    		{ add_option('WPDM_option' , $data); }
    		else
    		{ update_option('WPDM_option' , $data); }
    		}
    
    	function deactivate()
    		{
    		//deactivation commands go here
    		delete_option('WPDM_option');
    		}
  4. MikeChallis
    Member
    Posted 2 weeks ago #

    In my plugins, I only delete options with the register_uninstall_hook. Because if you use the register_deactivation_hook options will be deleted with automatic plugin upgrades, or if an admin deactivates plugins for troubleshooting reasons.

    The code you posted will not work.
    This is what I would do:

    register_activation_hook(__File__,'wp_download_manager_activate');
    
    // options deleted when this plugin is deleted in WP 2.7+
    if ( function_exists('register_uninstall_hook') ) {
        register_uninstall_hook(__FILE__,'wp_download_manager_delete');
    }
    
    function wp_download_manager_activate()
    		{
    		//stuff plugin should do on activation goes here
    		$data = array('title' => "WPDM_option");
    		if ( ! get_option('WPDM_option'))
    		{ add_option('WPDM_option' , $data); }
    		else
    		{ update_option('WPDM_option' , $data); }
    }
    
    function wp_download_manager_delete()
    		{
    		//delete commands go here
    		delete_option('WPDM_option');
    }

    If you are using a class, your function wp_download_manager_deactivate must not be in the class or it will not work.

    Also you should not use too generic function names or they will clash with other plugins or WP itself (notice I changed them)

    You can look at one of my plugins if you want to see how I do it.
    http://wordpress.org/extend/plugins/si-contact-form/

  5. philbert_mcpleb
    Member
    Posted 1 week ago #

    thanks for that, i can't test it for a few days as i have no home internet until my ISP fixes it. i will let you know how i get on.

  6. philbert_mcpleb
    Member
    Posted 1 week ago #

    Just been able to try the changes you suggested. they seem to be working well. Many thanks

Reply

You must log in to post.

About this Topic

Tags