Problem with 'register_activation_hook' using static function
-
Hello
I’m now building a plugin using class and facing a problem.
I created a class as below, which is a simplified version,class MyClass { public static function register_activation_hook() { $new_page = array( 'comment_status' => 'closed', 'ping_status' => 'closed', 'post_content' => 'default content', 'post_status' => 'publish', 'post_title' => 'default title', 'post_type' => 'page' ); $new_page_id = wp_insert_post( $new_page ); } public function __construct() { // } } register_activation_hook( __FILE__, MyClass::register_activation_hook ); $myClass = new MyClass();If I activate it, it returns an error message,
Fatal error: Call to a member function get_page_permastruct() on a non-object in /homepages/mysite/wp-includes/link-template.php on line 271
It seems that $new_page_id = wp_insert_post( $new_page ); causes the error.
If I make register_activation_hook as just public function and call it within the constructor, it works fine. I don’t think that it doesn’t really matter but I would like to know why it doesn’t work…
Any tip or help would be grateful!Many thanks
The topic ‘Problem with 'register_activation_hook' using static function’ is closed to new replies.