| @@ -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. |
| @@ -108,12 +48,12 @@ | ||
| 108 | 48 | */ |
| 109 | 49 | protected $should_clear_cache = true; |
| 110 | 50 | |
| 111 | 51 | public function __construct() { |
| 52 | + | |
| 112 | 53 | if ( empty( $this->plugin_slug ) ) { |
| 113 | 54 | $this->plugin_slug = preg_replace( '/[^a-zA-Z0-9_\s]/', '', str_replace( ' ', '_', strtolower( $this->plugin_name ) ) ); |
| 114 | 55 | } |
| 115 | - | |
| 116 | 56 | if ( empty( $this->option_name ) ) { |
| 117 | 57 | $this->option_name = 'edd_' . $this->plugin_slug . '_license_'; |
| 118 | 58 | } |
| 119 | 59 | |
| @@ -123,46 +63,38 @@ | ||
| 123 | 63 | add_filter( 'frm_installed_addons', array( &$this, 'insert_installed_addon' ) ); |
| 124 | 64 | $this->edd_plugin_updater(); |
| 125 | 65 | } |
| 126 | 66 | |
| 127 | - /** | |
| 128 | - * @return void | |
| 129 | - */ | |
| 130 | 67 | public static function load_hooks() { |
| 131 | 68 | add_filter( 'frm_include_addon_page', '__return_true' ); |
| 132 | 69 | new static(); |
| 133 | 70 | } |
| 134 | 71 | |
| 135 | - /** | |
| 136 | - * @param array $plugins | |
| 137 | - * | |
| 138 | - * @return array | |
| 139 | - */ | |
| 140 | 72 | public function insert_installed_addon( $plugins ) { |
| 141 | 73 | $plugins[ $this->plugin_slug ] = $this; |
| 74 | + | |
| 142 | 75 | return $plugins; |
| 143 | 76 | } |
| 144 | 77 | |
| 145 | - /** | |
| 146 | - * @param string $plugin_slug | |
| 147 | - * | |
| 148 | - * @return false|FrmAddon | |
| 149 | - */ | |
| 150 | 78 | public static function get_addon( $plugin_slug ) { |
| 151 | 79 | $plugins = apply_filters( 'frm_installed_addons', array() ); |
| 152 | - return $plugins[ $plugin_slug ] ?? false; | |
| 80 | + $plugin = false; | |
| 81 | + if ( isset( $plugins[ $plugin_slug ] ) ) { | |
| 82 | + $plugin = $plugins[ $plugin_slug ]; | |
| 83 | + } | |
| 84 | + | |
| 85 | + return $plugin; | |
| 153 | 86 | } |
| 154 | 87 | |
| 155 | - /** | |
| 156 | - * @return void | |
| 157 | - */ | |
| 158 | 88 | public function edd_plugin_updater() { |
| 89 | + | |
| 159 | 90 | $this->is_license_revoked(); |
| 160 | 91 | $license = $this->license; |
| 161 | 92 | |
| 162 | 93 | add_action( 'after_plugin_row_' . plugin_basename( $this->plugin_file ), array( $this, 'maybe_show_license_message' ), 10, 2 ); |
| 163 | 94 | |
| 164 | - if ( $license ) { | |
| 95 | + if ( ! empty( $license ) ) { | |
| 96 | + | |
| 165 | 97 | if ( 'formidable/formidable.php' !== $this->plugin_folder ) { |
| 166 | 98 | add_filter( 'plugins_api', array( &$this, 'plugins_api_filter' ), 10, 3 ); |
| 167 | 99 | } |
| 168 | 100 | |
| @@ -181,22 +113,21 @@ | ||
| 181 | 113 | * |
| 182 | 114 | * @return object $_data |
| 183 | 115 | */ |
| 184 | 116 | public function plugins_api_filter( $_data, $_action = '', $_args = null ) { |
| 185 | - if ( $_action !== 'plugin_information' ) { | |
| 117 | + | |
| 118 | + if ( $_action != 'plugin_information' ) { | |
| 186 | 119 | return $_data; |
| 187 | 120 | } |
| 188 | 121 | |
| 189 | 122 | $slug = basename( $this->plugin_file, '.php' ); |
| 190 | 123 | $slug2 = str_replace( '/' . $slug . '.php', '', $this->plugin_folder ); |
| 191 | - | |
| 192 | - if ( empty( $_args->slug ) || ( $_args->slug !== $slug && $_args->slug !== $slug2 ) ) { | |
| 124 | + if ( empty( $_args->slug ) || ( $_args->slug != $slug && $_args->slug !== $slug2 ) ) { | |
| 193 | 125 | return $_data; |
| 194 | 126 | } |
| 195 | 127 | |
| 196 | 128 | $item_id = $this->download_id; |
| 197 | - | |
| 198 | - if ( ! $item_id ) { | |
| 129 | + if ( empty( $item_id ) ) { | |
| 199 | 130 | $_data = array( |
| 200 | 131 | 'name' => $this->plugin_name, |
| 201 | 132 | 'excerpt' => '', |
| 202 | 133 | 'changelog' => 'See the full changelog at <a href="' . esc_url( $this->store_url . '/changelog/' ) . '"></a>', |
| @@ -220,21 +151,16 @@ | ||
| 220 | 151 | |
| 221 | 152 | return (object) $_data; |
| 222 | 153 | } |
| 223 | 154 | |
| 224 | - /** | |
| 225 | - * @return string | |
| 226 | - */ | |
| 227 | 155 | public function get_license() { |
| 228 | 156 | $license = $this->maybe_get_pro_license(); |
| 229 | - | |
| 230 | - if ( $license ) { | |
| 157 | + if ( ! empty( $license ) ) { | |
| 231 | 158 | return $license; |
| 232 | 159 | } |
| 233 | 160 | |
| 234 | 161 | $license = trim( get_option( $this->option_name . 'key' ) ); |
| 235 | - | |
| 236 | - if ( ! $license ) { | |
| 162 | + if ( empty( $license ) ) { | |
| 237 | 163 | $license = $this->activate_defined_license(); |
| 238 | 164 | } |
| 239 | 165 | |
| 240 | 166 | return $license; |
| @@ -241,14 +167,12 @@ | ||
| 241 | 167 | } |
| 242 | 168 | |
| 243 | 169 | /** |
| 244 | 170 | * @since 3.04.03 |
| 245 | - * | |
| 246 | - * @return false|string | |
| 247 | 171 | */ |
| 248 | 172 | protected function maybe_get_pro_license() { |
| 249 | 173 | // prevent a loop if $this is the pro plugin |
| 250 | - $get_license = FrmAppHelper::pro_is_installed() && is_callable( 'FrmProAppHelper::get_updater' ) && $this->plugin_name !== 'Formidable Pro'; | |
| 174 | + $get_license = FrmAppHelper::pro_is_installed() && is_callable( 'FrmProAppHelper::get_updater' ) && $this->plugin_name != 'Formidable Pro'; | |
| 251 | 175 | |
| 252 | 176 | if ( ! $get_license ) { |
| 253 | 177 | return false; |
| 254 | 178 | } |
| @@ -255,15 +179,13 @@ | ||
| 255 | 179 | |
| 256 | 180 | $api = new FrmFormApi(); |
| 257 | 181 | $api->get_pro_updater(); |
| 258 | 182 | $license = $api->get_license(); |
| 259 | - | |
| 260 | - if ( ! $license ) { | |
| 183 | + if ( empty( $license ) ) { | |
| 261 | 184 | return false; |
| 262 | 185 | } |
| 263 | 186 | |
| 264 | 187 | $this->get_api_info( $license ); |
| 265 | - | |
| 266 | 188 | if ( ! $this->is_parent_licence ) { |
| 267 | 189 | $license = false; |
| 268 | 190 | } |
| 269 | 191 | |
| @@ -273,17 +195,13 @@ | ||
| 273 | 195 | /** |
| 274 | 196 | * Activate the license in wp-config.php |
| 275 | 197 | * |
| 276 | 198 | * @since 2.04 |
| 277 | - * | |
| 278 | - * @return string | |
| 279 | 199 | */ |
| 280 | 200 | public function activate_defined_license() { |
| 281 | 201 | $license = $this->get_defined_license(); |
| 282 | - | |
| 283 | - if ( $license && ! $this->is_active() && ! $this->checked_recently( '1 day' ) ) { | |
| 202 | + if ( ! empty( $license ) && ! $this->is_active() && ! $this->checked_recently( '1 day' ) ) { | |
| 284 | 203 | $response = $this->activate_license( $license ); |
| 285 | - | |
| 286 | 204 | if ( ! $response['success'] ) { |
| 287 | 205 | $license = ''; |
| 288 | 206 | } |
| 289 | 207 | } |
| @@ -294,28 +212,19 @@ | ||
| 294 | 212 | /** |
| 295 | 213 | * Check the wp-config.php for the license key |
| 296 | 214 | * |
| 297 | 215 | * @since 2.04 |
| 298 | - * | |
| 299 | - * @return false|string | |
| 300 | 216 | */ |
| 301 | 217 | public function get_defined_license() { |
| 302 | - $constant_name = 'FRM_' . strtoupper( $this->plugin_slug ) . '_LICENSE'; | |
| 303 | - return defined( $constant_name ) ? constant( $constant_name ) : false; | |
| 218 | + $consant_name = 'FRM_' . strtoupper( $this->plugin_slug ) . '_LICENSE'; | |
| 219 | + | |
| 220 | + return defined( $consant_name ) ? constant( $consant_name ) : false; | |
| 304 | 221 | } |
| 305 | 222 | |
| 306 | - /** | |
| 307 | - * @param string $license | |
| 308 | - * | |
| 309 | - * @return void | |
| 310 | - */ | |
| 311 | 223 | public function set_license( $license ) { |
| 312 | 224 | update_option( $this->option_name . 'key', $license ); |
| 313 | 225 | } |
| 314 | 226 | |
| 315 | - /** | |
| 316 | - * @return mixed | |
| 317 | - */ | |
| 318 | 227 | public function is_active() { |
| 319 | 228 | return get_option( $this->option_name . 'active' ); |
| 320 | 229 | } |
| 321 | 230 | |
| @@ -322,10 +231,8 @@ | ||
| 322 | 231 | /** |
| 323 | 232 | * @since 3.04.03 |
| 324 | 233 | * |
| 325 | 234 | * @param array|string $error |
| 326 | - * | |
| 327 | - * @return void | |
| 328 | 235 | */ |
| 329 | 236 | public function maybe_clear_license( $error ) { |
| 330 | 237 | if ( is_array( $error ) && $error['code'] === 'disabled' && $error['license'] === $this->license ) { |
| 331 | 238 | $this->clear_license(); |
| @@ -331,11 +238,8 @@ | ||
| 331 | 238 | $this->clear_license(); |
| 332 | 239 | } |
| 333 | 240 | } |
| 334 | 241 | |
| 335 | - /** | |
| 336 | - * @return void | |
| 337 | - */ | |
| 338 | 242 | public function clear_license() { |
| 339 | 243 | delete_option( $this->option_name . 'active' ); |
| 340 | 244 | delete_option( $this->option_name . 'key' ); |
| 341 | 245 | |
| @@ -357,9 +261,8 @@ | ||
| 357 | 261 | * @return void |
| 358 | 262 | */ |
| 359 | 263 | protected function maybe_set_active( $is_valid ) { |
| 360 | 264 | update_option( $this->option_name . 'active', $is_valid ); |
| 361 | - | |
| 362 | 265 | if ( $is_valid ) { |
| 363 | 266 | $this->set_active( $is_valid ); |
| 364 | 267 | return; |
| 365 | 268 | } |
| @@ -370,13 +273,8 @@ | ||
| 370 | 273 | delete_option( $this->option_name . 'key' ); |
| 371 | 274 | $this->license = ''; |
| 372 | 275 | } |
| 373 | 276 | |
| 374 | - /** | |
| 375 | - * @param bool $is_active | |
| 376 | - * | |
| 377 | - * @return void | |
| 378 | - */ | |
| 379 | 277 | public function set_active( $is_active ) { |
| 380 | 278 | $this->delete_cache(); |
| 381 | 279 | FrmAppHelper::save_combined_js(); |
| 382 | 280 | $this->update_pro_capabilities(); |
| @@ -385,10 +283,8 @@ | ||
| 385 | 283 | /** |
| 386 | 284 | * Updates roles capabilities after pro license is active. |
| 387 | 285 | * |
| 388 | 286 | * @since 5.0 |
| 389 | - * | |
| 390 | - * @return void | |
| 391 | 287 | */ |
| 392 | 288 | protected function update_pro_capabilities() { |
| 393 | 289 | global $wp_roles; |
| 394 | 290 | |
| @@ -398,11 +294,10 @@ | ||
| 398 | 294 | |
| 399 | 295 | $caps = FrmAppHelper::frm_capabilities( 'pro_only' ); |
| 400 | 296 | $roles = get_editable_roles(); |
| 401 | 297 | $settings = new FrmSettings(); |
| 402 | - | |
| 403 | 298 | foreach ( $caps as $cap => $cap_desc ) { |
| 404 | - $cap_roles = (array) ( $settings->$cap ?? 'administrator' ); | |
| 299 | + $cap_roles = (array) ( isset( $settings->$cap ) ? $settings->$cap : 'administrator' ); | |
| 405 | 300 | |
| 406 | 301 | // Make sure administrators always have permissions. |
| 407 | 302 | if ( ! in_array( 'administrator', $cap_roles, true ) ) { |
| 408 | 303 | array_push( $cap_roles, 'administrator' ); |
| @@ -408,9 +303,9 @@ | ||
| 408 | 303 | array_push( $cap_roles, 'administrator' ); |
| 409 | 304 | } |
| 410 | 305 | |
| 411 | 306 | foreach ( $roles as $role => $details ) { |
| 412 | - if ( in_array( $role, $cap_roles, true ) ) { | |
| 307 | + if ( in_array( $role, $cap_roles ) ) { | |
| 413 | 308 | $wp_roles->add_cap( $role, $cap ); |
| 414 | 309 | } else { |
| 415 | 310 | $wp_roles->remove_cap( $role, $cap ); |
| 416 | 311 | } |
| @@ -419,10 +314,8 @@ | ||
| 419 | 314 | } |
| 420 | 315 | |
| 421 | 316 | /** |
| 422 | 317 | * @since 3.04.03 |
| 423 | - * | |
| 424 | - * @return void | |
| 425 | 318 | */ |
| 426 | 319 | protected function delete_cache() { |
| 427 | 320 | delete_transient( 'frm_api_licence' ); |
| 428 | 321 | |
| @@ -439,11 +332,8 @@ | ||
| 439 | 332 | $api->reset_cached(); |
| 440 | 333 | |
| 441 | 334 | $api = new FrmSalesApi(); |
| 442 | 335 | $api->reset_cached(); |
| 443 | - | |
| 444 | - $api = new FrmStyleApi(); | |
| 445 | - $api->reset_cached(); | |
| 446 | 336 | } |
| 447 | 337 | |
| 448 | 338 | /** |
| 449 | 339 | * The Pro version includes the show_license_message function. |
| @@ -449,13 +339,8 @@ | ||
| 449 | 339 | * The Pro version includes the show_license_message function. |
| 450 | 340 | * We need an extra check before we allow it to show a message. |
| 451 | 341 | * |
| 452 | 342 | * @since 3.04.03 |
| 453 | - * | |
| 454 | - * @param string $file File path of the plugin. | |
| 455 | - * @param array $plugin Plugin data. | |
| 456 | - * | |
| 457 | - * @return void | |
| 458 | 343 | */ |
| 459 | 344 | public function maybe_show_license_message( $file, $plugin ) { |
| 460 | 345 | if ( $this->is_expired_addon || isset( $plugin['package'] ) ) { |
| 461 | 346 | // let's not show a ton of duplicate messages |
| @@ -464,30 +349,22 @@ | ||
| 464 | 349 | |
| 465 | 350 | $this->show_license_message( $file, $plugin ); |
| 466 | 351 | } |
| 467 | 352 | |
| 468 | - /** | |
| 469 | - * @param string $file File path of the plugin. | |
| 470 | - * @param array $plugin Plugin data. | |
| 471 | - * | |
| 472 | - * @return void | |
| 473 | - */ | |
| 474 | 353 | public function show_license_message( $file, $plugin ) { |
| 475 | 354 | $message = ''; |
| 476 | - | |
| 477 | 355 | if ( empty( $this->license ) ) { |
| 478 | 356 | /* translators: %1$s: Plugin name, %2$s: Start link HTML, %3$s: end link HTML */ |
| 479 | - $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>' ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong | |
| 357 | + $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>' ); | |
| 480 | 358 | } else { |
| 481 | 359 | $api = new FrmFormApi( $this->license ); |
| 482 | 360 | $errors = $api->error_for_license(); |
| 483 | - | |
| 484 | - if ( $errors ) { | |
| 361 | + if ( ! empty( $errors ) ) { | |
| 485 | 362 | $message = reset( $errors ); |
| 486 | 363 | } |
| 487 | 364 | } |
| 488 | 365 | |
| 489 | - if ( ! $message ) { | |
| 366 | + if ( empty( $message ) ) { | |
| 490 | 367 | return; |
| 491 | 368 | } |
| 492 | 369 | |
| 493 | 370 | $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' ); |
| @@ -492,19 +369,14 @@ | ||
| 492 | 369 | |
| 493 | 370 | $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' ); |
| 494 | 371 | $id = sanitize_title( $plugin['Name'] ) . '-next'; |
| 495 | 372 | |
| 496 | - 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>'; // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong | |
| 497 | - FrmAppHelper::kses_echo( $message, 'a' ); | |
| 498 | - echo '<script type="text/javascript">var d = document.getElementById("' . esc_attr( $id ) . '").previousSibling;if ( d !== null ){ d.className = d.className + " update"; }</script>'; // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong | |
| 373 | + 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>'; | |
| 374 | + echo FrmAppHelper::kses( $message, 'a' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 375 | + echo '<script type="text/javascript">var d = document.getElementById("' . esc_attr( $id ) . '").previousSibling;if ( d !== null ){ d.className = d.className + " update"; }</script>'; | |
| 499 | 376 | echo '</p></div></td></tr>'; |
| 500 | 377 | } |
| 501 | 378 | |
| 502 | - /** | |
| 503 | - * @param mixed $transient | |
| 504 | - * | |
| 505 | - * @return mixed | |
| 506 | - */ | |
| 507 | 379 | public function clear_expired_download( $transient ) { |
| 508 | 380 | if ( ! is_object( $transient ) ) { |
| 509 | 381 | return $transient; |
| 510 | 382 | } |
| @@ -535,15 +407,12 @@ | ||
| 535 | 407 | * |
| 536 | 408 | * @since 3.04.03 |
| 537 | 409 | * |
| 538 | 410 | * @param object $transient The current plugin info saved for update. |
| 539 | - * | |
| 540 | - * @return void | |
| 541 | 411 | */ |
| 542 | 412 | private function prepare_update_details( &$transient ) { |
| 543 | 413 | $version_info = $transient; |
| 544 | 414 | $has_beta_url = ! empty( $version_info->beta ); |
| 545 | - | |
| 546 | 415 | if ( $this->get_beta && ! $has_beta_url ) { |
| 547 | 416 | $version_info = (object) $this->get_api_info( $this->license ); |
| 548 | 417 | } |
| 549 | 418 | |
| @@ -548,9 +417,8 @@ | ||
| 548 | 417 | } |
| 549 | 418 | |
| 550 | 419 | if ( ! empty( $version_info->new_version ) ) { |
| 551 | 420 | $this->clear_old_plugin_version( $version_info ); |
| 552 | - | |
| 553 | 421 | if ( $version_info === false ) { |
| 554 | 422 | // Was cleared with timeout. |
| 555 | 423 | $transient = false; |
| 556 | 424 | } else { |
| @@ -566,12 +434,8 @@ | ||
| 566 | 434 | /** |
| 567 | 435 | * Get the API info for this plugin |
| 568 | 436 | * |
| 569 | 437 | * @since 3.04.03 |
| 570 | - * | |
| 571 | - * @param string $license The license key. | |
| 572 | - * | |
| 573 | - * @return array The API info for the plugin. | |
| 574 | 438 | */ |
| 575 | 439 | protected function get_api_info( $license ) { |
| 576 | 440 | $api = new FrmFormApi( $license ); |
| 577 | 441 | $addon = $api->get_addon_for_license( $this ); |
| @@ -592,17 +456,12 @@ | ||
| 592 | 456 | * Make sure transients don't stick around on sites that |
| 593 | 457 | * don't save the transient expiration |
| 594 | 458 | * |
| 595 | 459 | * @since 2.05.05 |
| 596 | - * | |
| 597 | - * @param object $version_info The version info for the plugin. | |
| 598 | - * | |
| 599 | - * @return void | |
| 600 | 460 | */ |
| 601 | 461 | private function clear_old_plugin_version( &$version_info ) { |
| 602 | 462 | $timeout = ! empty( $version_info->timeout ) ? $version_info->timeout : 0; |
| 603 | - | |
| 604 | - if ( $timeout && time() > $timeout ) { | |
| 463 | + if ( ! empty( $timeout ) && time() > $timeout ) { | |
| 605 | 464 | // Cache is expired. |
| 606 | 465 | $version_info = false; |
| 607 | 466 | $api = new FrmFormApi( $this->license ); |
| 608 | 467 | $api->reset_cached(); |
| @@ -613,18 +472,13 @@ | ||
| 613 | 472 | * The beta url is always included if the download has a beta. |
| 614 | 473 | * Check if the beta should be downloaded. |
| 615 | 474 | * |
| 616 | 475 | * @since 3.04.03 |
| 617 | - * | |
| 618 | - * @param object $version_info The version info for the plugin. | |
| 619 | - * | |
| 620 | - * @return void | |
| 621 | 476 | */ |
| 622 | 477 | private function maybe_use_beta_url( &$version_info ) { |
| 623 | 478 | if ( $this->get_beta && ! empty( $version_info->beta ) ) { |
| 624 | 479 | $version_info->new_version = $version_info->beta['version']; |
| 625 | 480 | $version_info->package = $version_info->beta['package']; |
| 626 | - | |
| 627 | 481 | if ( ! empty( $version_info->plugin ) ) { |
| 628 | 482 | $version_info->plugin = $version_info->beta['plugin']; |
| 629 | 483 | } |
| 630 | 484 | } |
| @@ -629,13 +483,8 @@ | ||
| 629 | 483 | } |
| 630 | 484 | } |
| 631 | 485 | } |
| 632 | 486 | |
| 633 | - /** | |
| 634 | - * @param object $transient | |
| 635 | - * | |
| 636 | - * @return bool | |
| 637 | - */ | |
| 638 | 487 | private function is_current_version( $transient ) { |
| 639 | 488 | if ( empty( $transient->checked ) || ! isset( $transient->checked[ $this->plugin_folder ] ) ) { |
| 640 | 489 | return false; |
| 641 | 490 | } |
| @@ -640,14 +489,13 @@ | ||
| 640 | 489 | return false; |
| 641 | 490 | } |
| 642 | 491 | |
| 643 | 492 | $response = empty( $transient->response ); |
| 644 | - | |
| 645 | 493 | if ( $response ) { |
| 646 | 494 | return true; |
| 647 | 495 | } |
| 648 | 496 | |
| 649 | - return isset( $transient->response ) && isset( $transient->response[ $this->plugin_folder ] ) && $transient->checked[ $this->plugin_folder ] === $transient->response[ $this->plugin_folder ]->new_version; // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong | |
| 497 | + return isset( $transient->response ) && isset( $transient->response[ $this->plugin_folder ] ) && $transient->checked[ $this->plugin_folder ] === $transient->response[ $this->plugin_folder ]->new_version; | |
| 650 | 498 | } |
| 651 | 499 | |
| 652 | 500 | /** |
| 653 | 501 | * @return bool |
| @@ -656,18 +504,12 @@ | ||
| 656 | 504 | $last_cleared = get_option( 'frm_last_cleared' ); |
| 657 | 505 | return $last_cleared && $last_cleared > gmdate( 'Y-m-d H:i:s', strtotime( '-5 minutes' ) ); |
| 658 | 506 | } |
| 659 | 507 | |
| 660 | - /** | |
| 661 | - * @return void | |
| 662 | - */ | |
| 663 | 508 | private function cleared_plugins() { |
| 664 | 509 | update_option( 'frm_last_cleared', gmdate( 'Y-m-d H:i:s' ) ); |
| 665 | 510 | } |
| 666 | 511 | |
| 667 | - /** | |
| 668 | - * @return void | |
| 669 | - */ | |
| 670 | 512 | private function is_license_revoked() { |
| 671 | 513 | if ( empty( $this->license ) || empty( $this->plugin_slug ) || isset( $_POST['license'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 672 | 514 | return; |
| 673 | 515 | } |
| @@ -682,9 +524,8 @@ | ||
| 682 | 524 | return; |
| 683 | 525 | } |
| 684 | 526 | |
| 685 | 527 | $response = $this->get_license_status(); |
| 686 | - | |
| 687 | 528 | if ( 'revoked' === $response['status'] || 'blocked' === $response['status'] || 'disabled' === $response['status'] || 'missing' === $response['status'] ) { |
| 688 | 529 | $this->clear_license(); |
| 689 | 530 | } |
| 690 | 531 | } |
| @@ -699,9 +540,8 @@ | ||
| 699 | 540 | */ |
| 700 | 541 | private function checked_recently( $time, $required_status = '' ) { |
| 701 | 542 | $last_checked = $this->last_checked(); |
| 702 | 543 | $is_429 = isset( $last_checked['response_code'] ) && 429 === $last_checked['response_code']; |
| 703 | - | |
| 704 | 544 | if ( $is_429 ) { |
| 705 | 545 | // If the last check was a a rate limit, we'll need to check again sooner. |
| 706 | 546 | $time = '5 minutes'; |
| 707 | 547 | $required_status = ''; |
| @@ -711,9 +551,9 @@ | ||
| 711 | 551 | // If the last check was invalid, we don't need to check again. |
| 712 | 552 | return true; |
| 713 | 553 | } |
| 714 | 554 | |
| 715 | - $checked_time = $last_checked['time'] ?? false; | |
| 555 | + $checked_time = isset( $last_checked['time'] ) ? $last_checked['time'] : false; | |
| 716 | 556 | $time_ago = gmdate( 'Y-m-d H:i:s', strtotime( '-' . $time ) ); |
| 717 | 557 | return $checked_time && $checked_time > $time_ago; |
| 718 | 558 | } |
| 719 | 559 | |
| @@ -722,16 +562,18 @@ | ||
| 722 | 562 | * |
| 723 | 563 | * @return array |
| 724 | 564 | */ |
| 725 | 565 | private function last_checked() { |
| 726 | - $last_checked = is_multisite() ? get_site_option( $this->transient_key() ) : get_option( $this->transient_key() ); | |
| 727 | - | |
| 566 | + if ( is_multisite() ) { | |
| 567 | + $last_checked = get_site_option( $this->transient_key() ); | |
| 568 | + } else { | |
| 569 | + $last_checked = get_option( $this->transient_key() ); | |
| 570 | + } | |
| 728 | 571 | if ( $last_checked && ! is_array( $last_checked ) ) { |
| 729 | 572 | // Get string into array for existing values. |
| 730 | 573 | $last_checked = array( 'time' => $last_checked ); |
| 731 | 574 | } |
| 732 | - | |
| 733 | - return $last_checked ? $last_checked : array(); | |
| 575 | + return $last_checked ? (array) $last_checked : array(); | |
| 734 | 576 | } |
| 735 | 577 | |
| 736 | 578 | /** |
| 737 | 579 | * @return void |
| @@ -737,9 +579,8 @@ | ||
| 737 | 579 | * @return void |
| 738 | 580 | */ |
| 739 | 581 | private function update_last_checked() { |
| 740 | 582 | $this->save_response['time'] = gmdate( 'Y-m-d H:i:s' ); |
| 741 | - | |
| 742 | 583 | if ( is_multisite() ) { |
| 743 | 584 | update_site_option( $this->transient_key(), $this->save_response ); |
| 744 | 585 | } else { |
| 745 | 586 | update_option( $this->transient_key(), $this->save_response ); |
| @@ -747,25 +588,19 @@ | ||
| 747 | 588 | } |
| 748 | 589 | |
| 749 | 590 | /** |
| 750 | 591 | * Use a new cache after the license is changed, or Formidable is updated. |
| 751 | - * | |
| 752 | - * @return string | |
| 753 | 592 | */ |
| 754 | 593 | private function transient_key() { |
| 755 | 594 | return 'frm_' . md5( sanitize_key( $this->license . '_' . $this->plugin_slug ) ); |
| 756 | 595 | } |
| 757 | 596 | |
| 758 | - /** | |
| 759 | - * @return void | |
| 760 | - */ | |
| 761 | 597 | public static function activate() { |
| 762 | 598 | FrmAppHelper::permission_check( 'frm_change_settings' ); |
| 763 | 599 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
| 764 | 600 | |
| 765 | 601 | $license = stripslashes( FrmAppHelper::get_param( 'license', '', 'post', 'sanitize_text_field' ) ); |
| 766 | - | |
| 767 | - if ( ! $license ) { | |
| 602 | + if ( empty( $license ) ) { | |
| 768 | 603 | wp_send_json( |
| 769 | 604 | array( |
| 770 | 605 | 'message' => __( 'Oops! You forgot to enter your license number.', 'formidable' ), |
| 771 | 606 | 'success' => false, |
| @@ -782,13 +617,8 @@ | ||
| 782 | 617 | } |
| 783 | 618 | |
| 784 | 619 | /** |
| 785 | 620 | * @since 4.08 |
| 786 | - * | |
| 787 | - * @param string $license The license key. | |
| 788 | - * @param string $plugin_slug The plugin slug. | |
| 789 | - * | |
| 790 | - * @return array The response from the license activation. | |
| 791 | 621 | */ |
| 792 | 622 | public static function activate_license_for_plugin( $license, $plugin_slug ) { |
| 793 | 623 | $this_plugin = self::get_addon( $plugin_slug ); |
| 794 | 624 | return $this_plugin->activate_license( $license ); |
| @@ -793,13 +623,8 @@ | ||
| 793 | 623 | $this_plugin = self::get_addon( $plugin_slug ); |
| 794 | 624 | return $this_plugin->activate_license( $license ); |
| 795 | 625 | } |
| 796 | 626 | |
| 797 | - /** | |
| 798 | - * @param string $license The license key. | |
| 799 | - * | |
| 800 | - * @return array The response from the license activation. | |
| 801 | - */ | |
| 802 | 627 | private function activate_license( $license ) { |
| 803 | 628 | $this->set_license( $license ); |
| 804 | 629 | $this->license = $license; |
| 805 | 630 | |
| @@ -812,9 +637,8 @@ | ||
| 812 | 637 | if ( $response['error'] ) { |
| 813 | 638 | $response['message'] = $response['status']; |
| 814 | 639 | } else { |
| 815 | 640 | $messages = $this->get_messages(); |
| 816 | - | |
| 817 | 641 | if ( is_string( $response['status'] ) && isset( $messages[ $response['status'] ] ) ) { |
| 818 | 642 | $response['message'] = $messages[ $response['status'] ]; |
| 819 | 643 | } else { |
| 820 | 644 | $response['message'] = FrmAppHelper::kses( $response['status'], array( 'a' ) ); |
| @@ -820,9 +644,8 @@ | ||
| 820 | 644 | $response['message'] = FrmAppHelper::kses( $response['status'], array( 'a' ) ); |
| 821 | 645 | } |
| 822 | 646 | |
| 823 | 647 | $is_valid = false; |
| 824 | - | |
| 825 | 648 | if ( 'valid' === $response['status'] ) { |
| 826 | 649 | $is_valid = 'valid'; |
| 827 | 650 | $response['success'] = true; |
| 828 | 651 | } |
| @@ -852,11 +675,8 @@ | ||
| 852 | 675 | ) |
| 853 | 676 | ); |
| 854 | 677 | } |
| 855 | 678 | |
| 856 | - /** | |
| 857 | - * @return array | |
| 858 | - */ | |
| 859 | 679 | private function get_license_status() { |
| 860 | 680 | $this->set_running(); |
| 861 | 681 | |
| 862 | 682 | $response = array( |
| @@ -862,11 +682,11 @@ | ||
| 862 | 682 | $response = array( |
| 863 | 683 | 'status' => 'missing', |
| 864 | 684 | 'error' => true, |
| 865 | 685 | ); |
| 866 | - | |
| 867 | 686 | if ( empty( $this->license ) ) { |
| 868 | 687 | $response['error'] = false; |
| 688 | + | |
| 869 | 689 | return $response; |
| 870 | 690 | } |
| 871 | 691 | |
| 872 | 692 | try { |
| @@ -890,11 +710,8 @@ | ||
| 890 | 710 | $this->done_running(); |
| 891 | 711 | return $response; |
| 892 | 712 | } |
| 893 | 713 | |
| 894 | - /** | |
| 895 | - * @return array | |
| 896 | - */ | |
| 897 | 714 | private function get_messages() { |
| 898 | 715 | return array( |
| 899 | 716 | 'valid' => __( 'Your license has been activated. Enjoy!', 'formidable' ), |
| 900 | 717 | 'invalid' => __( 'That license key is invalid', 'formidable' ), |
| @@ -907,10 +724,8 @@ | ||
| 907 | 724 | } |
| 908 | 725 | |
| 909 | 726 | /** |
| 910 | 727 | * @since 4.03 |
| 911 | - * | |
| 912 | - * @return void | |
| 913 | 728 | */ |
| 914 | 729 | public static function reset_cache() { |
| 915 | 730 | FrmAppHelper::permission_check( 'frm_change_settings' ); |
| 916 | 731 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
| @@ -925,11 +740,8 @@ | ||
| 925 | 740 | |
| 926 | 741 | wp_send_json( $response ); |
| 927 | 742 | } |
| 928 | 743 | |
| 929 | - /** | |
| 930 | - * @return void | |
| 931 | - */ | |
| 932 | 744 | public static function deactivate() { |
| 933 | 745 | FrmAppHelper::permission_check( 'frm_change_settings' ); |
| 934 | 746 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
| 935 | 747 | |
| @@ -938,13 +750,11 @@ | ||
| 938 | 750 | $response = array( |
| 939 | 751 | 'success' => false, |
| 940 | 752 | 'message' => '', |
| 941 | 753 | ); |
| 942 | - | |
| 943 | 754 | try { |
| 944 | 755 | // $license_data->license will be either "deactivated" or "failed" |
| 945 | 756 | $license_data = $this_plugin->send_mothership_request( 'deactivate_license' ); |
| 946 | - | |
| 947 | 757 | if ( is_array( $license_data ) && 'deactivated' === $license_data['license'] ) { |
| 948 | 758 | $response['success'] = true; |
| 949 | 759 | $response['message'] = __( 'That license was removed successfully', 'formidable' ); |
| 950 | 760 | } else { |
| @@ -961,10 +771,8 @@ | ||
| 961 | 771 | } |
| 962 | 772 | |
| 963 | 773 | /** |
| 964 | 774 | * @since 4.03 |
| 965 | - * | |
| 966 | - * @return FrmAddon | |
| 967 | 775 | */ |
| 968 | 776 | private static function set_license_from_post() { |
| 969 | 777 | $plugin_slug = FrmAppHelper::get_param( 'plugin', '', 'post', 'sanitize_text_field' ); |
| 970 | 778 | $this_plugin = self::get_addon( $plugin_slug ); |
| @@ -973,10 +781,8 @@ | ||
| 973 | 781 | return $this_plugin; |
| 974 | 782 | } |
| 975 | 783 | |
| 976 | 784 | /** |
| 977 | - * @param string $action | |
| 978 | - * | |
| 979 | 785 | * @return string |
| 980 | 786 | */ |
| 981 | 787 | public function send_mothership_request( $action ) { |
| 982 | 788 | $api_params = array( |
| @@ -983,9 +789,8 @@ | ||
| 983 | 789 | 'edd_action' => $action, |
| 984 | 790 | 'license' => $this->license, |
| 985 | 791 | 'url' => home_url(), |
| 986 | 792 | ); |
| 987 | - | |
| 988 | 793 | if ( is_numeric( $this->download_id ) ) { |
| 989 | 794 | $api_params['item_id'] = absint( $this->download_id ); |
| 990 | 795 | } else { |
| 991 | 796 | $api_params['item_name'] = rawurlencode( $this->plugin_name ); |
| @@ -1004,21 +809,23 @@ | ||
| 1004 | 809 | $body = wp_remote_retrieve_body( $resp ); |
| 1005 | 810 | $this->save_status = array( 'response_code' => wp_remote_retrieve_response_code( $resp ) ); |
| 1006 | 811 | |
| 1007 | 812 | $message = __( 'Your License Key was invalid', 'formidable' ); |
| 1008 | - | |
| 1009 | 813 | if ( is_wp_error( $resp ) ) { |
| 1010 | 814 | $link = FrmAppHelper::admin_upgrade_link( 'api', 'knowledgebase/why-cant-i-activate-formidable-pro/' ); |
| 1011 | 815 | /* translators: %1$s: Start link HTML, %2$s: End link HTML */ |
| 1012 | - $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>' ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong | |
| 816 | + $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>' ); | |
| 1013 | 817 | $message .= ' ' . $resp->get_error_message(); |
| 1014 | 818 | } elseif ( 'error' === $body || is_wp_error( $body ) ) { |
| 1015 | 819 | $message = __( 'You had an HTTP error connecting to the Formidable API', 'formidable' ); |
| 1016 | 820 | } else { |
| 1017 | 821 | $json_res = json_decode( $body, true ); |
| 1018 | - | |
| 1019 | 822 | if ( null !== $json_res ) { |
| 1020 | - $message = is_array( $json_res ) && isset( $json_res['error'] ) ? $json_res['error'] : $json_res; | |
| 823 | + if ( is_array( $json_res ) && isset( $json_res['error'] ) ) { | |
| 824 | + $message = $json_res['error']; | |
| 825 | + } else { | |
| 826 | + $message = $json_res; | |
| 827 | + } | |
| 1021 | 828 | } elseif ( ! empty( $resp['response'] ) && ! empty( $resp['response']['code'] ) ) { |
| 1022 | 829 | $resp['body'] = wp_strip_all_tags( $resp['body'] ); |
| 1023 | 830 | |
| 1024 | 831 | $message = sprintf( |
| @@ -1032,11 +839,8 @@ | ||
| 1032 | 839 | |
| 1033 | 840 | return $message; |
| 1034 | 841 | } |
| 1035 | 842 | |
| 1036 | - /** | |
| 1037 | - * @return void | |
| 1038 | - */ | |
| 1039 | 843 | public function manually_queue_update() { |
| 1040 | 844 | $updates = new stdClass(); |
| 1041 | 845 | $updates->last_checked = 0; |
| 1042 | 846 | $updates->response = array(); |