Skip to content

Instantly share code, notes, and snippets.

@spacetrack
Created February 13, 2014 20:16
Show Gist options
  • Save spacetrack/8982972 to your computer and use it in GitHub Desktop.
Save spacetrack/8982972 to your computer and use it in GitHub Desktop.
<?php
class EvalFileWithArgs_Command extends WP_CLI_Command {
/**
* Load and execute a PHP file after loading WordPress.
*
* ## EXAMPLES
*
* wp eval-file-with-args my-code.php arg1 arg2 arg3 arg4 arg5 arg6 arg7 arg8 arg9
*
* @synopsis <file> [<argA>] [<argB>] [<argC>] [<argD>] [<argE>] [<argF>] [<argG>] [<argH>] [<argI>]
*/
public function __invoke( $args, $assoc_args ) {
if ( !file_exists( $args[0] ) ) {
WP_CLI::error( "'$args[0]' does not exist." );
} else {
include( $args[0] );
}
}
}
WP_CLI::add_command( 'eval-file-with-args', 'EvalFileWithArgs_Command' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment