PhpStorm - Configuring to edit Wordpress - unable to find functions

I've followed all of the help I can about configuring PhpStorm to work with a Wordpress site.

- I've enabled Wordpress Integration and pointed this to the WAMP wordpress directory on my local hard drive
- The Wordpress plugin is installed and enabled
- I've included a PHP include path to the WAMP Wordpress directory

However when I come to edit a wordpress file, all of the functions are highglighted with "Undefined Function" and WordPress hook registration (with add_action and add_filter functions) doesn't work.

errors.PNG

Any ideas what else I need to check please?



Attachment(s):
wordpress enabled.PNG
wordpress plugin.PNG
11 comments
Comment actions Permalink

Please check your include paths (in Project View or Settings | Languages & Frameworks | PHP). Make sure that <WordPress installation>/wp-includes directory or one of its parents is there.

1
Comment actions Permalink

Yes - includes are all setup correctly and pointing to a wordpress directory containing wp-includes (please see attachments)




Attachment(s):
Capture 2.PNG
Capture.PNG
1
Comment actions Permalink

Please try "File | Invalidate Caches..." and restart IDE.

Any better?

1
Comment actions Permalink

Sorry - tried that - no change

File / Invalidate Cache - chose "Invalidate and Restart" - problem is still the same.

0
Comment actions Permalink

It's not clear at all what is going on there. Anything interesting in idea.log (Help | Show Log in ...) ?


1) Does it happens in every file? If not -- please attach whole file here.

2) Anything special on "Settings | Project | Directories"? Screenshot please.

3) Can you open a file that has at least one of those "unknown" functions defined (part of the WP installation) and show a screenshot of whole IDE window (yep -- whole IDE window please).

4) Can you create brand new project, create or copy one of the files you have problems there and configure it (project) so it has references to WP code. Better -- copy whole WP installation into separate folder, place such problematic file there as well and see if it will behave any better.

1
Comment actions Permalink

I think I may be experiencing the same problem. I setup a project for a theme,, using the following as the content root:

/wordpress/wp-content/themes/nameoftemplate/

Then I added the wordpress root under Languages & Frameworks --> PHP --> WordPress like so:

/wordpress/

And I included the same as a PHP include path:

/wordpress/

But it wasn't recognizing WordPress functions, etc.

What I ended up doing was setting the content root to /wordpress/ and it began recognizing all the functions.

This is a workaround, maybe it will work for you. It is annoying though because it means I can't just see the project files I'm working on...I have to see all the project files.

 

[Sorry folks, forgot we are in 2016.]

0
Comment actions Permalink

Go into File/Settings/Directories add both the Wordpress root as a Source Folders and your plugin/template/whatever project root.

For instance I have a MU WP plugin project in C:\Projects\MyProject . It has only the files I work with in source control.

I have a localhost install of Wordpress MultiSite in C:\Projects\www\MyProject . It has everything I need to run/debug the site locally.

Add both those directories to the project and tag them as Source Folders. That fixed the issue for me.

PS: If you get a duplicate definition because you have the same files in the WP root just navigate within that Source Folders and mark the appropriate directories/files as Excluded.

[PhpStorm 2018.3]

0
Comment actions Permalink

If anyone is still searching, here is the solution:

Preferences > Languages & Frameworks > PHP > Frameworks > tick the "Enable WordPress integration" checkbox then select the root directory of a WP site.

 

I'm using PHPStorm 2019.1

1

Please sign in to leave a comment.