class-auxels-plugin-check-update.php
6 years ago
class-auxin-dashboard-notice.php
7 years ago
class-auxin-license-activation.php
7 years ago
class-auxin-notices.php
6 years ago
class-auxin-upgrader-ajax-handlers.php
7 years ago
class-auxin-upgrader-http-api.php
6 years ago
class-auxin-upgrader-plugin.php
7 years ago
class-auxin-upgrader-prepare.php
6 years ago
class-auxin-upgrader-theme.php
7 years ago
class-auxels-plugin-check-update.php
154 lines
| 1 | <?php |
| 2 | /** |
| 3 | * |
| 4 | * |
| 5 | * @package Auxin |
| 6 | * @license LICENSE.txt |
| 7 | * @author averta |
| 8 | * @link http://phlox.pro/ |
| 9 | * @copyright (c) 2010-2020 averta |
| 10 | */ |
| 11 | |
| 12 | // no direct access allowed |
| 13 | if ( ! defined('ABSPATH') ) { |
| 14 | die(); |
| 15 | } |
| 16 | |
| 17 | |
| 18 | class AUXELS_Plugin_Check_Update { |
| 19 | /** |
| 20 | * The plugin current version |
| 21 | * @var string |
| 22 | */ |
| 23 | public $current_version; |
| 24 | |
| 25 | /** |
| 26 | * The plugin remote update path |
| 27 | * @var string |
| 28 | */ |
| 29 | public $update_path; |
| 30 | |
| 31 | /** |
| 32 | * Plugin Slug (plugin_directory/plugin_file.php) |
| 33 | * @var string |
| 34 | */ |
| 35 | public $plugin_slug; |
| 36 | |
| 37 | /** |
| 38 | * Plugin name (plugin_file) |
| 39 | * @var string |
| 40 | */ |
| 41 | public $slug; |
| 42 | |
| 43 | /** |
| 44 | * The item name while requesting to update api |
| 45 | * @var string |
| 46 | */ |
| 47 | public $request_name; |
| 48 | |
| 49 | /** |
| 50 | * The item ID in marketplace |
| 51 | * @var string |
| 52 | */ |
| 53 | public $plugin_id; |
| 54 | |
| 55 | |
| 56 | /** |
| 57 | * The item name while requesting to update api |
| 58 | * @var string |
| 59 | */ |
| 60 | public $plugin_file_path; |
| 61 | |
| 62 | /** |
| 63 | * The item name while requesting to update api |
| 64 | * @var string |
| 65 | */ |
| 66 | public $banners; |
| 67 | |
| 68 | |
| 69 | /** |
| 70 | * Initialize a new instance of the WordPress Auto-Update class |
| 71 | * @param string $current_version |
| 72 | * @param string $update_path |
| 73 | * @param string $plugin_slug |
| 74 | * @param string $slug |
| 75 | */ |
| 76 | function __construct( $current_version, $update_path, $plugin_slug, $slug, $item_request_name = '' ) { |
| 77 | // Set the class public variables |
| 78 | $this->current_version = $current_version; |
| 79 | $this->update_path = $update_path; |
| 80 | $this->plugin_slug = $plugin_slug; |
| 81 | $this->slug = $slug; |
| 82 | |
| 83 | $this->request_name = empty( $item_request_name ) ? $this->slug : $item_request_name; |
| 84 | |
| 85 | // define the alternative API for checking for updates |
| 86 | add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update') ); |
| 87 | } |
| 88 | |
| 89 | |
| 90 | /** |
| 91 | * Check the plugin version on update plugin transient expired |
| 92 | * |
| 93 | * @param $transient |
| 94 | * @return object $ transient |
| 95 | */ |
| 96 | public function check_update( $transient ) { |
| 97 | // Get the remote version |
| 98 | $remote_version = $this->get_remote_version(); |
| 99 | |
| 100 | return $transient; |
| 101 | } |
| 102 | |
| 103 | |
| 104 | /** |
| 105 | * Return the remote version |
| 106 | * @return string $remote_version |
| 107 | */ |
| 108 | public function get_remote_version() { |
| 109 | global $wp_version; |
| 110 | |
| 111 | $theme_data = wp_get_theme(); |
| 112 | if( is_child_theme() ) { |
| 113 | $theme_data = wp_get_theme( $theme_data->template ); |
| 114 | } |
| 115 | |
| 116 | if ( ! function_exists( 'get_plugins' ) ) { |
| 117 | require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 118 | } |
| 119 | $all_plugins = get_plugins(); |
| 120 | if( ! isset( $all_plugins[ $this->plugin_slug ] ) || empty( $all_plugins[ $this->plugin_slug ] ) ){ |
| 121 | return; |
| 122 | } |
| 123 | |
| 124 | $this_plugin = $all_plugins[ $this->plugin_slug ]; |
| 125 | if( ! is_array( $this_plugin ) ){ |
| 126 | $this_plugin = array(); |
| 127 | } |
| 128 | $this_plugin['ID'] = $this->plugin_id; |
| 129 | $this_plugin['Name'] = defined('THEME_NAME') ? THEME_NAME : 'Phlox'; |
| 130 | $this_plugin['Theme'] = $theme_data->Name; |
| 131 | $this_plugin['Version'] = defined('THEME_VERSION') ? THEME_VERSION : $theme_data->Version; |
| 132 | $this_plugin['Slug'] = defined('THEME_ID') ? THEME_ID : $this->slug; |
| 133 | $this_plugin['Activated'] = 0; |
| 134 | |
| 135 | $request = wp_remote_post( $this->update_path, array( |
| 136 | 'user-agent' => 'WordPress/'.$wp_version.'; '. get_site_url(), |
| 137 | 'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 3), |
| 138 | 'body' => array( |
| 139 | 'cat' => 'version-check', |
| 140 | 'action' => 'final', |
| 141 | 'type' => 'plugin', |
| 142 | 'item-name' => $this->request_name, |
| 143 | 'item-info' => $this_plugin |
| 144 | ) |
| 145 | ) |
| 146 | ); |
| 147 | |
| 148 | if ( ! is_wp_error( $request ) || wp_remote_retrieve_response_code( $request ) === 200 ) { |
| 149 | return $request['body']; |
| 150 | } |
| 151 | return false; |
| 152 | } |
| 153 | } |
| 154 |