page_slug != $_GET['page'] ) { return; } $this->init(); } /** * Initialize * * @since 4.1.1 * @access public */ public function init() { add_action( 'admin_enqueue_scripts', array( $this, 'enqueue' ), 30 ); $this->theme_versions = $this->get_theme_versions(); $this->plugin_versions = $this->get_plugin_versions(); } /** * Enqueue Styles & Scripts * * @since 4.1.1 * @access public */ public function enqueue() { wp_enqueue_script( 'updates' ); wp_enqueue_script( 'alpha-admin-wizard', alpha_framework_uri( '/admin/panel/wizard' . ALPHA_JS_SUFFIX ), array( 'jquery-core' ), true, 50 ); wp_localize_script( 'alpha-admin-wizard', 'alpha_version_control_params', array( 'wpnonce' => wp_create_nonce( 'alpha_version_control_nonce' ), ) ); } /** * Get Theme Versions * * @since 4.1.1 * @access public * * @return array versions */ public function get_theme_versions() { $rollback_versions = get_site_transient( 'alpha_theme_rollback_versions' ); if ( false === $rollback_versions ) { $max_version = 20; $current_index = 0; require_once ALPHA_FRAMEWORK_ADMIN . '/importer/importer-api.php'; $importer_api = new Alpha_Importer_API(); $versions = $importer_api->get_response( 'theme_rollback_versions' ); if ( is_wp_error( $versions ) || empty( $versions ) ) { return array(); } $rollback_versions = array(); foreach ( $versions as $version ) { if ( $max_version <= $current_index ) { break; } if ( version_compare( $version, ALPHA_VERSION, '>=' ) ) { continue; } $current_index ++; $rollback_versions[] = $version; } if ( ! empty( $rollback_versions ) ) { set_site_transient( 'alpha_theme_rollback_versions', $rollback_versions, WEEK_IN_SECONDS ); } } return $rollback_versions; } /** * Get Plugin Versions * * @since 4.1.1 * @access public * * @return array plugin versions */ public function get_plugin_versions() { $rollback_versions = get_site_transient( 'alpha_plugin_rollback_versions' ); if ( false === $rollback_versions ) { $max_version = 20; $current_index = 0; require_once ALPHA_FRAMEWORK_ADMIN . '/importer/importer-api.php'; $importer_api = new Alpha_Importer_API(); $versions = $importer_api->get_response( 'plugin_rollback_versions' ); if ( is_wp_error( $versions ) || empty( $versions ) ) { return array(); } $rollback_versions = array(); foreach ( $versions as $version ) { if ( $max_version <= $current_index ) { break; } if ( version_compare( $version, ALPHA_CORE_VERSION, '>=' ) ) { continue; } $current_index ++; $rollback_versions[] = $version; } set_site_transient( 'alpha_plugin_rollback_versions', $rollback_versions, WEEK_IN_SECONDS ); } return $rollback_versions; } /** * Check for update theme. * * @since 4.1.1 * @access public * * @param array $data themes info. * @return array $data */ public function alpha_check_for_update_theme( $data ) { $transient_data = get_site_transient( 'alpha_modify_theme_auto_update' ); if ( $transient_data ) { $data->response[ 'alpha' ] = $transient_data; } return $data; } /** * Check for update plugin * * @since 4.1.1 * @access public * * @param array $data themes info. * @return array $data */ public function alpha_check_for_update_plugin( $data ) { $transient_data = get_site_transient( 'alpha_modify_plugin_auto_update' ); if ( ! empty( $transient_data ) ) { $data->response[ 'alpha-core/alpha-core.php' ] = json_decode( wp_json_encode( $transient_data ), false ); } return $data; } /** * Modify theme auto updates * * @since 4.1.1 * @access public */ public function alpha_modify_theme_auto_updates() { if ( ! isset( $_REQUEST['wpnonce'] ) || ! wp_verify_nonce( $_REQUEST['wpnonce'], 'alpha_version_control_nonce' ) ) { wp_send_json( false ); die(); } delete_transient( 'alpha_modify_theme_auto_update' ); require_once ALPHA_FRAMEWORK_ADMIN . '/importer/importer-api.php'; $importer_api = new Alpha_Importer_API(); $args = $importer_api->generate_args( false ); $version = isset( $_REQUEST['version'] ) ? wp_unslash( $_REQUEST['version'] ) : ''; $args['version'] = $version; $package_url = add_query_arg( $args, $importer_api->get_url( 'theme_rollback' ) ); $transient_data = array( 'theme' => 'alpha', 'new_version' => $version, 'release_version' => $version, 'url' => $this->theme_url, 'package' => $package_url, ); set_site_transient( 'alpha_modify_theme_auto_update', $transient_data, WEEK_IN_SECONDS ); add_filter( 'site_transient_update_themes', array( $this, 'alpha_check_for_update_theme' ), 1 ); wp_send_json( true ); die(); } /** * Modify plugin auto updates * * @since 4.1.1 * @access public */ public function alpha_modify_plugin_auto_updates() { if ( ! isset( $_REQUEST['wpnonce'] ) || ! wp_verify_nonce( $_REQUEST['wpnonce'], 'alpha_version_control_nonce' ) ) { wp_send_json( false ); die(); } delete_transient( 'alpha_modify_plugin_auto_update' ); require_once ALPHA_FRAMEWORK_ADMIN . '/importer/importer-api.php'; $importer_api = new Alpha_Importer_API(); $args = $importer_api->generate_args( false ); $version = isset( $_REQUEST['version'] ) ? wp_unslash( $_REQUEST['version'] ) : ''; $args['version'] = $version; $package_url = add_query_arg( $args, $importer_api->get_url( 'plugin_rollback' ) ); $transient_data = array( 'slug' => 'alpha-core', 'plugin' => 'alpha-core/alpha-core.php', 'new_version' => $version, 'release_version' => $version, 'url' => $this->theme_url, 'package' => $package_url, ); set_site_transient( 'alpha_modify_plugin_auto_update', $transient_data, WEEK_IN_SECONDS ); add_filter( 'site_transient_update_plugins', array( $this, 'alpha_check_for_update_plugin' ), 1 ); wp_send_json( true ); die(); } /** * Add Tools to admin menu * * @since 1.0 * @access public */ public function add_admin_menu() { add_submenu_page( 'alpha', esc_html__( 'Version Control', 'alpus' ), esc_html__( 'Version Control', 'alpus' ), 'manage_options', $this->page_slug, array( $this, 'view_tools' ), 3 ); } /** * Render tools page * * @since 1.0 * @access public */ public function view_tools() { $admin_config = Alpha_Admin::get_instance()->admin_config; $title = array( 'title' => esc_html__( 'Version Control', 'alpus' ), 'desc' => sprintf( esc_html__( 'Experiencing an issue with New version? Rollback to a previous version before the issue appeared.', 'alpus' ), ALPHA_DISPLAY_NAME ), ); Alpha_Admin_Panel::get_instance()->view_header( 'version-control', $admin_config, $title ); $nonce = wp_create_nonce( 'alpha-version-control' ); ?> result ) ) { if ( $this->result['success'] ) { echo '
' . esc_html( $this->result['message'] ) . '
' . esc_html( $this->result['message'] ) . '