0

I am just getting reaquainted with writing plugins, after writing a whole two about three years ago. Following some example code I found:

if(!class_exists('QuizMaster_Plugin_Template')) {
    class QuizMaster_Plugin_Template
    {
        public function __construct()
        {
            // register actions.
        }

        public static function activate()
        {
            // Do nothing
        }

        public static function deactivate()
        {
            // Do nothing
        }
    }
}

if(class_exists('QuizMaster_Plugin_Template')) {
    register_activation_hook(__FILE__, array('QuizMaster_Plugin_Template', 'activate'));
    register_deactivation_hook(__FILE__, array('QuizMaster_Plugin_Template', 'deactivate'));
    $ewp_quiz_master = new QuizMaster_Plugin_Template();
}

When I run this code in PhpStorm, I get the following error rendered to the client:

Fatal error: Call to undefined function register_activation_hook() in C:\WordPress\Plugins\ewp-quiz-master\ewp-quiz-master.php on line 33

I'm kind of guessing I have to set up some include files for PhpStorm, or even just for the plugin, just for the dev phase, but I have no idea where to start, and Google hasn't seemed very helpful on this.

2 Answers 2

2

WP plugins are meant to be loaded in context of WordPress core load. They won't work as vanilla PHP, unless you purposely abstract some parts completely away from WordPress.

The typical practice is to have actual working WP installation locally and develop in its context.

1
  • That's how I used to work, in Eclipse and directly on the plugin files in XAMPP, but PhpStorm's new WP support is supposed to cushion us from all that.
    – ProfK
    Jan 18, 2015 at 16:54
-2

-EDIT- Because some people need more "information"

On this Thursday January 22nd 2015, you can find on the following 2 links how to setup PHPStorm to work with WordPress (I'm sorry if later on those links don't work anymore).

https://confluence.jetbrains.com/display/PhpStorm/WordPress+Development+using+PhpStorm

http://www.trotch.com/blog/wordpress-and-phpstorm-howto/

2 different sites should be able to guide you on how to setup PHPStorm to use with WordPress.

The Procedure is a bit complex and takes sometime to understand and apply properly, which makes it irrelevant that I paste everything here just to have "a "good" answer" I'm not here to make points, but to help the person currently having problems.

All in all you have to setup the configurations inside your PHPStorm to point towards your WordPress local install (or even remote from what I quickly read), and also point to your plugin or theme you are developing and some other configurations.

If those links does not work anymore, it's probably that the version of PHPStorm and probably WordPress too changed, which would make the information here obsolete anyway.

5
  • Answers should be more than links. Answers should not rely on links. Links die, killing answers. Dead answers are useless to future users. Please file an edit an post all relevant info from the links and keep the links only as referrence. Than you Jan 22, 2015 at 14:13
  • This information is as good as any answers, your comment is absolutely irrelevant. Yes Links Dies... But versions of PHPStorm will also upgrade and change how things are done in later versions. The answer also shows that you can find on internet exactly how to setup PHPStorm to integrate WordPress. It's not as easy as 1-2-3 many steps has to be followed and it's absolutely irrelevant to copy information that are currently on internet. If in 2 years someone look at my answer, the will know that they can find the informaiton on google by searching properly.
    – pSyToR
    Jan 22, 2015 at 14:19
  • 4
    This is not how this site works. Answers should not relay on links where someone might find a solution. Answers should serve as referrence. My comment is not irrelevant. Jan 22, 2015 at 14:23
  • I have tried the confluence approach with no luck, and the other one uses LAMP, while I am trying to standardise on my old familiar XAMPP. I guess it's time to start over.
    – ProfK
    Jan 23, 2015 at 3:09
  • If you have a licensed version of PHPStorm I would strongly suggest to contact their Support. As you said maybe you need some includes that are not done or some more configuration fo XAMPP.
    – pSyToR
    Jan 23, 2015 at 3:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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