• Resolved faridjc

    (@faridjc)


    I’m trying to find a way to retrieve the command being executed by WP-CLI (or the list of arguments) from a plugin.

    Is that possible? I searched the WP-CLI API documentation but couldn’t find a function that made is possible.

    • This topic was modified 1 year ago by faridjc.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator Jose Castaneda

    (@jcastaneda)

    THEME COFFEE MONKEY

    Hi there!

    My initial question on this would be what are you actually trying to do?

    Thread Starter faridjc

    (@faridjc)

    Hello there!

    I’m trying to prevent a function from continue its execution if the current request comes from WP-CLI and the command is neither “plugin list” or “plugin update”

    I came up with this solution, it could be cleaner, but it works:

    if ( defined( 'WP_CLI' ) ) {
         $args = $GLOBALS['argv'] ?? array();
         $exit = true;
    
         foreach ( $args as $i => $argument ) {
    
              if ( 'plugin' === $argument && ( 'list' === $args[ $i + 1 ] || 'update' === $args[ $i + 1 ] ) ) {
    
                   $exit = false;
    
                   break;
    
               }
    
         }
    
         if ( $exit ) {
              return;
         }
    }
    • This reply was modified 1 year ago by faridjc.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Retrieving command being executed by WP-CLI’ is closed to new replies.