gin_slug' => $plugin_slug, 'package_url' => sprintf( 'https://downloads.wordpress.org/plugin/%s.%s.zip', $plugin_slug, $_GET['version'] ), ] ); $rollback->run(); wp_die( '', esc_html__( 'Rollback to Previous Version', 'elementor' ), [ 'response' => 200, ] ); } /** * Tools page constructor. * * Initializing Elementor "Tools" page. * * @since 1.0.0 * @access public */ public function __construct() { parent::__construct(); if ( Plugin::$instance->experiments->is_feature_active( 'admin_menu_rearrangement' ) ) { add_action( 'elementor/admin/menu_registered/elementor', function( MainMenu $menu ) { $this->register_admin_menu( $menu ); } ); } else { add_action( 'admin_menu', function() { $this->register_admin_menu_legacy(); }, 205 ); } add_action( 'wp_ajax_elementor_clear_cache', [ $this, 'ajax_elementor_clear_cache' ] ); add_action( 'wp_ajax_elementor_replace_url', [ $this, 'ajax_elementor_replace_url' ] ); add_action( 'wp_ajax_elementor_recreate_kit', [ $this, 'ajax_elementor_recreate_kit' ] ); add_action( 'admin_post_elementor_rollback', [ $this, 'post_elementor_rollback' ] ); } private function get_rollback_versions() { $rollback_versions = get_transient( 'elementor_rollback_versions_' . ELEMENTOR_VERSION ); if ( false === $rollback_versions ) { $max_versions = 30; require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; $plugin_information = plugins_api( 'plugin_information', [ 'slug' => 'elementor', ] ); if ( empty( $plugin_information->versions ) || ! is_array( $plugin_information->versions ) ) { return []; } krsort( $plugin_information->versions ); $rollback_versions = []; $current_index = 0; foreach ( $plugin_information->versions as $version => $download_link ) { if ( $max_versions <= $current_index ) { break; } $lowercase_version = strtolower( $version ); $is_valid_rollback_version = ! preg_match( '/(trunk|beta|rc|dev)/i', $lowercase_version ); /** * Is rollback version is valid. * * Filters the check whether the rollback version is valid. * * @param bool $is_valid_rollback_version Whether the rollback version is valid. */ $is_valid_rollback_version = apply_filters( 'elementor/settings/tools/rollback/is_valid_rollback_version', $is_valid_rollback_version, $lowercase_version ); if ( ! $is_valid_rollback_version ) { continue; } if ( version_compare( $version, ELEMENTOR_VERSION, '>=' ) ) { continue; } $current_index++; $rollback_versions[] = $version; } set_transient( 'elementor_rollback_versions_' . ELEMENTOR_VERSION, $rollback_versions, WEEK_IN_SECONDS ); } return $rollback_versions; } /** * Create tabs. * * Return the tools page tabs, sections and fields. * * @since 1.5.0 * @access protected * * @return array An array with the page tabs, sections and fields. */ protected function create_tabs() { $rollback_html = ''; $tabs = [ 'general' => [ 'label' => esc_html__( 'General', 'elementor' ), 'sections' => [ 'tools' => [ 'fields' => [ 'clear_cache' => [ 'label' => esc_html__( 'Regenerate CSS & Data', 'elementor' ), 'field_args' => [ 'type' => 'raw_html', 'html' => sprintf( '', wp_create_nonce( 'elementor_clear_cache' ), esc_html__( 'Regenerate Files & Data', 'elementor' ) ), 'desc' => esc_html__( 'Styles set in Elementor are saved in CSS files in the uploads folder and in the site’s database. Recreate those files and settings, according to the most recent settings.', 'elementor' ), ], ], 'reset_api_data' => [ 'label' => esc_html__( 'Sync Library', 'elementor' ), 'field_args' => [ 'type' => 'raw_html', 'html' => sprintf( '', wp_create_nonce( 'elementor_reset_library' ), esc_html__( 'Sync Library', 'elementor' ) ), 'desc' => esc_html__( 'Elementor Library automatically updates on a daily basis. You can also manually update it by clicking on the sync button.', 'elementor' ), ], ], ], ], ], ], 'replace_url' => [ 'label' => esc_html__( 'Replace URL', 'elementor' ), 'sections' => [ 'replace_url' => [ 'callback' => function() { $intro_text = sprintf( /* translators: %s: WordPress backups documentation. */ __( 'Important: It is strongly recommended that you backup your database before using Replace URL.', 'elementor' ), 'http://go.elementor.com/wordpress-backups/' ); $intro_text = '
' . $intro_text . '
'; echo '

