我建议您将主题版本存储在数据库中,并将其与软件包版本进行比较,如果有差异,请在升级/安装操作中加载:
define( \'THEME_PREFIX_VERSION\', \'X.X\' );
/**
* Run upgrade/install.
*/
function theme_prefix_install() {
require_once dirname( __file__ ) . \'/install.php\';
}
if ( version_compare( get_option( \'theme_prefix_version\' ), THEME_PREFIX_VERSION, \'<\' ) )
add_action( \'init\', \'theme_prefix_install\' );
然后在
install.php
:
if ( ! defined( \'THEME_PREFIX_VERSION\' ) )
exit;
$version = get_option( \'theme_prefix_version\' );
if ( version_compare( $version, \'1.0\', \'<\' ) ) {
// Upgrade code required for version 1.0
}
if ( version_compare( $version, \'1.1\', \'<\' ) ) {
// Upgrade code required for version 1.1
}
// And so forth
// All updated, store current package version
update_option( \'theme_prefix_version\', THEME_PREFIX_VERSION );