| @@ -26,23 +26,19 @@ | ||
| 26 | 26 | protected static $plugin; |
| 27 | 27 | |
| 28 | 28 | /** |
| 29 | 29 | * @since 6.15 |
| 30 | - * | |
| 31 | - * @return void | |
| 32 | 30 | */ |
| 33 | 31 | public static function load_admin_hooks() { |
| 34 | - add_action( 'admin_menu', self::class . '::menu', 100 ); | |
| 35 | - add_filter( 'pre_set_site_transient_update_plugins', self::class . '::check_update' ); | |
| 32 | + add_action( 'admin_menu', __CLASS__ . '::menu', 100 ); | |
| 33 | + add_filter( 'pre_set_site_transient_update_plugins', __CLASS__ . '::check_update' ); | |
| 36 | 34 | |
| 37 | - if ( ! FrmAppHelper::is_admin_page( 'formidable-addons' ) ) { | |
| 38 | - return; | |
| 35 | + if ( FrmAppHelper::is_admin_page( 'formidable-addons' ) ) { | |
| 36 | + self::$request_addon_url = 'https://connect.formidableforms.com/add-on-request/'; | |
| 37 | + | |
| 38 | + add_action( 'admin_enqueue_scripts', __CLASS__ . '::enqueue_assets', 15 ); | |
| 39 | + add_filter( 'frm_show_footer_links', '__return_false' ); | |
| 39 | 40 | } |
| 40 | - | |
| 41 | - self::$request_addon_url = 'https://connect.formidableforms.com/add-on-request/'; | |
| 42 | - | |
| 43 | - add_action( 'admin_enqueue_scripts', self::class . '::enqueue_assets', 15 ); | |
| 44 | - add_filter( 'frm_show_footer_links', '__return_false' ); | |
| 45 | 41 | } |
| 46 | 42 | |
| 47 | 43 | /** |
| 48 | 44 | * Enqueues the Add-Ons page scripts and styles. |
| @@ -100,26 +96,20 @@ | ||
| 100 | 96 | return; |
| 101 | 97 | } |
| 102 | 98 | |
| 103 | 99 | $label = __( 'Add-Ons', 'formidable' ); |
| 104 | - $label = '<span style="color:#3FCA89">' . esc_html( $label ) . '</span>'; | |
| 100 | + $label = '<span style="color:#3FCA89">' . $label . '</span>'; | |
| 105 | 101 | |
| 106 | 102 | add_submenu_page( 'formidable', 'Formidable | ' . __( 'Add-Ons', 'formidable' ), $label, 'frm_view_forms', 'formidable-addons', 'FrmAddonsController::list_addons' ); |
| 107 | 103 | |
| 108 | - // Remove default created subpage, make the page with highest priority as default. | |
| 104 | + // remove default created subpage, make the page with highest priority as default. | |
| 109 | 105 | remove_submenu_page( 'formidable', 'formidable' ); |
| 110 | 106 | |
| 111 | 107 | if ( ! FrmAppHelper::pro_is_installed() ) { |
| 112 | - $cta_text = FrmSalesApi::get_best_sale_value( 'menu_cta_text' ); | |
| 113 | - | |
| 114 | - if ( ! $cta_text ) { | |
| 115 | - $cta_text = __( 'Upgrade', 'formidable' ); | |
| 116 | - } | |
| 117 | - | |
| 118 | 108 | add_submenu_page( |
| 119 | 109 | 'formidable', |
| 120 | 110 | 'Formidable | ' . __( 'Upgrade', 'formidable' ), |
| 121 | - '<span class="frm-upgrade-submenu">' . esc_html( $cta_text ) . '</span>', | |
| 111 | + '<span class="frm-upgrade-submenu">' . __( 'Upgrade', 'formidable' ) . '</span>', | |
| 122 | 112 | 'frm_view_forms', |
| 123 | 113 | 'formidable-pro-upgrade', |
| 124 | 114 | function () { |
| 125 | 115 | // This function doesn't need to do anything. |
| @@ -128,9 +118,9 @@ | ||
| 128 | 118 | ); |
| 129 | 119 | } elseif ( 'formidable-pro-upgrade' === FrmAppHelper::get_param( 'page' ) ) { |
| 130 | 120 | wp_safe_redirect( admin_url( 'admin.php?page=formidable' ) ); |
| 131 | 121 | exit; |
| 132 | - }//end if | |
| 122 | + } | |
| 133 | 123 | } |
| 134 | 124 | |
| 135 | 125 | /** |
| 136 | 126 | * @return void |
| @@ -147,9 +137,9 @@ | ||
| 147 | 137 | |
| 148 | 138 | if ( isset( $addons['error'] ) ) { |
| 149 | 139 | $api = new FrmFormApi(); |
| 150 | 140 | $errors = $api->get_error_from_response( $addons ); |
| 151 | - $license_type = $addons['error']['type'] ?? ''; | |
| 141 | + $license_type = isset( $addons['error']['type'] ) ? $addons['error']['type'] : ''; | |
| 152 | 142 | unset( $addons['error'] ); |
| 153 | 143 | } |
| 154 | 144 | |
| 155 | 145 | $pro = array( |
| @@ -156,10 +146,9 @@ | ||
| 156 | 146 | 'pro' => array( |
| 157 | 147 | 'title' => 'Formidable Forms Pro', |
| 158 | 148 | 'slug' => 'formidable-pro', |
| 159 | 149 | 'released' => '2011-02-05', |
| 160 | - 'docs' => 'knowledgebase/what-is-the-difference-between-the-lite-free-and-pro-version/', | |
| 161 | - 'docs_label' => __( 'Why Upgrade', 'formidable' ), | |
| 150 | + 'docs' => 'knowledgebase/', | |
| 162 | 151 | 'categories' => array( 'basic', 'plus', 'business', 'elite' ), |
| 163 | 152 | 'excerpt' => 'Create calculators, surveys, smart forms, and data-driven applications. Build directories, real estate listings, job boards, and much more.', |
| 164 | 153 | ), |
| 165 | 154 | ); |
| @@ -194,18 +183,15 @@ | ||
| 194 | 183 | ); |
| 195 | 184 | |
| 196 | 185 | // Extract the elements to move |
| 197 | 186 | foreach ( $plans as $plan ) { |
| 198 | - if ( ! isset( self::$categories[ $plan ] ) ) { | |
| 199 | - continue; | |
| 187 | + if ( isset( self::$categories[ $plan ] ) ) { | |
| 188 | + $bottom_categories[ $plan ] = self::$categories[ $plan ]; | |
| 189 | + unset( self::$categories[ $plan ] ); | |
| 200 | 190 | } |
| 201 | - | |
| 202 | - $bottom_categories[ $plan ] = self::$categories[ $plan ]; | |
| 203 | - unset( self::$categories[ $plan ] ); | |
| 204 | 191 | } |
| 205 | 192 | |
| 206 | 193 | $special_categories = array(); |
| 207 | - | |
| 208 | 194 | if ( 'elite' !== self::license_type() ) { |
| 209 | 195 | $special_categories['available-addons'] = array( |
| 210 | 196 | 'name' => __( 'Available', 'formidable' ), |
| 211 | 197 | // To be assigned via JavaScript. |
| @@ -237,9 +223,8 @@ | ||
| 237 | 223 | * |
| 238 | 224 | * @since 6.15 |
| 239 | 225 | * |
| 240 | 226 | * @param array $addon The addon array that will be modified by reference. |
| 241 | - * | |
| 242 | 227 | * @return void |
| 243 | 228 | */ |
| 244 | 229 | protected static function set_categories( &$addon ) { |
| 245 | 230 | if ( ! isset( $addon['categories'] ) ) { |
| @@ -270,11 +255,11 @@ | ||
| 270 | 255 | * @return void |
| 271 | 256 | */ |
| 272 | 257 | public static function license_settings() { |
| 273 | 258 | $plugins = apply_filters( 'frm_installed_addons', array() ); |
| 259 | + if ( empty( $plugins ) ) { | |
| 260 | + esc_html_e( 'There are no plugins on your site that require a license', 'formidable' ); | |
| 274 | 261 | |
| 275 | - if ( ! $plugins ) { | |
| 276 | - esc_html_e( 'There are no plugins on your site that require a license', 'formidable' ); | |
| 277 | 262 | return; |
| 278 | 263 | } |
| 279 | 264 | |
| 280 | 265 | ksort( $plugins ); |
| @@ -288,15 +273,15 @@ | ||
| 288 | 273 | protected static function get_api_addons() { |
| 289 | 274 | $api = new FrmFormApi(); |
| 290 | 275 | $addons = $api->get_api_info(); |
| 291 | 276 | |
| 292 | - if ( ! $addons ) { | |
| 293 | - return self::fallback_plugin_list(); | |
| 294 | - } | |
| 295 | - | |
| 296 | - foreach ( $addons as $k => $addon ) { | |
| 297 | - if ( empty( $addon['excerpt'] ) && $k !== 'error' ) { | |
| 298 | - unset( $addons[ $k ] ); | |
| 277 | + if ( empty( $addons ) ) { | |
| 278 | + $addons = self::fallback_plugin_list(); | |
| 279 | + } else { | |
| 280 | + foreach ( $addons as $k => $addon ) { | |
| 281 | + if ( empty( $addon['excerpt'] ) && $k !== 'error' ) { | |
| 282 | + unset( $addons[ $k ] ); | |
| 283 | + } | |
| 299 | 284 | } |
| 300 | 285 | } |
| 301 | 286 | |
| 302 | 287 | return $addons; |
| @@ -309,9 +294,11 @@ | ||
| 309 | 294 | * |
| 310 | 295 | * @return int Count of addons. |
| 311 | 296 | */ |
| 312 | 297 | public static function get_addons_count() { |
| 313 | - return count( self::get_api_addons() ); | |
| 298 | + $addons = self::get_api_addons(); | |
| 299 | + | |
| 300 | + return count( $addons ); | |
| 314 | 301 | } |
| 315 | 302 | |
| 316 | 303 | /** |
| 317 | 304 | * If the API is unable to connect, show something on the addons page |
| @@ -316,9 +303,8 @@ | ||
| 316 | 303 | /** |
| 317 | 304 | * If the API is unable to connect, show something on the addons page |
| 318 | 305 | * |
| 319 | 306 | * @since 3.04.03 |
| 320 | - * | |
| 321 | 307 | * @return array |
| 322 | 308 | */ |
| 323 | 309 | protected static function fallback_plugin_list() { |
| 324 | 310 | $list = array( |
| @@ -329,19 +315,19 @@ | ||
| 329 | 315 | 'excerpt' => 'Enhance your basic Formidable forms with a plethora of Pro field types and features. Create advanced forms and data-driven applications in minutes.', |
| 330 | 316 | ), |
| 331 | 317 | 'mailchimp' => array( |
| 332 | 318 | 'title' => 'Mailchimp Forms', |
| 333 | - 'excerpt' => 'Get on the path to more sales and leads in a matter of minutes. Add leads to a Mailchimp mailing list when they submit forms and update their information along with the entry.', // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong | |
| 319 | + 'excerpt' => 'Get on the path to more sales and leads in a matter of minutes. Add leads to a Mailchimp mailing list when they submit forms and update their information along with the entry.', | |
| 334 | 320 | ), |
| 335 | 321 | 'registration' => array( |
| 336 | 322 | 'title' => 'User Registration Forms', |
| 337 | 323 | 'link' => 'downloads/user-registration/', |
| 338 | - 'excerpt' => 'Give new users access to your site as quickly and painlessly as possible. Allow users to register, edit and be able to login to their profiles on your site from the front end in a clean, customized registration form.', // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong | |
| 324 | + 'excerpt' => 'Give new users access to your site as quickly and painlessly as possible. Allow users to register, edit and be able to login to their profiles on your site from the front end in a clean, customized registration form.', | |
| 339 | 325 | ), |
| 340 | 326 | 'paypal' => array( |
| 341 | 327 | 'title' => 'PayPal Standard Forms', |
| 342 | 328 | 'link' => 'downloads/paypal-standard/', |
| 343 | - 'excerpt' => 'Automate your business by collecting instant payments from your clients. Collect information, calculate a total, and send them on to PayPal. Require a payment before publishing content on your site.', // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong | |
| 329 | + 'excerpt' => 'Automate your business by collecting instant payments from your clients. Collect information, calculate a total, and send them on to PayPal. Require a payment before publishing content on your site.', | |
| 344 | 330 | ), |
| 345 | 331 | 'stripe' => array( |
| 346 | 332 | 'title' => 'Stripe Forms', |
| 347 | 333 | 'docs' => 'knowledgebase/stripe/', |
| @@ -373,9 +359,9 @@ | ||
| 373 | 359 | 'excerpt' => 'Instantly add Bootstrap styling to all your Formidable forms.', |
| 374 | 360 | ), |
| 375 | 361 | 'zapier' => array( |
| 376 | 362 | 'title' => 'Zapier Forms', |
| 377 | - 'excerpt' => 'Connect with hundreds of different applications through Zapier. Insert a new row in a Google docs spreadsheet, post on Twitter, or add a new Dropbox file with your form.', // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong | |
| 363 | + 'excerpt' => 'Connect with hundreds of different applications through Zapier. Insert a new row in a Google docs spreadsheet, post on Twitter, or add a new Dropbox file with your form.', | |
| 378 | 364 | ), |
| 379 | 365 | 'signature' => array( |
| 380 | 366 | 'title' => 'Digital Signature Forms', |
| 381 | 367 | 'excerpt' => 'Add a signature field to your form. The user may write their signature with a trackpad/mouse or just type it.', |
| @@ -408,9 +394,8 @@ | ||
| 408 | 394 | foreach ( $list as $k => $info ) { |
| 409 | 395 | $info['slug'] = $k; |
| 410 | 396 | $list[ $k ] = array_merge( $defaults, $info ); |
| 411 | 397 | } |
| 412 | - | |
| 413 | 398 | return $list; |
| 414 | 399 | } |
| 415 | 400 | |
| 416 | 401 | /** |
| @@ -416,28 +401,25 @@ | ||
| 416 | 401 | /** |
| 417 | 402 | * If Pro is missing but has been authenticated, include a download URL |
| 418 | 403 | * |
| 419 | 404 | * @since 3.04.03 |
| 420 | - * | |
| 421 | 405 | * @return string |
| 422 | 406 | */ |
| 423 | 407 | public static function get_pro_download_url() { |
| 424 | - $api = new FrmFormApi( self::get_pro_license() ); | |
| 408 | + $license = self::get_pro_license(); | |
| 409 | + $api = new FrmFormApi( $license ); | |
| 425 | 410 | $downloads = $api->get_api_info(); |
| 426 | 411 | $pro = self::get_pro_from_addons( $downloads ); |
| 427 | 412 | |
| 428 | - return $pro['url'] ?? ''; | |
| 413 | + return isset( $pro['url'] ) ? $pro['url'] : ''; | |
| 429 | 414 | } |
| 430 | 415 | |
| 431 | 416 | /** |
| 432 | 417 | * @since 4.08 |
| 433 | - * | |
| 434 | - * @return string | |
| 435 | 418 | */ |
| 436 | 419 | public static function get_pro_license() { |
| 437 | 420 | $pro_cred_store = 'frmpro-credentials'; |
| 438 | 421 | $pro_wpmu_store = 'frmpro-wpmu-sitewide'; |
| 439 | - | |
| 440 | 422 | if ( is_multisite() && get_site_option( $pro_wpmu_store ) ) { |
| 441 | 423 | $creds = get_site_option( $pro_cred_store ); |
| 442 | 424 | } else { |
| 443 | 425 | $creds = get_option( $pro_cred_store ); |
| @@ -447,18 +429,16 @@ | ||
| 447 | 429 | return ''; |
| 448 | 430 | } |
| 449 | 431 | |
| 450 | 432 | $license = $creds['license']; |
| 451 | - | |
| 452 | - if ( ! $license ) { | |
| 433 | + if ( empty( $license ) ) { | |
| 453 | 434 | return ''; |
| 454 | 435 | } |
| 455 | 436 | |
| 456 | - if ( str_contains( $license, '-' ) ) { | |
| 457 | - // This is a fix for licenses saved in the past | |
| 458 | - return strtoupper( $license ); | |
| 437 | + if ( strpos( $license, '-' ) ) { | |
| 438 | + // this is a fix for licenses saved in the past | |
| 439 | + $license = strtoupper( $license ); | |
| 459 | 440 | } |
| 460 | - | |
| 461 | 441 | return $license; |
| 462 | 442 | } |
| 463 | 443 | |
| 464 | 444 | /** |
| @@ -464,26 +444,20 @@ | ||
| 464 | 444 | /** |
| 465 | 445 | * @since 4.08 |
| 466 | 446 | * |
| 467 | 447 | * @param array $addons |
| 468 | - * | |
| 469 | 448 | * @return array |
| 470 | 449 | */ |
| 471 | 450 | protected static function get_pro_from_addons( $addons ) { |
| 472 | - return $addons['93790'] ?? array(); | |
| 451 | + return isset( $addons['93790'] ) ? $addons['93790'] : array(); | |
| 473 | 452 | } |
| 474 | 453 | |
| 475 | 454 | /** |
| 476 | 455 | * @since 4.06 |
| 477 | - * @since 6.31 Added the $force_type param. | |
| 478 | - * | |
| 479 | - * @param bool $force_type Whether to resolve grandfathered licenses to their real license type. | |
| 480 | - * | |
| 481 | - * @return string | |
| 482 | 456 | */ |
| 483 | - public static function license_type( $force_type = false ) { | |
| 457 | + public static function license_type() { | |
| 484 | 458 | if ( is_callable( 'FrmProAddonsController::license_type' ) ) { |
| 485 | - return FrmProAddonsController::license_type( $force_type ); | |
| 459 | + return FrmProAddonsController::license_type(); | |
| 486 | 460 | } |
| 487 | 461 | |
| 488 | 462 | return 'free'; |
| 489 | 463 | } |
| @@ -488,45 +462,8 @@ | ||
| 488 | 462 | return 'free'; |
| 489 | 463 | } |
| 490 | 464 | |
| 491 | 465 | /** |
| 492 | - * Determine the license status for payment fee decisions. | |
| 493 | - * | |
| 494 | - * Mirrors the API's determine_status_from_license_details logic. | |
| 495 | - * | |
| 496 | - * @since 6.31 | |
| 497 | - * | |
| 498 | - * @return string 'active', 'expired', or 'free'. | |
| 499 | - */ | |
| 500 | - public static function get_payment_license_status() { | |
| 501 | - $version_info = self::get_primary_license_info(); | |
| 502 | - | |
| 503 | - if ( ! $version_info ) { | |
| 504 | - return 'free'; | |
| 505 | - } | |
| 506 | - | |
| 507 | - $error = $version_info['error'] ?? array(); | |
| 508 | - | |
| 509 | - if ( is_array( $error ) ) { | |
| 510 | - $code = $error['code'] ?? ''; | |
| 511 | - | |
| 512 | - if ( 'expired' === $code ) { | |
| 513 | - return 'expired'; | |
| 514 | - } | |
| 515 | - | |
| 516 | - if ( 'grandfathered' === $code && isset( $error['expires'] ) && gmdate( 'Y-m-d', $error['expires'] ) < '2016-04-26' ) { | |
| 517 | - return 'free'; | |
| 518 | - } | |
| 519 | - } | |
| 520 | - | |
| 521 | - if ( in_array( self::license_type( true ), array( 'elite', 'business' ), true ) ) { | |
| 522 | - return 'active'; | |
| 523 | - } | |
| 524 | - | |
| 525 | - return 'free'; | |
| 526 | - } | |
| 527 | - | |
| 528 | - /** | |
| 529 | 466 | * @since 4.0.01 |
| 530 | 467 | * |
| 531 | 468 | * @return bool |
| 532 | 469 | */ |
| @@ -531,21 +468,18 @@ | ||
| 531 | 468 | * @return bool |
| 532 | 469 | */ |
| 533 | 470 | public static function is_license_expired() { |
| 534 | 471 | $version_info = self::get_primary_license_info(); |
| 535 | - | |
| 536 | 472 | if ( ! isset( $version_info['error'] ) ) { |
| 537 | 473 | return false; |
| 538 | 474 | } |
| 539 | 475 | |
| 540 | - $expires = $version_info['error']['expires'] ?? 0; | |
| 541 | - | |
| 542 | - if ( ! $expires || $expires > time() ) { | |
| 476 | + $expires = isset( $version_info['error']['expires'] ) ? $version_info['error']['expires'] : 0; | |
| 477 | + if ( empty( $expires ) || $expires > time() ) { | |
| 543 | 478 | return false; |
| 544 | 479 | } |
| 545 | 480 | |
| 546 | 481 | $rate_limited = ! empty( $version_info['response_code'] ) && 429 === (int) $version_info['response_code']; |
| 547 | - | |
| 548 | 482 | if ( $rate_limited ) { |
| 549 | 483 | // Do not return false positives for rate limited responses. |
| 550 | 484 | return false; |
| 551 | 485 | } |
| @@ -560,13 +494,11 @@ | ||
| 560 | 494 | * @return array|false |
| 561 | 495 | */ |
| 562 | 496 | public static function get_primary_license_info() { |
| 563 | 497 | $installed_addons = apply_filters( 'frm_installed_addons', array() ); |
| 564 | - | |
| 565 | - if ( ! $installed_addons || ! isset( $installed_addons['formidable_pro'] ) ) { | |
| 498 | + if ( empty( $installed_addons ) || ! isset( $installed_addons['formidable_pro'] ) ) { | |
| 566 | 499 | return false; |
| 567 | 500 | } |
| 568 | - | |
| 569 | 501 | $installed_addons = array( |
| 570 | 502 | 'formidable_pro' => $installed_addons['formidable_pro'], |
| 571 | 503 | ); |
| 572 | 504 | |
| @@ -574,12 +506,8 @@ | ||
| 574 | 506 | } |
| 575 | 507 | |
| 576 | 508 | /** |
| 577 | 509 | * @since 3.04.03 |
| 578 | - * | |
| 579 | - * @param mixed $transient | |
| 580 | - * | |
| 581 | - * @return object | |
| 582 | 510 | */ |
| 583 | 511 | public static function check_update( $transient ) { |
| 584 | 512 | if ( ! FrmAppHelper::pro_is_installed() ) { |
| 585 | 513 | // Don't make any changes if only Lite is installed. |
| @@ -590,10 +518,9 @@ | ||
| 590 | 518 | $transient = new stdClass(); |
| 591 | 519 | } |
| 592 | 520 | |
| 593 | 521 | $installed_addons = apply_filters( 'frm_installed_addons', array() ); |
| 594 | - | |
| 595 | - if ( ! $installed_addons ) { | |
| 522 | + if ( empty( $installed_addons ) ) { | |
| 596 | 523 | return $transient; |
| 597 | 524 | } |
| 598 | 525 | |
| 599 | 526 | $version_info = self::fill_update_addon_info( $installed_addons ); |
| @@ -607,20 +534,19 @@ | ||
| 607 | 534 | continue; |
| 608 | 535 | } |
| 609 | 536 | |
| 610 | 537 | $folder = $plugin->plugin; |
| 611 | - | |
| 612 | - if ( ! $folder ) { | |
| 538 | + if ( empty( $folder ) ) { | |
| 613 | 539 | continue; |
| 614 | 540 | } |
| 615 | 541 | |
| 616 | 542 | if ( ! self::is_installed( $folder ) ) { |
| 617 | - // Don't show an update if the plugin isn't installed | |
| 543 | + // don't show an update if the plugin isn't installed | |
| 618 | 544 | continue; |
| 619 | 545 | } |
| 620 | 546 | |
| 621 | - $wp_plugin = $wp_plugins[ $folder ] ?? array(); | |
| 622 | - $wp_version = $wp_plugin['Version'] ?? '1.0'; | |
| 547 | + $wp_plugin = isset( $wp_plugins[ $folder ] ) ? $wp_plugins[ $folder ] : array(); | |
| 548 | + $wp_version = isset( $wp_plugin['Version'] ) ? $wp_plugin['Version'] : '1.0'; | |
| 623 | 549 | $plugin->slug = explode( '/', $folder )[0]; |
| 624 | 550 | |
| 625 | 551 | if ( version_compare( $wp_version, $plugin->new_version, '<' ) ) { |
| 626 | 552 | $transient->response[ $folder ] = $plugin; |
| @@ -628,8 +554,9 @@ | ||
| 628 | 554 | $transient->no_update[ $folder ] = $plugin; |
| 629 | 555 | } |
| 630 | 556 | |
| 631 | 557 | $transient->checked[ $folder ] = $wp_version; |
| 558 | + | |
| 632 | 559 | }//end foreach |
| 633 | 560 | |
| 634 | 561 | return $transient; |
| 635 | 562 | } |
| @@ -639,9 +566,8 @@ | ||
| 639 | 566 | * Because this gets called on "pre_set_site_transient_update_plugins" an old version of FrmAppHelper may be loaded on plugin update. |
| 640 | 567 | * This means that trying to access FrmAppHelper::get_plugins when upgrading from a Lite version before v5.5 results in a one-off error. |
| 641 | 568 | * |
| 642 | 569 | * @since 5.5.2 |
| 643 | - * | |
| 644 | 570 | * @return array |
| 645 | 571 | */ |
| 646 | 572 | protected static function get_plugins() { |
| 647 | 573 | if ( ! function_exists( 'get_plugins' ) ) { |
| @@ -676,49 +602,43 @@ | ||
| 676 | 602 | $version_info = array(); |
| 677 | 603 | |
| 678 | 604 | foreach ( $installed_addons as $addon ) { |
| 679 | 605 | if ( $addon->store_url !== 'https://formidableforms.com' ) { |
| 680 | - // Check if this is a third-party addon | |
| 606 | + // check if this is a third-party addon | |
| 681 | 607 | continue; |
| 682 | 608 | } |
| 683 | 609 | |
| 684 | 610 | $new_license = $addon->license; |
| 685 | - | |
| 686 | - if ( ! $new_license || in_array( $new_license, $checked_licenses, true ) ) { | |
| 611 | + if ( empty( $new_license ) || in_array( $new_license, $checked_licenses ) ) { | |
| 687 | 612 | continue; |
| 688 | 613 | } |
| 689 | 614 | |
| 690 | 615 | $checked_licenses[] = $new_license; |
| 691 | - $api = new FrmFormApi( $new_license ); | |
| 692 | 616 | |
| 693 | - if ( ! $version_info ) { | |
| 617 | + $api = new FrmFormApi( $new_license ); | |
| 618 | + if ( empty( $version_info ) ) { | |
| 694 | 619 | $version_info = $api->get_api_info(); |
| 695 | 620 | continue; |
| 696 | 621 | } |
| 697 | 622 | |
| 698 | 623 | $plugin = $api->get_addon_for_license( $addon, $version_info ); |
| 699 | - | |
| 700 | - if ( ! $plugin ) { | |
| 624 | + if ( empty( $plugin ) ) { | |
| 701 | 625 | continue; |
| 702 | 626 | } |
| 703 | 627 | |
| 704 | - $download_id = $plugin['id'] ?? 0; | |
| 628 | + $download_id = isset( $plugin['id'] ) ? $plugin['id'] : 0; | |
| 629 | + if ( ! empty( $download_id ) && ! isset( $version_info[ $download_id ]['package'] ) ) { | |
| 630 | + // if this addon is using its own license, get the update url | |
| 631 | + $addon_info = $api->get_api_info(); | |
| 705 | 632 | |
| 706 | - if ( ! $download_id || isset( $version_info[ $download_id ]['package'] ) ) { | |
| 707 | - continue; | |
| 633 | + $version_info[ $download_id ] = $addon_info[ $download_id ]; | |
| 634 | + if ( isset( $addon_info['error'] ) ) { | |
| 635 | + $version_info[ $download_id ]['error'] = array( | |
| 636 | + 'message' => $addon_info['error']['message'], | |
| 637 | + 'code' => $addon_info['error']['code'], | |
| 638 | + ); | |
| 639 | + } | |
| 708 | 640 | } |
| 709 | - | |
| 710 | - // If this addon is using its own license, get the update url | |
| 711 | - $addon_info = $api->get_api_info(); | |
| 712 | - | |
| 713 | - $version_info[ $download_id ] = $addon_info[ $download_id ]; | |
| 714 | - | |
| 715 | - if ( isset( $addon_info['error'] ) ) { | |
| 716 | - $version_info[ $download_id ]['error'] = array( | |
| 717 | - 'message' => $addon_info['error']['message'], | |
| 718 | - 'code' => $addon_info['error']['code'], | |
| 719 | - ); | |
| 720 | - } | |
| 721 | 641 | }//end foreach |
| 722 | 642 | |
| 723 | 643 | return $version_info; |
| 724 | 644 | } |
| @@ -726,11 +646,9 @@ | ||
| 726 | 646 | /** |
| 727 | 647 | * Get the action link for an addon that isn't active. |
| 728 | 648 | * |
| 729 | 649 | * @since 3.06.03 |
| 730 | - * | |
| 731 | 650 | * @param string $plugin The plugin slug. |
| 732 | - * | |
| 733 | 651 | * @return array |
| 734 | 652 | */ |
| 735 | 653 | public static function install_link( $plugin ) { |
| 736 | 654 | $link = array(); |
| @@ -752,9 +670,9 @@ | ||
| 752 | 670 | 'categories' => $addon['categories'], |
| 753 | 671 | ); |
| 754 | 672 | } |
| 755 | 673 | |
| 756 | - if ( $link ) { | |
| 674 | + if ( ! empty( $link ) ) { | |
| 757 | 675 | $link['status'] = $addon['status']['type']; |
| 758 | 676 | } |
| 759 | 677 | } elseif ( current_user_can( 'activate_plugins' ) && self::is_installed( 'formidable-' . $plugin . '/formidable-' . $plugin . '.php' ) ) { |
| 760 | 678 | $link = array( |
| @@ -766,81 +684,34 @@ | ||
| 766 | 684 | return $link; |
| 767 | 685 | } |
| 768 | 686 | |
| 769 | 687 | /** |
| 770 | - * Get the JSON-encoded install data for a plugin update. | |
| 771 | - * | |
| 772 | - * @since 6.29 | |
| 773 | - * | |
| 774 | - * @param string $addon_slug The addon slug (e.g. 'pro', 'dates'). | |
| 775 | - * | |
| 776 | - * @return string JSON-encoded install data, or empty string if no URL is available. | |
| 777 | - */ | |
| 778 | - public static function get_update_install_data( $addon_slug ) { | |
| 779 | - $upgrading = self::install_link( $addon_slug ); | |
| 780 | - | |
| 781 | - if ( isset( $upgrading['class'] ) && 'frm-install-addon' === $upgrading['class'] ) { | |
| 782 | - return (string) json_encode( $upgrading ); | |
| 783 | - } | |
| 784 | - | |
| 785 | - if ( 'pro' === $addon_slug ) { | |
| 786 | - $download_url = self::get_pro_download_url(); | |
| 787 | - $plugin_file = 'formidable-pro/formidable-pro.php'; | |
| 788 | - } else { | |
| 789 | - $addon_data = self::get_addon( $addon_slug ); | |
| 790 | - $download_url = $addon_data && ! empty( $addon_data['url'] ) ? $addon_data['url'] : ''; | |
| 791 | - $plugin_file = $addon_data && ! empty( $addon_data['plugin'] ) ? $addon_data['plugin'] : 'formidable-' . $addon_slug . '/formidable-' . $addon_slug . '.php'; | |
| 792 | - } | |
| 793 | - | |
| 794 | - if ( ! $download_url ) { | |
| 795 | - $update_plugins = get_site_transient( 'update_plugins' ); | |
| 796 | - $plugin_update = $update_plugins->response[ $plugin_file ] ?? null; | |
| 797 | - $download_url = $plugin_update && ! empty( $plugin_update->package ) ? $plugin_update->package : ''; | |
| 798 | - } | |
| 799 | - | |
| 800 | - return $download_url ? (string) json_encode( | |
| 801 | - array( | |
| 802 | - 'url' => $download_url, | |
| 803 | - 'class' => 'frm-install-addon', | |
| 804 | - ) | |
| 805 | - ) : ''; | |
| 806 | - } | |
| 807 | - | |
| 808 | - /** | |
| 809 | 688 | * @since 4.09 |
| 810 | - * | |
| 811 | 689 | * @param string $plugin The plugin slug. |
| 812 | - * | |
| 813 | 690 | * @return array|false |
| 814 | 691 | */ |
| 815 | 692 | public static function get_addon( $plugin ) { |
| 816 | 693 | $addons = self::get_api_addons(); |
| 817 | 694 | self::prepare_addons( $addons ); |
| 818 | - | |
| 819 | 695 | foreach ( $addons as $addon ) { |
| 820 | 696 | $slug = explode( '/', $addon['plugin'] ); |
| 821 | - | |
| 822 | 697 | if ( $slug[0] === 'formidable-' . $plugin ) { |
| 823 | 698 | return $addon; |
| 824 | 699 | } |
| 825 | 700 | } |
| 826 | - | |
| 827 | 701 | return false; |
| 828 | 702 | } |
| 829 | 703 | |
| 830 | 704 | /** |
| 831 | 705 | * @since 4.09 |
| 832 | - * | |
| 833 | 706 | * @return string |
| 834 | 707 | */ |
| 835 | 708 | protected static function get_license_type() { |
| 836 | 709 | $license_type = ''; |
| 837 | 710 | $addons = self::get_api_addons(); |
| 838 | - | |
| 839 | 711 | if ( isset( $addons['error'] ) && isset( $addons['error']['type'] ) ) { |
| 840 | - return $addons['error']['type']; | |
| 712 | + $license_type = $addons['error']['type']; | |
| 841 | 713 | } |
| 842 | - | |
| 843 | 714 | return $license_type; |
| 844 | 715 | } |
| 845 | 716 | |
| 846 | 717 | /** |
| @@ -853,12 +724,11 @@ | ||
| 853 | 724 | */ |
| 854 | 725 | public static function get_addon_for_license( $addons, $license ) { |
| 855 | 726 | $download_id = $license->download_id; |
| 856 | 727 | $plugin = array(); |
| 857 | - | |
| 858 | - if ( ! $download_id && $addons ) { | |
| 728 | + if ( empty( $download_id ) && ! empty( $addons ) ) { | |
| 859 | 729 | foreach ( $addons as $addon ) { |
| 860 | - if ( 0 === strcasecmp( $license->plugin_name, $addon['title'] ) ) { | |
| 730 | + if ( strtolower( $license->plugin_name ) === strtolower( $addon['title'] ) ) { | |
| 861 | 731 | return $addon; |
| 862 | 732 | } |
| 863 | 733 | } |
| 864 | 734 | } elseif ( isset( $addons[ $download_id ] ) ) { |
| @@ -868,33 +738,29 @@ | ||
| 868 | 738 | return $plugin; |
| 869 | 739 | } |
| 870 | 740 | |
| 871 | 741 | /** |
| 872 | - * @param array $addons | |
| 873 | - * | |
| 874 | 742 | * @return void |
| 875 | 743 | */ |
| 876 | 744 | protected static function prepare_addons( &$addons ) { |
| 877 | - // Reset categories to prevent count accumulation across multiple calls. | |
| 878 | - self::$categories = array(); | |
| 879 | - | |
| 880 | 745 | $activate_url = ''; |
| 881 | - | |
| 882 | 746 | if ( current_user_can( 'activate_plugins' ) ) { |
| 883 | 747 | $activate_url = add_query_arg( array( 'action' => 'activate' ), admin_url( 'plugins.php' ) ); |
| 884 | 748 | } |
| 885 | 749 | |
| 886 | 750 | $loop_addons = $addons; |
| 887 | - | |
| 888 | 751 | foreach ( $loop_addons as $id => $addon ) { |
| 889 | 752 | if ( is_numeric( $id ) ) { |
| 890 | 753 | $slug = str_replace( array( '-wordpress-plugin', '-wordpress' ), '', $addon['slug'] ); |
| 891 | 754 | $file_name = $addon['plugin']; |
| 892 | 755 | } else { |
| 893 | - $slug = $id; | |
| 894 | - $base_file = $addon['file'] ?? 'formidable-' . $slug; | |
| 756 | + $slug = $id; | |
| 757 | + if ( isset( $addon['file'] ) ) { | |
| 758 | + $base_file = $addon['file']; | |
| 759 | + } else { | |
| 760 | + $base_file = 'formidable-' . $slug; | |
| 761 | + } | |
| 895 | 762 | $file_name = $base_file . '/' . $base_file . '.php'; |
| 896 | - | |
| 897 | 763 | if ( ! isset( $addon['plugin'] ) ) { |
| 898 | 764 | $addon['plugin'] = $file_name; |
| 899 | 765 | } |
| 900 | 766 | } |
| @@ -899,17 +765,10 @@ | ||
| 899 | 765 | } |
| 900 | 766 | } |
| 901 | 767 | |
| 902 | 768 | $addon['installed'] = self::is_installed( $file_name ); |
| 903 | - | |
| 904 | - if ( 'highrise' === $slug && ! $addon['installed'] ) { | |
| 905 | - unset( $addons[ $id ] ); | |
| 906 | - continue; | |
| 907 | - } | |
| 908 | - | |
| 909 | 769 | if ( $addon['installed'] && 'formidable-views/formidable-views.php' === $file_name ) { |
| 910 | 770 | $active_views_version = self::get_active_views_version(); |
| 911 | - | |
| 912 | 771 | if ( false !== $active_views_version && $slug !== $active_views_version ) { |
| 913 | 772 | $addon['installed'] = false; |
| 914 | 773 | } |
| 915 | 774 | } |
| @@ -915,9 +774,9 @@ | ||
| 915 | 774 | } |
| 916 | 775 | |
| 917 | 776 | $addon['activate_url'] = ''; |
| 918 | 777 | |
| 919 | - if ( $addon['installed'] && $activate_url && ! self::is_plugin_active( $file_name, $slug ) ) { | |
| 778 | + if ( $addon['installed'] && ! empty( $activate_url ) && ! self::is_plugin_active( $file_name, $slug ) ) { | |
| 920 | 779 | $addon['activate_url'] = add_query_arg( |
| 921 | 780 | array( |
| 922 | 781 | '_wpnonce' => wp_create_nonce( 'activate-plugin_' . $file_name ), |
| 923 | 782 | 'plugin' => $file_name, |
| @@ -943,11 +802,8 @@ | ||
| 943 | 802 | }//end foreach |
| 944 | 803 | } |
| 945 | 804 | |
| 946 | 805 | /** |
| 947 | - * @param string $file_name | |
| 948 | - * @param string $slug | |
| 949 | - * | |
| 950 | 806 | * @return bool |
| 951 | 807 | */ |
| 952 | 808 | private static function is_plugin_active( $file_name, $slug ) { |
| 953 | 809 | if ( 'formidable-views/formidable-views.php' === $file_name ) { |
| @@ -962,9 +818,8 @@ | ||
| 962 | 818 | private static function get_active_views_version() { |
| 963 | 819 | if ( ! is_callable( 'FrmViewsAppHelper::plugin_version' ) ) { |
| 964 | 820 | return false; |
| 965 | 821 | } |
| 966 | - | |
| 967 | 822 | $plugin_version = FrmViewsAppHelper::plugin_version(); |
| 968 | 823 | return version_compare( $plugin_version, '5.0', '>=' ) ? 'visual-views' : 'views'; |
| 969 | 824 | } |
| 970 | 825 | |
| @@ -970,25 +825,22 @@ | ||
| 970 | 825 | |
| 971 | 826 | /** |
| 972 | 827 | * @since 3.04.02 |
| 973 | 828 | * |
| 974 | - * @param string $link | |
| 975 | - * | |
| 976 | 829 | * @return void |
| 977 | 830 | */ |
| 978 | 831 | protected static function prepare_addon_link( &$link ) { |
| 979 | 832 | $site_url = 'https://formidableforms.com/'; |
| 980 | - | |
| 981 | - if ( ! str_starts_with( $link, 'http' ) ) { | |
| 833 | + if ( strpos( $link, 'http' ) !== 0 ) { | |
| 982 | 834 | $link = $site_url . $link; |
| 983 | 835 | } |
| 984 | - | |
| 985 | - $link = FrmAppHelper::make_affiliate_url( $link ); | |
| 986 | - | |
| 987 | - $utm = array( | |
| 988 | - 'campaign' => 'addons', | |
| 836 | + $link = FrmAppHelper::make_affiliate_url( $link ); | |
| 837 | + $query_args = array( | |
| 838 | + 'utm_source' => 'WordPress', | |
| 839 | + 'utm_medium' => 'addons', | |
| 840 | + 'utm_campaign' => 'liteplugin', | |
| 989 | 841 | ); |
| 990 | - $link = FrmAppHelper::maybe_add_missing_utm( $link, $utm ); | |
| 842 | + $link = add_query_arg( $query_args, $link ); | |
| 991 | 843 | } |
| 992 | 844 | |
| 993 | 845 | /** |
| 994 | 846 | * Add the status to the addon array. Status options are: |
| @@ -995,10 +847,8 @@ | ||
| 995 | 847 | * installed, active, not installed |
| 996 | 848 | * |
| 997 | 849 | * @since 3.04.02 |
| 998 | 850 | * |
| 999 | - * @param array $addon | |
| 1000 | - * | |
| 1001 | 851 | * @return void |
| 1002 | 852 | */ |
| 1003 | 853 | protected static function set_addon_status( &$addon ) { |
| 1004 | 854 | if ( ! empty( $addon['activate_url'] ) ) { |
| @@ -1025,9 +875,8 @@ | ||
| 1025 | 875 | * @param string $plugin |
| 1026 | 876 | * @param string $redirect |
| 1027 | 877 | * @param bool $network_wide |
| 1028 | 878 | * @param bool $silent |
| 1029 | - * | |
| 1030 | 879 | * @return WP_Error|null Null on success, WP_Error on invalid file. |
| 1031 | 880 | */ |
| 1032 | 881 | protected static function activate_plugin( $plugin, $redirect = '', $network_wide = false, $silent = false ) { |
| 1033 | 882 | if ( ! function_exists( 'activate_plugin' ) ) { |
| @@ -1042,9 +891,8 @@ | ||
| 1042 | 891 | * @since 6.8 |
| 1043 | 892 | * |
| 1044 | 893 | * @param string $plugin |
| 1045 | 894 | * @param bool $silent |
| 1046 | - * | |
| 1047 | 895 | * @return void |
| 1048 | 896 | */ |
| 1049 | 897 | protected static function deactivate_plugin( $plugin, $silent = false ) { |
| 1050 | 898 | if ( ! function_exists( 'deactivate_plugins' ) ) { |
| @@ -1058,9 +906,8 @@ | ||
| 1058 | 906 | * |
| 1059 | 907 | * @since 6.8 |
| 1060 | 908 | * |
| 1061 | 909 | * @param string $plugin |
| 1062 | - * | |
| 1063 | 910 | * @return true|WP_Error True on success, WP_Error on invalid file. |
| 1064 | 911 | */ |
| 1065 | 912 | protected static function uninstall_plugin( $plugin ) { |
| 1066 | 913 | if ( ! current_user_can( 'delete_plugins' ) ) { |
| @@ -1073,9 +920,13 @@ | ||
| 1073 | 920 | |
| 1074 | 921 | self::deactivate_plugin( $plugin, true ); |
| 1075 | 922 | $result = delete_plugins( array( $plugin ) ); |
| 1076 | 923 | |
| 1077 | - return is_wp_error( $result ) ? $result : true; | |
| 924 | + if ( is_wp_error( $result ) ) { | |
| 925 | + return $result; | |
| 926 | + } | |
| 927 | + | |
| 928 | + return true; | |
| 1078 | 929 | } |
| 1079 | 930 | |
| 1080 | 931 | /** |
| 1081 | 932 | * @since 5.0.10 |
| @@ -1082,9 +933,9 @@ | ||
| 1082 | 933 | * |
| 1083 | 934 | * @return string |
| 1084 | 935 | */ |
| 1085 | 936 | protected static function get_current_plugin() { |
| 1086 | - if ( ! self::$plugin ) { | |
| 937 | + if ( empty( self::$plugin ) ) { | |
| 1087 | 938 | self::$plugin = FrmAppHelper::get_param( 'plugin', '', 'post', 'esc_url_raw' ); |
| 1088 | 939 | } |
| 1089 | 940 | return self::$plugin; |
| 1090 | 941 | } |
| @@ -1091,9 +942,9 @@ | ||
| 1091 | 942 | |
| 1092 | 943 | /** |
| 1093 | 944 | * @since 4.08 |
| 1094 | 945 | * |
| 1095 | - * @return mixed[]|null | |
| 946 | + * @return array|void | |
| 1096 | 947 | */ |
| 1097 | 948 | protected static function download_and_activate() { |
| 1098 | 949 | if ( is_admin() ) { |
| 1099 | 950 | FrmAppHelper::set_current_screen_and_hook_suffix(); |
| @@ -1101,14 +952,12 @@ | ||
| 1101 | 952 | |
| 1102 | 953 | self::maybe_show_cred_form(); |
| 1103 | 954 | |
| 1104 | 955 | $installed = self::install_addon(); |
| 1105 | - | |
| 1106 | 956 | if ( is_array( $installed ) && isset( $installed['message'] ) ) { |
| 1107 | 957 | return $installed; |
| 1108 | 958 | } |
| 1109 | 959 | self::handle_addon_action( $installed, 'activate' ); |
| 1110 | - return null; | |
| 1111 | 960 | } |
| 1112 | 961 | |
| 1113 | 962 | /** |
| 1114 | 963 | * @since 3.04.02 |
| @@ -1119,9 +968,9 @@ | ||
| 1119 | 968 | if ( ! function_exists( 'request_filesystem_credentials' ) ) { |
| 1120 | 969 | include_once ABSPATH . 'wp-admin/includes/file.php'; |
| 1121 | 970 | } |
| 1122 | 971 | |
| 1123 | - // Start output buffering to catch the filesystem form if credentials are needed. | |
| 972 | + // Start output bufferring to catch the filesystem form if credentials are needed. | |
| 1124 | 973 | ob_start(); |
| 1125 | 974 | |
| 1126 | 975 | $show_form = false; |
| 1127 | 976 | $method = ''; |
| @@ -1138,8 +987,9 @@ | ||
| 1138 | 987 | |
| 1139 | 988 | if ( $show_form ) { |
| 1140 | 989 | $form = ob_get_clean(); |
| 1141 | 990 | $message = __( 'Sorry, your site requires FTP authentication. Please download plugins from FormidableForms.com and install them manually.', 'formidable' ); |
| 991 | + $data = $form; | |
| 1142 | 992 | $response = array( |
| 1143 | 993 | 'success' => false, |
| 1144 | 994 | 'message' => $message, |
| 1145 | 995 | 'form' => $form, |
| @@ -1167,10 +1017,8 @@ | ||
| 1167 | 1017 | * We do not need any extra credentials if we have gotten this far, |
| 1168 | 1018 | * so let's install the plugin. |
| 1169 | 1019 | * |
| 1170 | 1020 | * @since 3.04.02 |
| 1171 | - * | |
| 1172 | - * @return array|string | |
| 1173 | 1021 | */ |
| 1174 | 1022 | protected static function install_addon() { |
| 1175 | 1023 | require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
| 1176 | 1024 | |
| @@ -1184,15 +1032,14 @@ | ||
| 1184 | 1032 | } |
| 1185 | 1033 | |
| 1186 | 1034 | // Create the plugin upgrader with our custom skin. |
| 1187 | 1035 | $installer = new Plugin_Upgrader( new FrmInstallerSkin() ); |
| 1188 | - $installer->install( $download_url, array( 'overwrite_package' => true ) ); | |
| 1036 | + $installer->install( $download_url ); | |
| 1189 | 1037 | |
| 1190 | 1038 | // Flush the cache and return the newly installed plugin basename. |
| 1191 | 1039 | wp_cache_flush(); |
| 1192 | 1040 | |
| 1193 | 1041 | $plugin = $installer->plugin_info(); |
| 1194 | - | |
| 1195 | 1042 | if ( ! $plugin ) { |
| 1196 | 1043 | return array( |
| 1197 | 1044 | 'message' => 'Plugin was not installed. ' . $installer->result, |
| 1198 | 1045 | 'success' => false, |
| @@ -1197,9 +1044,8 @@ | ||
| 1197 | 1044 | 'message' => 'Plugin was not installed. ' . $installer->result, |
| 1198 | 1045 | 'success' => false, |
| 1199 | 1046 | ); |
| 1200 | 1047 | } |
| 1201 | - | |
| 1202 | 1048 | return $plugin; |
| 1203 | 1049 | } |
| 1204 | 1050 | |
| 1205 | 1051 | /** |
| @@ -1263,9 +1109,8 @@ | ||
| 1263 | 1109 | * @since 6.8 |
| 1264 | 1110 | * |
| 1265 | 1111 | * @param callable $action_callback The specific add-on action to be executed. |
| 1266 | 1112 | * @param callable|null $response_callback Optional. The response handling callback. Default null. |
| 1267 | - * | |
| 1268 | 1113 | * @return void |
| 1269 | 1114 | */ |
| 1270 | 1115 | private static function process_addon_action( $action_callback, $response_callback = null ) { |
| 1271 | 1116 | self::install_addon_permissions(); |
| @@ -1288,14 +1133,13 @@ | ||
| 1288 | 1133 | * @since 6.8 |
| 1289 | 1134 | * |
| 1290 | 1135 | * @param string $installed The plugin folder name with file name. |
| 1291 | 1136 | * @param string $action The action type ('activate', 'deactivate', 'uninstall'). |
| 1292 | - * | |
| 1293 | - * @return mixed[]|null | |
| 1137 | + * @return array|void | |
| 1294 | 1138 | */ |
| 1295 | 1139 | protected static function handle_addon_action( $installed, $action ) { |
| 1296 | 1140 | if ( ! $installed || ! $action ) { |
| 1297 | - return null; | |
| 1141 | + return; | |
| 1298 | 1142 | } |
| 1299 | 1143 | |
| 1300 | 1144 | $result = null; |
| 1301 | 1145 | switch ( $action ) { |
| @@ -1315,9 +1159,8 @@ | ||
| 1315 | 1159 | if ( $result->get_error_code() !== 'no_plugin_header' ) { |
| 1316 | 1160 | if ( wp_doing_ajax() ) { |
| 1317 | 1161 | wp_send_json_error( array( 'error' => $result->get_error_message() ) ); |
| 1318 | 1162 | } |
| 1319 | - | |
| 1320 | 1163 | return array( |
| 1321 | 1164 | 'message' => $result->get_error_message(), |
| 1322 | 1165 | 'success' => false, |
| 1323 | 1166 | ); |
| @@ -1331,14 +1174,17 @@ | ||
| 1331 | 1174 | * @return array |
| 1332 | 1175 | */ |
| 1333 | 1176 | private static function get_addon_activation_response() { |
| 1334 | 1177 | $activating_page = self::get_activating_page(); |
| 1335 | - $message = $activating_page ? __( 'Your plugin has been activated. Would you like to save and reload the page now?', 'formidable' ) : __( 'Your plugin has been activated.', 'formidable' ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong | |
| 1336 | 1178 | |
| 1337 | - return array( | |
| 1179 | + $message = $activating_page ? __( 'Your plugin has been activated. Would you like to save and reload the page now?', 'formidable' ) : __( 'Your plugin has been activated.', 'formidable' ); | |
| 1180 | + | |
| 1181 | + $response = array( | |
| 1338 | 1182 | 'message' => $message, |
| 1339 | 1183 | 'saveAndReload' => $activating_page, |
| 1340 | 1184 | ); |
| 1185 | + | |
| 1186 | + return $response; | |
| 1341 | 1187 | } |
| 1342 | 1188 | |
| 1343 | 1189 | /** |
| 1344 | 1190 | * Return a string that reflects the page from which the addon is being activated on, |
| @@ -1347,14 +1193,17 @@ | ||
| 1347 | 1193 | * @return string |
| 1348 | 1194 | */ |
| 1349 | 1195 | private static function get_activating_page() { |
| 1350 | 1196 | $referer = FrmAppHelper::get_server_value( 'HTTP_REFERER' ); |
| 1197 | + if ( false !== strpos( $referer, 'frm_action=settings' ) ) { | |
| 1198 | + return 'settings'; | |
| 1199 | + } | |
| 1351 | 1200 | |
| 1352 | - if ( str_contains( $referer, 'frm_action=settings' ) ) { | |
| 1353 | - return 'settings'; | |
| 1201 | + if ( false !== strpos( $referer, 'frm_action=edit' ) ) { | |
| 1202 | + return 'form_builder'; | |
| 1354 | 1203 | } |
| 1355 | 1204 | |
| 1356 | - return str_contains( $referer, 'frm_action=edit' ) ? 'form_builder' : ''; | |
| 1205 | + return ''; | |
| 1357 | 1206 | } |
| 1358 | 1207 | |
| 1359 | 1208 | /** |
| 1360 | 1209 | * Run security checks before installing |
| @@ -1365,14 +1214,12 @@ | ||
| 1365 | 1214 | */ |
| 1366 | 1215 | protected static function install_addon_permissions() { |
| 1367 | 1216 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
| 1368 | 1217 | |
| 1369 | - if ( current_user_can( 'activate_plugins' ) && self::get_current_plugin() ) { | |
| 1370 | - return; | |
| 1218 | + if ( ! current_user_can( 'activate_plugins' ) || ! self::get_current_plugin() ) { | |
| 1219 | + echo json_encode( true ); | |
| 1220 | + wp_die(); | |
| 1371 | 1221 | } |
| 1372 | - | |
| 1373 | - echo json_encode( true ); | |
| 1374 | - wp_die(); | |
| 1375 | 1222 | } |
| 1376 | 1223 | |
| 1377 | 1224 | /** |
| 1378 | 1225 | * @since 4.08 |
| @@ -1380,14 +1227,12 @@ | ||
| 1380 | 1227 | * @return string |
| 1381 | 1228 | */ |
| 1382 | 1229 | public static function connect_link() { |
| 1383 | 1230 | $auth = get_option( 'frm_connect_token' ); |
| 1384 | - | |
| 1385 | - if ( ! $auth ) { | |
| 1231 | + if ( empty( $auth ) ) { | |
| 1386 | 1232 | $auth = hash( 'sha512', wp_rand() ); |
| 1387 | - update_option( 'frm_connect_token', $auth, false ); | |
| 1233 | + update_option( 'frm_connect_token', $auth, 'no' ); | |
| 1388 | 1234 | } |
| 1389 | - | |
| 1390 | 1235 | $page = FrmAppHelper::simple_get( 'page', 'sanitize_title', 'formidable-settings' ); |
| 1391 | 1236 | $link = 'https://formidableforms.com/api-connect/'; |
| 1392 | 1237 | $args = array( |
| 1393 | 1238 | 'v' => 2, |
| @@ -1415,10 +1260,9 @@ | ||
| 1415 | 1260 | $post_url = FrmAppHelper::get_param( 'file_url', '', 'request', 'sanitize_text_field' ); |
| 1416 | 1261 | |
| 1417 | 1262 | // The download link is not required if already installed. |
| 1418 | 1263 | $is_installed = FrmAppHelper::pro_is_included(); |
| 1419 | - $file_missing = ! $is_installed && ! $post_url; | |
| 1420 | - | |
| 1264 | + $file_missing = ! $is_installed && empty( $post_url ); | |
| 1421 | 1265 | if ( ! $post_auth || $file_missing ) { |
| 1422 | 1266 | return false; |
| 1423 | 1267 | } |
| 1424 | 1268 | |
| @@ -1423,9 +1267,13 @@ | ||
| 1423 | 1267 | } |
| 1424 | 1268 | |
| 1425 | 1269 | // Verify auth. |
| 1426 | 1270 | $auth = get_option( 'frm_connect_token' ); |
| 1427 | - return $auth && hash_equals( $auth, $post_auth ); | |
| 1271 | + if ( empty( $auth ) || ! hash_equals( $auth, $post_auth ) ) { | |
| 1272 | + return false; | |
| 1273 | + } | |
| 1274 | + | |
| 1275 | + return true; | |
| 1428 | 1276 | } |
| 1429 | 1277 | |
| 1430 | 1278 | /** |
| 1431 | 1279 | * Install and/or activate the add-on file. |
| @@ -1436,17 +1284,17 @@ | ||
| 1436 | 1284 | */ |
| 1437 | 1285 | public static function install_addon_api() { |
| 1438 | 1286 | self::$plugin = FrmAppHelper::get_param( 'file_url', '', 'request', 'esc_url_raw' ); |
| 1439 | 1287 | |
| 1288 | + $error = esc_html__( 'Could not install an upgrade. Please download from formidableforms.com and install manually.', 'formidable' ); | |
| 1289 | + | |
| 1440 | 1290 | // Delete so cannot replay. |
| 1441 | 1291 | delete_option( 'frm_connect_token' ); |
| 1442 | 1292 | |
| 1443 | 1293 | // It's already installed and active. |
| 1444 | 1294 | $active = self::activate_plugin( 'formidable-pro/formidable-pro.php', false, false, true ); |
| 1445 | - | |
| 1446 | 1295 | if ( is_wp_error( $active ) ) { |
| 1447 | 1296 | $response = self::maybe_download_and_activate(); |
| 1448 | - | |
| 1449 | 1297 | if ( is_array( $response ) ) { |
| 1450 | 1298 | // The download failed. |
| 1451 | 1299 | return $response; |
| 1452 | 1300 | } |
| @@ -1452,12 +1300,11 @@ | ||
| 1452 | 1300 | } |
| 1453 | 1301 | } |
| 1454 | 1302 | |
| 1455 | 1303 | // If empty license, save it now. |
| 1456 | - if ( ! self::get_pro_license() && function_exists( 'load_formidable_pro' ) ) { | |
| 1304 | + if ( empty( self::get_pro_license() ) && function_exists( 'load_formidable_pro' ) ) { | |
| 1457 | 1305 | load_formidable_pro(); |
| 1458 | 1306 | $license = stripslashes( FrmAppHelper::get_param( 'key', '', 'request', 'sanitize_text_field' ) ); |
| 1459 | - | |
| 1460 | 1307 | if ( ! $license ) { |
| 1461 | 1308 | return array( |
| 1462 | 1309 | 'success' => false, |
| 1463 | 1310 | 'error' => 'That site does not have a valid license key.', |
| @@ -1464,9 +1311,8 @@ | ||
| 1464 | 1311 | ); |
| 1465 | 1312 | } |
| 1466 | 1313 | |
| 1467 | 1314 | $response = FrmAddon::activate_license_for_plugin( $license, 'formidable_pro' ); |
| 1468 | - | |
| 1469 | 1315 | if ( ! $response['success'] ) { |
| 1470 | 1316 | // Could not activate license. |
| 1471 | 1317 | return $response; |
| 1472 | 1318 | } |
| @@ -1491,9 +1337,8 @@ | ||
| 1491 | 1337 | } |
| 1492 | 1338 | |
| 1493 | 1339 | // Download plugin now. |
| 1494 | 1340 | $response = self::download_and_activate(); |
| 1495 | - | |
| 1496 | 1341 | if ( is_array( $response ) && isset( $response['success'] ) ) { |
| 1497 | 1342 | // The download failed. |
| 1498 | 1343 | return $response; |
| 1499 | 1344 | } |
| @@ -1507,9 +1352,8 @@ | ||
| 1507 | 1352 | * @since 4.09 |
| 1508 | 1353 | * |
| 1509 | 1354 | * @param string $plugin |
| 1510 | 1355 | * @param array|string $upgrade_link_args |
| 1511 | - * | |
| 1512 | 1356 | * @return void |
| 1513 | 1357 | */ |
| 1514 | 1358 | public static function conditional_action_button( $plugin, $upgrade_link_args ) { |
| 1515 | 1359 | if ( is_callable( 'FrmProAddonsController::conditional_action_button' ) ) { |
| @@ -1544,9 +1388,8 @@ | ||
| 1544 | 1388 | * @type false|string $license_type |
| 1545 | 1389 | * @type string $plan_required |
| 1546 | 1390 | * @type string $upgrade_link |
| 1547 | 1391 | * } |
| 1548 | - * | |
| 1549 | 1392 | * @return void |
| 1550 | 1393 | */ |
| 1551 | 1394 | public static function show_conditional_action_button( $atts ) { |
| 1552 | 1395 | if ( is_callable( 'FrmProAddonsController::show_conditional_action_button' ) ) { |
| @@ -1567,9 +1410,8 @@ | ||
| 1567 | 1410 | */ |
| 1568 | 1411 | public static function addon_upgrade_link( $addon, $upgrade_link ) { |
| 1569 | 1412 | $atts = is_array( $upgrade_link ) ? $upgrade_link : array(); |
| 1570 | 1413 | $upgrade_link = is_array( $upgrade_link ) ? $upgrade_link['link'] : $upgrade_link; |
| 1571 | - $text = ! empty( $atts['text'] ) ? $atts['text'] : __( 'Upgrade Now', 'formidable' ); | |
| 1572 | 1414 | |
| 1573 | 1415 | if ( $addon ) { |
| 1574 | 1416 | $upgrade_link .= '&utm_content=' . $addon['slug']; |
| 1575 | 1417 | } |
| @@ -1579,19 +1421,16 @@ | ||
| 1579 | 1421 | $upgrade_link = FrmAppHelper::admin_upgrade_link( 'addons', $addon['link'] ); |
| 1580 | 1422 | } |
| 1581 | 1423 | |
| 1582 | 1424 | $class = ! empty( $atts['class'] ) ? $atts['class'] : ''; |
| 1583 | - | |
| 1584 | - if ( ! str_contains( $class, 'frm-button' ) ) { | |
| 1425 | + if ( strpos( $class, 'frm-button' ) === false ) { | |
| 1585 | 1426 | $class .= ' frm-button-secondary frm-button-sm'; |
| 1586 | 1427 | } |
| 1587 | - // phpcs:disable Generic.WhiteSpace.ScopeIndent | |
| 1588 | 1428 | ?> |
| 1589 | - <a class="install-now button <?php echo esc_attr( $class ); ?>" href="<?php echo esc_url( $upgrade_link ); ?>" target="_blank" rel="noopener" aria-label="<?php esc_attr_e( 'Upgrade Now', 'formidable' ); ?>"><?php // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong ?> | |
| 1590 | - <?php echo esc_html( $text ); ?> | |
| 1429 | + <a class="install-now button <?php echo esc_attr( $class ); ?>" href="<?php echo esc_url( $upgrade_link ); ?>" target="_blank" rel="noopener" aria-label="<?php esc_attr_e( 'Upgrade Now', 'formidable' ); ?>"> | |
| 1430 | + <?php esc_html_e( 'Upgrade Now', 'formidable' ); ?> | |
| 1591 | 1431 | </a> |
| 1592 | 1432 | <?php |
| 1593 | - // phpcs:enable Generic.WhiteSpace.ScopeIndent | |
| 1594 | 1433 | } |
| 1595 | 1434 | |
| 1596 | 1435 | /** |
| 1597 | 1436 | * @since 3.04.02 |
| @@ -1601,9 +1440,8 @@ | ||
| 1601 | 1440 | public static function ajax_install_addon() { |
| 1602 | 1441 | self::install_addon_permissions(); |
| 1603 | 1442 | |
| 1604 | 1443 | $result = self::download_and_activate(); |
| 1605 | - | |
| 1606 | 1444 | if ( isset( $result['success'] ) && ! $result['success'] ) { |
| 1607 | 1445 | echo json_encode( $result ); |
| 1608 | 1446 | wp_die(); |
| 1609 | 1447 | } |
| @@ -1636,8 +1474,9 @@ | ||
| 1636 | 1474 | $allowed_url_list = apply_filters( 'frm_allowed_external_urls', $allowed_url_list ); |
| 1637 | 1475 | |
| 1638 | 1476 | if ( ! is_array( $allowed_url_list ) ) { |
| 1639 | 1477 | _doing_it_wrong( __METHOD__, 'Only an array of URLs could be used within this filter.', '6.3.1' ); |
| 1478 | + | |
| 1640 | 1479 | return array(); |
| 1641 | 1480 | } |
| 1642 | 1481 | |
| 1643 | 1482 | return $allowed_url_list; |
| @@ -1647,10 +1486,8 @@ | ||
| 1647 | 1486 | * Gets required plan for an addon. |
| 1648 | 1487 | * |
| 1649 | 1488 | * @since 6.4.2 |
| 1650 | 1489 | * |
| 1651 | - * @param int|string $addon_id | |
| 1652 | - * | |
| 1653 | 1490 | * @return string Empty string if no plan is required for active license. |
| 1654 | 1491 | */ |
| 1655 | 1492 | public static function get_addon_required_plan( $addon_id ) { |
| 1656 | 1493 | $api = new FrmFormApi(); |
| @@ -1661,9 +1498,9 @@ | ||
| 1661 | 1498 | $requires = FrmFormsHelper::get_plan_required( $dates ); |
| 1662 | 1499 | } |
| 1663 | 1500 | |
| 1664 | 1501 | if ( ! isset( $requires ) || ! is_string( $requires ) ) { |
| 1665 | - return ''; | |
| 1502 | + $requires = ''; | |
| 1666 | 1503 | } |
| 1667 | 1504 | |
| 1668 | 1505 | return $requires; |
| 1669 | 1506 | } |