1. Go to this page and download the library: Download jmslbam/wp-cli-base-command library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
jmslbam / wp-cli-base-command example snippets
use \JMSLBAM\WP_CLI\Base_Command;
class Import extends Base_Command {
function import( $args, $assoc_args ) {
$this->start_bulk_operation();
// Optional: Disable a bunch of pre-defined plugin actions
$this->disable_hooks();
// Optional: Call "free_up_memory" after importing X amount of posts
$this->free_up_memory();
// Finalize your command
$this->end_bulk_operation();
}
}
namespace JMSLBAM;
use JMSLBAM\WP_CLI\Base_Command;
use JMSLBAM\WP_CLI\Bulk_Task;
class Test extends Base_Command {
use Bulk_Task;
function run( $args, $assoc_args ) {
// $assoc_args['post_type'] = 'post';
$result = $this->loop_posts( $assoc_args, [ $this, 'do_something' ] );
}
private function do_something( $post_id, $assoc_args = [] ) {
$post = get_post( $post_id );
$post->post_title = $post->post_title . ' x';
\WP_CLI::line($post_id . '. ' . $post->post_title . ' (' . $post->ID . ')' );
\wp_update_post( $post ); // re-save post
}
}
if ( defined('WP_CLI') ) {
\WP_CLI::add_command( 'test', 'JMSLBAM\\Test' );
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.