versusbassz/wp-batcher 问题修复 & 功能扩展

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

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

versusbassz/wp-batcher

最新稳定版本:0.2.0

Composer 安装命令:

composer require versusbassz/wp-batcher

包简介

Iterate over thousands of posts/users/etc. in WordPress without getting OOM and writing boilerplate code

README 文档

README

If you need to change many items of the same type (posts, users, etc.) in WordPress (with possible Out-of-Memory result) this library helps you to write less code and avoid OOM.

Installation

composer require versusbassz/wp-batcher 0.1.*

How to use

Imagine you have 100000 posts in a database, and you need to iterate over them and change somehow.

Of course, you can't just use get_posts( [ 'nopaging' => true ] ), because you'll get Fatal error: memory limit has been exceeded bla bla bla... .

So to do the job you need to handle you posts consequentially chunk by chunk (e.g. 100 posts at a time).

The example of code without using the library:

$paged = 1;

wp_suspend_cache_addition( true );

while ( true ) {
	$items = get_posts( [
		'posts_per_page' => 100,
		'paged' => $paged,
		'orderby' => 'ID',
		'order' => 'ASC',
	] );

	if ( ! count( $items ) ) {
		break;
	}

	foreach ( $items as $item ) {
		// Payload
	}

	++$paged;
}

wp_suspend_cache_addition( false );

With using the library the code above turns into to:

use \Versusbassz\WpBatcher\WpBatcher;

$iterator = WpBatcher::get_posts();

foreach ( $iterator as $item ) {
	// Payload
}

And the library does more than just wp_suspend_cache_addition() under the hood.

Documentation

See Wiki

Compatibility

Versioning and stability

The project follows https://semver.org/

License

The license of the project is GPL v2 (or later)

统计信息

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

GitHub 信息

  • Stars: 10
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0-or-later
  • 更新时间: 2022-01-13

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固