packages_dir = plugin_dir_path( __FILE__ ) . 'packages' . DIRECTORY_SEPARATOR; $this->necessary_packages = $this->need_run_upgrades(); if ( ! empty( $this->necessary_packages ) ) { add_action( 'admin_menu', array( $this, 'admin_menu' ), 0 ); add_action( 'wp_loaded', array( $this, 'initialize_upgrade_packages' ), 0 ); } add_action( 'in_plugin_update_message-' . UM_PLUGIN, array( $this, 'in_plugin_update_message' ) ); } /** * Initialize packages for upgrade process. * Note: Making that only for the 'manage_options' user and when AJAX running. */ public function initialize_upgrade_packages() { if ( defined( 'DOING_AJAX' ) && DOING_AJAX && current_user_can( 'manage_options' ) ) { $this->init_packages_ajax(); add_action( 'wp_ajax_um_run_package', array( $this, 'ajax_run_package' ) ); add_action( 'wp_ajax_um_get_packages', array( $this, 'ajax_get_packages' ) ); } } /** * Function for major updates * */ function in_plugin_update_message( $args ) { $show_additional_notice = false; if ( isset( $args['new_version'] ) ) { $old_version_array = explode( '.', UM_VERSION ); $new_version_array = explode( '.', $args['new_version'] ); if ( $old_version_array[0] < $new_version_array[0] ) { $show_additional_notice = true; } else { if ( $old_version_array[1] < $new_version_array[1] ) { $show_additional_notice = true; } } } if ( $show_additional_notice ) { ob_start(); ?> get_allowed_html( 'admin_notice' ) ); ?> extensions()->get_list(); if ( empty( $extensions ) ) { return array(); } $upgrades = array(); foreach ( $extensions as $extension ) { $upgrades[ $extension ] = UM()->extensions()->get_packages( $extension ); } return $upgrades; } /** * Get array of necessary upgrade packages * * @return array */ function need_run_upgrades() { $um_last_version_upgrade = get_option( 'um_last_version_upgrade', '1.3.88' ); $diff_packages = array(); $all_packages = $this->get_packages(); foreach ( $all_packages as $package ) { if ( version_compare( $um_last_version_upgrade, $package, '<' ) && version_compare( $package, UM_VERSION, '<=' ) ) { $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 . $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 . $package . DIRECTORY_SEPARATOR . 'hooks.php'; if ( file_exists( $hooks_file ) ) { $pack_ajax_hooks = include_once $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 . $package . DIRECTORY_SEPARATOR . 'functions.php'; if ( file_exists( $handlers_file ) ) { include_once $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', __( 'empty', 'ultimate-member' ) ); ?>
%1$s version. Your latest DB version is %2$s. We recommend creating a backup of your site before running the update process. Do not exit the page before the update process has complete.', 'ultimate-member' ), UM_VERSION, $um_last_version_upgrade ), UM()->get_allowed_html( 'admin_notice' ) ); ?>
"Run" button, the update process will start. All information will be displayed in the "Upgrade Log" field.', 'ultimate-member' ); ?>