| @@ -5,93 +5,15 @@ | ||
| 5 | 5 | |
| 6 | 6 | class FrmAddonsController { |
| 7 | 7 | |
| 8 | 8 | /** |
| 9 | - * @var string | |
| 9 | + * @var string $plugin | |
| 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 | - */ | |
| 26 | 11 | protected static $plugin; |
| 27 | 12 | |
| 28 | 13 | /** |
| 29 | - * @since 6.15 | |
| 30 | - */ | |
| 31 | - public static function load_admin_hooks() { | |
| 32 | - add_action( 'admin_menu', self::class . '::menu', 100 ); | |
| 33 | - add_filter( 'pre_set_site_transient_update_plugins', self::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', self::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 | - * | |
| 48 | 14 | * @return void |
| 49 | 15 | */ |
| 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 | - */ | |
| 94 | 16 | public static function menu() { |
| 95 | 17 | if ( ! current_user_can( 'activate_plugins' ) ) { |
| 96 | 18 | return; |
| 97 | 19 | } |
| @@ -96,36 +18,25 @@ | ||
| 96 | 18 | return; |
| 97 | 19 | } |
| 98 | 20 | |
| 99 | 21 | $label = __( 'Add-Ons', 'formidable' ); |
| 100 | - $label = '<span style="color:#3FCA89">' . esc_html( $label ) . '</span>'; | |
| 22 | + $label = '<span style="color:#fe5a1d">' . $label . '</span>'; | |
| 101 | 23 | |
| 102 | 24 | add_submenu_page( 'formidable', 'Formidable | ' . __( 'Add-Ons', 'formidable' ), $label, 'frm_view_forms', 'formidable-addons', 'FrmAddonsController::list_addons' ); |
| 103 | 25 | |
| 104 | - // remove default created subpage, make the page with highest priority as default. | |
| 105 | - remove_submenu_page( 'formidable', 'formidable' ); | |
| 106 | - | |
| 107 | 26 | 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 | - | |
| 113 | 27 | add_submenu_page( |
| 114 | 28 | 'formidable', |
| 115 | 29 | 'Formidable | ' . __( 'Upgrade', 'formidable' ), |
| 116 | - '<span class="frm-upgrade-submenu">' . esc_html( $cta_text ) . '</span>', | |
| 30 | + '<span class="frm-upgrade-submenu">' . __( 'Upgrade', 'formidable' ) . '</span>', | |
| 117 | 31 | 'frm_view_forms', |
| 118 | 32 | 'formidable-pro-upgrade', |
| 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 | - } | |
| 33 | + 'FrmAddonsController::upgrade_to_pro' | |
| 123 | 34 | ); |
| 124 | 35 | } elseif ( 'formidable-pro-upgrade' === FrmAppHelper::get_param( 'page' ) ) { |
| 125 | 36 | wp_safe_redirect( admin_url( 'admin.php?page=formidable' ) ); |
| 126 | 37 | exit; |
| 127 | - }//end if | |
| 38 | + } | |
| 128 | 39 | } |
| 129 | 40 | |
| 130 | 41 | /** |
| 131 | 42 | * @return void |
| @@ -131,31 +42,28 @@ | ||
| 131 | 42 | * @return void |
| 132 | 43 | */ |
| 133 | 44 | public static function list_addons() { |
| 134 | 45 | FrmAppHelper::include_svg(); |
| 46 | + $installed_addons = apply_filters( 'frm_installed_addons', array() ); | |
| 47 | + $license_type = ''; | |
| 135 | 48 | |
| 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; | |
| 49 | + $addons = self::get_api_addons(); | |
| 50 | + $errors = array(); | |
| 142 | 51 | |
| 143 | 52 | if ( isset( $addons['error'] ) ) { |
| 144 | - $api = new FrmFormApi(); | |
| 145 | - $errors = $api->get_error_from_response( $addons ); | |
| 146 | - $license_type = $addons['error']['type'] ?? ''; | |
| 53 | + $api = new FrmFormApi(); | |
| 54 | + $errors = $api->get_error_from_response( $addons ); | |
| 55 | + $license_type = isset( $addons['error']['type'] ) ? $addons['error']['type'] : ''; | |
| 147 | 56 | unset( $addons['error'] ); |
| 148 | 57 | } |
| 149 | 58 | |
| 150 | - $pro = array( | |
| 59 | + $pro = array( | |
| 151 | 60 | 'pro' => array( |
| 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.', | |
| 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.', | |
| 158 | 66 | ), |
| 159 | 67 | ); |
| 160 | 68 | $addons = $pro + $addons; |
| 161 | 69 | self::prepare_addons( $addons ); |
| @@ -161,105 +69,14 @@ | ||
| 161 | 69 | self::prepare_addons( $addons ); |
| 162 | 70 | |
| 163 | 71 | $pricing = FrmAppHelper::admin_upgrade_link( 'addons' ); |
| 164 | 72 | |
| 165 | - self::organize_and_get_categories(); | |
| 166 | - $categories = self::$categories; | |
| 167 | - | |
| 168 | - include $view_path . 'index.php'; | |
| 73 | + include( FrmAppHelper::plugin_path() . '/classes/views/addons/list.php' ); | |
| 169 | 74 | } |
| 170 | 75 | |
| 171 | 76 | /** |
| 172 | - * Organize and set categories. | |
| 173 | - * | |
| 174 | - * @since 6.15 | |
| 175 | - * | |
| 176 | 77 | * @return void |
| 177 | 78 | */ |
| 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 | - */ | |
| 262 | 79 | public static function license_settings() { |
| 263 | 80 | $plugins = apply_filters( 'frm_installed_addons', array() ); |
| 264 | 81 | if ( empty( $plugins ) ) { |
| 265 | 82 | esc_html_e( 'There are no plugins on your site that require a license', 'formidable' ); |
| @@ -268,9 +85,9 @@ | ||
| 268 | 85 | } |
| 269 | 86 | |
| 270 | 87 | ksort( $plugins ); |
| 271 | 88 | |
| 272 | - include FrmAppHelper::plugin_path() . '/classes/views/addons/settings.php'; | |
| 89 | + include( FrmAppHelper::plugin_path() . '/classes/views/addons/settings.php' ); | |
| 273 | 90 | } |
| 274 | 91 | |
| 275 | 92 | /** |
| 276 | 93 | * @return array |
| @@ -292,21 +109,8 @@ | ||
| 292 | 109 | return $addons; |
| 293 | 110 | } |
| 294 | 111 | |
| 295 | 112 | /** |
| 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 | - /** | |
| 309 | 113 | * If the API is unable to connect, show something on the addons page |
| 310 | 114 | * |
| 311 | 115 | * @since 3.04.03 |
| 312 | 116 | * @return array |
| @@ -414,9 +218,9 @@ | ||
| 414 | 218 | $api = new FrmFormApi( $license ); |
| 415 | 219 | $downloads = $api->get_api_info(); |
| 416 | 220 | $pro = self::get_pro_from_addons( $downloads ); |
| 417 | 221 | |
| 418 | - return $pro['url'] ?? ''; | |
| 222 | + return isset( $pro['url'] ) ? $pro['url'] : ''; | |
| 419 | 223 | } |
| 420 | 224 | |
| 421 | 225 | /** |
| 422 | 226 | * @since 4.08 |
| @@ -452,9 +256,9 @@ | ||
| 452 | 256 | * @param array $addons |
| 453 | 257 | * @return array |
| 454 | 258 | */ |
| 455 | 259 | protected static function get_pro_from_addons( $addons ) { |
| 456 | - return $addons['93790'] ?? array(); | |
| 260 | + return isset( $addons['93790'] ) ? $addons['93790'] : array(); | |
| 457 | 261 | } |
| 458 | 262 | |
| 459 | 263 | /** |
| 460 | 264 | * @since 4.06 |
| @@ -468,10 +272,8 @@ | ||
| 468 | 272 | } |
| 469 | 273 | |
| 470 | 274 | /** |
| 471 | 275 | * @since 4.0.01 |
| 472 | - * | |
| 473 | - * @return bool | |
| 474 | 276 | */ |
| 475 | 277 | public static function is_license_expired() { |
| 476 | 278 | $version_info = self::get_primary_license_info(); |
| 477 | 279 | if ( ! isset( $version_info['error'] ) ) { |
| @@ -477,29 +279,30 @@ | ||
| 477 | 279 | if ( ! isset( $version_info['error'] ) ) { |
| 478 | 280 | return false; |
| 479 | 281 | } |
| 480 | 282 | |
| 481 | - $expires = $version_info['error']['expires'] ?? 0; | |
| 482 | - if ( empty( $expires ) || $expires > time() ) { | |
| 483 | - return false; | |
| 484 | - } | |
| 283 | + return $version_info['error']; | |
| 284 | + } | |
| 485 | 285 | |
| 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; | |
| 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(); | |
| 490 | 294 | } |
| 491 | 295 | |
| 492 | - return $version_info['error']; | |
| 296 | + return false; | |
| 493 | 297 | } |
| 494 | 298 | |
| 495 | 299 | /** |
| 496 | 300 | * @since 4.08 |
| 497 | - * @since 6.7 This is public. | |
| 498 | 301 | * |
| 499 | 302 | * @return array|false |
| 500 | 303 | */ |
| 501 | - public static function get_primary_license_info() { | |
| 304 | + protected static function get_primary_license_info() { | |
| 502 | 305 | $installed_addons = apply_filters( 'frm_installed_addons', array() ); |
| 503 | 306 | if ( empty( $installed_addons ) || ! isset( $installed_addons['formidable_pro'] ) ) { |
| 504 | 307 | return false; |
| 505 | 308 | } |
| @@ -531,9 +334,9 @@ | ||
| 531 | 334 | $version_info = self::fill_update_addon_info( $installed_addons ); |
| 532 | 335 | $transient->last_checked = time(); |
| 533 | 336 | $wp_plugins = self::get_plugins(); |
| 534 | 337 | |
| 535 | - foreach ( $version_info as $plugin ) { | |
| 338 | + foreach ( $version_info as $id => $plugin ) { | |
| 536 | 339 | $plugin = (object) $plugin; |
| 537 | 340 | |
| 538 | 341 | if ( ! isset( $plugin->new_version ) || ! isset( $plugin->package ) ) { |
| 539 | 342 | continue; |
| @@ -548,21 +351,20 @@ | ||
| 548 | 351 | // don't show an update if the plugin isn't installed |
| 549 | 352 | continue; |
| 550 | 353 | } |
| 551 | 354 | |
| 552 | - $wp_plugin = $wp_plugins[ $folder ] ?? array(); | |
| 553 | - $wp_version = $wp_plugin['Version'] ?? '1.0'; | |
| 554 | - $plugin->slug = explode( '/', $folder )[0]; | |
| 355 | + $wp_plugin = isset( $wp_plugins[ $folder ] ) ? $wp_plugins[ $folder ] : array(); | |
| 356 | + $wp_version = isset( $wp_plugin['Version'] ) ? $wp_plugin['Version'] : '1.0'; | |
| 555 | 357 | |
| 556 | 358 | if ( version_compare( $wp_version, $plugin->new_version, '<' ) ) { |
| 359 | + $slug = explode( '/', $folder ); | |
| 360 | + $plugin->slug = $slug[0]; | |
| 557 | 361 | $transient->response[ $folder ] = $plugin; |
| 558 | - } else { | |
| 559 | - $transient->no_update[ $folder ] = $plugin; | |
| 560 | 362 | } |
| 561 | 363 | |
| 562 | 364 | $transient->checked[ $folder ] = $wp_version; |
| 563 | 365 | |
| 564 | - }//end foreach | |
| 366 | + } | |
| 565 | 367 | |
| 566 | 368 | return $transient; |
| 567 | 369 | } |
| 568 | 370 | |
| @@ -585,9 +387,9 @@ | ||
| 585 | 387 | * Check if a plugin is installed before showing an update for it |
| 586 | 388 | * |
| 587 | 389 | * @since 3.05 |
| 588 | 390 | * |
| 589 | - * @param string $plugin The folder/filename.php for a plugin. | |
| 391 | + * @param string $plugin - the folder/filename.php for a plugin | |
| 590 | 392 | * |
| 591 | 393 | * @return bool - True if installed |
| 592 | 394 | */ |
| 593 | 395 | protected static function is_installed( $plugin ) { |
| @@ -629,9 +431,9 @@ | ||
| 629 | 431 | if ( empty( $plugin ) ) { |
| 630 | 432 | continue; |
| 631 | 433 | } |
| 632 | 434 | |
| 633 | - $download_id = $plugin['id'] ?? 0; | |
| 435 | + $download_id = isset( $plugin['id'] ) ? $plugin['id'] : 0; | |
| 634 | 436 | if ( ! empty( $download_id ) && ! isset( $version_info[ $download_id ]['package'] ) ) { |
| 635 | 437 | // if this addon is using its own license, get the update url |
| 636 | 438 | $addon_info = $api->get_api_info(); |
| 637 | 439 | |
| @@ -642,9 +444,9 @@ | ||
| 642 | 444 | 'code' => $addon_info['error']['code'], |
| 643 | 445 | ); |
| 644 | 446 | } |
| 645 | 447 | } |
| 646 | - }//end foreach | |
| 448 | + } | |
| 647 | 449 | |
| 648 | 450 | return $version_info; |
| 649 | 451 | } |
| 650 | 452 | |
| @@ -651,9 +453,9 @@ | ||
| 651 | 453 | /** |
| 652 | 454 | * Get the action link for an addon that isn't active. |
| 653 | 455 | * |
| 654 | 456 | * @since 3.06.03 |
| 655 | - * @param string $plugin The plugin slug. | |
| 457 | + * @param string $plugin The plugin slug | |
| 656 | 458 | * @return array |
| 657 | 459 | */ |
| 658 | 460 | public static function install_link( $plugin ) { |
| 659 | 461 | $link = array(); |
| @@ -664,14 +466,14 @@ | ||
| 664 | 466 | $link = array( |
| 665 | 467 | 'url' => $addon['plugin'], |
| 666 | 468 | 'class' => 'frm-activate-addon', |
| 667 | 469 | ); |
| 668 | - } elseif ( ! empty( $addon['url'] ) ) { | |
| 470 | + } elseif ( isset( $addon['url'] ) && ! empty( $addon['url'] ) ) { | |
| 669 | 471 | $link = array( |
| 670 | 472 | 'url' => $addon['url'], |
| 671 | 473 | 'class' => 'frm-install-addon', |
| 672 | 474 | ); |
| 673 | - } elseif ( ! empty( $addon['categories'] ) ) { | |
| 475 | + } elseif ( isset( $addon['categories'] ) && ! empty( $addon['categories'] ) ) { | |
| 674 | 476 | $link = array( |
| 675 | 477 | 'categories' => $addon['categories'], |
| 676 | 478 | ); |
| 677 | 479 | } |
| @@ -683,9 +485,9 @@ | ||
| 683 | 485 | $link = array( |
| 684 | 486 | 'url' => 'formidable-' . $plugin . '/formidable-' . $plugin . '.php', |
| 685 | 487 | 'class' => 'frm-activate-addon', |
| 686 | 488 | ); |
| 687 | - }//end if | |
| 489 | + } | |
| 688 | 490 | |
| 689 | 491 | return $link; |
| 690 | 492 | } |
| 691 | 493 | |
| @@ -690,12 +492,12 @@ | ||
| 690 | 492 | } |
| 691 | 493 | |
| 692 | 494 | /** |
| 693 | 495 | * @since 4.09 |
| 694 | - * @param string $plugin The plugin slug. | |
| 496 | + * @param string $plugin The plugin slug | |
| 695 | 497 | * @return array|false |
| 696 | 498 | */ |
| 697 | - public static function get_addon( $plugin ) { | |
| 499 | + protected static function get_addon( $plugin ) { | |
| 698 | 500 | $addons = self::get_api_addons(); |
| 699 | 501 | self::prepare_addons( $addons ); |
| 700 | 502 | foreach ( $addons as $addon ) { |
| 701 | 503 | $slug = explode( '/', $addon['plugin'] ); |
| @@ -721,10 +523,10 @@ | ||
| 721 | 523 | |
| 722 | 524 | /** |
| 723 | 525 | * @since 3.04.03 |
| 724 | 526 | * |
| 725 | - * @param array $addons | |
| 726 | - * @param object $license The FrmAddon object. | |
| 527 | + * @param array $addons | |
| 528 | + * @param object $license The FrmAddon object | |
| 727 | 529 | * |
| 728 | 530 | * @return array |
| 729 | 531 | */ |
| 730 | 532 | public static function get_addon_for_license( $addons, $license ) { |
| @@ -731,9 +533,9 @@ | ||
| 731 | 533 | $download_id = $license->download_id; |
| 732 | 534 | $plugin = array(); |
| 733 | 535 | if ( empty( $download_id ) && ! empty( $addons ) ) { |
| 734 | 536 | foreach ( $addons as $addon ) { |
| 735 | - if ( strtolower( $license->plugin_name ) === strtolower( $addon['title'] ) ) { | |
| 537 | + if ( strtolower( $license->plugin_name ) == strtolower( $addon['title'] ) ) { | |
| 736 | 538 | return $addon; |
| 737 | 539 | } |
| 738 | 540 | } |
| 739 | 541 | } elseif ( isset( $addons[ $download_id ] ) ) { |
| @@ -797,15 +599,13 @@ | ||
| 797 | 599 | |
| 798 | 600 | if ( ! isset( $addon['link'] ) ) { |
| 799 | 601 | $addon['link'] = 'downloads/' . $slug . '/'; |
| 800 | 602 | } |
| 603 | + self::prepare_addon_link( $addon['link'] ); | |
| 801 | 604 | |
| 802 | - self::prepare_addon_link( $addon['link'] ); | |
| 803 | 605 | self::set_addon_status( $addon ); |
| 804 | - self::set_categories( $addon ); | |
| 805 | - | |
| 806 | 606 | $addons[ $id ] = $addon; |
| 807 | - }//end foreach | |
| 607 | + } | |
| 808 | 608 | } |
| 809 | 609 | |
| 810 | 610 | /** |
| 811 | 611 | * @return bool |
| @@ -817,9 +617,9 @@ | ||
| 817 | 617 | return is_plugin_active( $file_name ); |
| 818 | 618 | } |
| 819 | 619 | |
| 820 | 620 | /** |
| 821 | - * @return false|string either 'visual-views' or 'views', false if one is not found. | |
| 621 | + * @return string|false either 'visual-views' or 'views', false if one is not found. | |
| 822 | 622 | */ |
| 823 | 623 | private static function get_active_views_version() { |
| 824 | 624 | if ( ! is_callable( 'FrmViewsAppHelper::plugin_version' ) ) { |
| 825 | 625 | return false; |
| @@ -838,13 +638,14 @@ | ||
| 838 | 638 | if ( strpos( $link, 'http' ) !== 0 ) { |
| 839 | 639 | $link = $site_url . $link; |
| 840 | 640 | } |
| 841 | 641 | $link = FrmAppHelper::make_affiliate_url( $link ); |
| 842 | - | |
| 843 | - $utm = array( | |
| 844 | - 'campaign' => 'addons', | |
| 642 | + $query_args = array( | |
| 643 | + 'utm_source' => 'WordPress', | |
| 644 | + 'utm_medium' => 'addons', | |
| 645 | + 'utm_campaign' => 'liteplugin', | |
| 845 | 646 | ); |
| 846 | - $link = FrmAppHelper::maybe_add_missing_utm( $link, $utm ); | |
| 647 | + $link = add_query_arg( $query_args, $link ); | |
| 847 | 648 | } |
| 848 | 649 | |
| 849 | 650 | /** |
| 850 | 651 | * Add the status to the addon array. Status options are: |
| @@ -873,64 +674,263 @@ | ||
| 873 | 674 | } |
| 874 | 675 | } |
| 875 | 676 | |
| 876 | 677 | /** |
| 877 | - * @since 5.5.2 | |
| 878 | - * | |
| 879 | - * @param string $plugin | |
| 880 | - * @param string $redirect | |
| 881 | - * @param bool $network_wide | |
| 882 | - * @param bool $silent | |
| 883 | - * @return WP_Error|null Null on success, WP_Error on invalid file. | |
| 678 | + * @return void | |
| 884 | 679 | */ |
| 885 | - protected static function activate_plugin( $plugin, $redirect = '', $network_wide = false, $silent = false ) { | |
| 886 | - if ( ! function_exists( 'activate_plugin' ) ) { | |
| 887 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; | |
| 888 | - } | |
| 889 | - return activate_plugin( $plugin, $redirect, $network_wide, $silent ); | |
| 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' ); | |
| 890 | 885 | } |
| 891 | 886 | |
| 892 | 887 | /** |
| 893 | - * Deactivate a specified plugin. | |
| 888 | + * Install Pro after connection with Formidable. | |
| 894 | 889 | * |
| 895 | - * @since 6.8 | |
| 890 | + * @since 4.02.05 | |
| 896 | 891 | * |
| 897 | - * @param string $plugin | |
| 898 | - * @param bool $silent | |
| 899 | 892 | * @return void |
| 900 | 893 | */ |
| 901 | - protected static function deactivate_plugin( $plugin, $silent = false ) { | |
| 902 | - if ( ! function_exists( 'deactivate_plugins' ) ) { | |
| 903 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; | |
| 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(); | |
| 904 | 901 | } |
| 905 | - deactivate_plugins( $plugin, $silent ); | |
| 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 | 917 | } |
| 907 | 918 | |
| 908 | 919 | /** |
| 909 | - * Uninstall a specified plugin. | |
| 920 | + * @since 5.5.2 | |
| 910 | 921 | * |
| 911 | - * @since 6.8 | |
| 912 | - * | |
| 913 | 922 | * @param string $plugin |
| 914 | - * @return true|WP_Error True on success, WP_Error on invalid file. | |
| 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 | 927 | */ |
| 916 | - protected static function uninstall_plugin( $plugin ) { | |
| 917 | - if ( ! current_user_can( 'delete_plugins' ) ) { | |
| 918 | - return new WP_Error( 'uninstall_failed', __( 'Current user cannot delete plugins.', 'formidable' ) ); | |
| 919 | - } | |
| 920 | - | |
| 921 | - if ( ! function_exists( 'delete_plugins' ) ) { | |
| 928 | + protected static function activate_plugin( $plugin, $redirect = '', $network_wide = false, $silent = false ) { | |
| 929 | + if ( ! function_exists( 'activate_plugin' ) ) { | |
| 922 | 930 | require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 923 | 931 | } |
| 924 | - | |
| 925 | - self::deactivate_plugin( $plugin, true ); | |
| 926 | - $result = delete_plugins( array( $plugin ) ); | |
| 927 | - | |
| 928 | - if ( is_wp_error( $result ) ) { | |
| 929 | - return $result; | |
| 930 | - } | |
| 931 | - | |
| 932 | - return true; | |
| 932 | + return activate_plugin( $plugin, $redirect, $network_wide, $silent ); | |
| 933 | 933 | } |
| 934 | 934 | |
| 935 | 935 | /** |
| 936 | 936 | * @since 5.0.10 |
| @@ -937,9 +937,9 @@ | ||
| 937 | 937 | * |
| 938 | 938 | * @return string |
| 939 | 939 | */ |
| 940 | 940 | protected static function get_current_plugin() { |
| 941 | - if ( empty( self::$plugin ) ) { | |
| 941 | + if ( ! isset( self::$plugin ) ) { | |
| 942 | 942 | self::$plugin = FrmAppHelper::get_param( 'plugin', '', 'post', 'esc_url_raw' ); |
| 943 | 943 | } |
| 944 | 944 | return self::$plugin; |
| 945 | 945 | } |
| @@ -945,10 +945,8 @@ | ||
| 945 | 945 | } |
| 946 | 946 | |
| 947 | 947 | /** |
| 948 | 948 | * @since 4.08 |
| 949 | - * | |
| 950 | - * @return array|void | |
| 951 | 949 | */ |
| 952 | 950 | protected static function download_and_activate() { |
| 953 | 951 | if ( is_admin() ) { |
| 954 | 952 | FrmAppHelper::set_current_screen_and_hook_suffix(); |
| @@ -959,9 +957,9 @@ | ||
| 959 | 957 | $installed = self::install_addon(); |
| 960 | 958 | if ( is_array( $installed ) && isset( $installed['message'] ) ) { |
| 961 | 959 | return $installed; |
| 962 | 960 | } |
| 963 | - self::handle_addon_action( $installed, 'activate' ); | |
| 961 | + self::maybe_activate_addon( $installed ); | |
| 964 | 962 | } |
| 965 | 963 | |
| 966 | 964 | /** |
| 967 | 965 | * @since 3.04.02 |
| @@ -969,12 +967,12 @@ | ||
| 969 | 967 | * @return void |
| 970 | 968 | */ |
| 971 | 969 | protected static function maybe_show_cred_form() { |
| 972 | 970 | if ( ! function_exists( 'request_filesystem_credentials' ) ) { |
| 973 | - include_once ABSPATH . 'wp-admin/includes/file.php'; | |
| 971 | + include_once( ABSPATH . 'wp-admin/includes/file.php' ); | |
| 974 | 972 | } |
| 975 | 973 | |
| 976 | - // Start output buffering to catch the filesystem form if credentials are needed. | |
| 974 | + // Start output bufferring to catch the filesystem form if credentials are needed. | |
| 977 | 975 | ob_start(); |
| 978 | 976 | |
| 979 | 977 | $show_form = false; |
| 980 | 978 | $method = ''; |
| @@ -1013,9 +1011,12 @@ | ||
| 1013 | 1011 | * |
| 1014 | 1012 | * @return bool |
| 1015 | 1013 | */ |
| 1016 | 1014 | public static function url_is_allowed( $download_url ) { |
| 1017 | - return FrmAppHelper::validate_url_is_in_s3_bucket( $download_url, 'zip' ) || in_array( $download_url, self::allowed_external_urls(), true ); | |
| 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 | 1019 | } |
| 1019 | 1020 | |
| 1020 | 1021 | /** |
| 1021 | 1022 | * We do not need any extra credentials if we have gotten this far, |
| @@ -1052,139 +1053,33 @@ | ||
| 1052 | 1053 | return $plugin; |
| 1053 | 1054 | } |
| 1054 | 1055 | |
| 1055 | 1056 | /** |
| 1056 | - * Handle the AJAX request to activate an add-on. | |
| 1057 | + * @since 3.06.03 | |
| 1057 | 1058 | * |
| 1058 | - * @since 6.8 | |
| 1059 | - * | |
| 1060 | 1059 | * @return void |
| 1061 | 1060 | */ |
| 1062 | 1061 | public static function ajax_activate_addon() { |
| 1063 | - self::process_addon_action( | |
| 1064 | - function ( $plugin ) { | |
| 1065 | - return self::handle_addon_action( $plugin, 'activate' ); | |
| 1066 | - }, | |
| 1067 | - array( 'FrmAddonsController', 'get_addon_activation_response' ) | |
| 1068 | - ); | |
| 1069 | - } | |
| 1070 | 1062 | |
| 1071 | - /** | |
| 1072 | - * @since 3.04.02 | |
| 1073 | - * | |
| 1074 | - * @param string $installed The plugin folder name with file name. | |
| 1075 | - */ | |
| 1076 | - protected static function maybe_activate_addon( $installed ) { | |
| 1077 | - self::ajax_activate_addon(); | |
| 1078 | - } | |
| 1063 | + self::install_addon_permissions(); | |
| 1079 | 1064 | |
| 1080 | - /** | |
| 1081 | - * Handle the AJAX request to deactivate an add-on. | |
| 1082 | - * | |
| 1083 | - * @since 6.8 | |
| 1084 | - * | |
| 1085 | - * @return void | |
| 1086 | - */ | |
| 1087 | - public static function ajax_deactivate_addon() { | |
| 1088 | - self::process_addon_action( | |
| 1089 | - function ( $plugin ) { | |
| 1090 | - return self::handle_addon_action( $plugin, 'deactivate' ); | |
| 1091 | - } | |
| 1092 | - ); | |
| 1093 | - } | |
| 1094 | - | |
| 1095 | - /** | |
| 1096 | - * Handle the AJAX request to uninstall an add-on. | |
| 1097 | - * | |
| 1098 | - * @since 6.8 | |
| 1099 | - * | |
| 1100 | - * @return void | |
| 1101 | - */ | |
| 1102 | - public static function ajax_uninstall_addon() { | |
| 1103 | - self::process_addon_action( | |
| 1104 | - function ( $plugin ) { | |
| 1105 | - return self::handle_addon_action( $plugin, 'uninstall' ); | |
| 1106 | - } | |
| 1107 | - ); | |
| 1108 | - } | |
| 1109 | - | |
| 1110 | - /** | |
| 1111 | - * Process a specific action (activate, deactivate, uninstall) on an add-on. | |
| 1112 | - * | |
| 1113 | - * @since 6.8 | |
| 1114 | - * | |
| 1115 | - * @param callable $action_callback The specific add-on action to be executed. | |
| 1116 | - * @param callable|null $response_callback Optional. The response handling callback. Default null. | |
| 1117 | - * @return void | |
| 1118 | - */ | |
| 1119 | - private static function process_addon_action( $action_callback, $response_callback = null ) { | |
| 1120 | - self::install_addon_permissions(); | |
| 1121 | 1065 | FrmAppHelper::set_current_screen_and_hook_suffix(); |
| 1122 | 1066 | |
| 1123 | 1067 | $plugin = FrmAppHelper::get_param( 'plugin', '', 'post', 'sanitize_text_field' ); |
| 1124 | - call_user_func( $action_callback, $plugin ); | |
| 1068 | + self::maybe_activate_addon( $plugin ); | |
| 1125 | 1069 | |
| 1126 | - if ( is_callable( $response_callback ) ) { | |
| 1127 | - wp_send_json_success( call_user_func( $response_callback ) ); | |
| 1128 | - return; | |
| 1129 | - } | |
| 1130 | - | |
| 1131 | - wp_send_json_success(); | |
| 1070 | + echo json_encode( self::get_addon_activation_response() ); | |
| 1071 | + wp_die(); | |
| 1132 | 1072 | } |
| 1133 | 1073 | |
| 1134 | 1074 | /** |
| 1135 | - * Attempt to perform a specific action (activate, deactivate, uninstall) on an add-on. | |
| 1136 | - * | |
| 1137 | - * @since 6.8 | |
| 1138 | - * | |
| 1139 | - * @param string $installed The plugin folder name with file name. | |
| 1140 | - * @param string $action The action type ('activate', 'deactivate', 'uninstall'). | |
| 1141 | - * @return array|void | |
| 1142 | - */ | |
| 1143 | - protected static function handle_addon_action( $installed, $action ) { | |
| 1144 | - if ( ! $installed || ! $action ) { | |
| 1145 | - return; | |
| 1146 | - } | |
| 1147 | - | |
| 1148 | - $result = null; | |
| 1149 | - switch ( $action ) { | |
| 1150 | - case 'activate': | |
| 1151 | - $result = self::activate_plugin( $installed ); | |
| 1152 | - break; | |
| 1153 | - case 'deactivate': | |
| 1154 | - self::deactivate_plugin( $installed ); | |
| 1155 | - break; | |
| 1156 | - case 'uninstall': | |
| 1157 | - $result = self::uninstall_plugin( $installed ); | |
| 1158 | - break; | |
| 1159 | - } | |
| 1160 | - | |
| 1161 | - if ( is_wp_error( $result ) ) { | |
| 1162 | - // Ignore the invalid header message that shows with nested plugins. | |
| 1163 | - if ( $result->get_error_code() !== 'no_plugin_header' ) { | |
| 1164 | - if ( wp_doing_ajax() ) { | |
| 1165 | - wp_send_json_error( array( 'error' => $result->get_error_message() ) ); | |
| 1166 | - } | |
| 1167 | - return array( | |
| 1168 | - 'message' => $result->get_error_message(), | |
| 1169 | - 'success' => false, | |
| 1170 | - ); | |
| 1171 | - } | |
| 1172 | - } | |
| 1173 | - | |
| 1174 | - return $result; | |
| 1175 | - } | |
| 1176 | - | |
| 1177 | - /** | |
| 1178 | 1075 | * @return array |
| 1179 | 1076 | */ |
| 1180 | 1077 | private static function get_addon_activation_response() { |
| 1181 | 1078 | $activating_page = self::get_activating_page(); |
| 1182 | 1079 | |
| 1183 | - $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' ); | |
| 1184 | - | |
| 1185 | 1080 | $response = array( |
| 1186 | - 'message' => $message, | |
| 1081 | + 'message' => __( 'Your plugin has been activated. Would you like to save and reload the page now?', 'formidable' ), | |
| 1187 | 1082 | 'saveAndReload' => $activating_page, |
| 1188 | 1083 | ); |
| 1189 | 1084 | |
| 1190 | 1085 | return $response; |
| @@ -1209,8 +1104,34 @@ | ||
| 1209 | 1104 | return ''; |
| 1210 | 1105 | } |
| 1211 | 1106 | |
| 1212 | 1107 | /** |
| 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 | + /** | |
| 1213 | 1134 | * Run security checks before installing |
| 1214 | 1135 | * |
| 1215 | 1136 | * @since 3.04.02 |
| 1216 | 1137 | * |
| @@ -1233,18 +1154,15 @@ | ||
| 1233 | 1154 | public static function connect_link() { |
| 1234 | 1155 | $auth = get_option( 'frm_connect_token' ); |
| 1235 | 1156 | if ( empty( $auth ) ) { |
| 1236 | 1157 | $auth = hash( 'sha512', wp_rand() ); |
| 1237 | - update_option( 'frm_connect_token', $auth, 'no' ); | |
| 1158 | + update_option( 'frm_connect_token', $auth ); | |
| 1238 | 1159 | } |
| 1239 | - $page = FrmAppHelper::simple_get( 'page', 'sanitize_title', 'formidable-settings' ); | |
| 1240 | - $link = 'https://formidableforms.com/api-connect/'; | |
| 1160 | + $link = FrmAppHelper::admin_upgrade_link( 'connect', 'api-connect' ); | |
| 1241 | 1161 | $args = array( |
| 1242 | 1162 | 'v' => 2, |
| 1243 | 1163 | 'siteurl' => FrmAppHelper::site_url(), |
| 1244 | 1164 | 'url' => get_rest_url(), |
| 1245 | - 'inst' => (int) FrmAppHelper::pro_is_included(), | |
| 1246 | - 'return' => $page, | |
| 1247 | 1165 | 'token' => $auth, |
| 1248 | 1166 | 'l' => self::get_pro_license(), |
| 1249 | 1167 | ); |
| 1250 | 1168 | |
| @@ -1262,12 +1180,9 @@ | ||
| 1262 | 1180 | // Verify params present (auth & download link). |
| 1263 | 1181 | $post_auth = FrmAppHelper::get_param( 'token', '', 'request', 'sanitize_text_field' ); |
| 1264 | 1182 | $post_url = FrmAppHelper::get_param( 'file_url', '', 'request', 'sanitize_text_field' ); |
| 1265 | 1183 | |
| 1266 | - // The download link is not required if already installed. | |
| 1267 | - $is_installed = FrmAppHelper::pro_is_included(); | |
| 1268 | - $file_missing = ! $is_installed && empty( $post_url ); | |
| 1269 | - if ( ! $post_auth || $file_missing ) { | |
| 1184 | + if ( empty( $post_auth ) || empty( $post_url ) ) { | |
| 1270 | 1185 | return false; |
| 1271 | 1186 | } |
| 1272 | 1187 | |
| 1273 | 1188 | // Verify auth. |
| @@ -1282,10 +1197,8 @@ | ||
| 1282 | 1197 | /** |
| 1283 | 1198 | * Install and/or activate the add-on file. |
| 1284 | 1199 | * |
| 1285 | 1200 | * @since 4.08 |
| 1286 | - * | |
| 1287 | - * @return array | |
| 1288 | 1201 | */ |
| 1289 | 1202 | public static function install_addon_api() { |
| 1290 | 1203 | self::$plugin = FrmAppHelper::get_param( 'file_url', '', 'request', 'esc_url_raw' ); |
| 1291 | 1204 | |
| @@ -1296,11 +1209,11 @@ | ||
| 1296 | 1209 | |
| 1297 | 1210 | // It's already installed and active. |
| 1298 | 1211 | $active = self::activate_plugin( 'formidable-pro/formidable-pro.php', false, false, true ); |
| 1299 | 1212 | if ( is_wp_error( $active ) ) { |
| 1300 | - $response = self::maybe_download_and_activate(); | |
| 1301 | - if ( is_array( $response ) ) { | |
| 1302 | - // The download failed. | |
| 1213 | + // Download plugin now. | |
| 1214 | + $response = self::download_and_activate(); | |
| 1215 | + if ( is_array( $response ) && isset( $response['success'] ) ) { | |
| 1303 | 1216 | return $response; |
| 1304 | 1217 | } |
| 1305 | 1218 | } |
| 1306 | 1219 | |
| @@ -1327,58 +1240,22 @@ | ||
| 1327 | 1240 | ); |
| 1328 | 1241 | } |
| 1329 | 1242 | |
| 1330 | 1243 | /** |
| 1331 | - * @since 6.8.3 | |
| 1332 | - * | |
| 1333 | - * @return array|true | |
| 1334 | - */ | |
| 1335 | - private static function maybe_download_and_activate() { | |
| 1336 | - if ( ! self::$plugin ) { | |
| 1337 | - return array( | |
| 1338 | - 'success' => false, | |
| 1339 | - 'message' => __( 'The plugin download was not found.', 'formidable' ), | |
| 1340 | - ); | |
| 1341 | - } | |
| 1342 | - | |
| 1343 | - // Download plugin now. | |
| 1344 | - $response = self::download_and_activate(); | |
| 1345 | - if ( is_array( $response ) && isset( $response['success'] ) ) { | |
| 1346 | - // The download failed. | |
| 1347 | - return $response; | |
| 1348 | - } | |
| 1349 | - | |
| 1350 | - return true; | |
| 1351 | - } | |
| 1352 | - | |
| 1353 | - /** | |
| 1354 | 1244 | * Render a conditional action button for a specified plugin |
| 1355 | 1245 | * |
| 1246 | + * @param string $plugin | |
| 1247 | + * @param array|string $upgrade_link_args | |
| 1356 | 1248 | * @since 4.09 |
| 1357 | - * | |
| 1358 | - * @param string $plugin | |
| 1359 | - * @param array|string $upgrade_link_args | |
| 1360 | - * @return void | |
| 1361 | 1249 | */ |
| 1362 | 1250 | public static function conditional_action_button( $plugin, $upgrade_link_args ) { |
| 1363 | 1251 | if ( is_callable( 'FrmProAddonsController::conditional_action_button' ) ) { |
| 1364 | - FrmProAddonsController::conditional_action_button( $plugin, $upgrade_link_args ); | |
| 1365 | - return; | |
| 1252 | + return FrmProAddonsController::conditional_action_button( $plugin, $upgrade_link_args ); | |
| 1366 | 1253 | } |
| 1367 | 1254 | |
| 1368 | 1255 | $addon = self::get_addon( $plugin ); |
| 1369 | 1256 | $upgrade_link = FrmAppHelper::admin_upgrade_link( $upgrade_link_args ); |
| 1370 | - | |
| 1371 | - if ( ! is_array( $upgrade_link_args ) ) { | |
| 1372 | - // A string $upgrade_link_args is used for the utm-medium value when calling | |
| 1373 | - // FrmAppHelper::admin_upgrade_link above. | |
| 1374 | - // For self::addon_upgrade_link, we'll pass just an empty array with the link key (set below). | |
| 1375 | - $upgrade_link_args = array(); | |
| 1376 | - } | |
| 1377 | - | |
| 1378 | - $upgrade_link_args['link'] = $upgrade_link; | |
| 1379 | - | |
| 1380 | - self::addon_upgrade_link( $addon, $upgrade_link_args ); | |
| 1257 | + self::addon_upgrade_link( $addon, $upgrade_link ); | |
| 1381 | 1258 | } |
| 1382 | 1259 | |
| 1383 | 1260 | /** |
| 1384 | 1261 | * Render a conditional action button for an add on |
| @@ -1384,22 +1261,16 @@ | ||
| 1384 | 1261 | * Render a conditional action button for an add on |
| 1385 | 1262 | * |
| 1386 | 1263 | * @since 4.09.01 |
| 1387 | 1264 | * |
| 1388 | - * @param array $atts { | |
| 1389 | - * Button attributes. | |
| 1390 | - * | |
| 1391 | - * @type array $addon | |
| 1392 | - * @type false|string $license_type | |
| 1393 | - * @type string $plan_required | |
| 1394 | - * @type string $upgrade_link | |
| 1395 | - * } | |
| 1396 | - * @return void | |
| 1265 | + * @param array $addon | |
| 1266 | + * @param string|false $license_type | |
| 1267 | + * @param string $plan_required | |
| 1268 | + * @param string $upgrade_link | |
| 1397 | 1269 | */ |
| 1398 | 1270 | public static function show_conditional_action_button( $atts ) { |
| 1399 | 1271 | if ( is_callable( 'FrmProAddonsController::show_conditional_action_button' ) ) { |
| 1400 | - FrmProAddonsController::show_conditional_action_button( $atts ); | |
| 1401 | - return; | |
| 1272 | + return FrmProAddonsController::show_conditional_action_button( $atts ); | |
| 1402 | 1273 | } |
| 1403 | 1274 | |
| 1404 | 1275 | self::addon_upgrade_link( $atts['addon'], $atts['upgrade_link'] ); |
| 1405 | 1276 | } |
| @@ -1406,18 +1277,13 @@ | ||
| 1406 | 1277 | |
| 1407 | 1278 | /** |
| 1408 | 1279 | * @since 4.09.01 |
| 1409 | 1280 | * |
| 1410 | - * @param array|false $addon | |
| 1411 | - * @param array|string $upgrade_link | |
| 1281 | + * @param array|false $addon | |
| 1412 | 1282 | * |
| 1413 | 1283 | * @return void |
| 1414 | 1284 | */ |
| 1415 | - public static function addon_upgrade_link( $addon, $upgrade_link ) { | |
| 1416 | - $atts = is_array( $upgrade_link ) ? $upgrade_link : array(); | |
| 1417 | - $upgrade_link = is_array( $upgrade_link ) ? $upgrade_link['link'] : $upgrade_link; | |
| 1418 | - $text = ! empty( $atts['text'] ) ? $atts['text'] : __( 'Upgrade Now', 'formidable' ); | |
| 1419 | - | |
| 1285 | + protected static function addon_upgrade_link( $addon, $upgrade_link ) { | |
| 1420 | 1286 | if ( $addon ) { |
| 1421 | 1287 | $upgrade_link .= '&utm_content=' . $addon['slug']; |
| 1422 | 1288 | } |
| 1423 | 1289 | |
| @@ -1424,16 +1290,11 @@ | ||
| 1424 | 1290 | if ( $addon && isset( $addon['categories'] ) && in_array( 'Solution', $addon['categories'], true ) ) { |
| 1425 | 1291 | // Solutions will go to a separate page. |
| 1426 | 1292 | $upgrade_link = FrmAppHelper::admin_upgrade_link( 'addons', $addon['link'] ); |
| 1427 | 1293 | } |
| 1428 | - | |
| 1429 | - $class = ! empty( $atts['class'] ) ? $atts['class'] : ''; | |
| 1430 | - if ( strpos( $class, 'frm-button' ) === false ) { | |
| 1431 | - $class .= ' frm-button-secondary frm-button-sm'; | |
| 1432 | - } | |
| 1433 | 1294 | ?> |
| 1434 | - <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' ); ?>"> | |
| 1435 | - <?php echo esc_html( $text ); ?> | |
| 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' ); ?> | |
| 1436 | 1297 | </a> |
| 1437 | 1298 | <?php |
| 1438 | 1299 | } |
| 1439 | 1300 | |
| @@ -1455,58 +1316,107 @@ | ||
| 1455 | 1316 | wp_die(); |
| 1456 | 1317 | } |
| 1457 | 1318 | |
| 1458 | 1319 | /** |
| 1459 | - * Allowed URLs used for internal source of plugins installation. | |
| 1320 | + * @since 4.06.02 | |
| 1460 | 1321 | * |
| 1461 | - * @since 6.3.1 | |
| 1322 | + * @deprecated 4.09.01 | |
| 1462 | 1323 | * |
| 1324 | + * @return void | |
| 1325 | + */ | |
| 1326 | + public static function ajax_multiple_addons() { | |
| 1327 | + FrmDeprecated::ajax_multiple_addons(); | |
| 1328 | + } | |
| 1329 | + | |
| 1330 | + /** | |
| 1331 | + * @since 3.04.03 | |
| 1332 | + * @deprecated 3.06 | |
| 1333 | + * @codeCoverageIgnore | |
| 1463 | 1334 | * @return array |
| 1464 | 1335 | */ |
| 1465 | - private static function allowed_external_urls() { | |
| 1466 | - $allowed_url_list = array( | |
| 1467 | - 'https://downloads.wordpress.org/plugin/formidable-gravity-forms-importer.zip', | |
| 1468 | - 'https://downloads.wordpress.org/plugin/formidable-import-pirate-forms.zip', | |
| 1469 | - 'https://downloads.wordpress.org/plugin/wp-mail-smtp.zip', | |
| 1470 | - ); | |
| 1336 | + public static function error_for_license( $license ) { | |
| 1337 | + return FrmDeprecated::error_for_license( $license ); | |
| 1338 | + } | |
| 1471 | 1339 | |
| 1472 | - /** | |
| 1473 | - * List of URLs used in plugin formidable internal installation. | |
| 1474 | - * | |
| 1475 | - * @since 6.3.1 | |
| 1476 | - * | |
| 1477 | - * @param array $allowed_url_list List of URLs. | |
| 1478 | - */ | |
| 1479 | - $allowed_url_list = apply_filters( 'frm_allowed_external_urls', $allowed_url_list ); | |
| 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 | + } | |
| 1480 | 1348 | |
| 1481 | - if ( ! is_array( $allowed_url_list ) ) { | |
| 1482 | - _doing_it_wrong( __METHOD__, 'Only an array of URLs could be used within this filter.', '6.3.1' ); | |
| 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 | + } | |
| 1483 | 1359 | |
| 1484 | - return array(); | |
| 1485 | - } | |
| 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 ); | |
| 1369 | + } | |
| 1486 | 1370 | |
| 1487 | - return $allowed_url_list; | |
| 1371 | + /** | |
| 1372 | + * @since 3.04.03 | |
| 1373 | + * | |
| 1374 | + * @deprecated 3.06 | |
| 1375 | + * | |
| 1376 | + * @codeCoverageIgnore | |
| 1377 | + * | |
| 1378 | + * @return void | |
| 1379 | + */ | |
| 1380 | + public static function reset_cached_addons( $license = '' ) { | |
| 1381 | + FrmDeprecated::reset_cached_addons( $license ); | |
| 1488 | 1382 | } |
| 1489 | 1383 | |
| 1490 | 1384 | /** |
| 1491 | - * Gets required plan for an addon. | |
| 1385 | + * @since 2.03.08 | |
| 1386 | + * @deprecated 3.04.03 | |
| 1387 | + * @codeCoverageIgnore | |
| 1492 | 1388 | * |
| 1493 | - * @since 6.4.2 | |
| 1389 | + * @param boolean $return | |
| 1390 | + * @param string $package | |
| 1494 | 1391 | * |
| 1495 | - * @return string Empty string if no plan is required for active license. | |
| 1392 | + * @return boolean | |
| 1496 | 1393 | */ |
| 1497 | - public static function get_addon_required_plan( $addon_id ) { | |
| 1498 | - $api = new FrmFormApi(); | |
| 1499 | - $addons = $api->get_api_info(); | |
| 1394 | + public static function add_shorten_edd_filename_filter( $return, $package ) { | |
| 1395 | + return FrmDeprecated::add_shorten_edd_filename_filter( $return, $package ); | |
| 1396 | + } | |
| 1500 | 1397 | |
| 1501 | - if ( is_array( $addons ) && array_key_exists( $addon_id, $addons ) ) { | |
| 1502 | - $dates = $addons[ $addon_id ]; | |
| 1503 | - $requires = FrmFormsHelper::get_plan_required( $dates ); | |
| 1504 | - } | |
| 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 | + } | |
| 1505 | 1411 | |
| 1506 | - if ( ! isset( $requires ) || ! is_string( $requires ) ) { | |
| 1507 | - $requires = ''; | |
| 1508 | - } | |
| 1509 | - | |
| 1510 | - return $requires; | |
| 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 | 1421 | } |
| 1512 | 1422 | } |