awesome9/updates 问题修复 & 功能扩展

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

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

awesome9/updates

Composer 安装命令:

composer require awesome9/updates

包简介

WordPress update manager.

README 文档

README

Awesome9 Latest Stable Version PHP from Packagist Total Downloads License

📃 About Updates

This package provides ease of running update routines within a WordPress plugin. It provides methods to check the current installed version of the plugin, determine which updates need to be applied, and apply those updates in order.

💾 Installation

composer require awesome9/updates

🕹 Usage

Step 1: Implement the Updates Class

To use the package, create a class that extends the Updates abstract class. Implement the following methods in your custom class:

  • get_updates() - Returns an associative array of version numbers and update file paths.
  • get_folder() - Returns the folder path where update files are stored.
  • get_version() - Returns the current plugin version.
  • get_option_name() - Returns the option name used to store the plugin version in the database.
use Awesome9\Updates\Updates;

class MyPluginUpdates extends Updates {

    /**
     * Define update versions and file paths.
     *
     * @return array<string, string>
     */
    public function get_updates(): array {
        return [
            '1.0.1' => 'updates/update-1.0.1.php',
            '1.0.2' => 'updates/update-1.0.2.php',
        ];
    }

    /**
     * Specify the updates folder path.
     *
     * @return string
     */
    public function get_folder(): string {
        return plugin_dir_path( __FILE__ ) . 'updates/';
    }

    /**
     * Get the current plugin version.
     *
     * @return string
     */
    public function get_version(): string {
        return '1.0.2'; // Replace with your plugin's current version
    }

    /**
     * Define the database option name for storing the plugin version.
     *
     * @return string
     */
    public function get_option_name(): string {
        return 'awesome9_plugin_version';
    }
}

Step 2: Initialize and Bind Hooks

In your plugin’s main file, instantiate your MyPluginUpdates class and bind the hooks to handle updates automatically:

$my_plugin_updates = new MyPluginUpdates();
$my_plugin_updates->hooks();

Step 3: Structure Your Plugin’s Update Files

Arrange your plugin folder to include separate files for each update version. Your folder structure might look like this:

my-plugin/
└── updates/
   ├── update-1.1.0.php
   └── update-1.1.1.php

Step 4: Write Update Files

Each update file should contain code for the specific update, like this example for update-1.0.1.php:

<?php
/**
 * Update routine for version 1.0.1
 *
 * @since 1.0.1
 */

/**
 * Example update function to remove obsolete roles.
 *
 * @since 1.0.1
 * @return void
 */
function awesome9_update_1_0_1_remove_roles() {
	remove_role( 'awesome9_manager' );
	remove_role( 'awesome9_employee' );
}

awesome9_update_1_0_1_remove_roles();

📖 Changelog

See the changelog file

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: Shell

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固