alleyinteractive/wp-bulk-task
Composer 安装命令:
composer require alleyinteractive/wp-bulk-task
包简介
A library to assist with running performant bulk tasks against WordPress objects.
README 文档
README
A library to assist with running performant bulk tasks against WordPress objects.
Background
This package provides a library to make it easier to run bulk tasks against a WordPress database in a performant way. It includes functionality to search through a WordPress database for posts, terms, and users, and using WP_Query-style arguments and keeps a cursor of its location within the database in case it is interrupted and needs to start again.
Releases
This package is released via Packagist for installation via Composer. It follows semantic versioning conventions.
Install
Requires Composer and PHP >= 8.1.
Use
Install this package via Composer:
composer require alleyinteractive/wp-bulk-task
Ensure that the Composer autoloader is loaded into your project:
require_once __DIR__ . '/vendor/autoload.php';
Then use the class in your custom CLI command:
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(); } }
For more information on usage, visit the wiki.
From Source
To work on this project locally, first add the repository to your project's
composer.json:
{
"repositories": [
{
"type": "path",
"url": "../path/to/wp-bulk-task",
"options": {
"symlink": true
}
}
]
}
Next, add the local development files to the require section of
composer.json:
{
"require": {
"alleyinteractive/wp-bulk-task": "@dev"
}
}
Finally, update composer to use the local copy of the package:
composer update alleyinteractive/wp-bulk-task --prefer-source
Changelog
This project keeps a changelog.
Development Process
See instructions above on installing from source. Pull requests are welcome from the community and will be considered for inclusion. Releases follow semantic versioning and are shipped on an as-needed basis.
Contributing
See our contributor guidelines for instructions on how to contribute to this open source project.
Project Structure
This is a Composer package that is published to Packagist.
Classes must be autoloadable using
alleyinteractive/composer-wordpress-autoloader and live in the src
directory, following standard WordPress naming conventions for classes.
Related Efforts
Maintainers
Contributors
Thanks to all of the contributors to this project.
License
This project is licensed under the GNU Public License (GPL) version 2 or later.
alleyinteractive/wp-bulk-task 适用场景与选型建议
alleyinteractive/wp-bulk-task 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 410.66k 次下载、GitHub Stars 达 21, 最近一次更新时间为 2022 年 11 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 alleyinteractive/wp-bulk-task 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 alleyinteractive/wp-bulk-task 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 410.66k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 21
- 点击次数: 24
- 依赖项目数: 4
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0-or-later
- 更新时间: 2022-11-16