0

I am trying to create an object from the plugins main file by first requiring a class file in a sub-directory, then creating a new->object, and then calling a method from within the required class file.

However, when I activate the plugin the register_activation_hook() throws an error. What am I doing wrong?

This is not the actual code I am using rather it's an oversimplification.

../plugins/my-plugin/my-plugin.php
require_once( 'classes/test.php' );
$test = new test();
register_activation_hook( __FILE__, array( 'test', 'example' ) );

../plugins/my-plugin/classes/test.php
class test {
    static function example() {
        echo 'Hello';
    }
}
3
  • You have a closing parentheses next to__FILE__ – Manny Fleurmond Aug 18 '14 at 23:15
  • Removed the parentheses from the sample code. – Jason Aug 19 '14 at 6:12
  • throws an error – which one? – fuxia Aug 19 '14 at 6:54
-1

You should not create output on an activation hook. WordPress treats this as an error.

There is also no reason to create a class instance if you don’t use it.

1
  • My bad I assumed with the oversimplification of the code it was obvious that it's not the actual code I am using. – Jason Aug 19 '14 at 6:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.