| @@ -2,119 +2,29 @@ | ||
| 2 | 2 | if ( ! defined( 'ABSPATH' ) ) { |
| 3 | 3 | die( 'You are not allowed to call this page directly.' ); |
| 4 | 4 | } |
| 5 | 5 | |
| 6 | -/** @phpstan-consistent-constructor */ | |
| 7 | 6 | class FrmAddon { |
| 8 | - | |
| 9 | - /** | |
| 10 | - * @var string | |
| 11 | - */ | |
| 12 | 7 | public $store_url = 'https://formidableforms.com'; |
| 13 | - | |
| 14 | - /** | |
| 15 | - * @var int|string|null | |
| 16 | - */ | |
| 17 | 8 | public $download_id; |
| 18 | - | |
| 19 | - /** | |
| 20 | - * @var string|null | |
| 21 | - */ | |
| 22 | 9 | public $plugin_file; |
| 23 | - | |
| 24 | - /** | |
| 25 | - * @var string | |
| 26 | - */ | |
| 27 | 10 | public $plugin_folder; |
| 28 | - | |
| 29 | - /** | |
| 30 | - * @var string | |
| 31 | - */ | |
| 32 | 11 | public $plugin_name; |
| 33 | - | |
| 34 | - /** | |
| 35 | - * @var string | |
| 36 | - */ | |
| 37 | 12 | public $plugin_slug; |
| 38 | - | |
| 39 | - /** | |
| 40 | - * @var string | |
| 41 | - */ | |
| 42 | 13 | public $option_name; |
| 43 | - | |
| 44 | - /** | |
| 45 | - * @var string|null | |
| 46 | - */ | |
| 47 | 14 | public $version; |
| 48 | - | |
| 49 | - /** | |
| 50 | - * @var string | |
| 51 | - */ | |
| 52 | 15 | public $author = 'Strategy11'; |
| 53 | - | |
| 54 | - /** | |
| 55 | - * @var bool | |
| 56 | - */ | |
| 57 | 16 | public $is_parent_licence = false; |
| 58 | - | |
| 59 | - /** | |
| 60 | - * @var bool | |
| 61 | - */ | |
| 62 | 17 | public $needs_license = true; |
| 63 | - | |
| 64 | - /** | |
| 65 | - * @var bool | |
| 66 | - */ | |
| 67 | 18 | private $is_expired_addon = false; |
| 68 | - | |
| 69 | - /** | |
| 70 | - * @var string|null | |
| 71 | - */ | |
| 72 | 19 | public $license; |
| 73 | - | |
| 74 | - /** | |
| 75 | - * @var bool | |
| 76 | - */ | |
| 77 | 20 | protected $get_beta = false; |
| 78 | 21 | |
| 79 | - /** | |
| 80 | - * @var array|null | |
| 81 | - */ | |
| 82 | - protected $save_status; | |
| 83 | - | |
| 84 | - /** | |
| 85 | - * This is used to decide whether the license checks should continue. | |
| 86 | - * The point is to avoid license issues when a site url changes. | |
| 87 | - * | |
| 88 | - * @since 6.8.3 | |
| 89 | - * | |
| 90 | - * @var array | |
| 91 | - */ | |
| 92 | - private $save_response = array(); | |
| 93 | - | |
| 94 | - /** | |
| 95 | - * This is used to flag other add ons not to send a request. | |
| 96 | - * We only want to send a single API request per page load. | |
| 97 | - * | |
| 98 | - * @since 6.8.3 | |
| 99 | - * | |
| 100 | - * @var string | |
| 101 | - */ | |
| 102 | - private $transient_lock_key = 'frm_activate_request_lock'; | |
| 103 | - | |
| 104 | - /** | |
| 105 | - * @since 6.8.3 | |
| 106 | - * | |
| 107 | - * @var bool | |
| 108 | - */ | |
| 109 | - protected $should_clear_cache = true; | |
| 110 | - | |
| 111 | 22 | public function __construct() { |
| 112 | 23 | |
| 113 | 24 | if ( empty( $this->plugin_slug ) ) { |
| 114 | 25 | $this->plugin_slug = preg_replace( '/[^a-zA-Z0-9_\s]/', '', str_replace( ' ', '_', strtolower( $this->plugin_name ) ) ); |
| 115 | 26 | } |
| 116 | - | |
| 117 | 27 | if ( empty( $this->option_name ) ) { |
| 118 | 28 | $this->option_name = 'edd_' . $this->plugin_slug . '_license_'; |
| 119 | 29 | } |
| 120 | 30 | |
| @@ -124,21 +34,13 @@ | ||
| 124 | 34 | add_filter( 'frm_installed_addons', array( &$this, 'insert_installed_addon' ) ); |
| 125 | 35 | $this->edd_plugin_updater(); |
| 126 | 36 | } |
| 127 | 37 | |
| 128 | - /** | |
| 129 | - * @return void | |
| 130 | - */ | |
| 131 | 38 | public static function load_hooks() { |
| 132 | 39 | add_filter( 'frm_include_addon_page', '__return_true' ); |
| 133 | - new static(); | |
| 40 | + //new static(); | |
| 134 | 41 | } |
| 135 | 42 | |
| 136 | - /** | |
| 137 | - * @param array $plugins | |
| 138 | - * | |
| 139 | - * @return array | |
| 140 | - */ | |
| 141 | 43 | public function insert_installed_addon( $plugins ) { |
| 142 | 44 | $plugins[ $this->plugin_slug ] = $this; |
| 143 | 45 | |
| 144 | 46 | return $plugins; |
| @@ -143,17 +45,11 @@ | ||
| 143 | 45 | |
| 144 | 46 | return $plugins; |
| 145 | 47 | } |
| 146 | 48 | |
| 147 | - /** | |
| 148 | - * @param string $plugin_slug | |
| 149 | - * | |
| 150 | - * @return false|FrmAddon | |
| 151 | - */ | |
| 152 | 49 | public static function get_addon( $plugin_slug ) { |
| 153 | 50 | $plugins = apply_filters( 'frm_installed_addons', array() ); |
| 154 | 51 | $plugin = false; |
| 155 | - | |
| 156 | 52 | if ( isset( $plugins[ $plugin_slug ] ) ) { |
| 157 | 53 | $plugin = $plugins[ $plugin_slug ]; |
| 158 | 54 | } |
| 159 | 55 | |
| @@ -159,11 +55,8 @@ | ||
| 159 | 55 | |
| 160 | 56 | return $plugin; |
| 161 | 57 | } |
| 162 | 58 | |
| 163 | - /** | |
| 164 | - * @return void | |
| 165 | - */ | |
| 166 | 59 | public function edd_plugin_updater() { |
| 167 | 60 | |
| 168 | 61 | $this->is_license_revoked(); |
| 169 | 62 | $license = $this->license; |
| @@ -180,13 +73,13 @@ | ||
| 180 | 73 | } |
| 181 | 74 | } |
| 182 | 75 | |
| 183 | 76 | /** |
| 184 | - * Updates information on the "View version 6.15 details" page with custom data. | |
| 77 | + * Updates information on the "View version x.x details" page with custom data. | |
| 185 | 78 | * |
| 186 | 79 | * @uses api_request() |
| 187 | 80 | * |
| 188 | - * @param mixed $_data | |
| 81 | + * @param mixed $_data | |
| 189 | 82 | * @param string $_action |
| 190 | 83 | * @param object $_args |
| 191 | 84 | * |
| 192 | 85 | * @return object $_data |
| @@ -196,17 +89,14 @@ | ||
| 196 | 89 | if ( $_action != 'plugin_information' ) { |
| 197 | 90 | return $_data; |
| 198 | 91 | } |
| 199 | 92 | |
| 200 | - $slug = basename( $this->plugin_file, '.php' ); | |
| 201 | - $slug2 = str_replace( '/' . $slug . '.php', '', $this->plugin_folder ); | |
| 202 | - | |
| 203 | - if ( empty( $_args->slug ) || ( $_args->slug != $slug && $_args->slug !== $slug2 ) ) { | |
| 93 | + $slug = basename( $this->plugin_file, '.php' ); | |
| 94 | + if ( ! isset( $_args->slug ) || $_args->slug != $slug ) { | |
| 204 | 95 | return $_data; |
| 205 | 96 | } |
| 206 | 97 | |
| 207 | 98 | $item_id = $this->download_id; |
| 208 | - | |
| 209 | 99 | if ( empty( $item_id ) ) { |
| 210 | 100 | $_data = array( |
| 211 | 101 | 'name' => $this->plugin_name, |
| 212 | 102 | 'excerpt' => '', |
| @@ -231,20 +121,15 @@ | ||
| 231 | 121 | |
| 232 | 122 | return (object) $_data; |
| 233 | 123 | } |
| 234 | 124 | |
| 235 | - /** | |
| 236 | - * @return string | |
| 237 | - */ | |
| 238 | 125 | public function get_license() { |
| 239 | 126 | $license = $this->maybe_get_pro_license(); |
| 240 | - | |
| 241 | 127 | if ( ! empty( $license ) ) { |
| 242 | 128 | return $license; |
| 243 | 129 | } |
| 244 | 130 | |
| 245 | 131 | $license = trim( get_option( $this->option_name . 'key' ) ); |
| 246 | - | |
| 247 | 132 | if ( empty( $license ) ) { |
| 248 | 133 | $license = $this->activate_defined_license(); |
| 249 | 134 | } |
| 250 | 135 | |
| @@ -252,10 +137,8 @@ | ||
| 252 | 137 | } |
| 253 | 138 | |
| 254 | 139 | /** |
| 255 | 140 | * @since 3.04.03 |
| 256 | - * | |
| 257 | - * @return false|string | |
| 258 | 141 | */ |
| 259 | 142 | protected function maybe_get_pro_license() { |
| 260 | 143 | // prevent a loop if $this is the pro plugin |
| 261 | 144 | $get_license = FrmAppHelper::pro_is_installed() && is_callable( 'FrmProAppHelper::get_updater' ) && $this->plugin_name != 'Formidable Pro'; |
| @@ -266,15 +149,13 @@ | ||
| 266 | 149 | |
| 267 | 150 | $api = new FrmFormApi(); |
| 268 | 151 | $api->get_pro_updater(); |
| 269 | 152 | $license = $api->get_license(); |
| 270 | - | |
| 271 | 153 | if ( empty( $license ) ) { |
| 272 | 154 | return false; |
| 273 | 155 | } |
| 274 | 156 | |
| 275 | 157 | $this->get_api_info( $license ); |
| 276 | - | |
| 277 | 158 | if ( ! $this->is_parent_licence ) { |
| 278 | 159 | $license = false; |
| 279 | 160 | } |
| 280 | 161 | |
| @@ -284,17 +165,14 @@ | ||
| 284 | 165 | /** |
| 285 | 166 | * Activate the license in wp-config.php |
| 286 | 167 | * |
| 287 | 168 | * @since 2.04 |
| 288 | - * | |
| 289 | - * @return string | |
| 290 | 169 | */ |
| 291 | 170 | public function activate_defined_license() { |
| 292 | 171 | $license = $this->get_defined_license(); |
| 293 | - | |
| 294 | - if ( ! empty( $license ) && ! $this->is_active() && ! $this->checked_recently( '1 day' ) ) { | |
| 172 | + if ( ! empty( $license ) && ! $this->is_active() && $this->is_time_to_auto_activate() ) { | |
| 295 | 173 | $response = $this->activate_license( $license ); |
| 296 | - | |
| 174 | + $this->set_auto_activate_time(); | |
| 297 | 175 | if ( ! $response['success'] ) { |
| 298 | 176 | $license = ''; |
| 299 | 177 | } |
| 300 | 178 | } |
| @@ -305,29 +183,35 @@ | ||
| 305 | 183 | /** |
| 306 | 184 | * Check the wp-config.php for the license key |
| 307 | 185 | * |
| 308 | 186 | * @since 2.04 |
| 309 | - * | |
| 310 | - * @return false|string | |
| 311 | 187 | */ |
| 312 | 188 | public function get_defined_license() { |
| 313 | - $constant_name = 'FRM_' . strtoupper( $this->plugin_slug ) . '_LICENSE'; | |
| 189 | + $consant_name = 'FRM_' . strtoupper( $this->plugin_slug ) . '_LICENSE'; | |
| 314 | 190 | |
| 315 | - return defined( $constant_name ) ? constant( $constant_name ) : false; | |
| 191 | + return defined( $consant_name ) ? constant( $consant_name ) : false; | |
| 316 | 192 | } |
| 317 | 193 | |
| 318 | - /** | |
| 319 | - * @param string $license | |
| 320 | - * | |
| 321 | - * @return void | |
| 322 | - */ | |
| 323 | 194 | public function set_license( $license ) { |
| 324 | 195 | update_option( $this->option_name . 'key', $license ); |
| 325 | 196 | } |
| 326 | 197 | |
| 327 | 198 | /** |
| 328 | - * @return mixed | |
| 199 | + * If the license is in the config, limit the frequency of checks. | |
| 200 | + * The license may be entered incorrectly, so we don't want to check on every page load. | |
| 201 | + * | |
| 202 | + * @since 2.04 | |
| 329 | 203 | */ |
| 204 | + private function is_time_to_auto_activate() { | |
| 205 | + $last_try = get_option( $this->option_name . 'last_activate' ); | |
| 206 | + | |
| 207 | + return ( ! $last_try || $last_try < strtotime( '-1 day' ) ); | |
| 208 | + } | |
| 209 | + | |
| 210 | + private function set_auto_activate_time() { | |
| 211 | + update_option( $this->option_name . 'last_activate', time() ); | |
| 212 | + } | |
| 213 | + | |
| 330 | 214 | public function is_active() { |
| 331 | 215 | return get_option( $this->option_name . 'active' ); |
| 332 | 216 | } |
| 333 | 217 | |
| @@ -333,63 +217,26 @@ | ||
| 333 | 217 | |
| 334 | 218 | /** |
| 335 | 219 | * @since 3.04.03 |
| 336 | 220 | * |
| 337 | - * @param array|string $error | |
| 338 | - * | |
| 339 | - * @return void | |
| 221 | + * @param array error | |
| 340 | 222 | */ |
| 341 | 223 | public function maybe_clear_license( $error ) { |
| 342 | - if ( is_array( $error ) && $error['code'] === 'disabled' && $error['license'] === $this->license ) { | |
| 224 | + if ( $error['code'] === 'disabled' && $error['license'] === $this->license ) { | |
| 343 | 225 | $this->clear_license(); |
| 344 | 226 | } |
| 345 | 227 | } |
| 346 | 228 | |
| 347 | - /** | |
| 348 | - * @return void | |
| 349 | - */ | |
| 350 | 229 | public function clear_license() { |
| 351 | 230 | delete_option( $this->option_name . 'active' ); |
| 352 | 231 | delete_option( $this->option_name . 'key' ); |
| 353 | - | |
| 354 | - if ( $this->should_clear_cache ) { | |
| 355 | - delete_site_option( $this->transient_key() ); | |
| 356 | - delete_option( $this->transient_key() ); | |
| 357 | - $this->delete_cache(); | |
| 358 | - $this->should_clear_cache = true; | |
| 359 | - } | |
| 232 | + delete_site_option( $this->transient_key() ); | |
| 233 | + delete_option( $this->transient_key() ); | |
| 234 | + $this->delete_cache(); | |
| 360 | 235 | } |
| 361 | 236 | |
| 362 | - /** | |
| 363 | - * Don't save an invalid license. | |
| 364 | - * | |
| 365 | - * @since 6.8.3 | |
| 366 | - * | |
| 367 | - * @param bool $is_valid If license activation was successful. | |
| 368 | - * | |
| 369 | - * @return void | |
| 370 | - */ | |
| 371 | - protected function maybe_set_active( $is_valid ) { | |
| 372 | - update_option( $this->option_name . 'active', $is_valid ); | |
| 373 | - | |
| 374 | - if ( $is_valid ) { | |
| 375 | - $this->set_active( $is_valid ); | |
| 376 | - return; | |
| 377 | - } | |
| 378 | - | |
| 379 | - // Don't save the license if it's invalid. | |
| 380 | - $this->should_clear_cache = false; | |
| 381 | - $this->clear_license(); | |
| 382 | - delete_option( $this->option_name . 'key' ); | |
| 383 | - $this->license = ''; | |
| 384 | - } | |
| 385 | - | |
| 386 | - /** | |
| 387 | - * @param bool $is_active | |
| 388 | - * | |
| 389 | - * @return void | |
| 390 | - */ | |
| 391 | 237 | public function set_active( $is_active ) { |
| 238 | + update_option( $this->option_name . 'active', $is_active ); | |
| 392 | 239 | $this->delete_cache(); |
| 393 | 240 | FrmAppHelper::save_combined_js(); |
| 394 | 241 | $this->update_pro_capabilities(); |
| 395 | 242 | } |
| @@ -397,27 +244,20 @@ | ||
| 397 | 244 | /** |
| 398 | 245 | * Updates roles capabilities after pro license is active. |
| 399 | 246 | * |
| 400 | 247 | * @since 5.0 |
| 401 | - * | |
| 402 | - * @return void | |
| 403 | 248 | */ |
| 404 | 249 | protected function update_pro_capabilities() { |
| 405 | 250 | global $wp_roles; |
| 406 | 251 | |
| 407 | - if ( ! function_exists( 'get_editable_roles' ) ) { | |
| 408 | - require_once ABSPATH . 'wp-admin/includes/user.php'; | |
| 409 | - } | |
| 410 | - | |
| 411 | 252 | $caps = FrmAppHelper::frm_capabilities( 'pro_only' ); |
| 412 | 253 | $roles = get_editable_roles(); |
| 413 | 254 | $settings = new FrmSettings(); |
| 414 | - | |
| 415 | 255 | foreach ( $caps as $cap => $cap_desc ) { |
| 416 | - $cap_roles = (array) ( $settings->$cap ?? 'administrator' ); | |
| 256 | + $cap_roles = (array) ( isset( $settings->$cap ) ? $settings->$cap : 'administrator' ); | |
| 417 | 257 | |
| 418 | 258 | // Make sure administrators always have permissions. |
| 419 | - if ( ! in_array( 'administrator', $cap_roles, true ) ) { | |
| 259 | + if ( ! in_array( 'administrator', $cap_roles ) ) { | |
| 420 | 260 | array_push( $cap_roles, 'administrator' ); |
| 421 | 261 | } |
| 422 | 262 | |
| 423 | 263 | foreach ( $roles as $role => $details ) { |
| @@ -431,28 +271,17 @@ | ||
| 431 | 271 | } |
| 432 | 272 | |
| 433 | 273 | /** |
| 434 | 274 | * @since 3.04.03 |
| 435 | - * | |
| 436 | - * @return void | |
| 437 | 275 | */ |
| 438 | 276 | protected function delete_cache() { |
| 439 | 277 | delete_transient( 'frm_api_licence' ); |
| 440 | 278 | |
| 441 | - // Cleanup option that has been removed. | |
| 442 | - delete_option( $this->option_name . 'last_activate' ); | |
| 443 | - | |
| 444 | 279 | $api = new FrmFormApi( $this->license ); |
| 445 | 280 | $api->reset_cached(); |
| 446 | 281 | |
| 447 | 282 | $api = new FrmFormTemplateApi( $this->license ); |
| 448 | 283 | $api->reset_cached(); |
| 449 | - | |
| 450 | - $api = new FrmApplicationApi( $this->license ); | |
| 451 | - $api->reset_cached(); | |
| 452 | - | |
| 453 | - $api = new FrmSalesApi(); | |
| 454 | - $api->reset_cached(); | |
| 455 | 284 | } |
| 456 | 285 | |
| 457 | 286 | /** |
| 458 | 287 | * The Pro version includes the show_license_message function. |
| @@ -458,13 +287,8 @@ | ||
| 458 | 287 | * The Pro version includes the show_license_message function. |
| 459 | 288 | * We need an extra check before we allow it to show a message. |
| 460 | 289 | * |
| 461 | 290 | * @since 3.04.03 |
| 462 | - * | |
| 463 | - * @param string $file File path of the plugin. | |
| 464 | - * @param array $plugin Plugin data. | |
| 465 | - * | |
| 466 | - * @return void | |
| 467 | 291 | */ |
| 468 | 292 | public function maybe_show_license_message( $file, $plugin ) { |
| 469 | 293 | if ( $this->is_expired_addon || isset( $plugin['package'] ) ) { |
| 470 | 294 | // let's not show a ton of duplicate messages |
| @@ -473,17 +297,10 @@ | ||
| 473 | 297 | |
| 474 | 298 | $this->show_license_message( $file, $plugin ); |
| 475 | 299 | } |
| 476 | 300 | |
| 477 | - /** | |
| 478 | - * @param string $file File path of the plugin. | |
| 479 | - * @param array $plugin Plugin data. | |
| 480 | - * | |
| 481 | - * @return void | |
| 482 | - */ | |
| 483 | 301 | public function show_license_message( $file, $plugin ) { |
| 484 | 302 | $message = ''; |
| 485 | - | |
| 486 | 303 | if ( empty( $this->license ) ) { |
| 487 | 304 | /* translators: %1$s: Plugin name, %2$s: Start link HTML, %3$s: end link HTML */ |
| 488 | 305 | $message = sprintf( esc_html__( 'Your %1$s license key is missing. Please add it on the %2$slicenses page%3$s.', 'formidable' ), esc_html( $this->plugin_name ), '<a href="' . esc_url( admin_url( 'admin.php?page=formidable-settings' ) ) . '">', '</a>' ); |
| 489 | 306 | } else { |
| @@ -488,9 +305,8 @@ | ||
| 488 | 305 | $message = sprintf( esc_html__( 'Your %1$s license key is missing. Please add it on the %2$slicenses page%3$s.', 'formidable' ), esc_html( $this->plugin_name ), '<a href="' . esc_url( admin_url( 'admin.php?page=formidable-settings' ) ) . '">', '</a>' ); |
| 489 | 306 | } else { |
| 490 | 307 | $api = new FrmFormApi( $this->license ); |
| 491 | 308 | $errors = $api->error_for_license(); |
| 492 | - | |
| 493 | 309 | if ( ! empty( $errors ) ) { |
| 494 | 310 | $message = reset( $errors ); |
| 495 | 311 | } |
| 496 | 312 | } |
| @@ -502,18 +318,13 @@ | ||
| 502 | 318 | $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' ); |
| 503 | 319 | $id = sanitize_title( $plugin['Name'] ) . '-next'; |
| 504 | 320 | |
| 505 | 321 | echo '<tr class="plugin-update-tr active" id="' . esc_attr( $id ) . '"><td colspan="' . esc_attr( $wp_list_table->get_column_count() ) . '" class="plugin-update colspanchange"><div class="update-message notice error inline notice-error notice-alt"><p>'; |
| 506 | - FrmAppHelper::kses_echo( $message, 'a' ); | |
| 322 | + echo FrmAppHelper::kses( $message, 'a' ); // WPCS: XSS ok. | |
| 507 | 323 | echo '<script type="text/javascript">var d = document.getElementById("' . esc_attr( $id ) . '").previousSibling;if ( d !== null ){ d.className = d.className + " update"; }</script>'; |
| 508 | 324 | echo '</p></div></td></tr>'; |
| 509 | 325 | } |
| 510 | 326 | |
| 511 | - /** | |
| 512 | - * @param mixed $transient | |
| 513 | - * | |
| 514 | - * @return mixed | |
| 515 | - */ | |
| 516 | 327 | public function clear_expired_download( $transient ) { |
| 517 | 328 | if ( ! is_object( $transient ) ) { |
| 518 | 329 | return $transient; |
| 519 | 330 | } |
| @@ -518,9 +329,9 @@ | ||
| 518 | 329 | return $transient; |
| 519 | 330 | } |
| 520 | 331 | |
| 521 | 332 | if ( $this->is_current_version( $transient ) ) { |
| 522 | - // Make sure it doesn't show there is an update if plugin is up-to-date. | |
| 333 | + //make sure it doesn't show there is an update if plugin is up-to-date | |
| 523 | 334 | if ( isset( $transient->response[ $this->plugin_folder ] ) ) { |
| 524 | 335 | unset( $transient->response[ $this->plugin_folder ] ); |
| 525 | 336 | } |
| 526 | 337 | } elseif ( isset( $transient->response ) && isset( $transient->response[ $this->plugin_folder ] ) ) { |
| @@ -543,25 +354,20 @@ | ||
| 543 | 354 | * Check if the plugin information is correct to allow an update |
| 544 | 355 | * |
| 545 | 356 | * @since 3.04.03 |
| 546 | 357 | * |
| 547 | - * @param object $transient The current plugin info saved for update. | |
| 548 | - * | |
| 549 | - * @return void | |
| 358 | + * @param object $transient - the current plugin info saved for update | |
| 550 | 359 | */ |
| 551 | 360 | private function prepare_update_details( &$transient ) { |
| 552 | 361 | $version_info = $transient; |
| 553 | - $has_beta_url = ! empty( $version_info->beta ); | |
| 554 | - | |
| 362 | + $has_beta_url = isset( $version_info->beta ) && ! empty( $version_info->beta ); | |
| 555 | 363 | if ( $this->get_beta && ! $has_beta_url ) { |
| 556 | 364 | $version_info = (object) $this->get_api_info( $this->license ); |
| 557 | 365 | } |
| 558 | 366 | |
| 559 | - if ( ! empty( $version_info->new_version ) ) { | |
| 367 | + if ( isset( $version_info->new_version ) && ! empty( $version_info->new_version ) ) { | |
| 560 | 368 | $this->clear_old_plugin_version( $version_info ); |
| 561 | - | |
| 562 | - if ( $version_info === false ) { | |
| 563 | - // Was cleared with timeout. | |
| 369 | + if ( $version_info === false ) { // was cleared with timeout | |
| 564 | 370 | $transient = false; |
| 565 | 371 | } else { |
| 566 | 372 | $this->maybe_use_beta_url( $version_info ); |
| 567 | 373 | |
| @@ -575,12 +381,8 @@ | ||
| 575 | 381 | /** |
| 576 | 382 | * Get the API info for this plugin |
| 577 | 383 | * |
| 578 | 384 | * @since 3.04.03 |
| 579 | - * | |
| 580 | - * @param string $license The license key. | |
| 581 | - * | |
| 582 | - * @return array The API info for the plugin. | |
| 583 | 385 | */ |
| 584 | 386 | protected function get_api_info( $license ) { |
| 585 | 387 | $api = new FrmFormApi( $license ); |
| 586 | 388 | $addon = $api->get_addon_for_license( $this ); |
| @@ -601,19 +403,13 @@ | ||
| 601 | 403 | * Make sure transients don't stick around on sites that |
| 602 | 404 | * don't save the transient expiration |
| 603 | 405 | * |
| 604 | 406 | * @since 2.05.05 |
| 605 | - * | |
| 606 | - * @param object $version_info The version info for the plugin. | |
| 607 | - * | |
| 608 | - * @return void | |
| 609 | 407 | */ |
| 610 | 408 | private function clear_old_plugin_version( &$version_info ) { |
| 611 | - $timeout = ! empty( $version_info->timeout ) ? $version_info->timeout : 0; | |
| 612 | - | |
| 409 | + $timeout = ( isset( $version_info->timeout ) && ! empty( $version_info->timeout ) ) ? $version_info->timeout : 0; | |
| 613 | 410 | if ( ! empty( $timeout ) && time() > $timeout ) { |
| 614 | - // Cache is expired. | |
| 615 | - $version_info = false; | |
| 411 | + $version_info = false; // Cache is expired | |
| 616 | 412 | $api = new FrmFormApi( $this->license ); |
| 617 | 413 | $api->reset_cached(); |
| 618 | 414 | } |
| 619 | 415 | } |
| @@ -622,36 +418,25 @@ | ||
| 622 | 418 | * The beta url is always included if the download has a beta. |
| 623 | 419 | * Check if the beta should be downloaded. |
| 624 | 420 | * |
| 625 | 421 | * @since 3.04.03 |
| 626 | - * | |
| 627 | - * @param object $version_info The version info for the plugin. | |
| 628 | - * | |
| 629 | - * @return void | |
| 630 | 422 | */ |
| 631 | 423 | private function maybe_use_beta_url( &$version_info ) { |
| 632 | - if ( $this->get_beta && ! empty( $version_info->beta ) ) { | |
| 424 | + if ( $this->get_beta && isset( $version_info->beta ) && ! empty( $version_info->beta ) ) { | |
| 633 | 425 | $version_info->new_version = $version_info->beta['version']; |
| 634 | 426 | $version_info->package = $version_info->beta['package']; |
| 635 | - | |
| 636 | - if ( ! empty( $version_info->plugin ) ) { | |
| 427 | + if ( isset( $version_info->plugin ) && ! empty( $version_info->plugin ) ) { | |
| 637 | 428 | $version_info->plugin = $version_info->beta['plugin']; |
| 638 | 429 | } |
| 639 | 430 | } |
| 640 | 431 | } |
| 641 | 432 | |
| 642 | - /** | |
| 643 | - * @param object $transient | |
| 644 | - * | |
| 645 | - * @return bool | |
| 646 | - */ | |
| 647 | 433 | private function is_current_version( $transient ) { |
| 648 | 434 | if ( empty( $transient->checked ) || ! isset( $transient->checked[ $this->plugin_folder ] ) ) { |
| 649 | 435 | return false; |
| 650 | 436 | } |
| 651 | 437 | |
| 652 | - $response = empty( $transient->response ); | |
| 653 | - | |
| 438 | + $response = ! isset( $transient->response ) || empty( $transient->response ); | |
| 654 | 439 | if ( $response ) { |
| 655 | 440 | return true; |
| 656 | 441 | } |
| 657 | 442 | |
| @@ -657,82 +442,23 @@ | ||
| 657 | 442 | |
| 658 | 443 | return isset( $transient->response ) && isset( $transient->response[ $this->plugin_folder ] ) && $transient->checked[ $this->plugin_folder ] === $transient->response[ $this->plugin_folder ]->new_version; |
| 659 | 444 | } |
| 660 | 445 | |
| 661 | - /** | |
| 662 | - * @return bool | |
| 663 | - */ | |
| 664 | 446 | private function has_been_cleared() { |
| 665 | 447 | $last_cleared = get_option( 'frm_last_cleared' ); |
| 666 | - return $last_cleared && $last_cleared > gmdate( 'Y-m-d H:i:s', strtotime( '-5 minutes' ) ); | |
| 448 | + | |
| 449 | + return ( $last_cleared && $last_cleared > gmdate( 'Y-m-d H:i:s', strtotime( '-5 minutes' ) ) ); | |
| 667 | 450 | } |
| 668 | 451 | |
| 669 | - /** | |
| 670 | - * @return void | |
| 671 | - */ | |
| 672 | 452 | private function cleared_plugins() { |
| 673 | 453 | update_option( 'frm_last_cleared', gmdate( 'Y-m-d H:i:s' ) ); |
| 674 | 454 | } |
| 675 | 455 | |
| 676 | - /** | |
| 677 | - * @return void | |
| 678 | - */ | |
| 679 | 456 | private function is_license_revoked() { |
| 680 | - if ( empty( $this->license ) || empty( $this->plugin_slug ) || isset( $_POST['license'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 457 | + if ( empty( $this->license ) || empty( $this->plugin_slug ) || isset( $_POST['license'] ) ) { // WPCS: CSRF ok. | |
| 681 | 458 | return; |
| 682 | 459 | } |
| 683 | 460 | |
| 684 | - if ( $this->get_defined_license() ) { | |
| 685 | - // Don't check if the license is defined in wp-config.php since we can't remove it. | |
| 686 | - return; | |
| 687 | - } | |
| 688 | - | |
| 689 | - // Only check weekly. | |
| 690 | - if ( $this->checked_recently( '7 days', 'valid' ) || $this->is_running() ) { | |
| 691 | - return; | |
| 692 | - } | |
| 693 | - | |
| 694 | - $response = $this->get_license_status(); | |
| 695 | - | |
| 696 | - if ( 'revoked' === $response['status'] || 'blocked' === $response['status'] || 'disabled' === $response['status'] || 'missing' === $response['status'] ) { | |
| 697 | - $this->clear_license(); | |
| 698 | - } | |
| 699 | - } | |
| 700 | - | |
| 701 | - /** | |
| 702 | - * Has this been checked too recently? | |
| 703 | - * | |
| 704 | - * @param string $time ie. '1 day'. | |
| 705 | - * @param string $required_status Return false if the last check does not match. ie 'valid'. | |
| 706 | - * | |
| 707 | - * @return bool | |
| 708 | - */ | |
| 709 | - private function checked_recently( $time, $required_status = '' ) { | |
| 710 | - $last_checked = $this->last_checked(); | |
| 711 | - $is_429 = isset( $last_checked['response_code'] ) && 429 === $last_checked['response_code']; | |
| 712 | - | |
| 713 | - if ( $is_429 ) { | |
| 714 | - // If the last check was a a rate limit, we'll need to check again sooner. | |
| 715 | - $time = '5 minutes'; | |
| 716 | - $required_status = ''; | |
| 717 | - } | |
| 718 | - | |
| 719 | - if ( $required_status && ( ! isset( $last_checked['status'] ) || $last_checked['status'] !== $required_status ) ) { | |
| 720 | - // If the last check was invalid, we don't need to check again. | |
| 721 | - return true; | |
| 722 | - } | |
| 723 | - | |
| 724 | - $checked_time = $last_checked['time'] ?? false; | |
| 725 | - $time_ago = gmdate( 'Y-m-d H:i:s', strtotime( '-' . $time ) ); | |
| 726 | - return $checked_time && $checked_time > $time_ago; | |
| 727 | - } | |
| 728 | - | |
| 729 | - /** | |
| 730 | - * @since 6.8.3 Switched to an array to store extra response info. | |
| 731 | - * | |
| 732 | - * @return array | |
| 733 | - */ | |
| 734 | - private function last_checked() { | |
| 735 | 461 | if ( is_multisite() ) { |
| 736 | 462 | $last_checked = get_site_option( $this->transient_key() ); |
| 737 | 463 | } else { |
| 738 | 464 | $last_checked = get_option( $this->transient_key() ); |
| @@ -737,52 +463,44 @@ | ||
| 737 | 463 | } else { |
| 738 | 464 | $last_checked = get_option( $this->transient_key() ); |
| 739 | 465 | } |
| 740 | 466 | |
| 741 | - if ( $last_checked && ! is_array( $last_checked ) ) { | |
| 742 | - // Get string into array for existing values. | |
| 743 | - $last_checked = array( 'time' => $last_checked ); | |
| 744 | - } | |
| 467 | + $seven_days_ago = gmdate( 'Y-m-d H:i:s', strtotime( '-7 days' ) ); | |
| 745 | 468 | |
| 746 | - return $last_checked ? $last_checked : array(); | |
| 747 | - } | |
| 469 | + if ( ! $last_checked || $last_checked < $seven_days_ago ) { | |
| 470 | + // check weekly | |
| 471 | + if ( is_multisite() ) { | |
| 472 | + update_site_option( $this->transient_key(), gmdate( 'Y-m-d H:i:s' ) ); | |
| 473 | + } else { | |
| 474 | + update_option( $this->transient_key(), gmdate( 'Y-m-d H:i:s' ) ); | |
| 475 | + } | |
| 748 | 476 | |
| 749 | - /** | |
| 750 | - * @return void | |
| 751 | - */ | |
| 752 | - private function update_last_checked() { | |
| 753 | - $this->save_response['time'] = gmdate( 'Y-m-d H:i:s' ); | |
| 754 | - | |
| 755 | - if ( is_multisite() ) { | |
| 756 | - update_site_option( $this->transient_key(), $this->save_response ); | |
| 757 | - } else { | |
| 758 | - update_option( $this->transient_key(), $this->save_response ); | |
| 477 | + $response = $this->get_license_status(); | |
| 478 | + if ( 'revoked' === $response['status'] || 'blocked' === $response['status'] || 'disabled' === $response['status'] ) { | |
| 479 | + $this->clear_license(); | |
| 480 | + } | |
| 759 | 481 | } |
| 760 | 482 | } |
| 761 | 483 | |
| 762 | 484 | /** |
| 763 | 485 | * Use a new cache after the license is changed, or Formidable is updated. |
| 764 | - * | |
| 765 | - * @return string | |
| 766 | 486 | */ |
| 767 | 487 | private function transient_key() { |
| 768 | 488 | return 'frm_' . md5( sanitize_key( $this->license . '_' . $this->plugin_slug ) ); |
| 769 | 489 | } |
| 770 | 490 | |
| 771 | - /** | |
| 772 | - * @return void | |
| 773 | - */ | |
| 774 | 491 | public static function activate() { |
| 775 | 492 | FrmAppHelper::permission_check( 'frm_change_settings' ); |
| 776 | 493 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
| 777 | 494 | |
| 778 | 495 | $license = stripslashes( FrmAppHelper::get_param( 'license', '', 'post', 'sanitize_text_field' ) ); |
| 779 | - | |
| 780 | 496 | if ( empty( $license ) ) { |
| 781 | - wp_send_json( | |
| 782 | - array( | |
| 783 | - 'message' => __( 'Oops! You forgot to enter your license number.', 'formidable' ), | |
| 784 | - 'success' => false, | |
| 497 | + wp_die( | |
| 498 | + json_encode( | |
| 499 | + array( | |
| 500 | + 'message' => __( 'Oops! You forgot to enter your license number.', 'formidable' ), | |
| 501 | + 'success' => false, | |
| 502 | + ) | |
| 785 | 503 | ) |
| 786 | 504 | ); |
| 787 | 505 | } |
| 788 | 506 | |
| @@ -788,20 +506,14 @@ | ||
| 788 | 506 | |
| 789 | 507 | $plugin_slug = FrmAppHelper::get_param( 'plugin', '', 'post', 'sanitize_text_field' ); |
| 790 | 508 | $response = self::activate_license_for_plugin( $license, $plugin_slug ); |
| 791 | 509 | |
| 792 | - FrmInbox::clear_cache(); | |
| 793 | - | |
| 794 | - wp_send_json( $response ); | |
| 510 | + echo json_encode( $response ); | |
| 511 | + wp_die(); | |
| 795 | 512 | } |
| 796 | 513 | |
| 797 | 514 | /** |
| 798 | 515 | * @since 4.08 |
| 799 | - * | |
| 800 | - * @param string $license The license key. | |
| 801 | - * @param string $plugin_slug The plugin slug. | |
| 802 | - * | |
| 803 | - * @return array The response from the license activation. | |
| 804 | 516 | */ |
| 805 | 517 | public static function activate_license_for_plugin( $license, $plugin_slug ) { |
| 806 | 518 | $this_plugin = self::get_addon( $plugin_slug ); |
| 807 | 519 | return $this_plugin->activate_license( $license ); |
| @@ -806,19 +518,12 @@ | ||
| 806 | 518 | $this_plugin = self::get_addon( $plugin_slug ); |
| 807 | 519 | return $this_plugin->activate_license( $license ); |
| 808 | 520 | } |
| 809 | 521 | |
| 810 | - /** | |
| 811 | - * @param string $license The license key. | |
| 812 | - * | |
| 813 | - * @return array The response from the license activation. | |
| 814 | - */ | |
| 815 | 522 | private function activate_license( $license ) { |
| 816 | 523 | $this->set_license( $license ); |
| 817 | 524 | $this->license = $license; |
| 818 | 525 | |
| 819 | - $this->die_if_not_allowed(); | |
| 820 | - | |
| 821 | 526 | $response = $this->get_license_status(); |
| 822 | 527 | $response['message'] = ''; |
| 823 | 528 | $response['success'] = false; |
| 824 | 529 | |
| @@ -825,9 +530,8 @@ | ||
| 825 | 530 | if ( $response['error'] ) { |
| 826 | 531 | $response['message'] = $response['status']; |
| 827 | 532 | } else { |
| 828 | 533 | $messages = $this->get_messages(); |
| 829 | - | |
| 830 | 534 | if ( is_string( $response['status'] ) && isset( $messages[ $response['status'] ] ) ) { |
| 831 | 535 | $response['message'] = $messages[ $response['status'] ]; |
| 832 | 536 | } else { |
| 833 | 537 | $response['message'] = FrmAppHelper::kses( $response['status'], array( 'a' ) ); |
| @@ -833,51 +537,23 @@ | ||
| 833 | 537 | $response['message'] = FrmAppHelper::kses( $response['status'], array( 'a' ) ); |
| 834 | 538 | } |
| 835 | 539 | |
| 836 | 540 | $is_valid = false; |
| 837 | - | |
| 838 | 541 | if ( 'valid' === $response['status'] ) { |
| 839 | 542 | $is_valid = 'valid'; |
| 840 | 543 | $response['success'] = true; |
| 841 | 544 | } |
| 842 | - $this->maybe_set_active( $is_valid ); | |
| 545 | + $this->set_active( $is_valid ); | |
| 843 | 546 | } |
| 844 | 547 | |
| 845 | - $this->update_last_checked(); | |
| 846 | - | |
| 847 | 548 | return $response; |
| 848 | 549 | } |
| 849 | 550 | |
| 850 | - /** | |
| 851 | - * Prevent this check from happening more than once per minute with the same license. | |
| 852 | - * | |
| 853 | - * @return void | |
| 854 | - */ | |
| 855 | - private function die_if_not_allowed() { | |
| 856 | - if ( ! $this->checked_recently( '2 minutes' ) ) { | |
| 857 | - return; | |
| 858 | - } | |
| 859 | - | |
| 860 | - // Don't check more than once per minute. | |
| 861 | - wp_send_json( | |
| 862 | - array( | |
| 863 | - 'message' => __( 'Please wait two minutes before trying again.', 'formidable' ), | |
| 864 | - 'success' => false, | |
| 865 | - ) | |
| 866 | - ); | |
| 867 | - } | |
| 868 | - | |
| 869 | - /** | |
| 870 | - * @return array | |
| 871 | - */ | |
| 872 | 551 | private function get_license_status() { |
| 873 | - $this->set_running(); | |
| 874 | - | |
| 875 | 552 | $response = array( |
| 876 | 553 | 'status' => 'missing', |
| 877 | 554 | 'error' => true, |
| 878 | 555 | ); |
| 879 | - | |
| 880 | 556 | if ( empty( $this->license ) ) { |
| 881 | 557 | $response['error'] = false; |
| 882 | 558 | |
| 883 | 559 | return $response; |
| @@ -888,11 +564,10 @@ | ||
| 888 | 564 | $license_data = $this->send_mothership_request( 'activate_license' ); |
| 889 | 565 | |
| 890 | 566 | // $license_data->license will be either "valid" or "invalid" |
| 891 | 567 | if ( is_array( $license_data ) ) { |
| 892 | - if ( ! empty( $license_data['license'] ) && in_array( $license_data['license'], array( 'valid', 'invalid' ), true ) ) { | |
| 893 | - $response['status'] = $license_data['license']; | |
| 894 | - $this->save_status['status'] = $license_data['license']; | |
| 568 | + if ( in_array( $license_data['license'], array( 'valid', 'invalid' ), true ) ) { | |
| 569 | + $response['status'] = $license_data['license']; | |
| 895 | 570 | } |
| 896 | 571 | } else { |
| 897 | 572 | $response['status'] = $license_data; |
| 898 | 573 | } |
| @@ -899,16 +574,11 @@ | ||
| 899 | 574 | } catch ( Exception $e ) { |
| 900 | 575 | $response['status'] = $e->getMessage(); |
| 901 | 576 | } |
| 902 | 577 | |
| 903 | - $this->update_last_checked(); | |
| 904 | - $this->done_running(); | |
| 905 | 578 | return $response; |
| 906 | 579 | } |
| 907 | 580 | |
| 908 | - /** | |
| 909 | - * @return array | |
| 910 | - */ | |
| 911 | 581 | private function get_messages() { |
| 912 | 582 | return array( |
| 913 | 583 | 'valid' => __( 'Your license has been activated. Enjoy!', 'formidable' ), |
| 914 | 584 | 'invalid' => __( 'That license key is invalid', 'formidable' ), |
| @@ -921,10 +591,8 @@ | ||
| 921 | 591 | } |
| 922 | 592 | |
| 923 | 593 | /** |
| 924 | 594 | * @since 4.03 |
| 925 | - * | |
| 926 | - * @return void | |
| 927 | 595 | */ |
| 928 | 596 | public static function reset_cache() { |
| 929 | 597 | FrmAppHelper::permission_check( 'frm_change_settings' ); |
| 930 | 598 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
| @@ -936,14 +604,12 @@ | ||
| 936 | 604 | 'success' => true, |
| 937 | 605 | 'message' => __( 'Cache cleared', 'formidable' ), |
| 938 | 606 | ); |
| 939 | 607 | |
| 940 | - wp_send_json( $response ); | |
| 608 | + echo json_encode( $response ); | |
| 609 | + wp_die(); | |
| 941 | 610 | } |
| 942 | 611 | |
| 943 | - /** | |
| 944 | - * @return void | |
| 945 | - */ | |
| 946 | 612 | public static function deactivate() { |
| 947 | 613 | FrmAppHelper::permission_check( 'frm_change_settings' ); |
| 948 | 614 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
| 949 | 615 | |
| @@ -952,13 +618,11 @@ | ||
| 952 | 618 | $response = array( |
| 953 | 619 | 'success' => false, |
| 954 | 620 | 'message' => '', |
| 955 | 621 | ); |
| 956 | - | |
| 957 | 622 | try { |
| 958 | 623 | // $license_data->license will be either "deactivated" or "failed" |
| 959 | 624 | $license_data = $this_plugin->send_mothership_request( 'deactivate_license' ); |
| 960 | - | |
| 961 | 625 | if ( is_array( $license_data ) && 'deactivated' === $license_data['license'] ) { |
| 962 | 626 | $response['success'] = true; |
| 963 | 627 | $response['message'] = __( 'That license was removed successfully', 'formidable' ); |
| 964 | 628 | } else { |
| @@ -968,17 +632,15 @@ | ||
| 968 | 632 | $response['message'] = $e->getMessage(); |
| 969 | 633 | } |
| 970 | 634 | |
| 971 | 635 | $this_plugin->clear_license(); |
| 972 | - FrmInbox::clear_cache(); | |
| 973 | 636 | |
| 974 | - wp_send_json( $response ); | |
| 637 | + echo json_encode( $response ); | |
| 638 | + wp_die(); | |
| 975 | 639 | } |
| 976 | 640 | |
| 977 | 641 | /** |
| 978 | 642 | * @since 4.03 |
| 979 | - * | |
| 980 | - * @return FrmAddon | |
| 981 | 643 | */ |
| 982 | 644 | private static function set_license_from_post() { |
| 983 | 645 | $plugin_slug = FrmAppHelper::get_param( 'plugin', '', 'post', 'sanitize_text_field' ); |
| 984 | 646 | $this_plugin = self::get_addon( $plugin_slug ); |
| @@ -986,13 +648,8 @@ | ||
| 986 | 648 | $this_plugin->license = $license; |
| 987 | 649 | return $this_plugin; |
| 988 | 650 | } |
| 989 | 651 | |
| 990 | - /** | |
| 991 | - * @param string $action | |
| 992 | - * | |
| 993 | - * @return string | |
| 994 | - */ | |
| 995 | 652 | public function send_mothership_request( $action ) { |
| 996 | 653 | $api_params = array( |
| 997 | 654 | 'edd_action' => $action, |
| 998 | 655 | 'license' => $this->license, |
| @@ -997,9 +654,8 @@ | ||
| 997 | 654 | 'edd_action' => $action, |
| 998 | 655 | 'license' => $this->license, |
| 999 | 656 | 'url' => home_url(), |
| 1000 | 657 | ); |
| 1001 | - | |
| 1002 | 658 | if ( is_numeric( $this->download_id ) ) { |
| 1003 | 659 | $api_params['item_id'] = absint( $this->download_id ); |
| 1004 | 660 | } else { |
| 1005 | 661 | $api_params['item_name'] = rawurlencode( $this->plugin_name ); |
| @@ -1010,27 +666,21 @@ | ||
| 1010 | 666 | 'timeout' => 25, |
| 1011 | 667 | 'user-agent' => $this->plugin_slug . '/' . $this->version . '; ' . get_bloginfo( 'url' ), |
| 1012 | 668 | ); |
| 1013 | 669 | |
| 1014 | - $resp = wp_remote_post( | |
| 1015 | - $this->store_url . '?l=' . urlencode( base64_encode( $this->license ) ), | |
| 1016 | - $arg_array | |
| 1017 | - ); | |
| 1018 | - $body = wp_remote_retrieve_body( $resp ); | |
| 1019 | - $this->save_status = array( 'response_code' => wp_remote_retrieve_response_code( $resp ) ); | |
| 670 | + $resp = wp_remote_post( $this->store_url, $arg_array ); | |
| 671 | + $body = wp_remote_retrieve_body( $resp ); | |
| 1020 | 672 | |
| 1021 | 673 | $message = __( 'Your License Key was invalid', 'formidable' ); |
| 1022 | - | |
| 1023 | 674 | if ( is_wp_error( $resp ) ) { |
| 1024 | 675 | $link = FrmAppHelper::admin_upgrade_link( 'api', 'knowledgebase/why-cant-i-activate-formidable-pro/' ); |
| 1025 | 676 | /* translators: %1$s: Start link HTML, %2$s: End link HTML */ |
| 1026 | - $message = sprintf( __( 'You had an error communicating with the Formidable API. %1$sClick here%2$s for more information.', 'formidable' ), '<a href="' . esc_url( $link ) . '" target="_blank">', '</a>' ); | |
| 677 | + $message = sprintf( __( 'You had an error communicating with the Formidable API. %1$sClick here%2$s for more information.', 'formidable' ), '<a href="' . esc_url( $link ) . '" target="_blank">', '</a>' ); | |
| 1027 | 678 | $message .= ' ' . $resp->get_error_message(); |
| 1028 | 679 | } elseif ( 'error' === $body || is_wp_error( $body ) ) { |
| 1029 | 680 | $message = __( 'You had an HTTP error connecting to the Formidable API', 'formidable' ); |
| 1030 | 681 | } else { |
| 1031 | 682 | $json_res = json_decode( $body, true ); |
| 1032 | - | |
| 1033 | 683 | if ( null !== $json_res ) { |
| 1034 | 684 | if ( is_array( $json_res ) && isset( $json_res['error'] ) ) { |
| 1035 | 685 | $message = $json_res['error']; |
| 1036 | 686 | } else { |
| @@ -1035,72 +685,17 @@ | ||
| 1035 | 685 | $message = $json_res['error']; |
| 1036 | 686 | } else { |
| 1037 | 687 | $message = $json_res; |
| 1038 | 688 | } |
| 1039 | - } elseif ( ! empty( $resp['response'] ) && ! empty( $resp['response']['code'] ) ) { | |
| 1040 | - $resp['body'] = wp_strip_all_tags( $resp['body'] ); | |
| 1041 | - | |
| 1042 | - $message = sprintf( | |
| 1043 | - /* translators: %1$s: Error code, %2$s: Error message */ | |
| 1044 | - esc_html__( 'There was a %1$s error: %2$s', 'formidable' ), | |
| 1045 | - esc_html( $resp['response']['code'] ), | |
| 1046 | - $resp['response']['message'] . ' ' . $resp['body'] | |
| 1047 | - ); | |
| 689 | + } elseif ( isset( $resp['response'] ) && isset( $resp['response']['code'] ) ) { | |
| 690 | + /* translators: %1$s: Error code, %2$s: Error message */ | |
| 691 | + $message = sprintf( __( 'There was a %1$s error: %2$s', 'formidable' ), $resp['response']['code'], $resp['response']['message'] . ' ' . $resp['body'] ); | |
| 1048 | 692 | } |
| 1049 | - }//end if | |
| 693 | + } | |
| 1050 | 694 | |
| 1051 | 695 | return $message; |
| 1052 | 696 | } |
| 1053 | 697 | |
| 1054 | - /** | |
| 1055 | - * @return void | |
| 1056 | - */ | |
| 1057 | 698 | public function manually_queue_update() { |
| 1058 | - $updates = new stdClass(); | |
| 1059 | - $updates->last_checked = 0; | |
| 1060 | - $updates->response = array(); | |
| 1061 | - $updates->translations = array(); | |
| 1062 | - $updates->no_update = array(); | |
| 1063 | - $updates->checked = array(); | |
| 1064 | - set_site_transient( 'update_plugins', $updates ); | |
| 1065 | - } | |
| 1066 | - | |
| 1067 | - /** | |
| 1068 | - * Set the transient key for the lock. It should be unique to the license. | |
| 1069 | - * | |
| 1070 | - * @since 6.8.3 | |
| 1071 | - * | |
| 1072 | - * @return bool | |
| 1073 | - */ | |
| 1074 | - protected function lock_key() { | |
| 1075 | - return $this->transient_lock_key . '_' . $this->license; | |
| 1076 | - } | |
| 1077 | - | |
| 1078 | - /** | |
| 1079 | - * Prevent multiple requests from running at the same time. | |
| 1080 | - * | |
| 1081 | - * @since 6.8.3 | |
| 1082 | - * | |
| 1083 | - * @return bool | |
| 1084 | - */ | |
| 1085 | - protected function is_running() { | |
| 1086 | - return get_transient( $this->lock_key() ); | |
| 1087 | - } | |
| 1088 | - | |
| 1089 | - /** | |
| 1090 | - * @since 6.8.3 | |
| 1091 | - * | |
| 1092 | - * @return void | |
| 1093 | - */ | |
| 1094 | - protected function set_running() { | |
| 1095 | - set_transient( $this->lock_key(), true, 2 * MINUTE_IN_SECONDS ); | |
| 1096 | - } | |
| 1097 | - | |
| 1098 | - /** | |
| 1099 | - * @since 6.8.3 | |
| 1100 | - * | |
| 1101 | - * @return void | |
| 1102 | - */ | |
| 1103 | - protected function done_running() { | |
| 1104 | - delete_transient( $this->lock_key() ); | |
| 699 | + set_site_transient( 'update_plugins', null ); | |
| 1105 | 700 | } |
| 1106 | 701 | } |