Support » Plugin: All-In-One Security (AIOS) – Security and Firewall » Undefined index: SERVER_PORT when using wpcli

  • When the plugin is activated and you try to use wpcli to issue commands, it throws exceptions of Undefined index: SERVER_PORT/SERVER_NAME in /classes/wp-security-utility.php:32

    This happens because the $_SERVER[] environment variables are not available via cli. An additional check needs to be implemented like:

    if ( 'cli' === php_sapi_name() || defined('STDIN') ) {
            // This section of the code runs when WordPress is being runned from the terminal
    } else {
            // This section of the code run when WordPress is being run from the browser
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor mbrsolution


    Thank you for reporting this. I have submitted a message to the plugin developers to investigate further your findings.

    Kind regards

    Plugin Contributor wpsolutions


    Hi @ikappas,
    I think that the neatest way to handle this is to perhaps put a check at the beginning of the get_current_page_url function along the lines of:

    if ( 'cli' === php_sapi_name() || defined('STDIN') ) {
            // return for cli case 
            return '';    

    Do you think the above will best solve your scenario?

    Thread Starter Ioannis Kappas


    Hi @wpsolutions

    I raised this issue mainly because I saw that wpcli was throwing errors with this plugin activated. I don’t have a specific use case other than executing wpcli commands successfully.

    I don’t know whether this kind of check should be implemented at the get_current_page_url function or higher up in the call stack.

    To better answer this question you probably need to decide on:
    Does this plugin need to load when running via CLI?
    If so does all of it need to load or only some parts?
    Do you plan to support wpcli with custom commands?

    Hope this helps.

    Plugin Contributor wpsolutions


    Ok thanks for your feedback.
    I think for now I can see no pressing reason to support cli commands for this plugin since it is virtually always used via browser.

    If in future cli support is needed, we can always revisit this and address this topic as needed.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Undefined index: SERVER_PORT when using wpcli’ is closed to new replies.