intelephense-docs
intelephense-docs copied to clipboard
[DOC]: Better way to get WordPress intellisense
Hi,
First of all thank you very much for this awesome package. Your package is one of many reasons why I moved from Sublimetext to VSCode (don't mean to start a war here though).
I have been fiddling around a bit, and have been trying various methods to add WordPress intellisense. My preference has always been to just add the plugin/theme directory to vscode workspace. But in order to get intellisense of WordPress core functions, I had to add WordPress source in the workspace too. Not a great fan of this.
Then I came across this and since I use composer anyway, getting intellisense was a breeze.
I would've wanted to contribute to some doc, but since I didn't find any, I am opening an issue explaining the method and I leave it upto you to do what-so-ever you wish.
These are just the steps one need to follow to get WP intellisense.
- First increase the default fileSize to 3MB or greater (VSCode > Preference > User Settings)
"intelephense.file.maxSize": 3000000
. - Now if you are using composer then
composer require --dev giacocorsiglia/wordpress-stubs
. - If you are not using composer then simply download wordpress-stubs.php and put it in your project directory (you probably don't want to track it with git).
- Now from vscode command palette simply do a
Intelephense: Clear Cache and Reload
. - Also disable any WordPress core snippets extension you might have.
And from then on, it just works. Here's a video.
set maxSize to 3200000 if giacocorsiglia/wordpress-stubs version is ^5.1
Up-to-date WP stubs are available here: https://github.com/php-stubs/wordpress-stubs
Is there a global way I can install this? I jump from WordPress project to project all day and installing this per project just doesn't seem feasible for me. Open to suggestions, otherwise I'll likely disable Intelephense entirely.
I would also like to know if there is a global way to do this. Adding this to each project seems unnecessary. I don't like to have files that I don't need in my project directories. Is there any extension that can be installed to accomplish this?
This was added in 1.3.3
See https://github.com/bmewburn/vscode-intelephense/issues/833#issuecomment-563984827
For those looking for an answer to this in 2021, simply install Intelephense, and in the settings, add Core
and Wordpress
to the Intelephense: Stubs
section in preferences.
No need to add the stubs through composer or download.
Thanks nichols-green.
For those who don't know much about vscode, I'll save you the search:
I'd like to add my 2 cents here. I wanted to set up vscode for WordPress development, and one of the first extensions I installed was PHP Intelephense. It proved to be ridiculously difficult to find Intelephense already ships with WordPress support and it has to explicitly be enabled. Only learned about this when digging through multiple GitHub issues.
A great first step would be to link to bmewburn/intelephense-docs in the main repo of the vscode extension. I looked everywhere for a link to the documentation.
Second, the documentation should include all optional features, with full descriptions. At least the premium features should be documented properly, there's no point in paying for features if you don't know how to use or enable them.
possible to integrate acf (advanced custom fields) too?
possible to integrate acf (advanced custom fields) too?
Yes, ACF stubs seem available here, so install those with Composer and add it to the stubs list
https://github.com/php-stubs?type=source
@ntwb I use this approach as well, and it works great! Wish there was a way to tell intelephense to search for globally installed stubs, so they don't have to be included in every project separately.
they don't have to be included in every project
I make many errors in my code (which I write ~once a month). Using three default checks makes me more confident.
- syntax errors
- coding style
- static analysis
I run my code after these do pass. (not before!)
Thanks nichols-green. For those who don't know much about vscode, I'll save you the search:
![]()
Thanks a lot this is a very helpful trick.