WordPress: register_activation_hook not working

I currently writing a wordpress plugin, and i encountered some problem.
my function does not run upon plugin activation… can somebody tell me where is the proble?


class my_plugin {

    public $ajaxurl;
    public $excanvas;
    public $plugin_path = '';

    function __construct()
    {

        register_activation_hook(__FILE__,array(&$this, 'install'));
    }


    public function wpmon_install()
    {
        //Copy my page template to current theme.

        $plugin_path    =   getcwd() . DIRECTORY_SEPARATOR . 'wp-content'. DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'wpmon' . DIRECTORY_SEPARATOR;
        $target_path    =   get_stylesheet_directory(). DIRECTORY_SEPARATOR;
        $target_path    =   str_replace('/',DIRECTORY_SEPARATOR,$target_path);
        $template_files =   glob($plugin_path . 'page_template'.DIRECTORY_SEPARATOR.'*.php');

        foreach($template_files as $files)
        {
            $basename = basename($files);
            try{
                $target = $target_path . $basename;
                copy($files , $target);

            }
            catch(Exception $e){

                $this->log_error( $e->getMessage());
            }
        }
    } 

but unfortunately the install function not working…
but when outside class this code inside ‘install’ func is working

Related posts

Leave a Reply

3 comments

  1. From the posted code I can see two problems. install should be changed to wpmon_install. Also you should add some code to initialize your class.

    i.e. $wp_mon = new my_plugin(); after class my_plugin { }

  2. Please check if you’re using softlink, the plugin must exactly in /path/to/wordpress/wp-content/plugins/yourplugin, meaning to say that yourplugin is not a softlink.

  3. You have WordPress trying to call a function called install in your class, but it doesn’t exist. So try changing:

    register_activation_hook(__FILE__,array(&$this, 'install'));
    

    to

    register_activation_hook(__FILE__,array(&$this, 'wpmon_install'));