alleyinteractive / wp-bulk-task
这是一个库,用于协助在WordPress对象上运行高效的大批量任务。
v1.0.0
2024-08-13 17:20 UTC
Requires
- php: >=8.1
- alleyinteractive/composer-wordpress-autoloader: ^1.0
Requires (Dev)
README
这是一个库,用于协助在WordPress对象上运行高效的大批量任务。
背景
此包提供了一个库,便于以高效的方式在WordPress数据库上运行大批量任务。它包括搜索WordPress数据库中的帖子、术语和用户的功能,并使用WP_Query风格的参数,并在数据库中保持游标的位置,以防中断后需要重新开始。
版本发布
此包通过Packagist发布,用于通过Composer安装。它遵循语义化版本控制约定。
安装
需要Composer和PHP >= 8.1
。
使用
通过Composer安装此包
composer require alleyinteractive/wp-bulk-task
确保将Composer自动加载器加载到您的项目中
require_once __DIR__ . '/vendor/autoload.php';
然后,在您的自定义CLI命令中使用该类
class My_Custom_CLI_Command extends WP_CLI_Command { use Bulk_Task_Side_Effects; /** * Replace all instances of 'apple' with 'banana' in post content. * * ## OPTIONS * * [--dry-run] * : If present, no updates will be made. * * [--rewind] * : Resets the cursor so the next time the command is run it will start from the beginning. * * ## EXAMPLES * * # Bananaify links. * $ wp my-custom-cli-command bananaify */ public function bananaify( $args, $assoc_args ) { $bulk_task = new \Alley\WP_Bulk_Task\Bulk_Task( 'bananaify', new \Alley\WP_Bulk_Task\Progress\PHP_CLI_Progress_Bar( __( 'Bulk Task: remove_broken_links', 'my-textdomain' ) ) ); // Handle rewind requests. if ( ! empty( $assoc_args['rewind'] ) ) { $bulk_task->cursor->reset(); WP_CLI::log( __( 'Rewound the cursor. Run again without the --rewind flag to process posts.', 'my-textdomain' ) ); return; } $this->pause_side_effects(); // Set up and run the bulk task. $dry_run = ! empty( $assoc_args['dry-run'] ); $bulk_task->run( [ 'post_status' => 'publish', 'post_type' => 'post', 'tax_query' => [ [ 'field' => 'slug', 'taxonomy' => 'category', 'terms' => 'fruit', ], ], ], function( $post ) use ( $dry_run ) { if ( false !== strpos( $post->post_content, 'apple' ) ) { $new_value = str_replace( 'apple', 'banana', $post->post_content ); if ( $dry_run ) { WP_CLI::log( 'Old post_content: ' . $post->post_content ); WP_CLI::log( 'New post_content: ' . $new_value ); } else { $post->post_content = $new_value; wp_update_post( $post ); } } } ); $this->resume_side_effects(); } }
有关使用方法的更多信息,请访问wiki。
从源代码安装
要在本地工作于此项目,首先将仓库添加到项目的composer.json
{ "repositories": [ { "type": "path", "url": "../path/to/wp-bulk-task", "options": { "symlink": true } } ] }
接下来,将本地开发文件添加到composer.json
的require
部分
{ "require": { "alleyinteractive/wp-bulk-task": "@dev" } }
最后,更新composer以使用此包的本地副本
composer update alleyinteractive/wp-bulk-task --prefer-source
变更日志
此项目保留变更日志。
开发流程
有关从源代码安装的说明,请参阅上面的说明。欢迎社区提交拉取请求,并将考虑将其包含在内。发布遵循语义化版本控制,并按需进行发货。
贡献
有关如何为这个开源项目做出贡献的说明,请参阅我们的贡献指南。
项目结构
这是一个发布到Packagist的Composer包。
类必须使用alleyinteractive/composer-wordpress-autoloader
进行自动加载,并位于src
目录中,遵循标准的WordPress类命名约定。
相关努力
维护者
贡献者
感谢所有贡献者为此项目做出贡献。
许可证
此项目受GNU公共许可证(GPL)版本2或更高版本的许可。