6

I'm new to visual studio code and intelephense. I'm working with WordPress and using a class called WP_CLI which's a system installed. So, if I'm not wrong, class WP_CLI is not in my path so I get Undefined type 'WP_CLI'.intelephense(1009)

The ideal solution for me would be to be able to tell inteliphense that WP_CLI is defined elsewhere and not to bother with this error. Not to disable Undefined type altogether.

I can't find the comment to disable it. I've found the similar /** @var int $foo */ for variables but I can't find the documentation for it so I can do the same with classes.

Is there an option to do that?

1
  • 1
    Yeah really annoying, the only solution I found so far was to disable all "undefined type" errors but that's not what I want.
    – Picard
    May 31, 2021 at 7:08

2 Answers 2

3

It's not super clear on how to install the stubs. in your project folder run

composer require --dev php-stubs/wp-cli-stubs

in that same folder, you will need a workspace file. they have the .code-workspace extension. in there you need

{
    "settings": {
        "intelephense.environment.includePaths": [
            "path/to/vendor"
        ]
    }
}

you also need WordPress in settings.intelephense.stubs

hope this saves someone some time and let me know if there is a better way

2

I found installing the stubs for WP_CLI fixes the issue.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

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.