Changeset 2588630
- Timestamp:
- 08/25/2021 03:12:18 PM (5 years ago)
- Location:
- wonderpush-web-push-notifications
- Files:
-
- 22 edited
- 1 copied
-
tags/1.9.0 (copied) (copied from wonderpush-web-push-notifications/trunk)
-
tags/1.9.0/lib/Api/Applications.php (modified) (1 diff)
-
tags/1.9.0/lib/Net/Response.php (modified) (2 diffs)
-
tags/1.9.0/lib/Obj/Application.php (modified) (2 diffs)
-
tags/1.9.0/lib/Params/DeliveriesCreateParams.php (modified) (3 diffs)
-
tags/1.9.0/readme.txt (modified) (2 diffs)
-
tags/1.9.0/wonderpush-admin.php (modified) (4 diffs)
-
tags/1.9.0/wonderpush-api.php (modified) (4 diffs)
-
tags/1.9.0/wonderpush-settings.php (modified) (1 diff)
-
tags/1.9.0/wonderpush-utils.php (modified) (3 diffs)
-
tags/1.9.0/wonderpush-woocommerce.php (modified) (1 diff)
-
tags/1.9.0/wonderpush.php (modified) (1 diff)
-
trunk/lib/Api/Applications.php (modified) (1 diff)
-
trunk/lib/Net/Response.php (modified) (2 diffs)
-
trunk/lib/Obj/Application.php (modified) (2 diffs)
-
trunk/lib/Params/DeliveriesCreateParams.php (modified) (3 diffs)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/wonderpush-admin.php (modified) (4 diffs)
-
trunk/wonderpush-api.php (modified) (4 diffs)
-
trunk/wonderpush-settings.php (modified) (1 diff)
-
trunk/wonderpush-utils.php (modified) (3 diffs)
-
trunk/wonderpush-woocommerce.php (modified) (1 diff)
-
trunk/wonderpush.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
wonderpush-web-push-notifications/tags/1.9.0/lib/Api/Applications.php
r2481484 r2588630 33 33 return $response->checkedResult('\WonderPush\Obj\ApplicationCollection'); 34 34 } 35 36 public function patch($applicationId, $body = array(), $params = array()) { 37 $response = $this->wp->rest()->patch('/applications/' . $applicationId, array_merge($params, array('body' => $body))); 38 return $response->checkedResult('\WonderPush\Obj\Application', 'application'); 39 } 35 40 } -
wonderpush-web-push-notifications/tags/1.9.0/lib/Net/Response.php
r2481484 r2588630 266 266 * @throws \WonderPush\Errors\Base 267 267 */ 268 public function checkedResult($cls ) {268 public function checkedResult($cls, $key = null) { 269 269 $exception = $this->exception(); 270 270 if ($exception) { … … 273 273 $this->parseBody(); 274 274 $body = $this->parsedBody(); 275 return new $cls($ body);275 return new $cls($key ? $body->{$key} : $body); 276 276 } 277 277 -
wonderpush-web-push-notifications/tags/1.9.0/lib/Obj/Application.php
r2481484 r2588630 25 25 /** @var WebSdkInitOptions */ 26 26 private $webSdkInitOptions; 27 /** @var object */ 28 private $urlParameters; 27 29 28 30 /** … … 120 122 return $this; 121 123 } 124 125 /** 126 * @return object 127 */ 128 public function getUrlParameters() 129 { 130 return $this->urlParameters ?: (object)array(); 131 } 132 133 /** 134 * @param object $urlParameters 135 * @return Application 136 */ 137 public function setUrlParameters($urlParameters) 138 { 139 $this->urlParameters = (object)$urlParameters; 140 return $this; 141 } 122 142 } -
wonderpush-web-push-notifications/tags/1.9.0/lib/Params/DeliveriesCreateParams.php
r2481484 r2588630 24 24 private $notificationId; 25 25 private $deliveryDate; 26 /** @var bool */ 27 private $inheritUrlParameters; 26 28 27 29 /** … … 54 56 'notificationId' => $this->notificationId, 55 57 'deliveryDate' => $this->deliveryDate ? $this->deliveryDate : null, 58 'inheritUrlParameters' => (bool)$this->inheritUrlParameters, 56 59 )); 57 60 } … … 199 202 return $this; 200 203 } 204 205 /** 206 * @return bool 207 */ 208 public function getInheritUrlParameters() { 209 return $this->inheritUrlParameters; 210 } 211 212 /** 213 * @param bool $inheritUrlParameters 214 * @return DeliveriesCreateParams 215 */ 216 public function setInheritUrlParameters($inheritUrlParameters) { 217 $this->inheritUrlParameters = $inheritUrlParameters; 218 return $this; 219 } 201 220 } -
wonderpush-web-push-notifications/tags/1.9.0/readme.txt
r2584905 r2588630 5 5 Requires at least: 5.0 6 6 Tested up to: 5.8 7 Stable tag: 1. 8.07 Stable tag: 1.9.0 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 90 90 91 91 == Changelog == 92 = 1.9.0 = 93 - Manage UTM parameters to automatically add to all your push notifications 94 92 95 = 1.8.0 = 93 96 - Allow selecting a segment from the WordPress editor, and a default segment from the WonderPush blogging settings -
wonderpush-web-push-notifications/tags/1.9.0/wonderpush-admin.php
r2584905 r2588630 3 3 4 4 class WonderPushAdmin { 5 const RESOURCES_VERSION = '1. 8.0';5 const RESOURCES_VERSION = '1.9.0'; 6 6 const MENU_SLUG = 'wonderpush'; 7 7 const META_BOX_ID = 'wonderpush_meta_box'; … … 58 58 $settings = WonderPushSettings::getSettings(); 59 59 $access_token = $settings->getAccessToken(); 60 $app = $access_token ? WonderPushUtils::application_from_access_token($access_token) : null; 60 61 61 62 // Add an nonce field so we can check for it later. … … 82 83 // UTM params 83 84 $utm_params = array(); 85 $url_parameters = $app ? (array)$app->getUrlParameters() : array(); 84 86 foreach (WonderPushUtils::utm_parameters() as $utm_parameter) { 85 87 $value = get_post_meta($post->ID, "wonderpush_$utm_parameter", true); 86 $value = $value ?: $settings->getUtmParameter($utm_parameter);88 $value = $value ?: array_key_exists($utm_parameter, $url_parameters) ? $url_parameters[$utm_parameter] : null; 87 89 $utm_params[$utm_parameter] = $value; 88 90 } … … 432 434 if ($large_image) $web->setImage($large_image); 433 435 $params = new \WonderPush\Params\DeliveriesCreateParams(); 436 $params->setInheritUrlParameters(true); 434 437 $params->setNotification($notification); 435 438 $params->setTargetSegmentIds($segmentId); -
wonderpush-web-push-notifications/tags/1.9.0/wonderpush-api.php
r2584905 r2588630 70 70 $app = WonderPushUtils::application_from_access_token($access_token); 71 71 } 72 $urlParameters = $app ? (object)array_merge($settings->getUtmParameters(), (array)$app->getUrlParameters()) : (object)array(); 72 73 self::returnResult((object)array( 73 74 'accessToken' => $access_token ? $access_token : null, … … 101 102 'ampButtonWidth' => (int)$settings->getAmpButtonWidth(), 102 103 'ampButtonHeight' => (int)$settings->getAmpButtonHeight(), 103 'utmSource' => $settings->getUtmSource(),104 'utmCampaign' => $settings->getUtmCampaign(),105 'utmMedium' => $settings->getUtmMedium(),106 'utmTerm' => $settings->getUtmTerm(),107 'utmContent' => $settings->getUtmContent(),104 'utmSource' => property_exists($urlParameters, 'utm_source') ? $urlParameters->utm_source : null, 105 'utmCampaign' => property_exists($urlParameters, 'utm_campaign') ? $urlParameters->utm_campaign : null, 106 'utmMedium' => property_exists($urlParameters, 'utm_medium') ? $urlParameters->utm_medium : null, 107 'utmTerm' => property_exists($urlParameters, 'utm_term') ? $urlParameters->utm_term : null, 108 'utmContent' => property_exists($urlParameters, 'utm_content') ? $urlParameters->utm_content : null, 108 109 'additionalInitOptionsJson' => $settings->getAdditionalInitOptionsJson(), 109 110 … … 250 251 251 252 // utm parameters 253 $urlParameters = $settings->getUtmParameters(); // They are deprecated 252 254 foreach (array('Source', 'Medium', 'Campaign', 'Term', 'Content') as $utm) { 253 255 $key = "utm$utm"; … … 262 264 $value = $value && strlen($value) ? $value : null; 263 265 264 $settings->setUtmParameter($utm, $value); 265 $save = true; 266 } 267 } 266 $urlParameters["utm_" . lcfirst($utm)] = $value; 267 } 268 } 269 WonderPushUtils::patch_application_url_parameters($settings->getAccessToken(), $urlParameters); 270 $settings->clearUtmParameters(); // They are deprecated 271 268 272 // Additional init options 269 273 if (array_key_exists('additionalInitOptionsJson', $_POST)) { -
wonderpush-web-push-notifications/tags/1.9.0/wonderpush-settings.php
r2584905 r2588630 264 264 } 265 265 266 /** 267 * @deprecated Use Application::getUrlParameters instead 268 */ 266 269 public function getUtmParameters() { 267 270 $utm_params = array(); 268 271 foreach (WonderPushUtils::utm_parameters() as $utm_parameter) { 269 $utm_params[$utm_parameter] = $this->getUtmParameter($utm_parameter); 272 $parameter = str_replace('utm_', '', $utm_parameter); 273 $parameter = "utm" . ucfirst($parameter); 274 $utm_params[$utm_parameter] = $this->get($parameter); 270 275 } 271 276 return $utm_params; 272 277 } 273 278 274 public function getUtmParameter($parameter) { 275 $parameter = str_replace('utm_', '', $parameter); 276 $parameter = ucfirst($parameter); 277 return $this->{"getUtm$parameter"}(); 278 } 279 public function setUtmParameter($parameter, $value) { 280 $parameter = str_replace('utm_', '', $parameter); 281 $parameter = ucfirst($parameter); 282 return $this->{"setUtm$parameter"}($value); 283 } 284 public function getUtmSource() { 285 return $this->get('utmSource'); 286 } 287 288 public function setUtmSource($value) { 289 $this->set('utmSource', $value); 290 return $this; 291 } 292 293 public function getUtmMedium() { 294 return $this->get('utmMedium'); 295 } 296 297 public function setUtmMedium($value) { 298 $this->set('utmMedium', $value); 299 return $this; 300 } 301 302 public function getUtmCampaign() { 303 return $this->get('utmCampaign'); 304 } 305 306 public function setUtmCampaign($value) { 307 $this->set('utmCampaign', $value); 308 return $this; 309 } 310 311 public function getUtmTerm() { 312 return $this->get('utmTerm'); 313 } 314 315 public function setUtmTerm($value) { 316 $this->set('utmTerm', $value); 317 return $this; 318 } 319 320 public function getUtmContent() { 321 return $this->get('utmContent'); 322 } 323 324 public function setUtmContent($value) { 325 $this->set('utmContent', $value); 326 return $this; 279 public function clearUtmParameters() { 280 foreach (WonderPushUtils::utm_parameters() as $utm_parameter) { 281 $parameter = str_replace('utm_', '', $utm_parameter); 282 $parameter = "utm" . ucfirst($parameter); 283 $this->set($parameter, null); 284 } 327 285 } 328 286 -
wonderpush-web-push-notifications/tags/1.9.0/wonderpush-utils.php
r2584905 r2588630 3 3 4 4 class WonderPushUtils { 5 const DEFAULT_CACHE_TTL = 300; 5 6 public static function is_wonderpush_installed() { 6 7 $settings = WonderPushSettings::getSettings(); … … 73 74 74 75 } 75 /** 76 77 /** 78 * @param string $access_token 79 * @param array $url_parameters 80 * @throws Exception 81 */ 82 public static function patch_application_url_parameters($access_token, $url_parameters) { 83 if (!$access_token) return; 84 $app = WonderPushUtils::application_from_access_token($access_token, 300, true); 85 if (!$app) return; 86 $merged_url_parameters = $app ? (array)$app->getUrlParameters() : array(); 87 $urlParametersUpdated = false; 88 foreach ($url_parameters as $utm => $value) { 89 if ($value && (!array_key_exists($utm, $merged_url_parameters) || $merged_url_parameters[$utm] !== $value)) { 90 $merged_url_parameters[$utm] = $value; 91 $urlParametersUpdated = true; 92 } else if (!$value && array_key_exists($utm, $merged_url_parameters) && $merged_url_parameters[$utm]) { 93 $merged_url_parameters[$utm] = null; 94 $urlParametersUpdated = true; 95 } 96 } 97 if ($urlParametersUpdated) { 98 error_log('$merged_url_parameters: ' . print_r($merged_url_parameters, true)); 99 $wp = new WonderPush\WonderPush($access_token); 100 $updatedApp = $wp->applications()->patch($app->getId(), array('urlParameters' => (object)$merged_url_parameters)); 101 $cache_key = "WonderPush:Application:" . $access_token; 102 set_transient($cache_key, $updatedApp, self::DEFAULT_CACHE_TTL); 103 } 104 } 105 /** 76 106 * Returns the first application associated with the provided access token, 77 107 * or false if the access token is not valid. … … 83 113 * @return false|\WonderPush\Obj\Application 84 114 */ 85 public static function application_from_access_token($access_token, $expiration = 300) {115 public static function application_from_access_token($access_token, $expiration = self::DEFAULT_CACHE_TTL, $forceFetch = false) { 86 116 // Cached value ? 87 117 $cache_key = "WonderPush:Application:" . $access_token; 88 $cached = get_transient($cache_key);118 $cached = $forceFetch ? null : get_transient($cache_key); 89 119 if ($cached) { 90 120 return $cached; -
wonderpush-web-push-notifications/tags/1.9.0/wonderpush-woocommerce.php
r2481484 r2588630 159 159 if ($product_image_url) $web->setImage($product_image_url); 160 160 $params = new \WonderPush\Params\DeliveriesCreateParams(); 161 $params->setInheritUrlParameters(true); 161 162 $params->setNotification($notification); 162 163 $params->setTargetUserIds(strval($customer_id)); -
wonderpush-web-push-notifications/tags/1.9.0/wonderpush.php
r2584905 r2588630 8 8 Author: WonderPush 9 9 Author URI: https://www.wonderpush.com/ 10 Version: 1. 8.010 Version: 1.9.0 11 11 License: GPLv2 or later 12 12 */ -
wonderpush-web-push-notifications/trunk/lib/Api/Applications.php
r2481484 r2588630 33 33 return $response->checkedResult('\WonderPush\Obj\ApplicationCollection'); 34 34 } 35 36 public function patch($applicationId, $body = array(), $params = array()) { 37 $response = $this->wp->rest()->patch('/applications/' . $applicationId, array_merge($params, array('body' => $body))); 38 return $response->checkedResult('\WonderPush\Obj\Application', 'application'); 39 } 35 40 } -
wonderpush-web-push-notifications/trunk/lib/Net/Response.php
r2481484 r2588630 266 266 * @throws \WonderPush\Errors\Base 267 267 */ 268 public function checkedResult($cls ) {268 public function checkedResult($cls, $key = null) { 269 269 $exception = $this->exception(); 270 270 if ($exception) { … … 273 273 $this->parseBody(); 274 274 $body = $this->parsedBody(); 275 return new $cls($ body);275 return new $cls($key ? $body->{$key} : $body); 276 276 } 277 277 -
wonderpush-web-push-notifications/trunk/lib/Obj/Application.php
r2481484 r2588630 25 25 /** @var WebSdkInitOptions */ 26 26 private $webSdkInitOptions; 27 /** @var object */ 28 private $urlParameters; 27 29 28 30 /** … … 120 122 return $this; 121 123 } 124 125 /** 126 * @return object 127 */ 128 public function getUrlParameters() 129 { 130 return $this->urlParameters ?: (object)array(); 131 } 132 133 /** 134 * @param object $urlParameters 135 * @return Application 136 */ 137 public function setUrlParameters($urlParameters) 138 { 139 $this->urlParameters = (object)$urlParameters; 140 return $this; 141 } 122 142 } -
wonderpush-web-push-notifications/trunk/lib/Params/DeliveriesCreateParams.php
r2481484 r2588630 24 24 private $notificationId; 25 25 private $deliveryDate; 26 /** @var bool */ 27 private $inheritUrlParameters; 26 28 27 29 /** … … 54 56 'notificationId' => $this->notificationId, 55 57 'deliveryDate' => $this->deliveryDate ? $this->deliveryDate : null, 58 'inheritUrlParameters' => (bool)$this->inheritUrlParameters, 56 59 )); 57 60 } … … 199 202 return $this; 200 203 } 204 205 /** 206 * @return bool 207 */ 208 public function getInheritUrlParameters() { 209 return $this->inheritUrlParameters; 210 } 211 212 /** 213 * @param bool $inheritUrlParameters 214 * @return DeliveriesCreateParams 215 */ 216 public function setInheritUrlParameters($inheritUrlParameters) { 217 $this->inheritUrlParameters = $inheritUrlParameters; 218 return $this; 219 } 201 220 } -
wonderpush-web-push-notifications/trunk/readme.txt
r2584905 r2588630 5 5 Requires at least: 5.0 6 6 Tested up to: 5.8 7 Stable tag: 1. 8.07 Stable tag: 1.9.0 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 90 90 91 91 == Changelog == 92 = 1.9.0 = 93 - Manage UTM parameters to automatically add to all your push notifications 94 92 95 = 1.8.0 = 93 96 - Allow selecting a segment from the WordPress editor, and a default segment from the WonderPush blogging settings -
wonderpush-web-push-notifications/trunk/wonderpush-admin.php
r2584905 r2588630 3 3 4 4 class WonderPushAdmin { 5 const RESOURCES_VERSION = '1. 8.0';5 const RESOURCES_VERSION = '1.9.0'; 6 6 const MENU_SLUG = 'wonderpush'; 7 7 const META_BOX_ID = 'wonderpush_meta_box'; … … 58 58 $settings = WonderPushSettings::getSettings(); 59 59 $access_token = $settings->getAccessToken(); 60 $app = $access_token ? WonderPushUtils::application_from_access_token($access_token) : null; 60 61 61 62 // Add an nonce field so we can check for it later. … … 82 83 // UTM params 83 84 $utm_params = array(); 85 $url_parameters = $app ? (array)$app->getUrlParameters() : array(); 84 86 foreach (WonderPushUtils::utm_parameters() as $utm_parameter) { 85 87 $value = get_post_meta($post->ID, "wonderpush_$utm_parameter", true); 86 $value = $value ?: $settings->getUtmParameter($utm_parameter);88 $value = $value ?: array_key_exists($utm_parameter, $url_parameters) ? $url_parameters[$utm_parameter] : null; 87 89 $utm_params[$utm_parameter] = $value; 88 90 } … … 432 434 if ($large_image) $web->setImage($large_image); 433 435 $params = new \WonderPush\Params\DeliveriesCreateParams(); 436 $params->setInheritUrlParameters(true); 434 437 $params->setNotification($notification); 435 438 $params->setTargetSegmentIds($segmentId); -
wonderpush-web-push-notifications/trunk/wonderpush-api.php
r2584905 r2588630 70 70 $app = WonderPushUtils::application_from_access_token($access_token); 71 71 } 72 $urlParameters = $app ? (object)array_merge($settings->getUtmParameters(), (array)$app->getUrlParameters()) : (object)array(); 72 73 self::returnResult((object)array( 73 74 'accessToken' => $access_token ? $access_token : null, … … 101 102 'ampButtonWidth' => (int)$settings->getAmpButtonWidth(), 102 103 'ampButtonHeight' => (int)$settings->getAmpButtonHeight(), 103 'utmSource' => $settings->getUtmSource(),104 'utmCampaign' => $settings->getUtmCampaign(),105 'utmMedium' => $settings->getUtmMedium(),106 'utmTerm' => $settings->getUtmTerm(),107 'utmContent' => $settings->getUtmContent(),104 'utmSource' => property_exists($urlParameters, 'utm_source') ? $urlParameters->utm_source : null, 105 'utmCampaign' => property_exists($urlParameters, 'utm_campaign') ? $urlParameters->utm_campaign : null, 106 'utmMedium' => property_exists($urlParameters, 'utm_medium') ? $urlParameters->utm_medium : null, 107 'utmTerm' => property_exists($urlParameters, 'utm_term') ? $urlParameters->utm_term : null, 108 'utmContent' => property_exists($urlParameters, 'utm_content') ? $urlParameters->utm_content : null, 108 109 'additionalInitOptionsJson' => $settings->getAdditionalInitOptionsJson(), 109 110 … … 250 251 251 252 // utm parameters 253 $urlParameters = $settings->getUtmParameters(); // They are deprecated 252 254 foreach (array('Source', 'Medium', 'Campaign', 'Term', 'Content') as $utm) { 253 255 $key = "utm$utm"; … … 262 264 $value = $value && strlen($value) ? $value : null; 263 265 264 $settings->setUtmParameter($utm, $value); 265 $save = true; 266 } 267 } 266 $urlParameters["utm_" . lcfirst($utm)] = $value; 267 } 268 } 269 WonderPushUtils::patch_application_url_parameters($settings->getAccessToken(), $urlParameters); 270 $settings->clearUtmParameters(); // They are deprecated 271 268 272 // Additional init options 269 273 if (array_key_exists('additionalInitOptionsJson', $_POST)) { -
wonderpush-web-push-notifications/trunk/wonderpush-settings.php
r2584905 r2588630 264 264 } 265 265 266 /** 267 * @deprecated Use Application::getUrlParameters instead 268 */ 266 269 public function getUtmParameters() { 267 270 $utm_params = array(); 268 271 foreach (WonderPushUtils::utm_parameters() as $utm_parameter) { 269 $utm_params[$utm_parameter] = $this->getUtmParameter($utm_parameter); 272 $parameter = str_replace('utm_', '', $utm_parameter); 273 $parameter = "utm" . ucfirst($parameter); 274 $utm_params[$utm_parameter] = $this->get($parameter); 270 275 } 271 276 return $utm_params; 272 277 } 273 278 274 public function getUtmParameter($parameter) { 275 $parameter = str_replace('utm_', '', $parameter); 276 $parameter = ucfirst($parameter); 277 return $this->{"getUtm$parameter"}(); 278 } 279 public function setUtmParameter($parameter, $value) { 280 $parameter = str_replace('utm_', '', $parameter); 281 $parameter = ucfirst($parameter); 282 return $this->{"setUtm$parameter"}($value); 283 } 284 public function getUtmSource() { 285 return $this->get('utmSource'); 286 } 287 288 public function setUtmSource($value) { 289 $this->set('utmSource', $value); 290 return $this; 291 } 292 293 public function getUtmMedium() { 294 return $this->get('utmMedium'); 295 } 296 297 public function setUtmMedium($value) { 298 $this->set('utmMedium', $value); 299 return $this; 300 } 301 302 public function getUtmCampaign() { 303 return $this->get('utmCampaign'); 304 } 305 306 public function setUtmCampaign($value) { 307 $this->set('utmCampaign', $value); 308 return $this; 309 } 310 311 public function getUtmTerm() { 312 return $this->get('utmTerm'); 313 } 314 315 public function setUtmTerm($value) { 316 $this->set('utmTerm', $value); 317 return $this; 318 } 319 320 public function getUtmContent() { 321 return $this->get('utmContent'); 322 } 323 324 public function setUtmContent($value) { 325 $this->set('utmContent', $value); 326 return $this; 279 public function clearUtmParameters() { 280 foreach (WonderPushUtils::utm_parameters() as $utm_parameter) { 281 $parameter = str_replace('utm_', '', $utm_parameter); 282 $parameter = "utm" . ucfirst($parameter); 283 $this->set($parameter, null); 284 } 327 285 } 328 286 -
wonderpush-web-push-notifications/trunk/wonderpush-utils.php
r2584905 r2588630 3 3 4 4 class WonderPushUtils { 5 const DEFAULT_CACHE_TTL = 300; 5 6 public static function is_wonderpush_installed() { 6 7 $settings = WonderPushSettings::getSettings(); … … 73 74 74 75 } 75 /** 76 77 /** 78 * @param string $access_token 79 * @param array $url_parameters 80 * @throws Exception 81 */ 82 public static function patch_application_url_parameters($access_token, $url_parameters) { 83 if (!$access_token) return; 84 $app = WonderPushUtils::application_from_access_token($access_token, 300, true); 85 if (!$app) return; 86 $merged_url_parameters = $app ? (array)$app->getUrlParameters() : array(); 87 $urlParametersUpdated = false; 88 foreach ($url_parameters as $utm => $value) { 89 if ($value && (!array_key_exists($utm, $merged_url_parameters) || $merged_url_parameters[$utm] !== $value)) { 90 $merged_url_parameters[$utm] = $value; 91 $urlParametersUpdated = true; 92 } else if (!$value && array_key_exists($utm, $merged_url_parameters) && $merged_url_parameters[$utm]) { 93 $merged_url_parameters[$utm] = null; 94 $urlParametersUpdated = true; 95 } 96 } 97 if ($urlParametersUpdated) { 98 error_log('$merged_url_parameters: ' . print_r($merged_url_parameters, true)); 99 $wp = new WonderPush\WonderPush($access_token); 100 $updatedApp = $wp->applications()->patch($app->getId(), array('urlParameters' => (object)$merged_url_parameters)); 101 $cache_key = "WonderPush:Application:" . $access_token; 102 set_transient($cache_key, $updatedApp, self::DEFAULT_CACHE_TTL); 103 } 104 } 105 /** 76 106 * Returns the first application associated with the provided access token, 77 107 * or false if the access token is not valid. … … 83 113 * @return false|\WonderPush\Obj\Application 84 114 */ 85 public static function application_from_access_token($access_token, $expiration = 300) {115 public static function application_from_access_token($access_token, $expiration = self::DEFAULT_CACHE_TTL, $forceFetch = false) { 86 116 // Cached value ? 87 117 $cache_key = "WonderPush:Application:" . $access_token; 88 $cached = get_transient($cache_key);118 $cached = $forceFetch ? null : get_transient($cache_key); 89 119 if ($cached) { 90 120 return $cached; -
wonderpush-web-push-notifications/trunk/wonderpush-woocommerce.php
r2481484 r2588630 159 159 if ($product_image_url) $web->setImage($product_image_url); 160 160 $params = new \WonderPush\Params\DeliveriesCreateParams(); 161 $params->setInheritUrlParameters(true); 161 162 $params->setNotification($notification); 162 163 $params->setTargetUserIds(strval($customer_id)); -
wonderpush-web-push-notifications/trunk/wonderpush.php
r2584905 r2588630 8 8 Author: WonderPush 9 9 Author URI: https://www.wonderpush.com/ 10 Version: 1. 8.010 Version: 1.9.0 11 11 License: GPLv2 or later 12 12 */
Note: See TracChangeset
for help on using the changeset viewer.