premium-addons-for-elementor
Last commit date
admin
8 years ago
assets
8 years ago
widgets
8 years ago
elementor-helper.php
8 years ago
index.php
8 years ago
premium-addons.php
8 years ago
queries.php
8 years ago
readme.txt
8 years ago
wp-updates-plugin.php
8 years ago
wp-updates-plugin.php
116 lines
| 1 | <?php |
| 2 | /* |
| 3 | WPUpdates Plugin Updater Class |
| 4 | http://wp-updates.com |
| 5 | v2.0 |
| 6 | |
| 7 | Example Usage: |
| 8 | require_once('wp-updates-plugin.php'); |
| 9 | new WPUpdatesPluginUpdater_1837( 'http://wp-updates.com/api/2/plugin', plugin_basename(__FILE__) ); |
| 10 | */ |
| 11 | |
| 12 | if( !class_exists('WPUpdatesPluginUpdater_1837') ) { |
| 13 | class WPUpdatesPluginUpdater_1837 { |
| 14 | |
| 15 | var $api_url; |
| 16 | var $plugin_id = 1837; |
| 17 | var $plugin_path; |
| 18 | var $plugin_slug; |
| 19 | var $license_key; |
| 20 | |
| 21 | function __construct( $api_url, $plugin_path, $license_key = null ) { |
| 22 | $this->api_url = $api_url; |
| 23 | $this->plugin_path = $plugin_path; |
| 24 | $this->license_key = $license_key; |
| 25 | if(strstr($plugin_path, '/')) list ($t1, $t2) = explode('/', $plugin_path); |
| 26 | else $t2 = $plugin_path; |
| 27 | $this->plugin_slug = str_replace('.php', '', $t2); |
| 28 | |
| 29 | add_filter( 'pre_set_site_transient_update_plugins', array(&$this, 'check_for_update') ); |
| 30 | add_filter( 'plugins_api', array(&$this, 'plugin_api_call'), 10, 3 ); |
| 31 | |
| 32 | // This is for testing only! |
| 33 | //set_site_transient( 'update_plugins', null ); |
| 34 | |
| 35 | // Show which variables are being requested when query plugin API |
| 36 | //add_filter( 'plugins_api_result', array(&$this, 'debug_result'), 10, 3 ); |
| 37 | } |
| 38 | |
| 39 | function check_for_update( $transient ) { |
| 40 | if(empty($transient->checked)) return $transient; |
| 41 | |
| 42 | $request_args = array( |
| 43 | 'id' => $this->plugin_id, |
| 44 | 'slug' => $this->plugin_slug, |
| 45 | 'version' => $transient->checked[$this->plugin_path] |
| 46 | ); |
| 47 | if ($this->license_key) $request_args['license'] = $this->license_key; |
| 48 | |
| 49 | $request_string = $this->prepare_request( 'update_check', $request_args ); |
| 50 | $raw_response = wp_remote_post( $this->api_url, $request_string ); |
| 51 | |
| 52 | $response = null; |
| 53 | if( !is_wp_error($raw_response) && ($raw_response['response']['code'] == 200) ) |
| 54 | $response = unserialize($raw_response['body']); |
| 55 | |
| 56 | if( is_object($response) && !empty($response) ) { |
| 57 | // Feed the update data into WP updater |
| 58 | $transient->response[$this->plugin_path] = $response; |
| 59 | return $transient; |
| 60 | } |
| 61 | |
| 62 | // Check to make sure there is not a similarly named plugin in the wordpress.org repository |
| 63 | if ( isset( $transient->response[$this->plugin_path] ) ) { |
| 64 | if ( strpos( $transient->response[$this->plugin_path]->package, 'wordpress.org' ) !== false ) { |
| 65 | unset($transient->response[$this->plugin_path]); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | return $transient; |
| 70 | } |
| 71 | |
| 72 | function plugin_api_call( $def, $action, $args ) { |
| 73 | if( !isset($args->slug) || $args->slug != $this->plugin_slug ) return $def; |
| 74 | |
| 75 | $plugin_info = get_site_transient('update_plugins'); |
| 76 | $request_args = array( |
| 77 | 'id' => $this->plugin_id, |
| 78 | 'slug' => $this->plugin_slug, |
| 79 | 'version' => (isset($plugin_info->checked)) ? $plugin_info->checked[$this->plugin_path] : 0 // Current version |
| 80 | ); |
| 81 | if ($this->license_key) $request_args['license'] = $this->license_key; |
| 82 | |
| 83 | $request_string = $this->prepare_request( $action, $request_args ); |
| 84 | $raw_response = wp_remote_post( $this->api_url, $request_string ); |
| 85 | |
| 86 | if( is_wp_error($raw_response) ){ |
| 87 | $res = new WP_Error('plugins_api_failed', __('An Unexpected HTTP Error occurred during the API request.</p> <p><a href="?" onclick="document.location.reload(); return false;">Try again</a>'), $raw_response->get_error_message()); |
| 88 | } else { |
| 89 | $res = unserialize($raw_response['body']); |
| 90 | if ($res === false) |
| 91 | $res = new WP_Error('plugins_api_failed', __('An unknown error occurred'), $raw_response['body']); |
| 92 | } |
| 93 | |
| 94 | return $res; |
| 95 | } |
| 96 | |
| 97 | function prepare_request( $action, $args ) { |
| 98 | global $wp_version; |
| 99 | |
| 100 | return array( |
| 101 | 'body' => array( |
| 102 | 'action' => $action, |
| 103 | 'request' => serialize($args), |
| 104 | 'api-key' => md5(home_url()) |
| 105 | ), |
| 106 | 'user-agent' => 'WordPress/'. $wp_version .'; '. home_url() |
| 107 | ); |
| 108 | } |
| 109 | |
| 110 | function debug_result( $res, $action, $args ) { |
| 111 | echo '<pre>'.print_r($res,true).'</pre>'; |
| 112 | return $res; |
| 113 | } |
| 114 | |
| 115 | } |
| 116 | } |