| @@ -13,8 +13,9 @@ | ||
| 13 | 13 | |
| 14 | 14 | /** |
| 15 | 15 | * Class PH_Plugin_Updates |
| 16 | 16 | */ |
| 17 | +// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedClassFound -- Legacy public global class PH_Plugin_Updates; preserving the existing PH_* class name is required for plugin and extension compatibility. | |
| 17 | 18 | class PH_Plugin_Updates { |
| 18 | 19 | |
| 19 | 20 | /** |
| 20 | 21 | * The upgrade notice shown inline. |
| @@ -30,40 +31,48 @@ | ||
| 30 | 31 | add_action( 'in_plugin_update_message-propertyhive/propertyhive.php', array( $this, 'in_plugin_update_message' ), 10, 2 ); |
| 31 | 32 | |
| 32 | 33 | if ( is_network_admin() || ! is_multisite() ) |
| 33 | 34 | { |
| 34 | - $license = PH()->license->get_current_license(); | |
| 35 | + $license_type = PH()->license->get_license_type(); | |
| 35 | 36 | |
| 36 | 37 | $valid_license = false; |
| 37 | 38 | |
| 38 | - if ( is_array($license) && empty($license) && get_option( 'propertyhive_license_key', '' ) != '' ) | |
| 39 | + if ( $license_type == 'old' ) | |
| 39 | 40 | { |
| 40 | - | |
| 41 | - } | |
| 42 | - elseif ( isset($license['active']) && $license['active'] != '1' ) | |
| 43 | - { | |
| 41 | + $license = PH()->license->get_current_license(); | |
| 44 | 42 | |
| 45 | - } | |
| 46 | - else | |
| 47 | - { | |
| 48 | - if ( isset($license['expires_at']) && $license['expires_at'] != '' ) | |
| 43 | + if ( is_array($license) && empty($license) && get_option( 'propertyhive_license_key', '' ) != '' ) | |
| 49 | 44 | { |
| 50 | - if ( strtotime($license['expires_at']) <= time() ) | |
| 51 | - { | |
| 52 | - // Expired | |
| 45 | + | |
| 46 | + } | |
| 47 | + elseif ( isset($license['active']) && $license['active'] != '1' ) | |
| 48 | + { | |
| 53 | 49 | |
| 54 | - } | |
| 55 | - elseif ( | |
| 56 | - strtotime($license['expires_at']) > time() && | |
| 57 | - strtotime($license['expires_at']) < (time() + 30 * 24 * 60 * 60) | |
| 58 | - ) | |
| 50 | + } | |
| 51 | + else | |
| 52 | + { | |
| 53 | + if ( isset($license['expires_at']) && $license['expires_at'] != '' ) | |
| 59 | 54 | { |
| 60 | - // Expires in less than 30 days | |
| 55 | + if ( strtotime($license['expires_at']) <= time() ) | |
| 56 | + { | |
| 57 | + // Expired | |
| 61 | 58 | |
| 59 | + } | |
| 60 | + else | |
| 61 | + { | |
| 62 | + // Valid | |
| 63 | + $valid_license = true; | |
| 64 | + } | |
| 62 | 65 | } |
| 63 | - elseif (strtotime($license['expires_at']) > time()) | |
| 66 | + } | |
| 67 | + } | |
| 68 | + elseif ( $license_type == 'pro' ) | |
| 69 | + { | |
| 70 | + // get new license information | |
| 71 | + if ( get_option('propertyhive_pro_license_key', '') != '' ) | |
| 72 | + { | |
| 73 | + if ( PH()->license->is_valid_pro_license_key() ) | |
| 64 | 74 | { |
| 65 | - // Valid | |
| 66 | 75 | $valid_license = true; |
| 67 | 76 | } |
| 68 | 77 | } |
| 69 | 78 | } |
| @@ -69,46 +78,64 @@ | ||
| 69 | 78 | } |
| 70 | 79 | |
| 71 | 80 | if ( !$valid_license ) |
| 72 | 81 | { |
| 73 | - $add_ons = @file_get_contents('http://wp-property-hive.com/add-ons-json.php'); | |
| 82 | + $add_ons = ''; | |
| 83 | + // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only refresh of public add-on metadata; this flag does not install, activate or change licensing. | |
| 84 | + if ( false === ( $add_ons = get_transient( 'propertyhive_features' ) ) || isset($_GET['ph_force_get_features']) ) | |
| 85 | + { | |
| 86 | + // It wasn't there, so regenerate the data and save the transient | |
| 87 | + $response = wp_remote_get( | |
| 88 | + 'https://wp-property-hive.com/add-ons-json.php', | |
| 89 | + array( | |
| 90 | + 'timeout' => 10 | |
| 91 | + ) | |
| 92 | + ); | |
| 74 | 93 | |
| 75 | - if ($add_ons !== FALSE && $add_ons !== '') | |
| 76 | - { | |
| 77 | - $add_ons = json_decode($add_ons); | |
| 78 | - | |
| 79 | - if ($add_ons !== FALSE && !empty($add_ons)) | |
| 80 | - { | |
| 81 | - foreach ($add_ons as $add_on) | |
| 82 | - { | |
| 83 | - $url = trim($add_on->url, '/'); | |
| 94 | + if ( !is_wp_error( $response ) && is_array( $response ) ) | |
| 95 | + { | |
| 96 | + $body = $response['body']; // use the content | |
| 84 | 97 | |
| 85 | - if ( | |
| 86 | - isset($add_on->wordpress_plugin_file) && $add_on->wordpress_plugin_file != '' && $add_on->wordpress_plugin_file != false && | |
| 87 | - isset($add_on->wordpress_version_option_name) && $add_on->wordpress_version_option_name != '' && $add_on->wordpress_version_option_name != false | |
| 88 | - ) | |
| 98 | + $add_ons = json_decode($body, TRUE); | |
| 99 | + | |
| 100 | + if ( $add_ons !== FALSE && is_array($add_ons) && !empty($add_ons) ) | |
| 101 | + { | |
| 102 | + set_transient( 'propertyhive_features', $add_ons, DAY_IN_SECONDS ); | |
| 103 | + } | |
| 104 | + } | |
| 105 | + } | |
| 106 | + | |
| 107 | + if ($add_ons !== FALSE && !empty($add_ons)) | |
| 108 | + { | |
| 109 | + foreach ($add_ons as $add_on) | |
| 110 | + { | |
| 111 | + $url = trim($add_on['url'], '/'); | |
| 112 | + | |
| 113 | + if ( | |
| 114 | + isset($add_on['wordpress_plugin_file']) && $add_on['wordpress_plugin_file'] != '' && $add_on['wordpress_plugin_file'] != false && | |
| 115 | + isset($add_on['wordpress_version_option_name']) && $add_on['wordpress_version_option_name'] != '' && $add_on['wordpress_version_option_name'] != false | |
| 116 | + ) | |
| 117 | + { | |
| 118 | + $plugin_file = $add_on['wordpress_plugin_file']; | |
| 119 | + | |
| 120 | + if ( is_plugin_active($plugin_file) ) | |
| 89 | 121 | { |
| 90 | - $plugin_file = $add_on->wordpress_plugin_file; | |
| 122 | + $current_version = get_option($add_on['wordpress_version_option_name'], ''); | |
| 91 | 123 | |
| 92 | - if ( is_plugin_active($plugin_file) ) | |
| 124 | + if ( $current_version != '' ) | |
| 93 | 125 | { |
| 94 | - $current_version = get_option($add_on->wordpress_version_option_name, ''); | |
| 126 | + // check if add on update available | |
| 127 | + $new_version = $add_on['version']; | |
| 95 | 128 | |
| 96 | - if ( $current_version != '' ) | |
| 129 | + if ( version_compare($new_version, $current_version) == 1 ) | |
| 97 | 130 | { |
| 98 | - // check if add on update available | |
| 99 | - $new_version = $add_on->version; | |
| 100 | - | |
| 101 | - if( version_compare($new_version, $current_version) == 1 ) | |
| 102 | - { | |
| 103 | - add_action( 'after_plugin_row_' . $plugin_file, array( $this, 'test' ), 10, 3 ); | |
| 104 | - } | |
| 131 | + add_action( 'after_plugin_row_' . $plugin_file, array( $this, 'test' ), 10, 3 ); | |
| 105 | 132 | } |
| 106 | - } | |
| 133 | + } | |
| 107 | 134 | } |
| 108 | - } | |
| 109 | - } | |
| 110 | - } | |
| 135 | + } | |
| 136 | + } | |
| 137 | + } | |
| 111 | 138 | } |
| 112 | 139 | } |
| 113 | 140 | } |
| 114 | 141 | |
| @@ -119,12 +146,12 @@ | ||
| 119 | 146 | } else { |
| 120 | 147 | $active_class = is_plugin_active( $plugin_file ) ? ' active' : ''; |
| 121 | 148 | } |
| 122 | 149 | |
| 123 | - echo '<tr class="plugin-update-tr' . $active_class . '"> | |
| 150 | + echo '<tr class="plugin-update-tr' . esc_attr($active_class) . '"> | |
| 124 | 151 | <td colspan="3" class="plugin-update colspanchange"> |
| 125 | 152 | <div class="update-message notice inline notice-warning notice-alt"> |
| 126 | - <p>An update is available for this add on. It is recommended that you update to ensure you receive the latest features and bug fixes. You can access all updates to any purchased add ons for 12 months by <a href="https://wp-property-hive.com/product/12-month-license-key-subscription/" target="_blank">purchasing a license key</a>.</p> | |
| 153 | + <p>An update is available for this plugin. It is recommended that you update to ensure you receive the latest features and bug fixes. You can access updates to plugins by <a href="https://wp-property-hive.com/pricing/?src=plugin-update-notice" target="_blank">purchasing a pro package</a>.</p> | |
| 127 | 154 | </div> |
| 128 | 155 | </td> |
| 129 | 156 | </tr>'; |
| 130 | 157 | } |
| @@ -138,9 +165,9 @@ | ||
| 138 | 165 | public function in_plugin_update_message( $args, $response ) { |
| 139 | 166 | $this->new_version = $response->new_version; |
| 140 | 167 | $this->upgrade_notice = $this->get_upgrade_notice( $response->new_version ); |
| 141 | 168 | |
| 142 | - echo apply_filters( 'propertyhive_in_plugin_update_message', $this->upgrade_notice ? '<br><span style="color:#900">' . wp_kses_post( $this->upgrade_notice ) . '</span>' : '' ); // phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped | |
| 169 | + echo apply_filters( 'propertyhive_in_plugin_update_message', $this->upgrade_notice ? '<br><span style="color:#900">' . wp_kses_post( $this->upgrade_notice ) . '</span>' : '' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- The remote notice is sanitized with wp_kses_post before this trusted PHP extension HTML filter. | |
| 143 | 170 | } |
| 144 | 171 | |
| 145 | 172 | /** |
| 146 | 173 | * Get the upgrade notice from WordPress.org. |