duangangpin078794 2012-09-27 05:31
浏览 125

Wordpress:register_activation_hook无效

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

  • 写回答

3条回答 默认 最新

  • douyong6585 2012-09-27 05:47
    关注

    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'));
    
    评论

报告相同问题?

悬赏问题

  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序