aaemnnosttv / wp-cli-login-command

Log in to WordPress with secure passwordless magic links.
https://aaemnnost.tv/wp-cli-commands/login/
MIT License
301 stars 48 forks source link

Undefined constant WP_CLI error #73

Closed icodus closed 1 year ago

icodus commented 1 year ago

If "WP_CLI" is not defined in wp-cli-login-server.php ( not called from wp_cli ) then the line (defined('WP_CLI') && WP_CLI) is trying to use undefined WP_CLI constant or I'm missing something obvious?

aaemnnosttv commented 1 year ago

Sorry, I don't quite understand the issue. Did you see this error or are you asking if it's possible?

If you've experienced an error, please provide more detail as to the context, including the full error message and trace if possible. Thanks 👍

icodus commented 1 year ago

VS Code shows "Undefined constant 'WP_CLI_Login\WP_CLI" error. Seems logical to me. Adding if (!defined('WP_CLI')) { define('WP_CLI', 'false'); } clears the error.

aaemnnosttv commented 1 year ago

Glad to hear there is no error 😄

The usage you're referring to is safe because it checks that the constant is defined before using it https://github.com/aaemnnosttv/wp-cli-login-command/blob/ab20aee280de98974ac5b22b635c533d41faf296/plugin/wp-cli-login-server.php#L35

It sounds like VS Code is complaining because the code is in the WP_CLI_Login namespace but will fall back to the global constant since it isn't defined in this namespace. The defined check will always reference the global namespace though.

The plugin shouldn't define a constant that is only intended to be defined by WP CLI but that would fix the usage it's complaining about.

Thanks for your interest in contributing. Cheers!