' . esc_html__( 'Replace URL', 'elementor' ) . '

'; Utils::print_unescaped_internal_string( $intro_text ); }, 'fields' => [ 'replace_url' => [ 'label' => esc_html__( 'Update Site Address (URL)', 'elementor' ), 'field_args' => [ 'type' => 'raw_html', 'html' => sprintf( '', wp_create_nonce( 'elementor_replace_url' ), esc_html__( 'Replace URL', 'elementor' ) ), 'desc' => esc_html__( 'Enter your old and new URLs for your WordPress installation, to update all Elementor data (Relevant for domain transfers or move to \'HTTPS\').', 'elementor' ), ], ], ], ], ], ], 'versions' => [ 'show_if' => static::can_user_rollback_versions(), 'label' => esc_html__( 'Version Control', 'elementor' ), 'sections' => [ 'rollback' => [ 'label' => esc_html__( 'Rollback to Previous Version', 'elementor' ), 'callback' => function() { $intro_text = sprintf( /* translators: %s: Elementor version. */ esc_html__( 'Experiencing an issue with Elementor version %s? Rollback to a previous version before the issue appeared.', 'elementor' ), ELEMENTOR_VERSION ); $intro_text = '

' . $intro_text . '

'; Utils::print_unescaped_internal_string( $intro_text ); }, 'fields' => [ 'rollback' => [ 'label' => esc_html__( 'Rollback Version', 'elementor' ), 'field_args' => [ 'type' => 'raw_html', 'html' => sprintf( $rollback_html . '%s', wp_nonce_url( admin_url( 'admin-post.php?action=elementor_rollback&version=VERSION' ), 'elementor_rollback' ), esc_html__( 'Reinstall', 'elementor' ) ), 'desc' => '' . esc_html__( 'Warning: Please backup your database before making the rollback.', 'elementor' ) . '', ], ], ], ], 'beta' => [ 'label' => esc_html__( 'Become a Beta Tester', 'elementor' ), 'callback' => function() { echo '

' . esc_html__( 'Turn-on Beta Tester, to get notified when a new beta version of Elementor or Elementor Pro is available. The Beta version will not install automatically. You always have the option to ignore it.', 'elementor' ) . '

'; echo sprintf( /* translators: 1: Link open tag, 2: Link close tag. */ esc_html__( '%1$sClick here%2$s to join our first-to-know email updates.', 'elementor' ), '', '' ); }, 'fields' => [ 'beta' => [ 'label' => esc_html__( 'Beta Tester', 'elementor' ), 'field_args' => [ 'type' => 'select', 'std' => 'no', 'options' => [ 'no' => esc_html__( 'Disable', 'elementor' ), 'yes' => esc_html__( 'Enable', 'elementor' ), ], 'desc' => '' . esc_html__( 'Please Note: We do not recommend updating to a beta version on production sites.', 'elementor' ) . '', ], ], ], ], ], ], ]; if ( ! Plugin::$instance->kits_manager->get_active_kit()->get_id() ) { $tabs['general']['sections']['tools']['fields']['recreate_kit'] = [ 'label' => __( 'Recreate Kit', 'elementor' ), 'field_args' => [ 'type' => 'raw_html', 'html' => sprintf( '', wp_create_nonce( 'elementor_recreate_kit' ), __( 'Recreate Kit', 'elementor' ) ), 'desc' => esc_html__( 'It seems like your site doesn\'t have any active Kit. The active Kit includes all of your Site Settings. By recreating your Kit you will able to start edit your Site Settings again.', 'elementor' ), ], ]; } return $tabs; } /** * Get tools page title. * * Retrieve the title for the tools page. * * @since 1.5.0 * @access protected * * @return string Tools page title. */ protected function get_page_title() { return esc_html__( 'Tools', 'elementor' ); } /** * Check if the current user can access the version control tab and rollback versions. * * @return bool */ public static function can_user_rollback_versions() { return current_user_can( 'activate_plugins' ) && current_user_can( 'update_plugins' ); } }