定制 jmslbam/wp-cli-base-command 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

jmslbam/wp-cli-base-command

最新稳定版本:2.0.1

Composer 安装命令:

composer require jmslbam/wp-cli-base-command

包简介

A base command for WP-CLI

README 文档

README

Install via composer require jmslbam/wp-cli-base-command.

Extend your own command:

<?php

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();
    }
}

Use Bulk task helper

Use the Bulk_Task to easily loop over all kind of CPT's and preform a task on it.

<?php
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' );
}

Example command output:

➜  wp test run --post_type=product
50. Heavy Duty Silk Gloves x (50)
49. Durable Rubber Bench x (49)
17. WordCamp x (17)
3 items processed.

Other posiblities:

wp test run --post_type=accommodation --taxonomy=region --term=france

Or any other WP_Query argument

统计信息

  • 总下载量: 25
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0-or-later
  • 更新时间: 2023-09-11