jmslbam/wp-cli-base-command 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

jmslbam/wp-cli-base-command

最新稳定版本:v2.3.0

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 or Terms and preform a task on it.

We've got $this->loop_posts() and $this->loop_terms() to choose from. Below an example for looping posts:

<?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 --terms=france

Or any other WP_Query argument

统计信息

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

GitHub 信息

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

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固