| @@ -4,82 +4,22 @@ | ||
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | /** @phpstan-consistent-constructor */ |
| 7 | 7 | class FrmAddon { |
| 8 | - | |
| 9 | - /** | |
| 10 | - * @var string | |
| 11 | - */ | |
| 12 | 8 | public $store_url = 'https://formidableforms.com'; |
| 13 | - | |
| 14 | - /** | |
| 15 | - * @var int|string|null | |
| 16 | - */ | |
| 17 | 9 | public $download_id; |
| 18 | - | |
| 19 | - /** | |
| 20 | - * @var string|null | |
| 21 | - */ | |
| 22 | 10 | public $plugin_file; |
| 23 | - | |
| 24 | - /** | |
| 25 | - * @var string | |
| 26 | - */ | |
| 27 | 11 | public $plugin_folder; |
| 28 | - | |
| 29 | - /** | |
| 30 | - * @var string | |
| 31 | - */ | |
| 32 | 12 | public $plugin_name; |
| 33 | - | |
| 34 | - /** | |
| 35 | - * @var string | |
| 36 | - */ | |
| 37 | 13 | public $plugin_slug; |
| 38 | - | |
| 39 | - /** | |
| 40 | - * @var string | |
| 41 | - */ | |
| 42 | 14 | public $option_name; |
| 43 | - | |
| 44 | - /** | |
| 45 | - * @var string|null | |
| 46 | - */ | |
| 47 | 15 | public $version; |
| 48 | - | |
| 49 | - /** | |
| 50 | - * @var string | |
| 51 | - */ | |
| 52 | - public $author = 'Strategy11'; | |
| 53 | - | |
| 54 | - /** | |
| 55 | - * @var bool | |
| 56 | - */ | |
| 16 | + public $author = 'Strategy11'; | |
| 57 | 17 | public $is_parent_licence = false; |
| 58 | - | |
| 59 | - /** | |
| 60 | - * @var bool | |
| 61 | - */ | |
| 62 | - public $needs_license = true; | |
| 63 | - | |
| 64 | - /** | |
| 65 | - * @var bool | |
| 66 | - */ | |
| 18 | + public $needs_license = true; | |
| 67 | 19 | private $is_expired_addon = false; |
| 68 | - | |
| 69 | - /** | |
| 70 | - * @var string|null | |
| 71 | - */ | |
| 72 | 20 | public $license; |
| 73 | - | |
| 74 | - /** | |
| 75 | - * @var bool | |
| 76 | - */ | |
| 77 | 21 | protected $get_beta = false; |
| 78 | - | |
| 79 | - /** | |
| 80 | - * @var array|null | |
| 81 | - */ | |
| 82 | 22 | protected $save_status; |
| 83 | 23 | |
| 84 | 24 | /** |
| 85 | 25 | * This is used to decide whether the license checks should continue. |
| @@ -112,9 +52,8 @@ | ||
| 112 | 52 | |
| 113 | 53 | if ( empty( $this->plugin_slug ) ) { |
| 114 | 54 | $this->plugin_slug = preg_replace( '/[^a-zA-Z0-9_\s]/', '', str_replace( ' ', '_', strtolower( $this->plugin_name ) ) ); |
| 115 | 55 | } |
| 116 | - | |
| 117 | 56 | if ( empty( $this->option_name ) ) { |
| 118 | 57 | $this->option_name = 'edd_' . $this->plugin_slug . '_license_'; |
| 119 | 58 | } |
| 120 | 59 | |
| @@ -124,21 +63,13 @@ | ||
| 124 | 63 | add_filter( 'frm_installed_addons', array( &$this, 'insert_installed_addon' ) ); |
| 125 | 64 | $this->edd_plugin_updater(); |
| 126 | 65 | } |
| 127 | 66 | |
| 128 | - /** | |
| 129 | - * @return void | |
| 130 | - */ | |
| 131 | 67 | public static function load_hooks() { |
| 132 | 68 | add_filter( 'frm_include_addon_page', '__return_true' ); |
| 133 | 69 | new static(); |
| 134 | 70 | } |
| 135 | 71 | |
| 136 | - /** | |
| 137 | - * @param array $plugins | |
| 138 | - * | |
| 139 | - * @return array | |
| 140 | - */ | |
| 141 | 72 | public function insert_installed_addon( $plugins ) { |
| 142 | 73 | $plugins[ $this->plugin_slug ] = $this; |
| 143 | 74 | |
| 144 | 75 | return $plugins; |
| @@ -143,17 +74,11 @@ | ||
| 143 | 74 | |
| 144 | 75 | return $plugins; |
| 145 | 76 | } |
| 146 | 77 | |
| 147 | - /** | |
| 148 | - * @param string $plugin_slug | |
| 149 | - * | |
| 150 | - * @return false|FrmAddon | |
| 151 | - */ | |
| 152 | 78 | public static function get_addon( $plugin_slug ) { |
| 153 | 79 | $plugins = apply_filters( 'frm_installed_addons', array() ); |
| 154 | 80 | $plugin = false; |
| 155 | - | |
| 156 | 81 | if ( isset( $plugins[ $plugin_slug ] ) ) { |
| 157 | 82 | $plugin = $plugins[ $plugin_slug ]; |
| 158 | 83 | } |
| 159 | 84 | |
| @@ -159,11 +84,8 @@ | ||
| 159 | 84 | |
| 160 | 85 | return $plugin; |
| 161 | 86 | } |
| 162 | 87 | |
| 163 | - /** | |
| 164 | - * @return void | |
| 165 | - */ | |
| 166 | 88 | public function edd_plugin_updater() { |
| 167 | 89 | |
| 168 | 90 | $this->is_license_revoked(); |
| 169 | 91 | $license = $this->license; |
| @@ -198,15 +120,13 @@ | ||
| 198 | 120 | } |
| 199 | 121 | |
| 200 | 122 | $slug = basename( $this->plugin_file, '.php' ); |
| 201 | 123 | $slug2 = str_replace( '/' . $slug . '.php', '', $this->plugin_folder ); |
| 202 | - | |
| 203 | 124 | if ( empty( $_args->slug ) || ( $_args->slug != $slug && $_args->slug !== $slug2 ) ) { |
| 204 | 125 | return $_data; |
| 205 | 126 | } |
| 206 | 127 | |
| 207 | 128 | $item_id = $this->download_id; |
| 208 | - | |
| 209 | 129 | if ( empty( $item_id ) ) { |
| 210 | 130 | $_data = array( |
| 211 | 131 | 'name' => $this->plugin_name, |
| 212 | 132 | 'excerpt' => '', |
| @@ -231,20 +151,15 @@ | ||
| 231 | 151 | |
| 232 | 152 | return (object) $_data; |
| 233 | 153 | } |
| 234 | 154 | |
| 235 | - /** | |
| 236 | - * @return string | |
| 237 | - */ | |
| 238 | 155 | public function get_license() { |
| 239 | 156 | $license = $this->maybe_get_pro_license(); |
| 240 | - | |
| 241 | 157 | if ( ! empty( $license ) ) { |
| 242 | 158 | return $license; |
| 243 | 159 | } |
| 244 | 160 | |
| 245 | 161 | $license = trim( get_option( $this->option_name . 'key' ) ); |
| 246 | - | |
| 247 | 162 | if ( empty( $license ) ) { |
| 248 | 163 | $license = $this->activate_defined_license(); |
| 249 | 164 | } |
| 250 | 165 | |
| @@ -252,10 +167,8 @@ | ||
| 252 | 167 | } |
| 253 | 168 | |
| 254 | 169 | /** |
| 255 | 170 | * @since 3.04.03 |
| 256 | - * | |
| 257 | - * @return false|string | |
| 258 | 171 | */ |
| 259 | 172 | protected function maybe_get_pro_license() { |
| 260 | 173 | // prevent a loop if $this is the pro plugin |
| 261 | 174 | $get_license = FrmAppHelper::pro_is_installed() && is_callable( 'FrmProAppHelper::get_updater' ) && $this->plugin_name != 'Formidable Pro'; |
| @@ -266,15 +179,13 @@ | ||
| 266 | 179 | |
| 267 | 180 | $api = new FrmFormApi(); |
| 268 | 181 | $api->get_pro_updater(); |
| 269 | 182 | $license = $api->get_license(); |
| 270 | - | |
| 271 | 183 | if ( empty( $license ) ) { |
| 272 | 184 | return false; |
| 273 | 185 | } |
| 274 | 186 | |
| 275 | 187 | $this->get_api_info( $license ); |
| 276 | - | |
| 277 | 188 | if ( ! $this->is_parent_licence ) { |
| 278 | 189 | $license = false; |
| 279 | 190 | } |
| 280 | 191 | |
| @@ -284,17 +195,13 @@ | ||
| 284 | 195 | /** |
| 285 | 196 | * Activate the license in wp-config.php |
| 286 | 197 | * |
| 287 | 198 | * @since 2.04 |
| 288 | - * | |
| 289 | - * @return string | |
| 290 | 199 | */ |
| 291 | 200 | public function activate_defined_license() { |
| 292 | 201 | $license = $this->get_defined_license(); |
| 293 | - | |
| 294 | 202 | if ( ! empty( $license ) && ! $this->is_active() && ! $this->checked_recently( '1 day' ) ) { |
| 295 | 203 | $response = $this->activate_license( $license ); |
| 296 | - | |
| 297 | 204 | if ( ! $response['success'] ) { |
| 298 | 205 | $license = ''; |
| 299 | 206 | } |
| 300 | 207 | } |
| @@ -305,29 +212,19 @@ | ||
| 305 | 212 | /** |
| 306 | 213 | * Check the wp-config.php for the license key |
| 307 | 214 | * |
| 308 | 215 | * @since 2.04 |
| 309 | - * | |
| 310 | - * @return false|string | |
| 311 | 216 | */ |
| 312 | 217 | public function get_defined_license() { |
| 313 | - $constant_name = 'FRM_' . strtoupper( $this->plugin_slug ) . '_LICENSE'; | |
| 218 | + $consant_name = 'FRM_' . strtoupper( $this->plugin_slug ) . '_LICENSE'; | |
| 314 | 219 | |
| 315 | - return defined( $constant_name ) ? constant( $constant_name ) : false; | |
| 220 | + return defined( $consant_name ) ? constant( $consant_name ) : false; | |
| 316 | 221 | } |
| 317 | 222 | |
| 318 | - /** | |
| 319 | - * @param string $license | |
| 320 | - * | |
| 321 | - * @return void | |
| 322 | - */ | |
| 323 | 223 | public function set_license( $license ) { |
| 324 | 224 | update_option( $this->option_name . 'key', $license ); |
| 325 | 225 | } |
| 326 | 226 | |
| 327 | - /** | |
| 328 | - * @return mixed | |
| 329 | - */ | |
| 330 | 227 | public function is_active() { |
| 331 | 228 | return get_option( $this->option_name . 'active' ); |
| 332 | 229 | } |
| 333 | 230 | |
| @@ -334,10 +231,8 @@ | ||
| 334 | 231 | /** |
| 335 | 232 | * @since 3.04.03 |
| 336 | 233 | * |
| 337 | 234 | * @param array|string $error |
| 338 | - * | |
| 339 | - * @return void | |
| 340 | 235 | */ |
| 341 | 236 | public function maybe_clear_license( $error ) { |
| 342 | 237 | if ( is_array( $error ) && $error['code'] === 'disabled' && $error['license'] === $this->license ) { |
| 343 | 238 | $this->clear_license(); |
| @@ -343,11 +238,8 @@ | ||
| 343 | 238 | $this->clear_license(); |
| 344 | 239 | } |
| 345 | 240 | } |
| 346 | 241 | |
| 347 | - /** | |
| 348 | - * @return void | |
| 349 | - */ | |
| 350 | 242 | public function clear_license() { |
| 351 | 243 | delete_option( $this->option_name . 'active' ); |
| 352 | 244 | delete_option( $this->option_name . 'key' ); |
| 353 | 245 | |
| @@ -369,9 +261,8 @@ | ||
| 369 | 261 | * @return void |
| 370 | 262 | */ |
| 371 | 263 | protected function maybe_set_active( $is_valid ) { |
| 372 | 264 | update_option( $this->option_name . 'active', $is_valid ); |
| 373 | - | |
| 374 | 265 | if ( $is_valid ) { |
| 375 | 266 | $this->set_active( $is_valid ); |
| 376 | 267 | return; |
| 377 | 268 | } |
| @@ -382,13 +273,8 @@ | ||
| 382 | 273 | delete_option( $this->option_name . 'key' ); |
| 383 | 274 | $this->license = ''; |
| 384 | 275 | } |
| 385 | 276 | |
| 386 | - /** | |
| 387 | - * @param bool $is_active | |
| 388 | - * | |
| 389 | - * @return void | |
| 390 | - */ | |
| 391 | 277 | public function set_active( $is_active ) { |
| 392 | 278 | $this->delete_cache(); |
| 393 | 279 | FrmAppHelper::save_combined_js(); |
| 394 | 280 | $this->update_pro_capabilities(); |
| @@ -397,10 +283,8 @@ | ||
| 397 | 283 | /** |
| 398 | 284 | * Updates roles capabilities after pro license is active. |
| 399 | 285 | * |
| 400 | 286 | * @since 5.0 |
| 401 | - * | |
| 402 | - * @return void | |
| 403 | 287 | */ |
| 404 | 288 | protected function update_pro_capabilities() { |
| 405 | 289 | global $wp_roles; |
| 406 | 290 | |
| @@ -410,11 +294,10 @@ | ||
| 410 | 294 | |
| 411 | 295 | $caps = FrmAppHelper::frm_capabilities( 'pro_only' ); |
| 412 | 296 | $roles = get_editable_roles(); |
| 413 | 297 | $settings = new FrmSettings(); |
| 414 | - | |
| 415 | 298 | foreach ( $caps as $cap => $cap_desc ) { |
| 416 | - $cap_roles = (array) ( $settings->$cap ?? 'administrator' ); | |
| 299 | + $cap_roles = (array) ( isset( $settings->$cap ) ? $settings->$cap : 'administrator' ); | |
| 417 | 300 | |
| 418 | 301 | // Make sure administrators always have permissions. |
| 419 | 302 | if ( ! in_array( 'administrator', $cap_roles, true ) ) { |
| 420 | 303 | array_push( $cap_roles, 'administrator' ); |
| @@ -431,10 +314,8 @@ | ||
| 431 | 314 | } |
| 432 | 315 | |
| 433 | 316 | /** |
| 434 | 317 | * @since 3.04.03 |
| 435 | - * | |
| 436 | - * @return void | |
| 437 | 318 | */ |
| 438 | 319 | protected function delete_cache() { |
| 439 | 320 | delete_transient( 'frm_api_licence' ); |
| 440 | 321 | |
| @@ -448,11 +329,8 @@ | ||
| 448 | 329 | $api->reset_cached(); |
| 449 | 330 | |
| 450 | 331 | $api = new FrmApplicationApi( $this->license ); |
| 451 | 332 | $api->reset_cached(); |
| 452 | - | |
| 453 | - $api = new FrmSalesApi(); | |
| 454 | - $api->reset_cached(); | |
| 455 | 333 | } |
| 456 | 334 | |
| 457 | 335 | /** |
| 458 | 336 | * The Pro version includes the show_license_message function. |
| @@ -458,13 +336,8 @@ | ||
| 458 | 336 | * The Pro version includes the show_license_message function. |
| 459 | 337 | * We need an extra check before we allow it to show a message. |
| 460 | 338 | * |
| 461 | 339 | * @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 | 340 | */ |
| 468 | 341 | public function maybe_show_license_message( $file, $plugin ) { |
| 469 | 342 | if ( $this->is_expired_addon || isset( $plugin['package'] ) ) { |
| 470 | 343 | // let's not show a ton of duplicate messages |
| @@ -473,17 +346,10 @@ | ||
| 473 | 346 | |
| 474 | 347 | $this->show_license_message( $file, $plugin ); |
| 475 | 348 | } |
| 476 | 349 | |
| 477 | - /** | |
| 478 | - * @param string $file File path of the plugin. | |
| 479 | - * @param array $plugin Plugin data. | |
| 480 | - * | |
| 481 | - * @return void | |
| 482 | - */ | |
| 483 | 350 | public function show_license_message( $file, $plugin ) { |
| 484 | 351 | $message = ''; |
| 485 | - | |
| 486 | 352 | if ( empty( $this->license ) ) { |
| 487 | 353 | /* translators: %1$s: Plugin name, %2$s: Start link HTML, %3$s: end link HTML */ |
| 488 | 354 | $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 | 355 | } else { |
| @@ -488,9 +354,8 @@ | ||
| 488 | 354 | $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 | 355 | } else { |
| 490 | 356 | $api = new FrmFormApi( $this->license ); |
| 491 | 357 | $errors = $api->error_for_license(); |
| 492 | - | |
| 493 | 358 | if ( ! empty( $errors ) ) { |
| 494 | 359 | $message = reset( $errors ); |
| 495 | 360 | } |
| 496 | 361 | } |
| @@ -502,18 +367,13 @@ | ||
| 502 | 367 | $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' ); |
| 503 | 368 | $id = sanitize_title( $plugin['Name'] ) . '-next'; |
| 504 | 369 | |
| 505 | 370 | 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' ); | |
| 371 | + echo FrmAppHelper::kses( $message, 'a' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 507 | 372 | echo '<script type="text/javascript">var d = document.getElementById("' . esc_attr( $id ) . '").previousSibling;if ( d !== null ){ d.className = d.className + " update"; }</script>'; |
| 508 | 373 | echo '</p></div></td></tr>'; |
| 509 | 374 | } |
| 510 | 375 | |
| 511 | - /** | |
| 512 | - * @param mixed $transient | |
| 513 | - * | |
| 514 | - * @return mixed | |
| 515 | - */ | |
| 516 | 376 | public function clear_expired_download( $transient ) { |
| 517 | 377 | if ( ! is_object( $transient ) ) { |
| 518 | 378 | return $transient; |
| 519 | 379 | } |
| @@ -544,15 +404,12 @@ | ||
| 544 | 404 | * |
| 545 | 405 | * @since 3.04.03 |
| 546 | 406 | * |
| 547 | 407 | * @param object $transient The current plugin info saved for update. |
| 548 | - * | |
| 549 | - * @return void | |
| 550 | 408 | */ |
| 551 | 409 | private function prepare_update_details( &$transient ) { |
| 552 | 410 | $version_info = $transient; |
| 553 | 411 | $has_beta_url = ! empty( $version_info->beta ); |
| 554 | - | |
| 555 | 412 | if ( $this->get_beta && ! $has_beta_url ) { |
| 556 | 413 | $version_info = (object) $this->get_api_info( $this->license ); |
| 557 | 414 | } |
| 558 | 415 | |
| @@ -557,9 +414,8 @@ | ||
| 557 | 414 | } |
| 558 | 415 | |
| 559 | 416 | if ( ! empty( $version_info->new_version ) ) { |
| 560 | 417 | $this->clear_old_plugin_version( $version_info ); |
| 561 | - | |
| 562 | 418 | if ( $version_info === false ) { |
| 563 | 419 | // Was cleared with timeout. |
| 564 | 420 | $transient = false; |
| 565 | 421 | } else { |
| @@ -575,12 +431,8 @@ | ||
| 575 | 431 | /** |
| 576 | 432 | * Get the API info for this plugin |
| 577 | 433 | * |
| 578 | 434 | * @since 3.04.03 |
| 579 | - * | |
| 580 | - * @param string $license The license key. | |
| 581 | - * | |
| 582 | - * @return array The API info for the plugin. | |
| 583 | 435 | */ |
| 584 | 436 | protected function get_api_info( $license ) { |
| 585 | 437 | $api = new FrmFormApi( $license ); |
| 586 | 438 | $addon = $api->get_addon_for_license( $this ); |
| @@ -601,16 +453,11 @@ | ||
| 601 | 453 | * Make sure transients don't stick around on sites that |
| 602 | 454 | * don't save the transient expiration |
| 603 | 455 | * |
| 604 | 456 | * @since 2.05.05 |
| 605 | - * | |
| 606 | - * @param object $version_info The version info for the plugin. | |
| 607 | - * | |
| 608 | - * @return void | |
| 609 | 457 | */ |
| 610 | 458 | private function clear_old_plugin_version( &$version_info ) { |
| 611 | 459 | $timeout = ! empty( $version_info->timeout ) ? $version_info->timeout : 0; |
| 612 | - | |
| 613 | 460 | if ( ! empty( $timeout ) && time() > $timeout ) { |
| 614 | 461 | // Cache is expired. |
| 615 | 462 | $version_info = false; |
| 616 | 463 | $api = new FrmFormApi( $this->license ); |
| @@ -622,18 +469,13 @@ | ||
| 622 | 469 | * The beta url is always included if the download has a beta. |
| 623 | 470 | * Check if the beta should be downloaded. |
| 624 | 471 | * |
| 625 | 472 | * @since 3.04.03 |
| 626 | - * | |
| 627 | - * @param object $version_info The version info for the plugin. | |
| 628 | - * | |
| 629 | - * @return void | |
| 630 | 473 | */ |
| 631 | 474 | private function maybe_use_beta_url( &$version_info ) { |
| 632 | 475 | if ( $this->get_beta && ! empty( $version_info->beta ) ) { |
| 633 | 476 | $version_info->new_version = $version_info->beta['version']; |
| 634 | 477 | $version_info->package = $version_info->beta['package']; |
| 635 | - | |
| 636 | 478 | if ( ! empty( $version_info->plugin ) ) { |
| 637 | 479 | $version_info->plugin = $version_info->beta['plugin']; |
| 638 | 480 | } |
| 639 | 481 | } |
| @@ -638,13 +480,8 @@ | ||
| 638 | 480 | } |
| 639 | 481 | } |
| 640 | 482 | } |
| 641 | 483 | |
| 642 | - /** | |
| 643 | - * @param object $transient | |
| 644 | - * | |
| 645 | - * @return bool | |
| 646 | - */ | |
| 647 | 484 | private function is_current_version( $transient ) { |
| 648 | 485 | if ( empty( $transient->checked ) || ! isset( $transient->checked[ $this->plugin_folder ] ) ) { |
| 649 | 486 | return false; |
| 650 | 487 | } |
| @@ -649,9 +486,8 @@ | ||
| 649 | 486 | return false; |
| 650 | 487 | } |
| 651 | 488 | |
| 652 | 489 | $response = empty( $transient->response ); |
| 653 | - | |
| 654 | 490 | if ( $response ) { |
| 655 | 491 | return true; |
| 656 | 492 | } |
| 657 | 493 | |
| @@ -665,18 +501,12 @@ | ||
| 665 | 501 | $last_cleared = get_option( 'frm_last_cleared' ); |
| 666 | 502 | return $last_cleared && $last_cleared > gmdate( 'Y-m-d H:i:s', strtotime( '-5 minutes' ) ); |
| 667 | 503 | } |
| 668 | 504 | |
| 669 | - /** | |
| 670 | - * @return void | |
| 671 | - */ | |
| 672 | 505 | private function cleared_plugins() { |
| 673 | 506 | update_option( 'frm_last_cleared', gmdate( 'Y-m-d H:i:s' ) ); |
| 674 | 507 | } |
| 675 | 508 | |
| 676 | - /** | |
| 677 | - * @return void | |
| 678 | - */ | |
| 679 | 509 | private function is_license_revoked() { |
| 680 | 510 | if ( empty( $this->license ) || empty( $this->plugin_slug ) || isset( $_POST['license'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 681 | 511 | return; |
| 682 | 512 | } |
| @@ -691,9 +521,8 @@ | ||
| 691 | 521 | return; |
| 692 | 522 | } |
| 693 | 523 | |
| 694 | 524 | $response = $this->get_license_status(); |
| 695 | - | |
| 696 | 525 | if ( 'revoked' === $response['status'] || 'blocked' === $response['status'] || 'disabled' === $response['status'] || 'missing' === $response['status'] ) { |
| 697 | 526 | $this->clear_license(); |
| 698 | 527 | } |
| 699 | 528 | } |
| @@ -708,9 +537,8 @@ | ||
| 708 | 537 | */ |
| 709 | 538 | private function checked_recently( $time, $required_status = '' ) { |
| 710 | 539 | $last_checked = $this->last_checked(); |
| 711 | 540 | $is_429 = isset( $last_checked['response_code'] ) && 429 === $last_checked['response_code']; |
| 712 | - | |
| 713 | 541 | if ( $is_429 ) { |
| 714 | 542 | // If the last check was a a rate limit, we'll need to check again sooner. |
| 715 | 543 | $time = '5 minutes'; |
| 716 | 544 | $required_status = ''; |
| @@ -720,9 +548,9 @@ | ||
| 720 | 548 | // If the last check was invalid, we don't need to check again. |
| 721 | 549 | return true; |
| 722 | 550 | } |
| 723 | 551 | |
| 724 | - $checked_time = $last_checked['time'] ?? false; | |
| 552 | + $checked_time = isset( $last_checked['time'] ) ? $last_checked['time'] : false; | |
| 725 | 553 | $time_ago = gmdate( 'Y-m-d H:i:s', strtotime( '-' . $time ) ); |
| 726 | 554 | return $checked_time && $checked_time > $time_ago; |
| 727 | 555 | } |
| 728 | 556 | |
| @@ -736,15 +564,13 @@ | ||
| 736 | 564 | $last_checked = get_site_option( $this->transient_key() ); |
| 737 | 565 | } else { |
| 738 | 566 | $last_checked = get_option( $this->transient_key() ); |
| 739 | 567 | } |
| 740 | - | |
| 741 | 568 | if ( $last_checked && ! is_array( $last_checked ) ) { |
| 742 | 569 | // Get string into array for existing values. |
| 743 | 570 | $last_checked = array( 'time' => $last_checked ); |
| 744 | 571 | } |
| 745 | - | |
| 746 | - return $last_checked ? $last_checked : array(); | |
| 572 | + return $last_checked ? (array) $last_checked : array(); | |
| 747 | 573 | } |
| 748 | 574 | |
| 749 | 575 | /** |
| 750 | 576 | * @return void |
| @@ -750,9 +576,8 @@ | ||
| 750 | 576 | * @return void |
| 751 | 577 | */ |
| 752 | 578 | private function update_last_checked() { |
| 753 | 579 | $this->save_response['time'] = gmdate( 'Y-m-d H:i:s' ); |
| 754 | - | |
| 755 | 580 | if ( is_multisite() ) { |
| 756 | 581 | update_site_option( $this->transient_key(), $this->save_response ); |
| 757 | 582 | } else { |
| 758 | 583 | update_option( $this->transient_key(), $this->save_response ); |
| @@ -760,24 +585,18 @@ | ||
| 760 | 585 | } |
| 761 | 586 | |
| 762 | 587 | /** |
| 763 | 588 | * Use a new cache after the license is changed, or Formidable is updated. |
| 764 | - * | |
| 765 | - * @return string | |
| 766 | 589 | */ |
| 767 | 590 | private function transient_key() { |
| 768 | 591 | return 'frm_' . md5( sanitize_key( $this->license . '_' . $this->plugin_slug ) ); |
| 769 | 592 | } |
| 770 | 593 | |
| 771 | - /** | |
| 772 | - * @return void | |
| 773 | - */ | |
| 774 | 594 | public static function activate() { |
| 775 | 595 | FrmAppHelper::permission_check( 'frm_change_settings' ); |
| 776 | 596 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
| 777 | 597 | |
| 778 | 598 | $license = stripslashes( FrmAppHelper::get_param( 'license', '', 'post', 'sanitize_text_field' ) ); |
| 779 | - | |
| 780 | 599 | if ( empty( $license ) ) { |
| 781 | 600 | wp_send_json( |
| 782 | 601 | array( |
| 783 | 602 | 'message' => __( 'Oops! You forgot to enter your license number.', 'formidable' ), |
| @@ -788,20 +607,13 @@ | ||
| 788 | 607 | |
| 789 | 608 | $plugin_slug = FrmAppHelper::get_param( 'plugin', '', 'post', 'sanitize_text_field' ); |
| 790 | 609 | $response = self::activate_license_for_plugin( $license, $plugin_slug ); |
| 791 | 610 | |
| 792 | - FrmInbox::clear_cache(); | |
| 793 | - | |
| 794 | 611 | wp_send_json( $response ); |
| 795 | 612 | } |
| 796 | 613 | |
| 797 | 614 | /** |
| 798 | 615 | * @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 | 616 | */ |
| 805 | 617 | public static function activate_license_for_plugin( $license, $plugin_slug ) { |
| 806 | 618 | $this_plugin = self::get_addon( $plugin_slug ); |
| 807 | 619 | return $this_plugin->activate_license( $license ); |
| @@ -806,13 +618,8 @@ | ||
| 806 | 618 | $this_plugin = self::get_addon( $plugin_slug ); |
| 807 | 619 | return $this_plugin->activate_license( $license ); |
| 808 | 620 | } |
| 809 | 621 | |
| 810 | - /** | |
| 811 | - * @param string $license The license key. | |
| 812 | - * | |
| 813 | - * @return array The response from the license activation. | |
| 814 | - */ | |
| 815 | 622 | private function activate_license( $license ) { |
| 816 | 623 | $this->set_license( $license ); |
| 817 | 624 | $this->license = $license; |
| 818 | 625 | |
| @@ -825,9 +632,8 @@ | ||
| 825 | 632 | if ( $response['error'] ) { |
| 826 | 633 | $response['message'] = $response['status']; |
| 827 | 634 | } else { |
| 828 | 635 | $messages = $this->get_messages(); |
| 829 | - | |
| 830 | 636 | if ( is_string( $response['status'] ) && isset( $messages[ $response['status'] ] ) ) { |
| 831 | 637 | $response['message'] = $messages[ $response['status'] ]; |
| 832 | 638 | } else { |
| 833 | 639 | $response['message'] = FrmAppHelper::kses( $response['status'], array( 'a' ) ); |
| @@ -833,9 +639,8 @@ | ||
| 833 | 639 | $response['message'] = FrmAppHelper::kses( $response['status'], array( 'a' ) ); |
| 834 | 640 | } |
| 835 | 641 | |
| 836 | 642 | $is_valid = false; |
| 837 | - | |
| 838 | 643 | if ( 'valid' === $response['status'] ) { |
| 839 | 644 | $is_valid = 'valid'; |
| 840 | 645 | $response['success'] = true; |
| 841 | 646 | } |
| @@ -865,11 +670,8 @@ | ||
| 865 | 670 | ) |
| 866 | 671 | ); |
| 867 | 672 | } |
| 868 | 673 | |
| 869 | - /** | |
| 870 | - * @return array | |
| 871 | - */ | |
| 872 | 674 | private function get_license_status() { |
| 873 | 675 | $this->set_running(); |
| 874 | 676 | |
| 875 | 677 | $response = array( |
| @@ -875,9 +677,8 @@ | ||
| 875 | 677 | $response = array( |
| 876 | 678 | 'status' => 'missing', |
| 877 | 679 | 'error' => true, |
| 878 | 680 | ); |
| 879 | - | |
| 880 | 681 | if ( empty( $this->license ) ) { |
| 881 | 682 | $response['error'] = false; |
| 882 | 683 | |
| 883 | 684 | return $response; |
| @@ -904,11 +705,8 @@ | ||
| 904 | 705 | $this->done_running(); |
| 905 | 706 | return $response; |
| 906 | 707 | } |
| 907 | 708 | |
| 908 | - /** | |
| 909 | - * @return array | |
| 910 | - */ | |
| 911 | 709 | private function get_messages() { |
| 912 | 710 | return array( |
| 913 | 711 | 'valid' => __( 'Your license has been activated. Enjoy!', 'formidable' ), |
| 914 | 712 | 'invalid' => __( 'That license key is invalid', 'formidable' ), |
| @@ -921,10 +719,8 @@ | ||
| 921 | 719 | } |
| 922 | 720 | |
| 923 | 721 | /** |
| 924 | 722 | * @since 4.03 |
| 925 | - * | |
| 926 | - * @return void | |
| 927 | 723 | */ |
| 928 | 724 | public static function reset_cache() { |
| 929 | 725 | FrmAppHelper::permission_check( 'frm_change_settings' ); |
| 930 | 726 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
| @@ -939,11 +735,8 @@ | ||
| 939 | 735 | |
| 940 | 736 | wp_send_json( $response ); |
| 941 | 737 | } |
| 942 | 738 | |
| 943 | - /** | |
| 944 | - * @return void | |
| 945 | - */ | |
| 946 | 739 | public static function deactivate() { |
| 947 | 740 | FrmAppHelper::permission_check( 'frm_change_settings' ); |
| 948 | 741 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
| 949 | 742 | |
| @@ -952,13 +745,11 @@ | ||
| 952 | 745 | $response = array( |
| 953 | 746 | 'success' => false, |
| 954 | 747 | 'message' => '', |
| 955 | 748 | ); |
| 956 | - | |
| 957 | 749 | try { |
| 958 | 750 | // $license_data->license will be either "deactivated" or "failed" |
| 959 | 751 | $license_data = $this_plugin->send_mothership_request( 'deactivate_license' ); |
| 960 | - | |
| 961 | 752 | if ( is_array( $license_data ) && 'deactivated' === $license_data['license'] ) { |
| 962 | 753 | $response['success'] = true; |
| 963 | 754 | $response['message'] = __( 'That license was removed successfully', 'formidable' ); |
| 964 | 755 | } else { |
| @@ -968,9 +759,8 @@ | ||
| 968 | 759 | $response['message'] = $e->getMessage(); |
| 969 | 760 | } |
| 970 | 761 | |
| 971 | 762 | $this_plugin->clear_license(); |
| 972 | - FrmInbox::clear_cache(); | |
| 973 | 763 | |
| 974 | 764 | wp_send_json( $response ); |
| 975 | 765 | } |
| 976 | 766 | |
| @@ -975,10 +765,8 @@ | ||
| 975 | 765 | } |
| 976 | 766 | |
| 977 | 767 | /** |
| 978 | 768 | * @since 4.03 |
| 979 | - * | |
| 980 | - * @return FrmAddon | |
| 981 | 769 | */ |
| 982 | 770 | private static function set_license_from_post() { |
| 983 | 771 | $plugin_slug = FrmAppHelper::get_param( 'plugin', '', 'post', 'sanitize_text_field' ); |
| 984 | 772 | $this_plugin = self::get_addon( $plugin_slug ); |
| @@ -987,10 +775,8 @@ | ||
| 987 | 775 | return $this_plugin; |
| 988 | 776 | } |
| 989 | 777 | |
| 990 | 778 | /** |
| 991 | - * @param string $action | |
| 992 | - * | |
| 993 | 779 | * @return string |
| 994 | 780 | */ |
| 995 | 781 | public function send_mothership_request( $action ) { |
| 996 | 782 | $api_params = array( |
| @@ -997,9 +783,8 @@ | ||
| 997 | 783 | 'edd_action' => $action, |
| 998 | 784 | 'license' => $this->license, |
| 999 | 785 | 'url' => home_url(), |
| 1000 | 786 | ); |
| 1001 | - | |
| 1002 | 787 | if ( is_numeric( $this->download_id ) ) { |
| 1003 | 788 | $api_params['item_id'] = absint( $this->download_id ); |
| 1004 | 789 | } else { |
| 1005 | 790 | $api_params['item_name'] = rawurlencode( $this->plugin_name ); |
| @@ -1018,9 +803,8 @@ | ||
| 1018 | 803 | $body = wp_remote_retrieve_body( $resp ); |
| 1019 | 804 | $this->save_status = array( 'response_code' => wp_remote_retrieve_response_code( $resp ) ); |
| 1020 | 805 | |
| 1021 | 806 | $message = __( 'Your License Key was invalid', 'formidable' ); |
| 1022 | - | |
| 1023 | 807 | if ( is_wp_error( $resp ) ) { |
| 1024 | 808 | $link = FrmAppHelper::admin_upgrade_link( 'api', 'knowledgebase/why-cant-i-activate-formidable-pro/' ); |
| 1025 | 809 | /* translators: %1$s: Start link HTML, %2$s: End link HTML */ |
| 1026 | 810 | $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>' ); |
| @@ -1028,9 +812,8 @@ | ||
| 1028 | 812 | } elseif ( 'error' === $body || is_wp_error( $body ) ) { |
| 1029 | 813 | $message = __( 'You had an HTTP error connecting to the Formidable API', 'formidable' ); |
| 1030 | 814 | } else { |
| 1031 | 815 | $json_res = json_decode( $body, true ); |
| 1032 | - | |
| 1033 | 816 | if ( null !== $json_res ) { |
| 1034 | 817 | if ( is_array( $json_res ) && isset( $json_res['error'] ) ) { |
| 1035 | 818 | $message = $json_res['error']; |
| 1036 | 819 | } else { |
| @@ -1050,11 +833,8 @@ | ||
| 1050 | 833 | |
| 1051 | 834 | return $message; |
| 1052 | 835 | } |
| 1053 | 836 | |
| 1054 | - /** | |
| 1055 | - * @return void | |
| 1056 | - */ | |
| 1057 | 837 | public function manually_queue_update() { |
| 1058 | 838 | $updates = new stdClass(); |
| 1059 | 839 | $updates->last_checked = 0; |
| 1060 | 840 | $updates->response = array(); |