setup-wizard
9 months ago
templates
9 months ago
admin-bar.php
9 months ago
admin-helper.php
9 months ago
admin-notices.php
9 months ago
beta-testers.php
9 months ago
duplicator.php
9 months ago
elements.php
9 months ago
feedback.php
9 months ago
keys.php
9 months ago
pa-rollback.php
9 months ago
pa-rollback.php
166 lines
| 1 | <?php |
| 2 | /** |
| 3 | * PA Rollback |
| 4 | */ |
| 5 | |
| 6 | namespace PremiumAddons\Admin\Includes; |
| 7 | |
| 8 | if ( ! defined( 'ABSPATH' ) ) { |
| 9 | exit; |
| 10 | } |
| 11 | |
| 12 | /** |
| 13 | * Class Admin_Helper |
| 14 | */ |
| 15 | class PA_Rollback { |
| 16 | |
| 17 | /** |
| 18 | * Plugin URL |
| 19 | * |
| 20 | * @var package_url |
| 21 | */ |
| 22 | protected $package_url; |
| 23 | |
| 24 | /** |
| 25 | * Plugin Version |
| 26 | * |
| 27 | * @var version |
| 28 | */ |
| 29 | protected $version; |
| 30 | |
| 31 | /** |
| 32 | * Plugin Name |
| 33 | * |
| 34 | * @var plugin_name |
| 35 | */ |
| 36 | protected $plugin_name; |
| 37 | |
| 38 | /** |
| 39 | * Plugin Slug |
| 40 | * |
| 41 | * @var plugin_slug |
| 42 | */ |
| 43 | protected $plugin_slug; |
| 44 | |
| 45 | /** |
| 46 | * Constructor for the class |
| 47 | * |
| 48 | * @param array $args plugin args. |
| 49 | */ |
| 50 | public function __construct( $args = array() ) { |
| 51 | foreach ( $args as $key => $value ) { |
| 52 | $this->{$key} = $value; |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Print Inline Style |
| 58 | * |
| 59 | * Used to print inline style on rollback page |
| 60 | * |
| 61 | * @since 0.0.1 |
| 62 | * @access private |
| 63 | */ |
| 64 | private function print_inline_style() { |
| 65 | ?> |
| 66 | |
| 67 | <style> |
| 68 | .wrap { |
| 69 | overflow: hidden; |
| 70 | } |
| 71 | |
| 72 | h1 { |
| 73 | background: #6ec1e4; |
| 74 | text-align: center; |
| 75 | color: #fff !important; |
| 76 | padding: 70px !important; |
| 77 | text-transform: uppercase; |
| 78 | letter-spacing: 1px; |
| 79 | } |
| 80 | h1 img { |
| 81 | max-width: 300px; |
| 82 | display: block; |
| 83 | margin: auto auto 50px; |
| 84 | } |
| 85 | </style> |
| 86 | |
| 87 | <?php |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Apply package |
| 92 | * |
| 93 | * @since 0.0.1 |
| 94 | * @access private |
| 95 | */ |
| 96 | protected function apply_package() { |
| 97 | |
| 98 | $update_plugins = get_site_transient( 'update_plugins' ); |
| 99 | |
| 100 | if ( ! is_object( $update_plugins ) ) { |
| 101 | |
| 102 | $update_plugins = new \stdClass(); |
| 103 | } |
| 104 | |
| 105 | $plugin_info = new \stdClass(); |
| 106 | |
| 107 | $plugin_info->new_version = $this->version; |
| 108 | |
| 109 | $plugin_info->slug = $this->plugin_slug; |
| 110 | |
| 111 | $plugin_info->package = $this->package_url; |
| 112 | |
| 113 | $plugin_info->url = 'https://premiumaddons.com/'; |
| 114 | |
| 115 | $update_plugins->response[ $this->plugin_name ] = $plugin_info; |
| 116 | |
| 117 | set_site_transient( 'update_plugins', $update_plugins ); |
| 118 | |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * Upgrade |
| 123 | * |
| 124 | * Rollback update |
| 125 | * |
| 126 | * @since 0.0.1 |
| 127 | * @access private |
| 128 | */ |
| 129 | protected function upgrade() { |
| 130 | |
| 131 | require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
| 132 | |
| 133 | $logo_url = PREMIUM_ADDONS_URL . 'admin/images/pa-logo-symbol.png'; |
| 134 | |
| 135 | $upgrader_args = array( |
| 136 | 'url' => 'update.php?action=upgrade-plugin&plugin=' . rawurlencode( $this->plugin_name ), |
| 137 | 'plugin' => $this->plugin_name, |
| 138 | 'nonce' => 'upgrade-plugin_' . $this->plugin_name, |
| 139 | 'title' => '<img src="' . $logo_url . '" alt="Premium Addons">' . __( 'Rolling Back to Version ', 'premium-addons-for-elementor' ) . $this->version, |
| 140 | ); |
| 141 | |
| 142 | $this->print_inline_style(); |
| 143 | |
| 144 | $upgrader = new \Plugin_Upgrader( new \Plugin_Upgrader_Skin( $upgrader_args ) ); |
| 145 | |
| 146 | $upgrader->upgrade( $this->plugin_name ); |
| 147 | |
| 148 | } |
| 149 | |
| 150 | /** |
| 151 | * Run |
| 152 | * |
| 153 | * Trigger rollback functions |
| 154 | * |
| 155 | * @since 0.0.1 |
| 156 | * @access private |
| 157 | */ |
| 158 | public function run() { |
| 159 | |
| 160 | $this->apply_package(); |
| 161 | |
| 162 | $this->upgrade(); |
| 163 | |
| 164 | } |
| 165 | } |
| 166 |