WP-CLI - Call Internal Command from PHP

<?php /** Execute a WP-CLI command from a PHP script with WordPress loaded $ wp eval-file $PWD/testing.php --debug */ if ( defined( 'WP_CLI' ) && WP_CLI ) { $response = WP_CLI::launch_self( 'theme list', array(), array ( 'format' => 'json' ), false, true ); $themes = json_decode( $response->stdout ); WP_CLI\Utils\format_items( 'table', $themes, array ( 'name', 'status', 'enabled', 'version', 'update' ) ); WP_CLI::success( "The script has run!" ); }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.