packages_dir = plugin_dir_path( __FILE__ ) . 'packages' . DIRECTORY_SEPARATOR;
$this->necessary_packages = $this->need_run_upgrades();
if ( ! empty( $this->necessary_packages ) ) {
add_action( 'admin_notices', array( $this, 'need_upgrade' ) );
$this->init_packages_ajax();
add_action( 'admin_menu', array( $this, 'admin_menu' ), 0 );
add_action( 'wp_ajax_um_run_package', array( $this, 'ajax_run_package' ) );
add_action( 'wp_ajax_um_get_packages', array( $this, 'ajax_get_packages' ) );
} else {
add_action( 'admin_notices', array( $this, 'updated_successfully' ) );
}
}
function need_upgrade() {
?>
here', 'ultimate-member' ), add_query_arg( array( 'page' => 'um_upgrade' ), admin_url( 'admin.php' ) ) ) ?>
get_packages();
$um_last_version_upgrade = get_option( 'um_last_version_upgrade' );
if ( ! $um_last_version_upgrade ) {
return $all_packages;
}
$diff_packages = array();
foreach ( $all_packages as $package ) {
if ( version_compare( $um_last_version_upgrade, $package, '<' ) ) {
$diff_packages[] = $package;
}
}
return $diff_packages;
}
/**
* Get all upgrade packages
*
* @return array
*/
function get_packages() {
$update_versions = array();
$handle = opendir( $this->packages_dir );
if ( $handle ) {
while ( false !== ( $filename = readdir( $handle ) ) ) {
if ( $filename != '.' && $filename != '..' ) {
if ( is_dir( $this->packages_dir . DIRECTORY_SEPARATOR . $filename ) ) {
$update_versions[] = $filename;
}
}
}
closedir( $handle );
usort( $update_versions, array( &$this, 'version_compare_sort' ) );
}
return $update_versions;
}
/**
*
*/
function init_packages_ajax() {
foreach ( $this->necessary_packages as $package ) {
$hooks_file = $this->packages_dir . DIRECTORY_SEPARATOR . $package . DIRECTORY_SEPARATOR . 'hooks.php';
if ( file_exists( $hooks_file ) ) {
$pack_ajax_hooks = include $hooks_file;
foreach ( $pack_ajax_hooks as $action => $function ) {
add_action( 'wp_ajax_um_' . $action, "um_upgrade_$function" );
}
}
}
}
/**
*
*/
function init_packages_ajax_handlers() {
foreach ( $this->necessary_packages as $package ) {
$handlers_file = $this->packages_dir . DIRECTORY_SEPARATOR . $package . DIRECTORY_SEPARATOR . 'functions.php';
if ( file_exists( $handlers_file ) ) {
include $handlers_file;
}
}
}
/**
* Add Upgrades admin menu
*/
function admin_menu() {
add_submenu_page( 'ultimatemember', __( 'Upgrade', 'ultimate-member' ), '' . __( 'Upgrade', 'ultimate-member' ) . '', 'manage_options', 'um_upgrade', array( &$this, 'upgrade_page' ) );
}
/**
* Upgrade Menu Callback Page
*/
function upgrade_page() {
$um_last_version_upgrade = get_option( 'um_last_version_upgrade' ); ?>
You have installed you need to upgrade your previous
Upgrade Log
packages_dir . DIRECTORY_SEPARATOR . $_POST['pack'] . DIRECTORY_SEPARATOR . 'init.php';
ob_get_flush();
exit;
}
}
function ajax_get_packages() {
$update_versions = $this->need_run_upgrades();
wp_send_json_success( array( 'packages' => $update_versions ) );
}
/**
* Load packages
*/
/*public function packages() {
if ( ! ini_get( 'safe_mode' ) ) {
@set_time_limit(0);
}
$this->set_update_versions();
$um_last_version_upgrade = get_option( 'um_last_version_upgrade' );
$um_last_version_upgrade = ! $um_last_version_upgrade ? '0.0.0' : $um_last_version_upgrade;
foreach ( $this->update_versions as $update_version ) {
if ( version_compare( $update_version, $um_last_version_upgrade, '<=' ) )
continue;
if ( version_compare( $update_version, ultimatemember_version, '>' ) )
continue;
$file_path = $this->packages_dir . $update_version . '.php';
if ( file_exists( $file_path ) ) {
include_once( $file_path );
update_option( 'um_last_version_upgrade', $update_version );
}
}
}*/
/**
* Parse packages dir for packages files
*/
function set_update_versions() {
$update_versions = array();
$handle = opendir( $this->packages_dir );
if ( $handle ) {
while ( false !== ( $filename = readdir( $handle ) ) ) {
if ( $filename != '.' && $filename != '..' )
$update_versions[] = preg_replace( '/(.*?)\.php/i', '$1', $filename );
}
closedir( $handle );
usort( $update_versions, array( &$this, 'version_compare_sort' ) );
$this->update_versions = $update_versions;
}
}
/**
* Parse packages dir for packages files
*/
/*function set_update_versions_() {
$update_versions = array();
$handle = opendir( $this->packages_dir );
if ( $handle ) {
while ( false !== ( $filename = readdir( $handle ) ) ) {
if ( $filename != '.' && $filename != '..' ) {
var_dump( $filename );
if ( is_dir( $this->packages_dir . DIRECTORY_SEPARATOR . $filename ) ) {
$update_versions[] = $filename;
}
}
}
closedir( $handle );
usort( $update_versions, array( &$this, 'version_compare_sort' ) );
$this->update_packages = $update_versions;
}
}*/
/**
* Sort versions by version compare function
* @param $a
* @param $b
* @return mixed
*/
function version_compare_sort( $a, $b ) {
return version_compare( $a, $b );
}
}
}