Changeset 2973600
- Timestamp:
- 10/01/2023 10:41:07 PM (2 years ago)
- Location:
- vistawp
- Files:
-
- 6 edited
- 1 copied
-
tags/1.2.1 (copied) (copied from vistawp/trunk)
-
tags/1.2.1/includes/options/license-manager.php (modified) (8 diffs)
-
tags/1.2.1/readme.txt (modified) (1 diff)
-
tags/1.2.1/vista.php (modified) (1 diff)
-
trunk/includes/options/license-manager.php (modified) (8 diffs)
-
trunk/readme.txt (modified) (1 diff)
-
trunk/vista.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
vistawp/tags/1.2.1/includes/options/license-manager.php
r2961844 r2973600 18 18 * set this to NULL and use the below two constants to set up choices. 19 19 * Otherwise, if this is set to an int or string, that will be used 20 * as the pricing tier ID/product ID on vistawp 20 * as the pricing tier ID/product ID when calling the EDD API on vistawp.com 21 * 21 22 * @var string|int 22 23 */ 23 private const TIER = 20333; 24 25 /** 26 * Maps names of pricing tiers to their item ID on vistawp.com 27 * Names are used to populate the settings page dropdown 28 * If this array needs updating, there's a corresponding array named $tiers in the auto-updater code 29 * at the bottom of vista.php which will also need updating. The two arrays should be identical. 24 private const TIER = 23071; 25 26 /** 27 * Maps names of pricing tiers to their item ID in EDD on vistawp.com 28 * Names are used to populate the settings page dropdown, 29 * IDs are used to validate the license key with the API. 30 30 * @var array<string> 31 31 */ 32 32 private const TIER_ID = array( 33 "Starter" => "20333", 34 "Premium" => "20336", 35 "Premium Pro" => "20338", 36 "Enterprise" => "20340", 33 "VistaWP Monthly Subscription" => "23071", 34 "Vista Yearly Subscription" => "20670", 37 35 ); 38 36 39 37 /** 40 38 * Maps string tier names to int levels 41 * Other classes in this plugin use these levels to determine whether certain features 42 * are accessible to the user 39 * Other classes in this plugin may use these levels 40 * to determine whether certain features are accessible to the user, 41 * although tiered features currently are not implemented. 43 42 * @var array<int> 44 43 */ 45 44 private const TIER_LEVEL = array( 46 "Starter" => 1, 47 "Premium" => 2, 48 "Premium Pro" => 3, 49 "Enterprise" => 4, 45 "VistaWP Monthly Subscription" => 1, 46 "Vista Yearly Subscription" => 1, 50 47 ); 51 48 … … 98 95 $this->valid = (bool) (\get_option('vista_license_valid', NULL) ?? false); 99 96 100 V\Main::get_instance()->register_style('vsta_admin', \vista_plugin_url("/css/admin.css")); 97 V\Main::get_instance()->register_style( 98 'vsta_admin', 99 \vista_plugin_url("/css/admin.css") 100 ); 101 101 102 102 if (\is_admin()) { … … 134 134 $this->key = \sanitize_key($_POST['vsta-license-key']); 135 135 if (is_null(self::TIER)) { 136 $this->tier = \sanitize_text_field( $_POST['vsta-tier']);136 $this->tier = \sanitize_text_field($_POST['vsta-tier']); 137 137 } 138 138 139 139 // Validate with API. This outputs the result html to the page 140 140 $this->api_verify(); 141 // Only update if the license key passed validation, or if the user cleared it to get demo data 141 // Only update if the license key passed validation, 142 // or if the user cleared it to get demo data 142 143 if ($this->valid || !$this->key) { 143 144 \update_option('vista_license_key', $this->key); … … 159 160 * Validates the key with the API 160 161 * and outputs HTML to the page indicating the result. 161 * Sets $this->valid to indicate the result as well 162 * Sets $this->valid (and the corresponding WP setting) 163 * to indicate the result as well, but does not update the key 164 * or tier class vars or WP options 162 165 */ 163 166 protected function api_verify() { 164 $api = new \VSTA\API\License_API($this->key, self::TIER ?? self::TIER_ID[$this->tier]); 167 // Here we retrive the tier ID from the mapping, 168 // if a single tier is not hardcoded 169 $api = new \VSTA\API\License_API( 170 $this->key, 171 self::TIER ?? self::TIER_ID[$this->tier] 172 ); 165 173 $result = $api->activate(); 166 174 175 // API returns null for success; update options accordingly 167 176 if (is_null($result)) { 168 177 \update_option("vista_license_valid", true); 169 178 $this->valid = true; 170 179 } else { 171 ?><div class="notice notice-error">Error: <?php echo esc_html($result) ?></div><?php 180 ?> 181 <div class="notice notice-error"> 182 Error: <?php echo esc_html($result) 183 ?></div><?php 172 184 173 185 \update_option("vista_license_valid", false); … … 184 196 $licenseKey = $this->get_key(); 185 197 $licenseStatus = $licenseKey ? 'Active' : 'Disabled'; 186 187 198 ?> 188 199 … … 209 220 > 210 221 222 <?php 223 // If the tier is hardcoded, don't show the dropdown. Otherwise, 224 // this displays a dropdown to select the user's pricing tier 225 if (is_null(self::TIER)): 226 ?> 227 <br> 228 <label class="vista-license-label" for="vsta-tier">Subscription Tier</label> 229 <select name="vsta-tier" id="vsta-tier" required> 230 <?php 231 foreach (self::TIER_ID as $name => $unused) { 232 if ($name == $this->tier) { 233 echo "<option selected>" . esc_html($name) . "</option>"; 234 } else { 235 echo "<option>" . esc_html($name) . "</option>" ; 236 } 237 } 238 ?> 239 </select> 240 <?php endif; ?> 241 211 242 <input type="submit" class="vsta-btn-go" name="submit" value="Activate"> 212 243 <button class="vsta-btn-danger" id="vsta-deactivate-btn" name="deactivate" value="1">Clear</button> … … 256 287 257 288 /** 258 * Gets the level of the pricing tier of this subscription, from 0 (no license) to 4 (enterprise) 259 * Mappings from tiers to levels are found in TIER_LEVEL 289 * Gets the level of the pricing tier of this subscription. 290 * Mappings from tiers to levels are found in TIER_LEVEL. 291 * Currently unused. 260 292 * @return int Pricing tier level 261 293 */ … … 263 295 if (!$this->valid) 264 296 return 0; 265 return self::TIER ?? (is_null($this->tier) ? 0 : self::TIER_LEVEL[$this->tier]); 297 return self::TIER ?? 298 (is_null($this->tier) ? 0 : self::TIER_LEVEL[$this->tier]); 266 299 } 267 300 } -
vistawp/tags/1.2.1/readme.txt
r2964274 r2973600 5 5 Requires at least: 4.7 6 6 Tested up to: 6.3 7 Stable tag: 1.2. 07 Stable tag: 1.2.1 8 8 Requires PHP: 7.0 9 9 License: GPLv2 or later -
vistawp/tags/1.2.1/vista.php
r2964274 r2973600 3 3 * Plugin Name: VistaWP 4 4 * Description: Retrieves and displays real estate listings 5 * Version: 1.2. 05 * Version: 1.2.1 6 6 * Author: VistaWP 7 7 * Author URI: https://vistawp.com/ -
vistawp/trunk/includes/options/license-manager.php
r2961844 r2973600 18 18 * set this to NULL and use the below two constants to set up choices. 19 19 * Otherwise, if this is set to an int or string, that will be used 20 * as the pricing tier ID/product ID on vistawp 20 * as the pricing tier ID/product ID when calling the EDD API on vistawp.com 21 * 21 22 * @var string|int 22 23 */ 23 private const TIER = 20333; 24 25 /** 26 * Maps names of pricing tiers to their item ID on vistawp.com 27 * Names are used to populate the settings page dropdown 28 * If this array needs updating, there's a corresponding array named $tiers in the auto-updater code 29 * at the bottom of vista.php which will also need updating. The two arrays should be identical. 24 private const TIER = 23071; 25 26 /** 27 * Maps names of pricing tiers to their item ID in EDD on vistawp.com 28 * Names are used to populate the settings page dropdown, 29 * IDs are used to validate the license key with the API. 30 30 * @var array<string> 31 31 */ 32 32 private const TIER_ID = array( 33 "Starter" => "20333", 34 "Premium" => "20336", 35 "Premium Pro" => "20338", 36 "Enterprise" => "20340", 33 "VistaWP Monthly Subscription" => "23071", 34 "Vista Yearly Subscription" => "20670", 37 35 ); 38 36 39 37 /** 40 38 * Maps string tier names to int levels 41 * Other classes in this plugin use these levels to determine whether certain features 42 * are accessible to the user 39 * Other classes in this plugin may use these levels 40 * to determine whether certain features are accessible to the user, 41 * although tiered features currently are not implemented. 43 42 * @var array<int> 44 43 */ 45 44 private const TIER_LEVEL = array( 46 "Starter" => 1, 47 "Premium" => 2, 48 "Premium Pro" => 3, 49 "Enterprise" => 4, 45 "VistaWP Monthly Subscription" => 1, 46 "Vista Yearly Subscription" => 1, 50 47 ); 51 48 … … 98 95 $this->valid = (bool) (\get_option('vista_license_valid', NULL) ?? false); 99 96 100 V\Main::get_instance()->register_style('vsta_admin', \vista_plugin_url("/css/admin.css")); 97 V\Main::get_instance()->register_style( 98 'vsta_admin', 99 \vista_plugin_url("/css/admin.css") 100 ); 101 101 102 102 if (\is_admin()) { … … 134 134 $this->key = \sanitize_key($_POST['vsta-license-key']); 135 135 if (is_null(self::TIER)) { 136 $this->tier = \sanitize_text_field( $_POST['vsta-tier']);136 $this->tier = \sanitize_text_field($_POST['vsta-tier']); 137 137 } 138 138 139 139 // Validate with API. This outputs the result html to the page 140 140 $this->api_verify(); 141 // Only update if the license key passed validation, or if the user cleared it to get demo data 141 // Only update if the license key passed validation, 142 // or if the user cleared it to get demo data 142 143 if ($this->valid || !$this->key) { 143 144 \update_option('vista_license_key', $this->key); … … 159 160 * Validates the key with the API 160 161 * and outputs HTML to the page indicating the result. 161 * Sets $this->valid to indicate the result as well 162 * Sets $this->valid (and the corresponding WP setting) 163 * to indicate the result as well, but does not update the key 164 * or tier class vars or WP options 162 165 */ 163 166 protected function api_verify() { 164 $api = new \VSTA\API\License_API($this->key, self::TIER ?? self::TIER_ID[$this->tier]); 167 // Here we retrive the tier ID from the mapping, 168 // if a single tier is not hardcoded 169 $api = new \VSTA\API\License_API( 170 $this->key, 171 self::TIER ?? self::TIER_ID[$this->tier] 172 ); 165 173 $result = $api->activate(); 166 174 175 // API returns null for success; update options accordingly 167 176 if (is_null($result)) { 168 177 \update_option("vista_license_valid", true); 169 178 $this->valid = true; 170 179 } else { 171 ?><div class="notice notice-error">Error: <?php echo esc_html($result) ?></div><?php 180 ?> 181 <div class="notice notice-error"> 182 Error: <?php echo esc_html($result) 183 ?></div><?php 172 184 173 185 \update_option("vista_license_valid", false); … … 184 196 $licenseKey = $this->get_key(); 185 197 $licenseStatus = $licenseKey ? 'Active' : 'Disabled'; 186 187 198 ?> 188 199 … … 209 220 > 210 221 222 <?php 223 // If the tier is hardcoded, don't show the dropdown. Otherwise, 224 // this displays a dropdown to select the user's pricing tier 225 if (is_null(self::TIER)): 226 ?> 227 <br> 228 <label class="vista-license-label" for="vsta-tier">Subscription Tier</label> 229 <select name="vsta-tier" id="vsta-tier" required> 230 <?php 231 foreach (self::TIER_ID as $name => $unused) { 232 if ($name == $this->tier) { 233 echo "<option selected>" . esc_html($name) . "</option>"; 234 } else { 235 echo "<option>" . esc_html($name) . "</option>" ; 236 } 237 } 238 ?> 239 </select> 240 <?php endif; ?> 241 211 242 <input type="submit" class="vsta-btn-go" name="submit" value="Activate"> 212 243 <button class="vsta-btn-danger" id="vsta-deactivate-btn" name="deactivate" value="1">Clear</button> … … 256 287 257 288 /** 258 * Gets the level of the pricing tier of this subscription, from 0 (no license) to 4 (enterprise) 259 * Mappings from tiers to levels are found in TIER_LEVEL 289 * Gets the level of the pricing tier of this subscription. 290 * Mappings from tiers to levels are found in TIER_LEVEL. 291 * Currently unused. 260 292 * @return int Pricing tier level 261 293 */ … … 263 295 if (!$this->valid) 264 296 return 0; 265 return self::TIER ?? (is_null($this->tier) ? 0 : self::TIER_LEVEL[$this->tier]); 297 return self::TIER ?? 298 (is_null($this->tier) ? 0 : self::TIER_LEVEL[$this->tier]); 266 299 } 267 300 } -
vistawp/trunk/readme.txt
r2964274 r2973600 5 5 Requires at least: 4.7 6 6 Tested up to: 6.3 7 Stable tag: 1.2. 07 Stable tag: 1.2.1 8 8 Requires PHP: 7.0 9 9 License: GPLv2 or later -
vistawp/trunk/vista.php
r2964274 r2973600 3 3 * Plugin Name: VistaWP 4 4 * Description: Retrieves and displays real estate listings 5 * Version: 1.2. 05 * Version: 1.2.1 6 6 * Author: VistaWP 7 7 * Author URI: https://vistawp.com/
Note: See TracChangeset
for help on using the changeset viewer.