wp-forge/wp-upgrade-handler 问题修复 & 功能扩展

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

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

wp-forge/wp-upgrade-handler

Composer 安装命令:

composer require wp-forge/wp-upgrade-handler

包简介

A drop-in library for handling upgrade routines in WordPress plugins and themes.

README 文档

README

A drop-in library for handling upgrade routines in WordPress plugins and themes.

Installation

  • Run composer require wp-forge/wp-upgrade-handler
  • Make sure you require the vendor/autoload.php file in your project.

Usage

Here is an example of how to use this library in a WordPress plugin or theme:

<?php

use WP_Forge\UpgradeHandler\UpgradeHandler;

// Define the current plugin version in the code
define( 'MY_PLUGIN_VERSION', '1.4.1' );

// Only handle upgrades in the admin
if ( is_admin() ) {

	// Handle plugin upgrades
	$upgrade_handler = new UpgradeHandler(
		__DIR__ . '/upgrades',              // Directory where upgrade routines live
		get_option( 'my_plugin_version' ),  // Old plugin version (from database)
		MY_PLUGIN_VERSION                   // New plugin version (from code)
	);

	// Returns true if the old version doesn't match the new version
	$did_upgrade = $upgrade_handler->maybe_upgrade();

	if ( $did_upgrade ) {
		// If an upgrade occurred, update the new version in the database to prevent running the routine(s) again.
		update_option( 'my_plugin_version', MY_PLUGIN_VERSION, true );
	}
}

If you just released version 1.4.1 of your plugin, but created upgrade routines for 1.4.1 and 1.3.9, anyone upgrading from version 1.3.8 or earlier would have both of those upgrade routines run automatically. If someone is upgrading from version 1.3.9 or greater, then only the 1.4.1 upgrade routine would be run.

Creating an Upgrade Routine

As an example, let's assume I just released version 1.4.1 of my plugin. The upgrade routine needs to change an option name in the database. All I need to do after adding the previous code from above is to create a file named 1.4.1.php in my upgrades directory.

The following would be the contents of that file:

<?php

// Rename 'old_option' to 'new_option', if necessary.
$old_option = get_option( 'old_option' );
if( $old_option ) {
    update_option( 'new_option', get_option( 'old_option' ) );
    delete_option( 'old_option' );
}

wp-forge/wp-upgrade-handler 适用场景与选型建议

wp-forge/wp-upgrade-handler 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 240.24k 次下载、GitHub Stars 达 8, 最近一次更新时间为 2020 年 05 月 21 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 wp-forge/wp-upgrade-handler 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 wp-forge/wp-upgrade-handler 我们能提供哪些服务?
定制开发 / 二次开发

基于 wp-forge/wp-upgrade-handler 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 240.24k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 8
  • 点击次数: 16
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: GPL-2.0-or-later
  • 更新时间: 2020-05-21