compatibility
6 years ago
templates
6 years ago
class-addons-category.php
6 years ago
class-addons-integration.php
6 years ago
class-beta-testers.php
6 years ago
class-helper-functions.php
6 years ago
elementor-helper.php
6 years ago
plugin.php
6 years ago
class-beta-testers.php
93 lines
| 1 | <?php |
| 2 | |
| 3 | if ( ! defined( 'ABSPATH' ) ) exit; |
| 4 | |
| 5 | class Premium_Beta_Testers { |
| 6 | |
| 7 | private $transient_key; |
| 8 | |
| 9 | /** |
| 10 | * Get beta version |
| 11 | * |
| 12 | * Checks if the version in trunk is beta |
| 13 | * |
| 14 | * @since 2.1.3 |
| 15 | * @access public |
| 16 | */ |
| 17 | private function get_beta_version() { |
| 18 | |
| 19 | $beta_version = get_site_transient( $this->transient_key ); |
| 20 | |
| 21 | if ( false === $beta_version ) { |
| 22 | |
| 23 | $beta_version = 'false'; |
| 24 | |
| 25 | $response = wp_remote_get( 'https://plugins.svn.wordpress.org/premium-addons-for-elementor/trunk/readme.txt' ); |
| 26 | |
| 27 | if ( ! is_wp_error( $response ) && ! empty( $response['body'] ) ) { |
| 28 | preg_match( '/Beta tag: (.*)/i', $response['body'], $matches ); |
| 29 | if ( isset( $matches[1] ) ) { |
| 30 | $beta_version = $matches[1]; |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | set_site_transient( $this->transient_key, $beta_version, 6 * HOUR_IN_SECONDS ); |
| 35 | |
| 36 | } |
| 37 | |
| 38 | return $beta_version; |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Get version |
| 43 | * |
| 44 | * Checks if the version in trunk is beta |
| 45 | * |
| 46 | * @since 2.1.3 |
| 47 | * @access public |
| 48 | */ |
| 49 | public function compare_version( $transient ) { |
| 50 | |
| 51 | if ( empty( $transient->checked ) ) { |
| 52 | return $transient; |
| 53 | } |
| 54 | |
| 55 | delete_site_transient( $this->transient_key ); |
| 56 | |
| 57 | $plugin_slug = basename( PREMIUM_ADDONS_FILE , '.php' ); |
| 58 | |
| 59 | $beta_version = $this->get_beta_version(); |
| 60 | |
| 61 | if ( 'false' !== $beta_version && version_compare( $beta_version, PREMIUM_ADDONS_VERSION, '>' ) ) { |
| 62 | |
| 63 | $response = new \stdClass(); |
| 64 | |
| 65 | $response->plugin = $plugin_slug; |
| 66 | |
| 67 | $response->slug = $plugin_slug; |
| 68 | |
| 69 | $response->new_version = $beta_version; |
| 70 | |
| 71 | $response->url = 'https://premiumaddons.com/'; |
| 72 | |
| 73 | $response->package = sprintf( 'https://downloads.wordpress.org/plugin/premium-addons-for-elementor.%s.zip', $beta_version ); |
| 74 | |
| 75 | echo $response->package; |
| 76 | |
| 77 | $transient->response[ PREMIUM_ADDONS_BASENAME ] = $response; |
| 78 | } |
| 79 | |
| 80 | return $transient; |
| 81 | } |
| 82 | public function __construct() { |
| 83 | $check_component_active = isset(get_option( 'pa_beta_save_settings' )['is-beta-tester']) ? get_option( 'pa_beta_save_settings' )['is-beta-tester'] : 1; |
| 84 | if ( 0 !== $check_component_active ) { |
| 85 | return; |
| 86 | } |
| 87 | |
| 88 | $this->transient_key = md5( 'premium_addons_beta_response_key' ); |
| 89 | |
| 90 | add_filter( 'pre_set_site_transient_update_plugins', [ $this, 'compare_version' ] ); |
| 91 | } |
| 92 | } |
| 93 |