mirror of
https://gh.wpcy.net/https://github.com/Anyape/updatepulse-server.git
synced 2026-05-06 06:32:22 +08:00
| .. | ||
| languages | ||
| class-wp-update-migrate.php | ||
| LICENSE | ||
| README.md | ||
WP Update Migrate - WordPress plugins and themes update path library
Description
Provide a clear upgrade path to plugins and themes: each version has its own script to upgrade database and file system in case of major update.
Requirements
Before enabling migrations with the code below, setup your plugin properly by making sure:
- the
wp-update-migratefolder library is present in alibdirectory at the root of the plugin or theme - to change
'example_prefix'with a unique prefix identifier for your plugin or theme,snake_caseformat - to change
'example_function'with the name of the function to remove from or add to the action queue - to have an
updatesdirectory at the root of the plugin or theme - to name each file in the
updatesfolder with a version number as file name (example:1.5.3.php) - each update file in the
updatesdirectory have a single update function, and do not include any logic outside of that function - the update function name in each update file follows the pattern:
[example_prefix]_update_to_[version]- example: in
1.5.3.php, the function ismy_plugin_update_to_1_5_3with[example_prefix]of valuemy_plugin - example: in
2.4.9.php, the function ismy_theme_update_to_2_4_9with[example_prefix]of valuemy_theme
- example: in
- each update function returns
(bool) truein case of success, aWP_Errorobject otherwise
Code to include in the main plugin file
require_once plugin_dir_path( __FILE__ ) . 'lib/wp-update-migrate/class-wp-update-migrate.php';
$hook = 'plugins_loaded';
add_action( $hook, function() {
$update_migrate = WP_Update_Migrate::get_instance( __FILE__, 'example_prefix' );
if ( false === $update_migrate->get_result() ) {
/**
* @todo
* Execute your own logic here in case the update failed.
*
* if ( false !== has_action( 'example_action', 'example_function' ) ) {
* remove_action( 'example_action', 'example_function', 10 );
* }
**/
}
if ( true === $update_migrate->get_result() ) {
/**
* @todo
* Execute your own logic here in case an update was applied successfully.
*
* if ( false === has_action( 'example_action', 'example_function' ) ) {
* add_action( 'example_action', 'example_function', 10 );
* }
**/
}
}, PHP_INT_MIN );
Code to include in theme's functions.php
require_once plugin_dir_path( __FILE__ ) . 'lib/wp-update-migrate/class-wp-update-migrate.php';
$hook = 'after_setup_theme';
add_action( $hook, function() {
$update_migrate = WP_Update_Migrate::get_instance( __FILE__, 'example_prefix' );
if ( false === $update_migrate->get_result() ) {
/**
* @todo
* Execute your own logic here in case the update failed.
*
* if ( false !== has_action( 'example_action', 'example_function' ) ) {
* remove_action( 'example_action', 'example_function', 10 );
* }
**/
}
if ( true === $update_migrate->get_result() ) {
/**
* @todo
* Execute your own logic here in case an update was applied successfully.
*
* if ( false === has_action( 'example_action', 'example_function' ) ) {
* add_action( 'example_action', 'example_function', 10 );
* }
**/
}
}, PHP_INT_MIN );