• pm1932

    (@pm1932)


    Hello,
    Using the built-in wpcli hook before_run_command I’d like to be able to check to see if the command being run is search-replace. But for the life of me I can’t figure out how to get this. code:

    function nrd_before_any_command_run() {
        //
        // need to replace COMMAND with the actual command being run.
        if( 'search-replace' == COMMAND ) {
            WP_CLI::confirm( "Are you sure?" );
        }
    }
    
    WP_CLI::add_hook( 'before_run_command', 'nrd_before_any_command_run' );

    Thanks for any help!

Viewing 1 replies (of 1 total)
  • Thread Starter pm1932

    (@pm1932)

    In case anyone else was looking, here’s what I ended up with

    function nrd_before_any_command() {
        if( 'search-replace' == WP_CLI::get_runner()->arguments[0] ) {
            WP_CLI::confirm( "testing..." );
        }
    }
    
    WP_CLI::add_hook( 'before_run_command', 'nrd_before_any_command' );
Viewing 1 replies (of 1 total)
  • The topic ‘WPCLI get the name of command’ is closed to new replies.