php - plugin activation hook not working in wordpress -
i'm trying develop first wordpress plugin , got staled in first stage. i'm trying setup options , database tables when plugin activated, no luck. no matter do, plugin activates, database untouched , options not stored in db. tried echoing inside constructor, seems never reaches it. have debug activated in wp, no error being reported. function not being hooked. can spot what's wrong code?
thanks in advance.
class myplugin { private static $instance; public static function get_instance() { if ( ! self::$instance ) { self::$instance = new self(); } return self::$instance; } private function __construct() { register_activation_hook( __file__, array( &$this, 'plugin_activate' ) ); } public function plugin_activate() { if ( version_compare( get_bloginfo( 'version' ), '3.8.2', ' < ' ) ) { deactivate_plugins( basename( __file__ ) ); } else { $rlm_rsvplus_options = array( 'db_version' => '1.0', 'event_name' => '', 'end_date' => '', ); update_option( 'rlm_myplugin_options', $rlm_myplugin_options ); require_once( "includes/rlm_myplugin_db_setup.php" );//it never reaches file. } } } $myplugin = myplugin::get_instance();
the register_activation_hook
call needs outside of class itself.
something like:
class myplugin { private static $instance; public static function get_instance() { if ( ! self::$instance ) { self::$instance = new self(); } return self::$instance; } private function __construct() { // other stuff here } public function plugin_activate() { if ( version_compare( get_bloginfo( 'version' ), '3.8.2', ' < ' ) ) { deactivate_plugins( basename( __file__ ) ); } else { $rlm_rsvplus_options = array( 'db_version' => '1.0', 'event_name' => '', 'end_date' => '', ); update_option( 'rlm_myplugin_options', $rlm_myplugin_options ); require_once( "includes/rlm_myplugin_db_setup.php" ); } } register_activation_hook( __file__, array( 'myplugin', 'plugin_activate' ) );
you can read more on following tutorial http://www.yaconiello.com/blog/how-to-write-wordpress-plugin/
Comments
Post a Comment