packages_dir = plugin_dir_path( __FILE__ ) . 'packages' . DIRECTORY_SEPARATOR; $this->necessary_packages = $this->need_run_upgrades(); if ( ! empty( $this->necessary_packages ) ) { $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' ) ); } //add_action( 'in_plugin_update_message-' . um_plugin, array( $this, 'in_plugin_update_message' ) ); } /** * Function for major updates * */ /*function in_plugin_update_message( $args ) { $lastversion = get_option( '%UNIQUE_ID%_last_version', false ); if ( $lastversion && version_compare( $lastversion, %UNIQUE_ID%_current_version, '>' ) ) { $upgrade_notice = get_option( '%UNIQUE_ID%_major_update' . $lastversion ); echo '' . wp_kses_post( $upgrade_notice ); } }*/ /** * Get array of necessary upgrade packages * * @return array */ function need_run_upgrades() { $um_last_version_upgrade = get_option( 'um_last_version_upgrade' ); //first install if ( ! $um_last_version_upgrade ) { $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, '<' ) ) { $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', __( 'empty', 'ultimate-member' ) ); ?>

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 ); } } }