Title: Problem with &#039;register_activation_hook&#039; using static function
Last modified: August 21, 2016

---

# Problem with 'register_activation_hook' using static function

 *  [Junnie](https://wordpress.org/support/users/mad3000/)
 * (@mad3000)
 * [12 years, 10 months ago](https://wordpress.org/support/topic/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.

## Tags

 * [class](https://wordpress.org/support/topic-tag/class/)

 * 0 replies
 * 1 participant
 * Last reply from: [Junnie](https://wordpress.org/support/users/mad3000/)
 * Last activity: [12 years, 10 months ago](https://wordpress.org/support/topic/problem-with-register_activation_hook-using-static-function/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
