| @@ -5,15 +5,93 @@ | ||
| 5 | 5 | |
| 6 | 6 | class FrmAddonsController { |
| 7 | 7 | |
| 8 | 8 | /** |
| 9 | - * @var string $plugin | |
| 9 | + * @var string | |
| 10 | 10 | */ |
| 11 | + const SCRIPT_HANDLE = 'frm-addons-page'; | |
| 12 | + | |
| 13 | + /** | |
| 14 | + * @var array | |
| 15 | + */ | |
| 16 | + private static $categories = array(); | |
| 17 | + | |
| 18 | + /** | |
| 19 | + * @var string | |
| 20 | + */ | |
| 21 | + private static $request_addon_url; | |
| 22 | + | |
| 23 | + /** | |
| 24 | + * @var string | |
| 25 | + */ | |
| 11 | 26 | protected static $plugin; |
| 12 | 27 | |
| 13 | 28 | /** |
| 29 | + * @since 6.15 | |
| 30 | + */ | |
| 31 | + public static function load_admin_hooks() { | |
| 32 | + add_action( 'admin_menu', __CLASS__ . '::menu', 100 ); | |
| 33 | + add_filter( 'pre_set_site_transient_update_plugins', __CLASS__ . '::check_update' ); | |
| 34 | + | |
| 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' ); | |
| 40 | + } | |
| 41 | + } | |
| 42 | + | |
| 43 | + /** | |
| 44 | + * Enqueues the Add-Ons page scripts and styles. | |
| 45 | + * | |
| 46 | + * @since 6.15 | |
| 47 | + * | |
| 14 | 48 | * @return void |
| 15 | 49 | */ |
| 50 | + public static function enqueue_assets() { | |
| 51 | + $plugin_url = FrmAppHelper::plugin_url(); | |
| 52 | + $version = FrmAppHelper::plugin_version(); | |
| 53 | + $js_dependencies = array( | |
| 54 | + 'wp-i18n', | |
| 55 | + // This prevents a console error "wp.hooks is undefined" in WP versions older than 5.7. | |
| 56 | + 'wp-hooks', | |
| 57 | + 'formidable_dom', | |
| 58 | + ); | |
| 59 | + | |
| 60 | + // Enqueue styles that needed. | |
| 61 | + wp_enqueue_style( 'formidable-admin' ); | |
| 62 | + wp_enqueue_style( 'formidable-grids' ); | |
| 63 | + | |
| 64 | + // Register and enqueue Add-Ons page style. | |
| 65 | + wp_register_style( self::SCRIPT_HANDLE, $plugin_url . '/css/admin/addons-page.css', array(), $version ); | |
| 66 | + wp_enqueue_style( self::SCRIPT_HANDLE ); | |
| 67 | + | |
| 68 | + // Register and enqueue Add-Ons page script. | |
| 69 | + wp_register_script( self::SCRIPT_HANDLE, $plugin_url . '/js/addons-page.js', $js_dependencies, $version, true ); | |
| 70 | + wp_localize_script( self::SCRIPT_HANDLE, 'frmAddonsVars', self::get_js_variables() ); | |
| 71 | + wp_enqueue_script( self::SCRIPT_HANDLE ); | |
| 72 | + wp_set_script_translations( self::SCRIPT_HANDLE, 'formidable' ); | |
| 73 | + | |
| 74 | + FrmAppHelper::dequeue_extra_global_scripts(); | |
| 75 | + } | |
| 76 | + | |
| 77 | + /** | |
| 78 | + * Get the Add-Ons page JS variables as an array. | |
| 79 | + * | |
| 80 | + * @since 6.15 | |
| 81 | + * | |
| 82 | + * @return array | |
| 83 | + */ | |
| 84 | + private static function get_js_variables() { | |
| 85 | + return array( | |
| 86 | + 'proIsIncluded' => FrmAppHelper::pro_is_included(), | |
| 87 | + 'addonRequestURL' => self::$request_addon_url, | |
| 88 | + ); | |
| 89 | + } | |
| 90 | + | |
| 91 | + /** | |
| 92 | + * @return void | |
| 93 | + */ | |
| 16 | 94 | public static function menu() { |
| 17 | 95 | if ( ! current_user_can( 'activate_plugins' ) ) { |
| 18 | 96 | return; |
| 19 | 97 | } |
| @@ -18,25 +96,36 @@ | ||
| 18 | 96 | return; |
| 19 | 97 | } |
| 20 | 98 | |
| 21 | 99 | $label = __( 'Add-Ons', 'formidable' ); |
| 22 | - $label = '<span style="color:#fe5a1d">' . $label . '</span>'; | |
| 100 | + $label = '<span style="color:#3FCA89">' . esc_html( $label ) . '</span>'; | |
| 23 | 101 | |
| 24 | 102 | add_submenu_page( 'formidable', 'Formidable | ' . __( 'Add-Ons', 'formidable' ), $label, 'frm_view_forms', 'formidable-addons', 'FrmAddonsController::list_addons' ); |
| 25 | 103 | |
| 104 | + // remove default created subpage, make the page with highest priority as default. | |
| 105 | + remove_submenu_page( 'formidable', 'formidable' ); | |
| 106 | + | |
| 26 | 107 | if ( ! FrmAppHelper::pro_is_installed() ) { |
| 108 | + $cta_text = FrmSalesApi::get_best_sale_value( 'menu_cta_text' ); | |
| 109 | + if ( ! $cta_text ) { | |
| 110 | + $cta_text = __( 'Upgrade', 'formidable' ); | |
| 111 | + } | |
| 112 | + | |
| 27 | 113 | add_submenu_page( |
| 28 | 114 | 'formidable', |
| 29 | 115 | 'Formidable | ' . __( 'Upgrade', 'formidable' ), |
| 30 | - '<span class="frm-upgrade-submenu">' . __( 'Upgrade', 'formidable' ) . '</span>', | |
| 116 | + '<span class="frm-upgrade-submenu">' . esc_html( $cta_text ) . '</span>', | |
| 31 | 117 | 'frm_view_forms', |
| 32 | 118 | 'formidable-pro-upgrade', |
| 33 | - 'FrmAddonsController::upgrade_to_pro' | |
| 119 | + function () { | |
| 120 | + // This function doesn't need to do anything. | |
| 121 | + // The redirect is handled earlier to avoid issues with the headers being sent. | |
| 122 | + } | |
| 34 | 123 | ); |
| 35 | 124 | } elseif ( 'formidable-pro-upgrade' === FrmAppHelper::get_param( 'page' ) ) { |
| 36 | 125 | wp_safe_redirect( admin_url( 'admin.php?page=formidable' ) ); |
| 37 | 126 | exit; |
| 38 | - } | |
| 127 | + }//end if | |
| 39 | 128 | } |
| 40 | 129 | |
| 41 | 130 | /** |
| 42 | 131 | * @return void |
| @@ -42,28 +131,31 @@ | ||
| 42 | 131 | * @return void |
| 43 | 132 | */ |
| 44 | 133 | public static function list_addons() { |
| 45 | 134 | FrmAppHelper::include_svg(); |
| 46 | - $installed_addons = apply_filters( 'frm_installed_addons', array() ); | |
| 47 | - $license_type = ''; | |
| 48 | 135 | |
| 49 | - $addons = self::get_api_addons(); | |
| 50 | - $errors = array(); | |
| 136 | + $view_path = FrmAppHelper::plugin_path() . '/classes/views/addons/'; | |
| 137 | + $installed_addons = apply_filters( 'frm_installed_addons', array() ); | |
| 138 | + $addons = self::get_api_addons(); | |
| 139 | + $errors = array(); | |
| 140 | + $license_type = ''; | |
| 141 | + $request_addon_url = self::$request_addon_url; | |
| 51 | 142 | |
| 52 | 143 | if ( isset( $addons['error'] ) ) { |
| 53 | - $api = new FrmFormApi(); | |
| 54 | - $errors = $api->get_error_from_response( $addons ); | |
| 144 | + $api = new FrmFormApi(); | |
| 145 | + $errors = $api->get_error_from_response( $addons ); | |
| 55 | 146 | $license_type = isset( $addons['error']['type'] ) ? $addons['error']['type'] : ''; |
| 56 | 147 | unset( $addons['error'] ); |
| 57 | 148 | } |
| 58 | 149 | |
| 59 | - $pro = array( | |
| 150 | + $pro = array( | |
| 60 | 151 | 'pro' => array( |
| 61 | - 'title' => 'Formidable Forms Pro', | |
| 62 | - 'slug' => 'formidable-pro', | |
| 63 | - 'released' => '2011-02-05', | |
| 64 | - 'docs' => 'knowledgebase/', | |
| 65 | - 'excerpt' => 'Create calculators, surveys, smart forms, and data-driven applications. Build directories, real estate listings, job boards, and much more.', | |
| 152 | + 'title' => 'Formidable Forms Pro', | |
| 153 | + 'slug' => 'formidable-pro', | |
| 154 | + 'released' => '2011-02-05', | |
| 155 | + 'docs' => 'knowledgebase/', | |
| 156 | + 'categories' => array( 'basic', 'plus', 'business', 'elite' ), | |
| 157 | + 'excerpt' => 'Create calculators, surveys, smart forms, and data-driven applications. Build directories, real estate listings, job boards, and much more.', | |
| 66 | 158 | ), |
| 67 | 159 | ); |
| 68 | 160 | $addons = $pro + $addons; |
| 69 | 161 | self::prepare_addons( $addons ); |
| @@ -69,14 +161,105 @@ | ||
| 69 | 161 | self::prepare_addons( $addons ); |
| 70 | 162 | |
| 71 | 163 | $pricing = FrmAppHelper::admin_upgrade_link( 'addons' ); |
| 72 | 164 | |
| 73 | - include( FrmAppHelper::plugin_path() . '/classes/views/addons/list.php' ); | |
| 165 | + self::organize_and_get_categories(); | |
| 166 | + $categories = self::$categories; | |
| 167 | + | |
| 168 | + include $view_path . 'index.php'; | |
| 74 | 169 | } |
| 75 | 170 | |
| 76 | 171 | /** |
| 172 | + * Organize and set categories. | |
| 173 | + * | |
| 174 | + * @since 6.15 | |
| 175 | + * | |
| 77 | 176 | * @return void |
| 78 | 177 | */ |
| 178 | + protected static function organize_and_get_categories() { | |
| 179 | + unset( self::$categories['strategy11'] ); | |
| 180 | + ksort( self::$categories ); | |
| 181 | + | |
| 182 | + $bottom_categories = array(); | |
| 183 | + $plans = FrmFormsHelper::get_license_types( | |
| 184 | + array( | |
| 185 | + 'include_all' => false, | |
| 186 | + 'case_lower' => true, | |
| 187 | + ) | |
| 188 | + ); | |
| 189 | + | |
| 190 | + // Extract the elements to move | |
| 191 | + foreach ( $plans as $plan ) { | |
| 192 | + if ( isset( self::$categories[ $plan ] ) ) { | |
| 193 | + $bottom_categories[ $plan ] = self::$categories[ $plan ]; | |
| 194 | + unset( self::$categories[ $plan ] ); | |
| 195 | + } | |
| 196 | + } | |
| 197 | + | |
| 198 | + $special_categories = array(); | |
| 199 | + if ( 'elite' !== self::license_type() ) { | |
| 200 | + $special_categories['available-addons'] = array( | |
| 201 | + 'name' => __( 'Available', 'formidable' ), | |
| 202 | + // To be assigned via JavaScript. | |
| 203 | + 'count' => 0, | |
| 204 | + ); | |
| 205 | + } | |
| 206 | + | |
| 207 | + $special_categories['active-addons'] = array( | |
| 208 | + 'name' => __( 'Active', 'formidable' ), | |
| 209 | + // To be assigned via JavaScript. | |
| 210 | + 'count' => 0, | |
| 211 | + ); | |
| 212 | + | |
| 213 | + $special_categories['all-items'] = array( | |
| 214 | + 'name' => __( 'All Add-Ons', 'formidable' ), | |
| 215 | + // To be assigned via JavaScript. | |
| 216 | + 'count' => 0, | |
| 217 | + ); | |
| 218 | + | |
| 219 | + self::$categories = array_merge( | |
| 220 | + $special_categories, | |
| 221 | + self::$categories, | |
| 222 | + $bottom_categories | |
| 223 | + ); | |
| 224 | + } | |
| 225 | + | |
| 226 | + /** | |
| 227 | + * Organize and set categories. | |
| 228 | + * | |
| 229 | + * @since 6.15 | |
| 230 | + * | |
| 231 | + * @param array $addon The addon array that will be modified by reference. | |
| 232 | + * @return void | |
| 233 | + */ | |
| 234 | + protected static function set_categories( &$addon ) { | |
| 235 | + if ( ! isset( $addon['categories'] ) ) { | |
| 236 | + return; | |
| 237 | + } | |
| 238 | + | |
| 239 | + $addon['category-slugs'] = array(); | |
| 240 | + | |
| 241 | + foreach ( $addon['categories'] as $category ) { | |
| 242 | + $category = FrmFormsHelper::convert_legacy_package_names( $category ); | |
| 243 | + $category_slug = sanitize_title( $category ); | |
| 244 | + | |
| 245 | + // Add the slug to the new array. | |
| 246 | + $addon['category-slugs'][] = $category_slug; | |
| 247 | + | |
| 248 | + if ( ! isset( self::$categories[ $category_slug ] ) ) { | |
| 249 | + self::$categories[ $category_slug ] = array( | |
| 250 | + 'name' => $category, | |
| 251 | + 'count' => 0, | |
| 252 | + ); | |
| 253 | + } | |
| 254 | + | |
| 255 | + ++self::$categories[ $category_slug ]['count']; | |
| 256 | + } | |
| 257 | + } | |
| 258 | + | |
| 259 | + /** | |
| 260 | + * @return void | |
| 261 | + */ | |
| 79 | 262 | public static function license_settings() { |
| 80 | 263 | $plugins = apply_filters( 'frm_installed_addons', array() ); |
| 81 | 264 | if ( empty( $plugins ) ) { |
| 82 | 265 | esc_html_e( 'There are no plugins on your site that require a license', 'formidable' ); |
| @@ -85,9 +268,9 @@ | ||
| 85 | 268 | } |
| 86 | 269 | |
| 87 | 270 | ksort( $plugins ); |
| 88 | 271 | |
| 89 | - include( FrmAppHelper::plugin_path() . '/classes/views/addons/settings.php' ); | |
| 272 | + include FrmAppHelper::plugin_path() . '/classes/views/addons/settings.php'; | |
| 90 | 273 | } |
| 91 | 274 | |
| 92 | 275 | /** |
| 93 | 276 | * @return array |
| @@ -109,8 +292,21 @@ | ||
| 109 | 292 | return $addons; |
| 110 | 293 | } |
| 111 | 294 | |
| 112 | 295 | /** |
| 296 | + * Retrieves the count of available addons. | |
| 297 | + * | |
| 298 | + * @since 6.9 | |
| 299 | + * | |
| 300 | + * @return int Count of addons. | |
| 301 | + */ | |
| 302 | + public static function get_addons_count() { | |
| 303 | + $addons = self::get_api_addons(); | |
| 304 | + | |
| 305 | + return count( $addons ); | |
| 306 | + } | |
| 307 | + | |
| 308 | + /** | |
| 113 | 309 | * If the API is unable to connect, show something on the addons page |
| 114 | 310 | * |
| 115 | 311 | * @since 3.04.03 |
| 116 | 312 | * @return array |
| @@ -272,8 +468,10 @@ | ||
| 272 | 468 | } |
| 273 | 469 | |
| 274 | 470 | /** |
| 275 | 471 | * @since 4.0.01 |
| 472 | + * | |
| 473 | + * @return bool | |
| 276 | 474 | */ |
| 277 | 475 | public static function is_license_expired() { |
| 278 | 476 | $version_info = self::get_primary_license_info(); |
| 279 | 477 | if ( ! isset( $version_info['error'] ) ) { |
| @@ -279,30 +477,29 @@ | ||
| 279 | 477 | if ( ! isset( $version_info['error'] ) ) { |
| 280 | 478 | return false; |
| 281 | 479 | } |
| 282 | 480 | |
| 283 | - return $version_info['error']; | |
| 284 | - } | |
| 481 | + $expires = isset( $version_info['error']['expires'] ) ? $version_info['error']['expires'] : 0; | |
| 482 | + if ( empty( $expires ) || $expires > time() ) { | |
| 483 | + return false; | |
| 484 | + } | |
| 285 | 485 | |
| 286 | - /** | |
| 287 | - * @since 4.08 | |
| 288 | - * | |
| 289 | - * @return boolean|int false or the number of days until expiration. | |
| 290 | - */ | |
| 291 | - public static function is_license_expiring() { | |
| 292 | - if ( is_callable( 'FrmProAddonsController::is_license_expiring' ) ) { | |
| 293 | - return FrmProAddonsController::is_license_expiring(); | |
| 486 | + $rate_limited = ! empty( $version_info['response_code'] ) && 429 === (int) $version_info['response_code']; | |
| 487 | + if ( $rate_limited ) { | |
| 488 | + // Do not return false positives for rate limited responses. | |
| 489 | + return false; | |
| 294 | 490 | } |
| 295 | 491 | |
| 296 | - return false; | |
| 492 | + return $version_info['error']; | |
| 297 | 493 | } |
| 298 | 494 | |
| 299 | 495 | /** |
| 300 | 496 | * @since 4.08 |
| 497 | + * @since 6.7 This is public. | |
| 301 | 498 | * |
| 302 | 499 | * @return array|false |
| 303 | 500 | */ |
| 304 | - protected static function get_primary_license_info() { | |
| 501 | + public static function get_primary_license_info() { | |
| 305 | 502 | $installed_addons = apply_filters( 'frm_installed_addons', array() ); |
| 306 | 503 | if ( empty( $installed_addons ) || ! isset( $installed_addons['formidable_pro'] ) ) { |
| 307 | 504 | return false; |
| 308 | 505 | } |
| @@ -334,9 +531,9 @@ | ||
| 334 | 531 | $version_info = self::fill_update_addon_info( $installed_addons ); |
| 335 | 532 | $transient->last_checked = time(); |
| 336 | 533 | $wp_plugins = self::get_plugins(); |
| 337 | 534 | |
| 338 | - foreach ( $version_info as $id => $plugin ) { | |
| 535 | + foreach ( $version_info as $plugin ) { | |
| 339 | 536 | $plugin = (object) $plugin; |
| 340 | 537 | |
| 341 | 538 | if ( ! isset( $plugin->new_version ) || ! isset( $plugin->package ) ) { |
| 342 | 539 | continue; |
| @@ -351,20 +548,21 @@ | ||
| 351 | 548 | // don't show an update if the plugin isn't installed |
| 352 | 549 | continue; |
| 353 | 550 | } |
| 354 | 551 | |
| 355 | - $wp_plugin = isset( $wp_plugins[ $folder ] ) ? $wp_plugins[ $folder ] : array(); | |
| 356 | - $wp_version = isset( $wp_plugin['Version'] ) ? $wp_plugin['Version'] : '1.0'; | |
| 552 | + $wp_plugin = isset( $wp_plugins[ $folder ] ) ? $wp_plugins[ $folder ] : array(); | |
| 553 | + $wp_version = isset( $wp_plugin['Version'] ) ? $wp_plugin['Version'] : '1.0'; | |
| 554 | + $plugin->slug = explode( '/', $folder )[0]; | |
| 357 | 555 | |
| 358 | 556 | if ( version_compare( $wp_version, $plugin->new_version, '<' ) ) { |
| 359 | - $slug = explode( '/', $folder ); | |
| 360 | - $plugin->slug = $slug[0]; | |
| 361 | 557 | $transient->response[ $folder ] = $plugin; |
| 558 | + } else { | |
| 559 | + $transient->no_update[ $folder ] = $plugin; | |
| 362 | 560 | } |
| 363 | 561 | |
| 364 | 562 | $transient->checked[ $folder ] = $wp_version; |
| 365 | 563 | |
| 366 | - } | |
| 564 | + }//end foreach | |
| 367 | 565 | |
| 368 | 566 | return $transient; |
| 369 | 567 | } |
| 370 | 568 | |
| @@ -387,9 +585,9 @@ | ||
| 387 | 585 | * Check if a plugin is installed before showing an update for it |
| 388 | 586 | * |
| 389 | 587 | * @since 3.05 |
| 390 | 588 | * |
| 391 | - * @param string $plugin - the folder/filename.php for a plugin | |
| 589 | + * @param string $plugin The folder/filename.php for a plugin. | |
| 392 | 590 | * |
| 393 | 591 | * @return bool - True if installed |
| 394 | 592 | */ |
| 395 | 593 | protected static function is_installed( $plugin ) { |
| @@ -444,9 +642,9 @@ | ||
| 444 | 642 | 'code' => $addon_info['error']['code'], |
| 445 | 643 | ); |
| 446 | 644 | } |
| 447 | 645 | } |
| 448 | - } | |
| 646 | + }//end foreach | |
| 449 | 647 | |
| 450 | 648 | return $version_info; |
| 451 | 649 | } |
| 452 | 650 | |
| @@ -453,9 +651,9 @@ | ||
| 453 | 651 | /** |
| 454 | 652 | * Get the action link for an addon that isn't active. |
| 455 | 653 | * |
| 456 | 654 | * @since 3.06.03 |
| 457 | - * @param string $plugin The plugin slug | |
| 655 | + * @param string $plugin The plugin slug. | |
| 458 | 656 | * @return array |
| 459 | 657 | */ |
| 460 | 658 | public static function install_link( $plugin ) { |
| 461 | 659 | $link = array(); |
| @@ -466,14 +664,14 @@ | ||
| 466 | 664 | $link = array( |
| 467 | 665 | 'url' => $addon['plugin'], |
| 468 | 666 | 'class' => 'frm-activate-addon', |
| 469 | 667 | ); |
| 470 | - } elseif ( isset( $addon['url'] ) && ! empty( $addon['url'] ) ) { | |
| 668 | + } elseif ( ! empty( $addon['url'] ) ) { | |
| 471 | 669 | $link = array( |
| 472 | 670 | 'url' => $addon['url'], |
| 473 | 671 | 'class' => 'frm-install-addon', |
| 474 | 672 | ); |
| 475 | - } elseif ( isset( $addon['categories'] ) && ! empty( $addon['categories'] ) ) { | |
| 673 | + } elseif ( ! empty( $addon['categories'] ) ) { | |
| 476 | 674 | $link = array( |
| 477 | 675 | 'categories' => $addon['categories'], |
| 478 | 676 | ); |
| 479 | 677 | } |
| @@ -485,9 +683,9 @@ | ||
| 485 | 683 | $link = array( |
| 486 | 684 | 'url' => 'formidable-' . $plugin . '/formidable-' . $plugin . '.php', |
| 487 | 685 | 'class' => 'frm-activate-addon', |
| 488 | 686 | ); |
| 489 | - } | |
| 687 | + }//end if | |
| 490 | 688 | |
| 491 | 689 | return $link; |
| 492 | 690 | } |
| 493 | 691 | |
| @@ -492,12 +690,12 @@ | ||
| 492 | 690 | } |
| 493 | 691 | |
| 494 | 692 | /** |
| 495 | 693 | * @since 4.09 |
| 496 | - * @param string $plugin The plugin slug | |
| 694 | + * @param string $plugin The plugin slug. | |
| 497 | 695 | * @return array|false |
| 498 | 696 | */ |
| 499 | - protected static function get_addon( $plugin ) { | |
| 697 | + public static function get_addon( $plugin ) { | |
| 500 | 698 | $addons = self::get_api_addons(); |
| 501 | 699 | self::prepare_addons( $addons ); |
| 502 | 700 | foreach ( $addons as $addon ) { |
| 503 | 701 | $slug = explode( '/', $addon['plugin'] ); |
| @@ -523,10 +721,10 @@ | ||
| 523 | 721 | |
| 524 | 722 | /** |
| 525 | 723 | * @since 3.04.03 |
| 526 | 724 | * |
| 527 | - * @param array $addons | |
| 528 | - * @param object $license The FrmAddon object | |
| 725 | + * @param array $addons | |
| 726 | + * @param object $license The FrmAddon object. | |
| 529 | 727 | * |
| 530 | 728 | * @return array |
| 531 | 729 | */ |
| 532 | 730 | public static function get_addon_for_license( $addons, $license ) { |
| @@ -533,9 +731,9 @@ | ||
| 533 | 731 | $download_id = $license->download_id; |
| 534 | 732 | $plugin = array(); |
| 535 | 733 | if ( empty( $download_id ) && ! empty( $addons ) ) { |
| 536 | 734 | foreach ( $addons as $addon ) { |
| 537 | - if ( strtolower( $license->plugin_name ) == strtolower( $addon['title'] ) ) { | |
| 735 | + if ( strtolower( $license->plugin_name ) === strtolower( $addon['title'] ) ) { | |
| 538 | 736 | return $addon; |
| 539 | 737 | } |
| 540 | 738 | } |
| 541 | 739 | } elseif ( isset( $addons[ $download_id ] ) ) { |
| @@ -599,13 +797,15 @@ | ||
| 599 | 797 | |
| 600 | 798 | if ( ! isset( $addon['link'] ) ) { |
| 601 | 799 | $addon['link'] = 'downloads/' . $slug . '/'; |
| 602 | 800 | } |
| 801 | + | |
| 603 | 802 | self::prepare_addon_link( $addon['link'] ); |
| 803 | + self::set_addon_status( $addon ); | |
| 804 | + self::set_categories( $addon ); | |
| 604 | 805 | |
| 605 | - self::set_addon_status( $addon ); | |
| 606 | 806 | $addons[ $id ] = $addon; |
| 607 | - } | |
| 807 | + }//end foreach | |
| 608 | 808 | } |
| 609 | 809 | |
| 610 | 810 | /** |
| 611 | 811 | * @return bool |
| @@ -617,9 +817,9 @@ | ||
| 617 | 817 | return is_plugin_active( $file_name ); |
| 618 | 818 | } |
| 619 | 819 | |
| 620 | 820 | /** |
| 621 | - * @return string|false either 'visual-views' or 'views', false if one is not found. | |
| 821 | + * @return false|string either 'visual-views' or 'views', false if one is not found. | |
| 622 | 822 | */ |
| 623 | 823 | private static function get_active_views_version() { |
| 624 | 824 | if ( ! is_callable( 'FrmViewsAppHelper::plugin_version' ) ) { |
| 625 | 825 | return false; |
| @@ -674,263 +874,64 @@ | ||
| 674 | 874 | } |
| 675 | 875 | } |
| 676 | 876 | |
| 677 | 877 | /** |
| 678 | - * @return void | |
| 878 | + * @since 5.5.2 | |
| 879 | + * | |
| 880 | + * @param string $plugin | |
| 881 | + * @param string $redirect | |
| 882 | + * @param bool $network_wide | |
| 883 | + * @param bool $silent | |
| 884 | + * @return WP_Error|null Null on success, WP_Error on invalid file. | |
| 679 | 885 | */ |
| 680 | - public static function upgrade_to_pro() { | |
| 681 | - FrmAppHelper::include_svg(); | |
| 682 | - | |
| 683 | - $link_parts = array( | |
| 684 | - 'medium' => 'upgrade', | |
| 685 | - 'content' => 'button', | |
| 686 | - ); | |
| 687 | - | |
| 688 | - $features = array( | |
| 689 | - 'Display Entries' => array( | |
| 690 | - array( | |
| 691 | - 'label' => 'Display form data with virtually limitless views', | |
| 692 | - 'link' => array( | |
| 693 | - 'content' => 'views', | |
| 694 | - 'param' => 'views-display-form-data', | |
| 695 | - ), | |
| 696 | - 'lite' => false, | |
| 697 | - ), | |
| 698 | - array( | |
| 699 | - 'label' => 'Generate graphs and stats based on your submitted data', | |
| 700 | - 'link' => array( | |
| 701 | - 'content' => 'graphs', | |
| 702 | - 'param' => 'statistics-graphs-wordpress-forms', | |
| 703 | - ), | |
| 704 | - 'lite' => false, | |
| 705 | - ), | |
| 706 | - ), | |
| 707 | - 'Entry Management' => array( | |
| 708 | - array( | |
| 709 | - 'label' => 'Import entries from a CSV', | |
| 710 | - 'link' => array( | |
| 711 | - 'content' => 'import-entries', | |
| 712 | - 'param' => 'importing-exporting-wordpress-forms', | |
| 713 | - ), | |
| 714 | - 'lite' => false, | |
| 715 | - ), | |
| 716 | - array( | |
| 717 | - 'label' => 'Logged-in users can save drafts and return later', | |
| 718 | - 'link' => array( | |
| 719 | - 'content' => 'save-drafts', | |
| 720 | - 'param' => 'save-drafts-wordpress-form', | |
| 721 | - ), | |
| 722 | - 'lite' => false, | |
| 723 | - ), | |
| 724 | - array( | |
| 725 | - 'label' => 'Flexibly and powerfully view, edit, and delete entries from anywhere on your site', | |
| 726 | - 'link' => array( | |
| 727 | - 'content' => 'front-edit', | |
| 728 | - 'param' => 'wordpress-front-end-editing', | |
| 729 | - ), | |
| 730 | - 'lite' => false, | |
| 731 | - ), | |
| 732 | - array( | |
| 733 | - 'label' => 'View form submissions from the back-end', | |
| 734 | - 'lite' => true, | |
| 735 | - ), | |
| 736 | - array( | |
| 737 | - 'label' => 'Export your entries to a CSV', | |
| 738 | - 'lite' => true, | |
| 739 | - ), | |
| 740 | - ), | |
| 741 | - 'Form Building' => array( | |
| 742 | - array( | |
| 743 | - 'label' => 'Save a calculated value into a field', | |
| 744 | - 'link' => array( | |
| 745 | - 'content' => 'calculations', | |
| 746 | - 'param' => 'field-calculations-wordpress-form', | |
| 747 | - ), | |
| 748 | - 'lite' => false, | |
| 749 | - ), | |
| 750 | - array( | |
| 751 | - 'label' => 'Allow multiple file uploads', | |
| 752 | - 'link' => array( | |
| 753 | - 'content' => 'file-uploads', | |
| 754 | - 'param' => 'wordpress-multi-file-upload-fields', | |
| 755 | - ), | |
| 756 | - 'lite' => false, | |
| 757 | - ), | |
| 758 | - array( | |
| 759 | - 'label' => 'Repeat sections of fields', | |
| 760 | - 'link' => array( | |
| 761 | - 'content' => 'repeaters', | |
| 762 | - 'param' => 'repeatable-sections-forms', | |
| 763 | - ), | |
| 764 | - 'lite' => false, | |
| 765 | - ), | |
| 766 | - array( | |
| 767 | - 'label' => 'Hide and show fields conditionally based on other fields or the user\'s role', | |
| 768 | - 'link' => array( | |
| 769 | - 'content' => 'conditional-logic', | |
| 770 | - 'param' => 'conditional-logic-wordpress-forms', | |
| 771 | - ), | |
| 772 | - 'lite' => false, | |
| 773 | - ), | |
| 774 | - array( | |
| 775 | - 'label' => 'Confirmation fields', | |
| 776 | - 'link' => array( | |
| 777 | - 'content' => 'confirmation-fields', | |
| 778 | - 'param' => 'confirmation-fields-wordpress-forms', | |
| 779 | - ), | |
| 780 | - 'lite' => false, | |
| 781 | - ), | |
| 782 | - array( | |
| 783 | - 'label' => 'Multi-paged forms', | |
| 784 | - 'link' => array( | |
| 785 | - 'content' => 'page-breaks', | |
| 786 | - 'param' => 'wordpress-multi-page-forms', | |
| 787 | - ), | |
| 788 | - 'lite' => false, | |
| 789 | - ), | |
| 790 | - array( | |
| 791 | - 'label' => 'Include section headings, page breaks, rich text, dates, times, scales, star ratings, sliders, toggles, dynamic fields populated from other forms, passwords, and tags in advanced forms.', | |
| 792 | - 'lite' => false, | |
| 793 | - ), | |
| 794 | - array( | |
| 795 | - 'label' => 'Include text, email, url, paragraph text, radio, checkbox, dropdown fields, hidden fields, user ID fields, and HTML blocks in your form.', | |
| 796 | - 'lite' => true, | |
| 797 | - ), | |
| 798 | - array( | |
| 799 | - 'label' => 'Drag & Drop Form building', | |
| 800 | - 'link' => array( | |
| 801 | - 'content' => 'drag-drop', | |
| 802 | - 'param' => 'drag-drop-forms', | |
| 803 | - ), | |
| 804 | - 'lite' => true, | |
| 805 | - ), | |
| 806 | - array( | |
| 807 | - 'label' => 'Create forms from Templates', | |
| 808 | - 'link' => array( | |
| 809 | - 'content' => 'form-templates', | |
| 810 | - 'param' => 'wordpress-form-templates', | |
| 811 | - ), | |
| 812 | - 'lite' => true, | |
| 813 | - ), | |
| 814 | - array( | |
| 815 | - 'label' => 'Import and export forms with XML', | |
| 816 | - 'link' => array( | |
| 817 | - 'content' => 'import', | |
| 818 | - 'param' => 'importing-exporting-wordpress-forms', | |
| 819 | - ), | |
| 820 | - 'lite' => true, | |
| 821 | - ), | |
| 822 | - array( | |
| 823 | - 'label' => 'Use input placeholder text in your fields that clear when typing starts.', | |
| 824 | - 'lite' => true, | |
| 825 | - ), | |
| 826 | - ), | |
| 827 | - 'Form Actions' => array( | |
| 828 | - array( | |
| 829 | - 'label' => 'Conditionally send your email notifications based on values in your form', | |
| 830 | - 'link' => array( | |
| 831 | - 'content' => 'conditional-emails', | |
| 832 | - ), | |
| 833 | - 'lite' => false, | |
| 834 | - ), | |
| 835 | - array( | |
| 836 | - 'label' => 'Create and edit WordPress posts or custom posts from the front-end', | |
| 837 | - 'link' => array( | |
| 838 | - 'content' => 'create-posts', | |
| 839 | - 'param' => 'create-posts-pages-wordpress-forms', | |
| 840 | - ), | |
| 841 | - 'lite' => false, | |
| 842 | - ), | |
| 843 | - array( | |
| 844 | - 'label' => 'Send multiple emails and autoresponders', | |
| 845 | - 'link' => array( | |
| 846 | - 'content' => 'multiple-emails', | |
| 847 | - 'param' => 'virtually-unlimited-emails', | |
| 848 | - ), | |
| 849 | - 'lite' => true, | |
| 850 | - ), | |
| 851 | - ), | |
| 852 | - 'Form Appearance' => array( | |
| 853 | - array( | |
| 854 | - 'label' => 'Create Multiple styles for different forms', | |
| 855 | - 'link' => array( | |
| 856 | - 'content' => 'multiple-styles', | |
| 857 | - 'param' => 'wordpress-visual-form-styler', | |
| 858 | - ), | |
| 859 | - 'lite' => false, | |
| 860 | - ), | |
| 861 | - array( | |
| 862 | - 'label' => 'Customizable layout with CSS classes', | |
| 863 | - 'link' => array( | |
| 864 | - 'content' => 'form-layout', | |
| 865 | - 'param' => 'wordpress-mobile-friendly-forms', | |
| 866 | - ), | |
| 867 | - 'lite' => true, | |
| 868 | - ), | |
| 869 | - array( | |
| 870 | - 'label' => 'Customize the HTML for your forms', | |
| 871 | - 'link' => array( | |
| 872 | - 'content' => 'custom-html', | |
| 873 | - 'param' => 'customizable-html-wordpress-form', | |
| 874 | - ), | |
| 875 | - 'lite' => true, | |
| 876 | - ), | |
| 877 | - array( | |
| 878 | - 'label' => 'Style your form with the Visual Form Styler', | |
| 879 | - 'lite' => true, | |
| 880 | - ), | |
| 881 | - ), | |
| 882 | - ); | |
| 883 | - | |
| 884 | - include( FrmAppHelper::plugin_path() . '/classes/views/addons/upgrade_to_pro.php' ); | |
| 886 | + protected static function activate_plugin( $plugin, $redirect = '', $network_wide = false, $silent = false ) { | |
| 887 | + if ( ! function_exists( 'activate_plugin' ) ) { | |
| 888 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; | |
| 889 | + } | |
| 890 | + return activate_plugin( $plugin, $redirect, $network_wide, $silent ); | |
| 885 | 891 | } |
| 886 | 892 | |
| 887 | 893 | /** |
| 888 | - * Install Pro after connection with Formidable. | |
| 894 | + * Deactivate a specified plugin. | |
| 889 | 895 | * |
| 890 | - * @since 4.02.05 | |
| 896 | + * @since 6.8 | |
| 891 | 897 | * |
| 898 | + * @param string $plugin | |
| 899 | + * @param bool $silent | |
| 892 | 900 | * @return void |
| 893 | 901 | */ |
| 894 | - public static function connect_pro() { | |
| 895 | - FrmAppHelper::permission_check( 'install_plugins' ); | |
| 896 | - check_ajax_referer( 'frm_ajax', 'nonce' ); | |
| 897 | - | |
| 898 | - $url = self::get_current_plugin(); | |
| 899 | - if ( FrmAppHelper::pro_is_installed() || empty( $url ) ) { | |
| 900 | - wp_die(); | |
| 902 | + protected static function deactivate_plugin( $plugin, $silent = false ) { | |
| 903 | + if ( ! function_exists( 'deactivate_plugins' ) ) { | |
| 904 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; | |
| 901 | 905 | } |
| 902 | - | |
| 903 | - $response = array(); | |
| 904 | - | |
| 905 | - // It's already installed and active. | |
| 906 | - $active = self::activate_plugin( 'formidable-pro/formidable-pro.php', false, false, true ); | |
| 907 | - if ( is_wp_error( $active ) ) { | |
| 908 | - // The plugin was installed, but not active. Download it now. | |
| 909 | - self::ajax_install_addon(); | |
| 910 | - } else { | |
| 911 | - $response['active'] = true; | |
| 912 | - $response['success'] = true; | |
| 913 | - } | |
| 914 | - | |
| 915 | - echo json_encode( $response ); | |
| 916 | - wp_die(); | |
| 906 | + deactivate_plugins( $plugin, $silent ); | |
| 917 | 907 | } |
| 918 | 908 | |
| 919 | 909 | /** |
| 920 | - * @since 5.5.2 | |
| 910 | + * Uninstall a specified plugin. | |
| 921 | 911 | * |
| 912 | + * @since 6.8 | |
| 913 | + * | |
| 922 | 914 | * @param string $plugin |
| 923 | - * @param string $redirect | |
| 924 | - * @param bool $network_wide | |
| 925 | - * @param bool $silent | |
| 926 | - * @return null|WP_Error Null on success, WP_Error on invalid file. | |
| 915 | + * @return true|WP_Error True on success, WP_Error on invalid file. | |
| 927 | 916 | */ |
| 928 | - protected static function activate_plugin( $plugin, $redirect = '', $network_wide = false, $silent = false ) { | |
| 929 | - if ( ! function_exists( 'activate_plugin' ) ) { | |
| 917 | + protected static function uninstall_plugin( $plugin ) { | |
| 918 | + if ( ! current_user_can( 'delete_plugins' ) ) { | |
| 919 | + return new WP_Error( 'uninstall_failed', __( 'Current user cannot delete plugins.', 'formidable' ) ); | |
| 920 | + } | |
| 921 | + | |
| 922 | + if ( ! function_exists( 'delete_plugins' ) ) { | |
| 930 | 923 | require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 931 | 924 | } |
| 932 | - return activate_plugin( $plugin, $redirect, $network_wide, $silent ); | |
| 925 | + | |
| 926 | + self::deactivate_plugin( $plugin, true ); | |
| 927 | + $result = delete_plugins( array( $plugin ) ); | |
| 928 | + | |
| 929 | + if ( is_wp_error( $result ) ) { | |
| 930 | + return $result; | |
| 931 | + } | |
| 932 | + | |
| 933 | + return true; | |
| 933 | 934 | } |
| 934 | 935 | |
| 935 | 936 | /** |
| 936 | 937 | * @since 5.0.10 |
| @@ -937,9 +938,9 @@ | ||
| 937 | 938 | * |
| 938 | 939 | * @return string |
| 939 | 940 | */ |
| 940 | 941 | protected static function get_current_plugin() { |
| 941 | - if ( ! isset( self::$plugin ) ) { | |
| 942 | + if ( empty( self::$plugin ) ) { | |
| 942 | 943 | self::$plugin = FrmAppHelper::get_param( 'plugin', '', 'post', 'esc_url_raw' ); |
| 943 | 944 | } |
| 944 | 945 | return self::$plugin; |
| 945 | 946 | } |
| @@ -945,8 +946,10 @@ | ||
| 945 | 946 | } |
| 946 | 947 | |
| 947 | 948 | /** |
| 948 | 949 | * @since 4.08 |
| 950 | + * | |
| 951 | + * @return array|void | |
| 949 | 952 | */ |
| 950 | 953 | protected static function download_and_activate() { |
| 951 | 954 | if ( is_admin() ) { |
| 952 | 955 | FrmAppHelper::set_current_screen_and_hook_suffix(); |
| @@ -957,9 +960,9 @@ | ||
| 957 | 960 | $installed = self::install_addon(); |
| 958 | 961 | if ( is_array( $installed ) && isset( $installed['message'] ) ) { |
| 959 | 962 | return $installed; |
| 960 | 963 | } |
| 961 | - self::maybe_activate_addon( $installed ); | |
| 964 | + self::handle_addon_action( $installed, 'activate' ); | |
| 962 | 965 | } |
| 963 | 966 | |
| 964 | 967 | /** |
| 965 | 968 | * @since 3.04.02 |
| @@ -967,9 +970,9 @@ | ||
| 967 | 970 | * @return void |
| 968 | 971 | */ |
| 969 | 972 | protected static function maybe_show_cred_form() { |
| 970 | 973 | if ( ! function_exists( 'request_filesystem_credentials' ) ) { |
| 971 | - include_once( ABSPATH . 'wp-admin/includes/file.php' ); | |
| 974 | + include_once ABSPATH . 'wp-admin/includes/file.php'; | |
| 972 | 975 | } |
| 973 | 976 | |
| 974 | 977 | // Start output bufferring to catch the filesystem form if credentials are needed. |
| 975 | 978 | ob_start(); |
| @@ -1011,12 +1014,9 @@ | ||
| 1011 | 1014 | * |
| 1012 | 1015 | * @return bool |
| 1013 | 1016 | */ |
| 1014 | 1017 | public static function url_is_allowed( $download_url ) { |
| 1015 | - return ( | |
| 1016 | - FrmAppHelper::validate_url_is_in_s3_bucket( $download_url, 'zip' ) || | |
| 1017 | - ( strpos( $download_url, 'https://downloads.wordpress.org/plugin' ) === 0 && substr_compare( $download_url, '.zip', -4 ) === 0 ) | |
| 1018 | - ); | |
| 1018 | + return FrmAppHelper::validate_url_is_in_s3_bucket( $download_url, 'zip' ) || in_array( $download_url, self::allowed_external_urls(), true ); | |
| 1019 | 1019 | } |
| 1020 | 1020 | |
| 1021 | 1021 | /** |
| 1022 | 1022 | * We do not need any extra credentials if we have gotten this far, |
| @@ -1053,33 +1053,139 @@ | ||
| 1053 | 1053 | return $plugin; |
| 1054 | 1054 | } |
| 1055 | 1055 | |
| 1056 | 1056 | /** |
| 1057 | - * @since 3.06.03 | |
| 1057 | + * Handle the AJAX request to activate an add-on. | |
| 1058 | 1058 | * |
| 1059 | + * @since 6.8 | |
| 1060 | + * | |
| 1059 | 1061 | * @return void |
| 1060 | 1062 | */ |
| 1061 | 1063 | public static function ajax_activate_addon() { |
| 1064 | + self::process_addon_action( | |
| 1065 | + function ( $plugin ) { | |
| 1066 | + return self::handle_addon_action( $plugin, 'activate' ); | |
| 1067 | + }, | |
| 1068 | + array( 'FrmAddonsController', 'get_addon_activation_response' ) | |
| 1069 | + ); | |
| 1070 | + } | |
| 1062 | 1071 | |
| 1072 | + /** | |
| 1073 | + * @since 3.04.02 | |
| 1074 | + * | |
| 1075 | + * @param string $installed The plugin folder name with file name. | |
| 1076 | + */ | |
| 1077 | + protected static function maybe_activate_addon( $installed ) { | |
| 1078 | + self::ajax_activate_addon(); | |
| 1079 | + } | |
| 1080 | + | |
| 1081 | + /** | |
| 1082 | + * Handle the AJAX request to deactivate an add-on. | |
| 1083 | + * | |
| 1084 | + * @since 6.8 | |
| 1085 | + * | |
| 1086 | + * @return void | |
| 1087 | + */ | |
| 1088 | + public static function ajax_deactivate_addon() { | |
| 1089 | + self::process_addon_action( | |
| 1090 | + function ( $plugin ) { | |
| 1091 | + return self::handle_addon_action( $plugin, 'deactivate' ); | |
| 1092 | + } | |
| 1093 | + ); | |
| 1094 | + } | |
| 1095 | + | |
| 1096 | + /** | |
| 1097 | + * Handle the AJAX request to uninstall an add-on. | |
| 1098 | + * | |
| 1099 | + * @since 6.8 | |
| 1100 | + * | |
| 1101 | + * @return void | |
| 1102 | + */ | |
| 1103 | + public static function ajax_uninstall_addon() { | |
| 1104 | + self::process_addon_action( | |
| 1105 | + function ( $plugin ) { | |
| 1106 | + return self::handle_addon_action( $plugin, 'uninstall' ); | |
| 1107 | + } | |
| 1108 | + ); | |
| 1109 | + } | |
| 1110 | + | |
| 1111 | + /** | |
| 1112 | + * Process a specific action (activate, deactivate, uninstall) on an add-on. | |
| 1113 | + * | |
| 1114 | + * @since 6.8 | |
| 1115 | + * | |
| 1116 | + * @param callable $action_callback The specific add-on action to be executed. | |
| 1117 | + * @param callable|null $response_callback Optional. The response handling callback. Default null. | |
| 1118 | + * @return void | |
| 1119 | + */ | |
| 1120 | + private static function process_addon_action( $action_callback, $response_callback = null ) { | |
| 1063 | 1121 | self::install_addon_permissions(); |
| 1064 | - | |
| 1065 | 1122 | FrmAppHelper::set_current_screen_and_hook_suffix(); |
| 1066 | 1123 | |
| 1067 | 1124 | $plugin = FrmAppHelper::get_param( 'plugin', '', 'post', 'sanitize_text_field' ); |
| 1068 | - self::maybe_activate_addon( $plugin ); | |
| 1125 | + call_user_func( $action_callback, $plugin ); | |
| 1069 | 1126 | |
| 1070 | - echo json_encode( self::get_addon_activation_response() ); | |
| 1071 | - wp_die(); | |
| 1127 | + if ( is_callable( $response_callback ) ) { | |
| 1128 | + wp_send_json_success( call_user_func( $response_callback ) ); | |
| 1129 | + return; | |
| 1130 | + } | |
| 1131 | + | |
| 1132 | + wp_send_json_success(); | |
| 1072 | 1133 | } |
| 1073 | 1134 | |
| 1074 | 1135 | /** |
| 1136 | + * Attempt to perform a specific action (activate, deactivate, uninstall) on an add-on. | |
| 1137 | + * | |
| 1138 | + * @since 6.8 | |
| 1139 | + * | |
| 1140 | + * @param string $installed The plugin folder name with file name. | |
| 1141 | + * @param string $action The action type ('activate', 'deactivate', 'uninstall'). | |
| 1142 | + * @return array|void | |
| 1143 | + */ | |
| 1144 | + protected static function handle_addon_action( $installed, $action ) { | |
| 1145 | + if ( ! $installed || ! $action ) { | |
| 1146 | + return; | |
| 1147 | + } | |
| 1148 | + | |
| 1149 | + $result = null; | |
| 1150 | + switch ( $action ) { | |
| 1151 | + case 'activate': | |
| 1152 | + $result = self::activate_plugin( $installed ); | |
| 1153 | + break; | |
| 1154 | + case 'deactivate': | |
| 1155 | + self::deactivate_plugin( $installed ); | |
| 1156 | + break; | |
| 1157 | + case 'uninstall': | |
| 1158 | + $result = self::uninstall_plugin( $installed ); | |
| 1159 | + break; | |
| 1160 | + } | |
| 1161 | + | |
| 1162 | + if ( is_wp_error( $result ) ) { | |
| 1163 | + // Ignore the invalid header message that shows with nested plugins. | |
| 1164 | + if ( $result->get_error_code() !== 'no_plugin_header' ) { | |
| 1165 | + if ( wp_doing_ajax() ) { | |
| 1166 | + wp_send_json_error( array( 'error' => $result->get_error_message() ) ); | |
| 1167 | + } | |
| 1168 | + return array( | |
| 1169 | + 'message' => $result->get_error_message(), | |
| 1170 | + 'success' => false, | |
| 1171 | + ); | |
| 1172 | + } | |
| 1173 | + } | |
| 1174 | + | |
| 1175 | + return $result; | |
| 1176 | + } | |
| 1177 | + | |
| 1178 | + /** | |
| 1075 | 1179 | * @return array |
| 1076 | 1180 | */ |
| 1077 | 1181 | private static function get_addon_activation_response() { |
| 1078 | 1182 | $activating_page = self::get_activating_page(); |
| 1079 | 1183 | |
| 1184 | + $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' ); | |
| 1185 | + | |
| 1080 | 1186 | $response = array( |
| 1081 | - 'message' => __( 'Your plugin has been activated. Would you like to save and reload the page now?', 'formidable' ), | |
| 1187 | + 'message' => $message, | |
| 1082 | 1188 | 'saveAndReload' => $activating_page, |
| 1083 | 1189 | ); |
| 1084 | 1190 | |
| 1085 | 1191 | return $response; |
| @@ -1104,34 +1210,8 @@ | ||
| 1104 | 1210 | return ''; |
| 1105 | 1211 | } |
| 1106 | 1212 | |
| 1107 | 1213 | /** |
| 1108 | - * @since 3.04.02 | |
| 1109 | - * | |
| 1110 | - * @param string $installed The plugin folder name with file name | |
| 1111 | - */ | |
| 1112 | - protected static function maybe_activate_addon( $installed ) { | |
| 1113 | - if ( ! $installed ) { | |
| 1114 | - return; | |
| 1115 | - } | |
| 1116 | - | |
| 1117 | - $activate = self::activate_plugin( $installed ); | |
| 1118 | - if ( is_wp_error( $activate ) ) { | |
| 1119 | - // Ignore the invalid header message that shows with nested plugins. | |
| 1120 | - if ( $activate->get_error_code() !== 'no_plugin_header' ) { | |
| 1121 | - if ( wp_doing_ajax() ) { | |
| 1122 | - echo json_encode( array( 'error' => $activate->get_error_message() ) ); | |
| 1123 | - wp_die(); | |
| 1124 | - } | |
| 1125 | - return array( | |
| 1126 | - 'message' => $activate->get_error_message(), | |
| 1127 | - 'success' => false, | |
| 1128 | - ); | |
| 1129 | - } | |
| 1130 | - } | |
| 1131 | - } | |
| 1132 | - | |
| 1133 | - /** | |
| 1134 | 1214 | * Run security checks before installing |
| 1135 | 1215 | * |
| 1136 | 1216 | * @since 3.04.02 |
| 1137 | 1217 | * |
| @@ -1154,15 +1234,18 @@ | ||
| 1154 | 1234 | public static function connect_link() { |
| 1155 | 1235 | $auth = get_option( 'frm_connect_token' ); |
| 1156 | 1236 | if ( empty( $auth ) ) { |
| 1157 | 1237 | $auth = hash( 'sha512', wp_rand() ); |
| 1158 | - update_option( 'frm_connect_token', $auth ); | |
| 1238 | + update_option( 'frm_connect_token', $auth, 'no' ); | |
| 1159 | 1239 | } |
| 1160 | - $link = FrmAppHelper::admin_upgrade_link( 'connect', 'api-connect' ); | |
| 1240 | + $page = FrmAppHelper::simple_get( 'page', 'sanitize_title', 'formidable-settings' ); | |
| 1241 | + $link = 'https://formidableforms.com/api-connect/'; | |
| 1161 | 1242 | $args = array( |
| 1162 | 1243 | 'v' => 2, |
| 1163 | 1244 | 'siteurl' => FrmAppHelper::site_url(), |
| 1164 | 1245 | 'url' => get_rest_url(), |
| 1246 | + 'inst' => (int) FrmAppHelper::pro_is_included(), | |
| 1247 | + 'return' => $page, | |
| 1165 | 1248 | 'token' => $auth, |
| 1166 | 1249 | 'l' => self::get_pro_license(), |
| 1167 | 1250 | ); |
| 1168 | 1251 | |
| @@ -1180,9 +1263,12 @@ | ||
| 1180 | 1263 | // Verify params present (auth & download link). |
| 1181 | 1264 | $post_auth = FrmAppHelper::get_param( 'token', '', 'request', 'sanitize_text_field' ); |
| 1182 | 1265 | $post_url = FrmAppHelper::get_param( 'file_url', '', 'request', 'sanitize_text_field' ); |
| 1183 | 1266 | |
| 1184 | - if ( empty( $post_auth ) || empty( $post_url ) ) { | |
| 1267 | + // The download link is not required if already installed. | |
| 1268 | + $is_installed = FrmAppHelper::pro_is_included(); | |
| 1269 | + $file_missing = ! $is_installed && empty( $post_url ); | |
| 1270 | + if ( ! $post_auth || $file_missing ) { | |
| 1185 | 1271 | return false; |
| 1186 | 1272 | } |
| 1187 | 1273 | |
| 1188 | 1274 | // Verify auth. |
| @@ -1197,8 +1283,10 @@ | ||
| 1197 | 1283 | /** |
| 1198 | 1284 | * Install and/or activate the add-on file. |
| 1199 | 1285 | * |
| 1200 | 1286 | * @since 4.08 |
| 1287 | + * | |
| 1288 | + * @return array | |
| 1201 | 1289 | */ |
| 1202 | 1290 | public static function install_addon_api() { |
| 1203 | 1291 | self::$plugin = FrmAppHelper::get_param( 'file_url', '', 'request', 'esc_url_raw' ); |
| 1204 | 1292 | |
| @@ -1209,11 +1297,11 @@ | ||
| 1209 | 1297 | |
| 1210 | 1298 | // It's already installed and active. |
| 1211 | 1299 | $active = self::activate_plugin( 'formidable-pro/formidable-pro.php', false, false, true ); |
| 1212 | 1300 | if ( is_wp_error( $active ) ) { |
| 1213 | - // Download plugin now. | |
| 1214 | - $response = self::download_and_activate(); | |
| 1215 | - if ( is_array( $response ) && isset( $response['success'] ) ) { | |
| 1301 | + $response = self::maybe_download_and_activate(); | |
| 1302 | + if ( is_array( $response ) ) { | |
| 1303 | + // The download failed. | |
| 1216 | 1304 | return $response; |
| 1217 | 1305 | } |
| 1218 | 1306 | } |
| 1219 | 1307 | |
| @@ -1240,22 +1328,58 @@ | ||
| 1240 | 1328 | ); |
| 1241 | 1329 | } |
| 1242 | 1330 | |
| 1243 | 1331 | /** |
| 1332 | + * @since 6.8.3 | |
| 1333 | + * | |
| 1334 | + * @return array|true | |
| 1335 | + */ | |
| 1336 | + private static function maybe_download_and_activate() { | |
| 1337 | + if ( ! self::$plugin ) { | |
| 1338 | + return array( | |
| 1339 | + 'success' => false, | |
| 1340 | + 'message' => __( 'The plugin download was not found.', 'formidable' ), | |
| 1341 | + ); | |
| 1342 | + } | |
| 1343 | + | |
| 1344 | + // Download plugin now. | |
| 1345 | + $response = self::download_and_activate(); | |
| 1346 | + if ( is_array( $response ) && isset( $response['success'] ) ) { | |
| 1347 | + // The download failed. | |
| 1348 | + return $response; | |
| 1349 | + } | |
| 1350 | + | |
| 1351 | + return true; | |
| 1352 | + } | |
| 1353 | + | |
| 1354 | + /** | |
| 1244 | 1355 | * Render a conditional action button for a specified plugin |
| 1245 | 1356 | * |
| 1246 | - * @param string $plugin | |
| 1357 | + * @since 4.09 | |
| 1358 | + * | |
| 1359 | + * @param string $plugin | |
| 1247 | 1360 | * @param array|string $upgrade_link_args |
| 1248 | - * @since 4.09 | |
| 1361 | + * @return void | |
| 1249 | 1362 | */ |
| 1250 | 1363 | public static function conditional_action_button( $plugin, $upgrade_link_args ) { |
| 1251 | 1364 | if ( is_callable( 'FrmProAddonsController::conditional_action_button' ) ) { |
| 1252 | - return FrmProAddonsController::conditional_action_button( $plugin, $upgrade_link_args ); | |
| 1365 | + FrmProAddonsController::conditional_action_button( $plugin, $upgrade_link_args ); | |
| 1366 | + return; | |
| 1253 | 1367 | } |
| 1254 | 1368 | |
| 1255 | 1369 | $addon = self::get_addon( $plugin ); |
| 1256 | 1370 | $upgrade_link = FrmAppHelper::admin_upgrade_link( $upgrade_link_args ); |
| 1257 | - self::addon_upgrade_link( $addon, $upgrade_link ); | |
| 1371 | + | |
| 1372 | + if ( ! is_array( $upgrade_link_args ) ) { | |
| 1373 | + // A string $upgrade_link_args is used for the utm-medium value when calling | |
| 1374 | + // FrmAppHelper::admin_upgrade_link above. | |
| 1375 | + // For self::addon_upgrade_link, we'll pass just an empty array with the link key (set below). | |
| 1376 | + $upgrade_link_args = array(); | |
| 1377 | + } | |
| 1378 | + | |
| 1379 | + $upgrade_link_args['link'] = $upgrade_link; | |
| 1380 | + | |
| 1381 | + self::addon_upgrade_link( $addon, $upgrade_link_args ); | |
| 1258 | 1382 | } |
| 1259 | 1383 | |
| 1260 | 1384 | /** |
| 1261 | 1385 | * Render a conditional action button for an add on |
| @@ -1261,16 +1385,22 @@ | ||
| 1261 | 1385 | * Render a conditional action button for an add on |
| 1262 | 1386 | * |
| 1263 | 1387 | * @since 4.09.01 |
| 1264 | 1388 | * |
| 1265 | - * @param array $addon | |
| 1266 | - * @param string|false $license_type | |
| 1267 | - * @param string $plan_required | |
| 1268 | - * @param string $upgrade_link | |
| 1389 | + * @param array $atts { | |
| 1390 | + * Button attributes. | |
| 1391 | + * | |
| 1392 | + * @type array $addon | |
| 1393 | + * @type false|string $license_type | |
| 1394 | + * @type string $plan_required | |
| 1395 | + * @type string $upgrade_link | |
| 1396 | + * } | |
| 1397 | + * @return void | |
| 1269 | 1398 | */ |
| 1270 | 1399 | public static function show_conditional_action_button( $atts ) { |
| 1271 | 1400 | if ( is_callable( 'FrmProAddonsController::show_conditional_action_button' ) ) { |
| 1272 | - return FrmProAddonsController::show_conditional_action_button( $atts ); | |
| 1401 | + FrmProAddonsController::show_conditional_action_button( $atts ); | |
| 1402 | + return; | |
| 1273 | 1403 | } |
| 1274 | 1404 | |
| 1275 | 1405 | self::addon_upgrade_link( $atts['addon'], $atts['upgrade_link'] ); |
| 1276 | 1406 | } |
| @@ -1277,13 +1407,18 @@ | ||
| 1277 | 1407 | |
| 1278 | 1408 | /** |
| 1279 | 1409 | * @since 4.09.01 |
| 1280 | 1410 | * |
| 1281 | - * @param array|false $addon | |
| 1411 | + * @param array|false $addon | |
| 1412 | + * @param array|string $upgrade_link | |
| 1282 | 1413 | * |
| 1283 | 1414 | * @return void |
| 1284 | 1415 | */ |
| 1285 | - protected static function addon_upgrade_link( $addon, $upgrade_link ) { | |
| 1416 | + public static function addon_upgrade_link( $addon, $upgrade_link ) { | |
| 1417 | + $atts = is_array( $upgrade_link ) ? $upgrade_link : array(); | |
| 1418 | + $upgrade_link = is_array( $upgrade_link ) ? $upgrade_link['link'] : $upgrade_link; | |
| 1419 | + $text = ! empty( $atts['text'] ) ? $atts['text'] : __( 'Upgrade Now', 'formidable' ); | |
| 1420 | + | |
| 1286 | 1421 | if ( $addon ) { |
| 1287 | 1422 | $upgrade_link .= '&utm_content=' . $addon['slug']; |
| 1288 | 1423 | } |
| 1289 | 1424 | |
| @@ -1290,11 +1425,16 @@ | ||
| 1290 | 1425 | if ( $addon && isset( $addon['categories'] ) && in_array( 'Solution', $addon['categories'], true ) ) { |
| 1291 | 1426 | // Solutions will go to a separate page. |
| 1292 | 1427 | $upgrade_link = FrmAppHelper::admin_upgrade_link( 'addons', $addon['link'] ); |
| 1293 | 1428 | } |
| 1429 | + | |
| 1430 | + $class = ! empty( $atts['class'] ) ? $atts['class'] : ''; | |
| 1431 | + if ( strpos( $class, 'frm-button' ) === false ) { | |
| 1432 | + $class .= ' frm-button-secondary frm-button-sm'; | |
| 1433 | + } | |
| 1294 | 1434 | ?> |
| 1295 | - <a class="install-now button frm-button-secondary frm-button-sm" href="<?php echo esc_url( $upgrade_link ); ?>" target="_blank" rel="noopener" aria-label="<?php esc_attr_e( 'Upgrade Now', 'formidable' ); ?>"> | |
| 1296 | - <?php esc_html_e( 'Upgrade Now', 'formidable' ); ?> | |
| 1435 | + <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' ); ?>"> | |
| 1436 | + <?php echo esc_html( $text ); ?> | |
| 1297 | 1437 | </a> |
| 1298 | 1438 | <?php |
| 1299 | 1439 | } |
| 1300 | 1440 | |
| @@ -1316,107 +1456,58 @@ | ||
| 1316 | 1456 | wp_die(); |
| 1317 | 1457 | } |
| 1318 | 1458 | |
| 1319 | 1459 | /** |
| 1320 | - * @since 4.06.02 | |
| 1460 | + * Allowed URLs used for internal source of plugins installation. | |
| 1321 | 1461 | * |
| 1322 | - * @deprecated 4.09.01 | |
| 1462 | + * @since 6.3.1 | |
| 1323 | 1463 | * |
| 1324 | - * @return void | |
| 1464 | + * @return array | |
| 1325 | 1465 | */ |
| 1326 | - public static function ajax_multiple_addons() { | |
| 1327 | - FrmDeprecated::ajax_multiple_addons(); | |
| 1328 | - } | |
| 1466 | + private static function allowed_external_urls() { | |
| 1467 | + $allowed_url_list = array( | |
| 1468 | + 'https://downloads.wordpress.org/plugin/formidable-gravity-forms-importer.zip', | |
| 1469 | + 'https://downloads.wordpress.org/plugin/formidable-import-pirate-forms.zip', | |
| 1470 | + 'https://downloads.wordpress.org/plugin/wp-mail-smtp.zip', | |
| 1471 | + ); | |
| 1329 | 1472 | |
| 1330 | - /** | |
| 1331 | - * @since 3.04.03 | |
| 1332 | - * @deprecated 3.06 | |
| 1333 | - * @codeCoverageIgnore | |
| 1334 | - * @return array | |
| 1335 | - */ | |
| 1336 | - public static function error_for_license( $license ) { | |
| 1337 | - return FrmDeprecated::error_for_license( $license ); | |
| 1338 | - } | |
| 1473 | + /** | |
| 1474 | + * List of URLs used in plugin formidable internal installation. | |
| 1475 | + * | |
| 1476 | + * @since 6.3.1 | |
| 1477 | + * | |
| 1478 | + * @param array $allowed_url_list List of URLs. | |
| 1479 | + */ | |
| 1480 | + $allowed_url_list = apply_filters( 'frm_allowed_external_urls', $allowed_url_list ); | |
| 1339 | 1481 | |
| 1340 | - /** | |
| 1341 | - * @since 3.04.03 | |
| 1342 | - * @deprecated 3.06 | |
| 1343 | - * @codeCoverageIgnore | |
| 1344 | - */ | |
| 1345 | - public static function get_pro_updater() { | |
| 1346 | - return FrmDeprecated::get_pro_updater(); | |
| 1347 | - } | |
| 1482 | + if ( ! is_array( $allowed_url_list ) ) { | |
| 1483 | + _doing_it_wrong( __METHOD__, 'Only an array of URLs could be used within this filter.', '6.3.1' ); | |
| 1348 | 1484 | |
| 1349 | - /** | |
| 1350 | - * @since 3.04.03 | |
| 1351 | - * @deprecated 3.06 | |
| 1352 | - * @codeCoverageIgnore | |
| 1353 | - * | |
| 1354 | - * @return array | |
| 1355 | - */ | |
| 1356 | - public static function get_addon_info( $license = '' ) { | |
| 1357 | - return FrmDeprecated::get_addon_info( $license ); | |
| 1358 | - } | |
| 1485 | + return array(); | |
| 1486 | + } | |
| 1359 | 1487 | |
| 1360 | - /** | |
| 1361 | - * @since 3.04.03 | |
| 1362 | - * @deprecated 3.06 | |
| 1363 | - * @codeCoverageIgnore | |
| 1364 | - * | |
| 1365 | - * @return string | |
| 1366 | - */ | |
| 1367 | - public static function get_cache_key( $license ) { | |
| 1368 | - return FrmDeprecated::get_cache_key( $license ); | |
| 1488 | + return $allowed_url_list; | |
| 1369 | 1489 | } |
| 1370 | 1490 | |
| 1371 | 1491 | /** |
| 1372 | - * @since 3.04.03 | |
| 1492 | + * Gets required plan for an addon. | |
| 1373 | 1493 | * |
| 1374 | - * @deprecated 3.06 | |
| 1494 | + * @since 6.4.2 | |
| 1375 | 1495 | * |
| 1376 | - * @codeCoverageIgnore | |
| 1377 | - * | |
| 1378 | - * @return void | |
| 1496 | + * @return string Empty string if no plan is required for active license. | |
| 1379 | 1497 | */ |
| 1380 | - public static function reset_cached_addons( $license = '' ) { | |
| 1381 | - FrmDeprecated::reset_cached_addons( $license ); | |
| 1382 | - } | |
| 1498 | + public static function get_addon_required_plan( $addon_id ) { | |
| 1499 | + $api = new FrmFormApi(); | |
| 1500 | + $addons = $api->get_api_info(); | |
| 1383 | 1501 | |
| 1384 | - /** | |
| 1385 | - * @since 2.03.08 | |
| 1386 | - * @deprecated 3.04.03 | |
| 1387 | - * @codeCoverageIgnore | |
| 1388 | - * | |
| 1389 | - * @param boolean $return | |
| 1390 | - * @param string $package | |
| 1391 | - * | |
| 1392 | - * @return boolean | |
| 1393 | - */ | |
| 1394 | - public static function add_shorten_edd_filename_filter( $return, $package ) { | |
| 1395 | - return FrmDeprecated::add_shorten_edd_filename_filter( $return, $package ); | |
| 1396 | - } | |
| 1502 | + if ( is_array( $addons ) && array_key_exists( $addon_id, $addons ) ) { | |
| 1503 | + $dates = $addons[ $addon_id ]; | |
| 1504 | + $requires = FrmFormsHelper::get_plan_required( $dates ); | |
| 1505 | + } | |
| 1397 | 1506 | |
| 1398 | - /** | |
| 1399 | - * @since 2.03.08 | |
| 1400 | - * @deprecated 3.04.03 | |
| 1401 | - * @codeCoverageIgnore | |
| 1402 | - * | |
| 1403 | - * @param string $filename | |
| 1404 | - * @param string $ext | |
| 1405 | - * | |
| 1406 | - * @return string | |
| 1407 | - */ | |
| 1408 | - public static function shorten_edd_filename( $filename, $ext ) { | |
| 1409 | - return FrmDeprecated::shorten_edd_filename( $filename, $ext ); | |
| 1410 | - } | |
| 1507 | + if ( ! isset( $requires ) || ! is_string( $requires ) ) { | |
| 1508 | + $requires = ''; | |
| 1509 | + } | |
| 1411 | 1510 | |
| 1412 | - /** | |
| 1413 | - * @deprecated 3.04.03 | |
| 1414 | - * | |
| 1415 | - * @codeCoverageIgnore | |
| 1416 | - * | |
| 1417 | - * @return void | |
| 1418 | - */ | |
| 1419 | - public static function get_licenses() { | |
| 1420 | - FrmDeprecated::get_licenses(); | |
| 1511 | + return $requires; | |
| 1421 | 1512 | } |
| 1422 | 1513 | } |