| @@ -1,47 +1,27 @@ | ||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 3 | - die( 'You are not allowed to call this page directly.' ); | |
| 4 | -} | |
| 5 | 2 | |
| 6 | 3 | class FrmAddonsController { |
| 7 | 4 | |
| 8 | - /** | |
| 9 | - * @var string $plugin | |
| 10 | - */ | |
| 11 | - protected static $plugin; | |
| 12 | - | |
| 13 | - /** | |
| 14 | - * @return void | |
| 15 | - */ | |
| 16 | 5 | public static function menu() { |
| 17 | 6 | if ( ! current_user_can( 'activate_plugins' ) ) { |
| 18 | 7 | return; |
| 19 | 8 | } |
| 20 | 9 | |
| 21 | - $label = __( 'Add-Ons', 'formidable' ); | |
| 22 | - $label = '<span style="color:#1da867">' . $label . '</span>'; | |
| 10 | + add_submenu_page( 'formidable', 'Formidable | ' . __( 'Add-Ons', 'formidable' ), __( 'Add-Ons', 'formidable' ), 'frm_view_forms', 'formidable-addons', 'FrmAddonsController::list_addons' ); | |
| 23 | 11 | |
| 24 | - add_submenu_page( 'formidable', 'Formidable | ' . __( 'Add-Ons', 'formidable' ), $label, 'frm_view_forms', 'formidable-addons', 'FrmAddonsController::list_addons' ); | |
| 25 | - | |
| 26 | 12 | if ( ! FrmAppHelper::pro_is_installed() ) { |
| 27 | 13 | add_submenu_page( |
| 28 | 14 | 'formidable', |
| 29 | - 'Formidable | ' . __( 'Upgrade', 'formidable' ), | |
| 30 | - '<span class="frm-upgrade-submenu">' . __( 'Upgrade', 'formidable' ) . '</span>', | |
| 15 | + 'Formidable | ' . __( 'Upgrade to Pro', 'formidable' ), | |
| 16 | + '<span style="color:#f15a24">' . __( 'Upgrade to Pro', 'formidable' ) . '</span>', | |
| 31 | 17 | 'frm_view_forms', |
| 32 | 18 | 'formidable-pro-upgrade', |
| 33 | 19 | 'FrmAddonsController::upgrade_to_pro' |
| 34 | 20 | ); |
| 35 | - } elseif ( 'formidable-pro-upgrade' === FrmAppHelper::get_param( 'page' ) ) { | |
| 36 | - wp_safe_redirect( admin_url( 'admin.php?page=formidable' ) ); | |
| 37 | - exit; | |
| 38 | 21 | } |
| 39 | 22 | } |
| 40 | 23 | |
| 41 | - /** | |
| 42 | - * @return void | |
| 43 | - */ | |
| 44 | 24 | public static function list_addons() { |
| 45 | 25 | FrmAppHelper::include_svg(); |
| 46 | 26 | $installed_addons = apply_filters( 'frm_installed_addons', array() ); |
| 47 | 27 | $license_type = ''; |
| @@ -54,19 +34,8 @@ | ||
| 54 | 34 | $errors = $api->get_error_from_response( $addons ); |
| 55 | 35 | $license_type = isset( $addons['error']['type'] ) ? $addons['error']['type'] : ''; |
| 56 | 36 | unset( $addons['error'] ); |
| 57 | 37 | } |
| 58 | - | |
| 59 | - $pro = array( | |
| 60 | - '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.', | |
| 66 | - ), | |
| 67 | - ); | |
| 68 | - $addons = $pro + $addons; | |
| 69 | 38 | self::prepare_addons( $addons ); |
| 70 | 39 | |
| 71 | 40 | $pricing = FrmAppHelper::admin_upgrade_link( 'addons' ); |
| 72 | 41 | |
| @@ -72,11 +41,8 @@ | ||
| 72 | 41 | |
| 73 | 42 | include( FrmAppHelper::plugin_path() . '/classes/views/addons/list.php' ); |
| 74 | 43 | } |
| 75 | 44 | |
| 76 | - /** | |
| 77 | - * @return void | |
| 78 | - */ | |
| 79 | 45 | public static function license_settings() { |
| 80 | 46 | $plugins = apply_filters( 'frm_installed_addons', array() ); |
| 81 | 47 | if ( empty( $plugins ) ) { |
| 82 | 48 | esc_html_e( 'There are no plugins on your site that require a license', 'formidable' ); |
| @@ -88,12 +54,9 @@ | ||
| 88 | 54 | |
| 89 | 55 | include( FrmAppHelper::plugin_path() . '/classes/views/addons/settings.php' ); |
| 90 | 56 | } |
| 91 | 57 | |
| 92 | - /** | |
| 93 | - * @return array | |
| 94 | - */ | |
| 95 | - protected static function get_api_addons() { | |
| 58 | + private static function get_api_addons() { | |
| 96 | 59 | $api = new FrmFormApi(); |
| 97 | 60 | $addons = $api->get_api_info(); |
| 98 | 61 | |
| 99 | 62 | if ( empty( $addons ) ) { |
| @@ -114,19 +77,19 @@ | ||
| 114 | 77 | * |
| 115 | 78 | * @since 3.04.03 |
| 116 | 79 | * @return array |
| 117 | 80 | */ |
| 118 | - protected static function fallback_plugin_list() { | |
| 119 | - $list = array( | |
| 81 | + private static function fallback_plugin_list() { | |
| 82 | + return array( | |
| 120 | 83 | 'formidable-pro' => array( |
| 121 | - 'title' => 'Formidable Forms Pro', | |
| 84 | + 'title' => 'Formidable Pro', | |
| 122 | 85 | 'link' => 'pricing/', |
| 123 | 86 | 'docs' => '', |
| 124 | 87 | 'excerpt' => 'Enhance your basic Formidable forms with a plethora of Pro field types and features. Create advanced forms and data-driven applications in minutes.', |
| 125 | 88 | ), |
| 126 | 89 | 'mailchimp' => array( |
| 127 | - 'title' => 'Mailchimp Forms', | |
| 128 | - 'excerpt' => 'Get on the path to more sales and leads in a matter of minutes. Add leads to a Mailchimp mailing list when they submit forms and update their information along with the entry.', | |
| 90 | + 'title' => 'MailChimp Forms', | |
| 91 | + 'excerpt' => 'Get on the path to more sales and leads in a matter of minutes. Add leads to a MailChimp mailing list when they submit forms and update their information along with the entry.', | |
| 129 | 92 | ), |
| 130 | 93 | 'registration' => array( |
| 131 | 94 | 'title' => 'User Registration Forms', |
| 132 | 95 | 'link' => 'downloads/user-registration/', |
| @@ -184,28 +147,9 @@ | ||
| 184 | 147 | 'title' => 'Twilio SMS Forms', |
| 185 | 148 | 'docs' => 'knowledgebase/twilio-add-on/', |
| 186 | 149 | 'excerpt' => 'Allow users to text their votes for polls created by Formidable Forms, or send SMS notifications when entries are submitted or updated.', |
| 187 | 150 | ), |
| 188 | - 'views' => array( | |
| 189 | - 'title' => 'Formidable Views', | |
| 190 | - 'excerpt' => 'Add the power of views to your Formidable Forms to display your form submissions in listings, tables, calendars, and more.', | |
| 191 | - ), | |
| 192 | - 'quiz_maker' => array( | |
| 193 | - 'title' => 'Quiz Maker', | |
| 194 | - 'link' => 'downloads/quiz-maker/', | |
| 195 | - 'excerpt' => 'Make quizzes, automatically score them and show user scores.', | |
| 196 | - ), | |
| 197 | 151 | ); |
| 198 | - | |
| 199 | - $defaults = array( | |
| 200 | - 'released' => '', | |
| 201 | - ); | |
| 202 | - | |
| 203 | - foreach ( $list as $k => $info ) { | |
| 204 | - $info['slug'] = $k; | |
| 205 | - $list[ $k ] = array_merge( $defaults, $info ); | |
| 206 | - } | |
| 207 | - return $list; | |
| 208 | 152 | } |
| 209 | 153 | |
| 210 | 154 | /** |
| 211 | 155 | * If Pro is missing but has been authenticated, include a download URL |
| @@ -213,20 +157,8 @@ | ||
| 213 | 157 | * @since 3.04.03 |
| 214 | 158 | * @return string |
| 215 | 159 | */ |
| 216 | 160 | public static function get_pro_download_url() { |
| 217 | - $license = self::get_pro_license(); | |
| 218 | - $api = new FrmFormApi( $license ); | |
| 219 | - $downloads = $api->get_api_info(); | |
| 220 | - $pro = self::get_pro_from_addons( $downloads ); | |
| 221 | - | |
| 222 | - return isset( $pro['url'] ) ? $pro['url'] : ''; | |
| 223 | - } | |
| 224 | - | |
| 225 | - /** | |
| 226 | - * @since 4.08 | |
| 227 | - */ | |
| 228 | - public static function get_pro_license() { | |
| 229 | 161 | $pro_cred_store = 'frmpro-credentials'; |
| 230 | 162 | $pro_wpmu_store = 'frmpro-wpmu-sitewide'; |
| 231 | 163 | if ( is_multisite() && get_site_option( $pro_wpmu_store ) ) { |
| 232 | 164 | $creds = get_site_option( $pro_cred_store ); |
| @@ -246,30 +178,14 @@ | ||
| 246 | 178 | if ( strpos( $license, '-' ) ) { |
| 247 | 179 | // this is a fix for licenses saved in the past |
| 248 | 180 | $license = strtoupper( $license ); |
| 249 | 181 | } |
| 250 | - return $license; | |
| 251 | - } | |
| 252 | 182 | |
| 253 | - /** | |
| 254 | - * @since 4.08 | |
| 255 | - * | |
| 256 | - * @param array $addons | |
| 257 | - * @return array | |
| 258 | - */ | |
| 259 | - protected static function get_pro_from_addons( $addons ) { | |
| 260 | - return isset( $addons['93790'] ) ? $addons['93790'] : array(); | |
| 261 | - } | |
| 183 | + $api = new FrmFormApi( $license ); | |
| 184 | + $downloads = $api->get_api_info(); | |
| 185 | + $pro = isset( $downloads['93790'] ) ? $downloads['93790'] : array(); | |
| 262 | 186 | |
| 263 | - /** | |
| 264 | - * @since 4.06 | |
| 265 | - */ | |
| 266 | - public static function license_type() { | |
| 267 | - if ( is_callable( 'FrmProAddonsController::license_type' ) ) { | |
| 268 | - return FrmProAddonsController::license_type(); | |
| 269 | - } | |
| 270 | - | |
| 271 | - return 'free'; | |
| 187 | + return isset( $pro['url'] ) ? $pro['url'] : ''; | |
| 272 | 188 | } |
| 273 | 189 | |
| 274 | 190 | /** |
| 275 | 191 | * @since 4.0.01 |
| @@ -274,35 +190,8 @@ | ||
| 274 | 190 | /** |
| 275 | 191 | * @since 4.0.01 |
| 276 | 192 | */ |
| 277 | 193 | public static function is_license_expired() { |
| 278 | - $version_info = self::get_primary_license_info(); | |
| 279 | - if ( ! isset( $version_info['error'] ) ) { | |
| 280 | - return false; | |
| 281 | - } | |
| 282 | - | |
| 283 | - return $version_info['error']; | |
| 284 | - } | |
| 285 | - | |
| 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(); | |
| 294 | - } | |
| 295 | - | |
| 296 | - return false; | |
| 297 | - } | |
| 298 | - | |
| 299 | - /** | |
| 300 | - * @since 4.08 | |
| 301 | - * | |
| 302 | - * @return array|false | |
| 303 | - */ | |
| 304 | - protected static function get_primary_license_info() { | |
| 305 | 194 | $installed_addons = apply_filters( 'frm_installed_addons', array() ); |
| 306 | 195 | if ( empty( $installed_addons ) || ! isset( $installed_addons['formidable_pro'] ) ) { |
| 307 | 196 | return false; |
| 308 | 197 | } |
| @@ -309,9 +198,14 @@ | ||
| 309 | 198 | $installed_addons = array( |
| 310 | 199 | 'formidable_pro' => $installed_addons['formidable_pro'], |
| 311 | 200 | ); |
| 312 | 201 | |
| 313 | - return self::fill_update_addon_info( $installed_addons ); | |
| 202 | + $version_info = self::fill_update_addon_info( $installed_addons ); | |
| 203 | + if ( ! isset( $version_info['error'] ) ) { | |
| 204 | + return false; | |
| 205 | + } | |
| 206 | + | |
| 207 | + return $version_info['error']; | |
| 314 | 208 | } |
| 315 | 209 | |
| 316 | 210 | /** |
| 317 | 211 | * @since 3.04.03 |
| @@ -316,13 +210,8 @@ | ||
| 316 | 210 | /** |
| 317 | 211 | * @since 3.04.03 |
| 318 | 212 | */ |
| 319 | 213 | public static function check_update( $transient ) { |
| 320 | - if ( ! FrmAppHelper::pro_is_installed() ) { | |
| 321 | - // Don't make any changes if only Lite is installed. | |
| 322 | - return $transient; | |
| 323 | - } | |
| 324 | - | |
| 325 | 214 | if ( ! is_object( $transient ) ) { |
| 326 | 215 | $transient = new stdClass(); |
| 327 | 216 | } |
| 328 | 217 | |
| @@ -330,12 +219,14 @@ | ||
| 330 | 219 | if ( empty( $installed_addons ) ) { |
| 331 | 220 | return $transient; |
| 332 | 221 | } |
| 333 | 222 | |
| 334 | - $version_info = self::fill_update_addon_info( $installed_addons ); | |
| 223 | + $version_info = self::fill_update_addon_info( $installed_addons ); | |
| 224 | + | |
| 335 | 225 | $transient->last_checked = time(); |
| 336 | - $wp_plugins = self::get_plugins(); | |
| 337 | 226 | |
| 227 | + $wp_plugins = get_plugins(); | |
| 228 | + | |
| 338 | 229 | foreach ( $version_info as $id => $plugin ) { |
| 339 | 230 | $plugin = (object) $plugin; |
| 340 | 231 | |
| 341 | 232 | if ( ! isset( $plugin->new_version ) || ! isset( $plugin->package ) ) { |
| @@ -368,23 +259,8 @@ | ||
| 368 | 259 | return $transient; |
| 369 | 260 | } |
| 370 | 261 | |
| 371 | 262 | /** |
| 372 | - * Copy of FrmAppHelper::get_plugins. | |
| 373 | - * Because this gets called on "pre_set_site_transient_update_plugins" an old version of FrmAppHelper may be loaded on plugin update. | |
| 374 | - * This means that trying to access FrmAppHelper::get_plugins when upgrading from a Lite version before v5.5 results in a one-off error. | |
| 375 | - * | |
| 376 | - * @since 5.5.2 | |
| 377 | - * @return array | |
| 378 | - */ | |
| 379 | - protected static function get_plugins() { | |
| 380 | - if ( ! function_exists( 'get_plugins' ) ) { | |
| 381 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; | |
| 382 | - } | |
| 383 | - return get_plugins(); | |
| 384 | - } | |
| 385 | - | |
| 386 | - /** | |
| 387 | 263 | * Check if a plugin is installed before showing an update for it |
| 388 | 264 | * |
| 389 | 265 | * @since 3.05 |
| 390 | 266 | * |
| @@ -391,10 +267,15 @@ | ||
| 391 | 267 | * @param string $plugin - the folder/filename.php for a plugin |
| 392 | 268 | * |
| 393 | 269 | * @return bool - True if installed |
| 394 | 270 | */ |
| 395 | - protected static function is_installed( $plugin ) { | |
| 396 | - $all_plugins = self::get_plugins(); | |
| 271 | + private static function is_installed( $plugin ) { | |
| 272 | + if ( ! function_exists( 'get_plugins' ) ) { | |
| 273 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; | |
| 274 | + } | |
| 275 | + | |
| 276 | + $all_plugins = get_plugins(); | |
| 277 | + | |
| 397 | 278 | return isset( $all_plugins[ $plugin ] ); |
| 398 | 279 | } |
| 399 | 280 | |
| 400 | 281 | /** |
| @@ -403,9 +284,9 @@ | ||
| 403 | 284 | * @param array $installed_addons |
| 404 | 285 | * |
| 405 | 286 | * @return array |
| 406 | 287 | */ |
| 407 | - protected static function fill_update_addon_info( $installed_addons ) { | |
| 288 | + private static function fill_update_addon_info( $installed_addons ) { | |
| 408 | 289 | $checked_licenses = array(); |
| 409 | 290 | $version_info = array(); |
| 410 | 291 | |
| 411 | 292 | foreach ( $installed_addons as $addon ) { |
| @@ -453,16 +334,22 @@ | ||
| 453 | 334 | /** |
| 454 | 335 | * Get the action link for an addon that isn't active. |
| 455 | 336 | * |
| 456 | 337 | * @since 3.06.03 |
| 457 | - * @param string $plugin The plugin slug | |
| 338 | + * @param string $addon The plugin slug | |
| 458 | 339 | * @return array |
| 459 | 340 | */ |
| 460 | 341 | public static function install_link( $plugin ) { |
| 461 | - $link = array(); | |
| 462 | - $addon = self::get_addon( $plugin ); | |
| 342 | + $link = array(); | |
| 343 | + $addons = self::get_api_addons(); | |
| 344 | + self::prepare_addons( $addons ); | |
| 463 | 345 | |
| 464 | - if ( $addon ) { | |
| 346 | + foreach ( $addons as $addon ) { | |
| 347 | + $slug = explode( '/', $addon['plugin'] ); | |
| 348 | + if ( $slug[0] !== 'formidable-' . $plugin ) { | |
| 349 | + continue; | |
| 350 | + } | |
| 351 | + | |
| 465 | 352 | if ( $addon['status']['type'] === 'installed' && ! empty( $addon['activate_url'] ) ) { |
| 466 | 353 | $link = array( |
| 467 | 354 | 'url' => $addon['plugin'], |
| 468 | 355 | 'class' => 'frm-activate-addon', |
| @@ -477,52 +364,13 @@ | ||
| 477 | 364 | 'categories' => $addon['categories'], |
| 478 | 365 | ); |
| 479 | 366 | } |
| 480 | 367 | |
| 481 | - if ( ! empty( $link ) ) { | |
| 482 | - $link['status'] = $addon['status']['type']; | |
| 483 | - } | |
| 484 | - } elseif ( current_user_can( 'activate_plugins' ) && self::is_installed( 'formidable-' . $plugin . '/formidable-' . $plugin . '.php' ) ) { | |
| 485 | - $link = array( | |
| 486 | - 'url' => 'formidable-' . $plugin . '/formidable-' . $plugin . '.php', | |
| 487 | - 'class' => 'frm-activate-addon', | |
| 488 | - ); | |
| 368 | + return $link; | |
| 489 | 369 | } |
| 490 | - | |
| 491 | - return $link; | |
| 492 | 370 | } |
| 493 | 371 | |
| 494 | 372 | /** |
| 495 | - * @since 4.09 | |
| 496 | - * @param string $plugin The plugin slug | |
| 497 | - * @return array|false | |
| 498 | - */ | |
| 499 | - protected static function get_addon( $plugin ) { | |
| 500 | - $addons = self::get_api_addons(); | |
| 501 | - self::prepare_addons( $addons ); | |
| 502 | - foreach ( $addons as $addon ) { | |
| 503 | - $slug = explode( '/', $addon['plugin'] ); | |
| 504 | - if ( $slug[0] === 'formidable-' . $plugin ) { | |
| 505 | - return $addon; | |
| 506 | - } | |
| 507 | - } | |
| 508 | - return false; | |
| 509 | - } | |
| 510 | - | |
| 511 | - /** | |
| 512 | - * @since 4.09 | |
| 513 | - * @return string | |
| 514 | - */ | |
| 515 | - protected static function get_license_type() { | |
| 516 | - $license_type = ''; | |
| 517 | - $addons = self::get_api_addons(); | |
| 518 | - if ( isset( $addons['error'] ) && isset( $addons['error']['type'] ) ) { | |
| 519 | - $license_type = $addons['error']['type']; | |
| 520 | - } | |
| 521 | - return $license_type; | |
| 522 | - } | |
| 523 | - | |
| 524 | - /** | |
| 525 | 373 | * @since 3.04.03 |
| 526 | 374 | * |
| 527 | 375 | * @param array $addons |
| 528 | 376 | * @param object $license The FrmAddon object |
| @@ -544,12 +392,9 @@ | ||
| 544 | 392 | |
| 545 | 393 | return $plugin; |
| 546 | 394 | } |
| 547 | 395 | |
| 548 | - /** | |
| 549 | - * @return void | |
| 550 | - */ | |
| 551 | - protected static function prepare_addons( &$addons ) { | |
| 396 | + private static function prepare_addons( &$addons ) { | |
| 552 | 397 | $activate_url = ''; |
| 553 | 398 | if ( current_user_can( 'activate_plugins' ) ) { |
| 554 | 399 | $activate_url = add_query_arg( array( 'action' => 'activate' ), admin_url( 'plugins.php' ) ); |
| 555 | 400 | } |
| @@ -566,24 +411,14 @@ | ||
| 566 | 411 | } else { |
| 567 | 412 | $base_file = 'formidable-' . $slug; |
| 568 | 413 | } |
| 569 | 414 | $file_name = $base_file . '/' . $base_file . '.php'; |
| 570 | - if ( ! isset( $addon['plugin'] ) ) { | |
| 571 | - $addon['plugin'] = $file_name; | |
| 572 | - } | |
| 573 | 415 | } |
| 574 | 416 | |
| 575 | - $addon['installed'] = self::is_installed( $file_name ); | |
| 576 | - if ( $addon['installed'] && 'formidable-views/formidable-views.php' === $file_name ) { | |
| 577 | - $active_views_version = self::get_active_views_version(); | |
| 578 | - if ( false !== $active_views_version && $slug !== $active_views_version ) { | |
| 579 | - $addon['installed'] = false; | |
| 580 | - } | |
| 581 | - } | |
| 582 | - | |
| 417 | + $addon['installed'] = self::is_installed( $file_name ); | |
| 583 | 418 | $addon['activate_url'] = ''; |
| 584 | 419 | |
| 585 | - if ( $addon['installed'] && ! empty( $activate_url ) && ! self::is_plugin_active( $file_name, $slug ) ) { | |
| 420 | + if ( $addon['installed'] && ! empty( $activate_url ) && ! is_plugin_active( $file_name ) ) { | |
| 586 | 421 | $addon['activate_url'] = add_query_arg( |
| 587 | 422 | array( |
| 588 | 423 | '_wpnonce' => wp_create_nonce( 'activate-plugin_' . $file_name ), |
| 589 | 424 | 'plugin' => $file_name, |
| @@ -607,34 +442,11 @@ | ||
| 607 | 442 | } |
| 608 | 443 | } |
| 609 | 444 | |
| 610 | 445 | /** |
| 611 | - * @return bool | |
| 612 | - */ | |
| 613 | - private static function is_plugin_active( $file_name, $slug ) { | |
| 614 | - if ( 'formidable-views/formidable-views.php' === $file_name ) { | |
| 615 | - return self::get_active_views_version() === $slug; | |
| 616 | - } | |
| 617 | - return is_plugin_active( $file_name ); | |
| 618 | - } | |
| 619 | - | |
| 620 | - /** | |
| 621 | - * @return string|false either 'visual-views' or 'views', false if one is not found. | |
| 622 | - */ | |
| 623 | - private static function get_active_views_version() { | |
| 624 | - if ( ! is_callable( 'FrmViewsAppHelper::plugin_version' ) ) { | |
| 625 | - return false; | |
| 626 | - } | |
| 627 | - $plugin_version = FrmViewsAppHelper::plugin_version(); | |
| 628 | - return version_compare( $plugin_version, '5.0', '>=' ) ? 'visual-views' : 'views'; | |
| 629 | - } | |
| 630 | - | |
| 631 | - /** | |
| 632 | 446 | * @since 3.04.02 |
| 633 | - * | |
| 634 | - * @return void | |
| 635 | 447 | */ |
| 636 | - protected static function prepare_addon_link( &$link ) { | |
| 448 | + private static function prepare_addon_link( &$link ) { | |
| 637 | 449 | $site_url = 'https://formidableforms.com/'; |
| 638 | 450 | if ( strpos( $link, 'http' ) !== 0 ) { |
| 639 | 451 | $link = $site_url . $link; |
| 640 | 452 | } |
| @@ -651,12 +463,10 @@ | ||
| 651 | 463 | * Add the status to the addon array. Status options are: |
| 652 | 464 | * installed, active, not installed |
| 653 | 465 | * |
| 654 | 466 | * @since 3.04.02 |
| 655 | - * | |
| 656 | - * @return void | |
| 657 | 467 | */ |
| 658 | - protected static function set_addon_status( &$addon ) { | |
| 468 | + private static function set_addon_status( &$addon ) { | |
| 659 | 469 | if ( ! empty( $addon['activate_url'] ) ) { |
| 660 | 470 | $addon['status'] = array( |
| 661 | 471 | 'type' => 'installed', |
| 662 | 472 | 'label' => __( 'Installed', 'formidable' ), |
| @@ -673,11 +483,8 @@ | ||
| 673 | 483 | ); |
| 674 | 484 | } |
| 675 | 485 | } |
| 676 | 486 | |
| 677 | - /** | |
| 678 | - * @return void | |
| 679 | - */ | |
| 680 | 487 | public static function upgrade_to_pro() { |
| 681 | 488 | FrmAppHelper::include_svg(); |
| 682 | 489 | |
| 683 | 490 | $link_parts = array( |
| @@ -690,9 +497,9 @@ | ||
| 690 | 497 | array( |
| 691 | 498 | 'label' => 'Display form data with virtually limitless views', |
| 692 | 499 | 'link' => array( |
| 693 | 500 | 'content' => 'views', |
| 694 | - 'param' => 'views-display-form-data', | |
| 501 | + 'anchor' => 'feature-display-form-data-views', | |
| 695 | 502 | ), |
| 696 | 503 | 'lite' => false, |
| 697 | 504 | ), |
| 698 | 505 | array( |
| @@ -698,9 +505,9 @@ | ||
| 698 | 505 | array( |
| 699 | 506 | 'label' => 'Generate graphs and stats based on your submitted data', |
| 700 | 507 | 'link' => array( |
| 701 | 508 | 'content' => 'graphs', |
| 702 | - 'param' => 'statistics-graphs-wordpress-forms', | |
| 509 | + 'anchor' => 'feature-create-a-graph-wordpress-forms', | |
| 703 | 510 | ), |
| 704 | 511 | 'lite' => false, |
| 705 | 512 | ), |
| 706 | 513 | ), |
| @@ -708,9 +515,9 @@ | ||
| 708 | 515 | array( |
| 709 | 516 | 'label' => 'Import entries from a CSV', |
| 710 | 517 | 'link' => array( |
| 711 | 518 | 'content' => 'import-entries', |
| 712 | - 'param' => 'importing-exporting-wordpress-forms', | |
| 519 | + 'anchor' => 'feature-importing-exporting-wordpress-forms', | |
| 713 | 520 | ), |
| 714 | 521 | 'lite' => false, |
| 715 | 522 | ), |
| 716 | 523 | array( |
| @@ -716,9 +523,9 @@ | ||
| 716 | 523 | array( |
| 717 | 524 | 'label' => 'Logged-in users can save drafts and return later', |
| 718 | 525 | 'link' => array( |
| 719 | 526 | 'content' => 'save-drafts', |
| 720 | - 'param' => 'save-drafts-wordpress-form', | |
| 527 | + 'anchor' => 'feature-save-and-continue-partial-submissions', | |
| 721 | 528 | ), |
| 722 | 529 | 'lite' => false, |
| 723 | 530 | ), |
| 724 | 531 | array( |
| @@ -724,9 +531,9 @@ | ||
| 724 | 531 | array( |
| 725 | 532 | 'label' => 'Flexibly and powerfully view, edit, and delete entries from anywhere on your site', |
| 726 | 533 | 'link' => array( |
| 727 | 534 | 'content' => 'front-edit', |
| 728 | - 'param' => 'wordpress-front-end-editing', | |
| 535 | + 'anchor' => 'feature-front-end-editing-wordpress', | |
| 729 | 536 | ), |
| 730 | 537 | 'lite' => false, |
| 731 | 538 | ), |
| 732 | 539 | array( |
| @@ -742,9 +549,9 @@ | ||
| 742 | 549 | array( |
| 743 | 550 | 'label' => 'Save a calculated value into a field', |
| 744 | 551 | 'link' => array( |
| 745 | 552 | 'content' => 'calculations', |
| 746 | - 'param' => 'field-calculations-wordpress-form', | |
| 553 | + 'anchor' => 'feature-wordpress-calculated-fields-form', | |
| 747 | 554 | ), |
| 748 | 555 | 'lite' => false, |
| 749 | 556 | ), |
| 750 | 557 | array( |
| @@ -750,9 +557,9 @@ | ||
| 750 | 557 | array( |
| 751 | 558 | 'label' => 'Allow multiple file uploads', |
| 752 | 559 | 'link' => array( |
| 753 | 560 | 'content' => 'file-uploads', |
| 754 | - 'param' => 'wordpress-multi-file-upload-fields', | |
| 561 | + 'anchor' => 'feature-wordpress-multiple-file-upload-form', | |
| 755 | 562 | ), |
| 756 | 563 | 'lite' => false, |
| 757 | 564 | ), |
| 758 | 565 | array( |
| @@ -758,9 +565,9 @@ | ||
| 758 | 565 | array( |
| 759 | 566 | 'label' => 'Repeat sections of fields', |
| 760 | 567 | 'link' => array( |
| 761 | 568 | 'content' => 'repeaters', |
| 762 | - 'param' => 'repeatable-sections-forms', | |
| 569 | + 'anchor' => 'feature-dynamically-add-form-fields', | |
| 763 | 570 | ), |
| 764 | 571 | 'lite' => false, |
| 765 | 572 | ), |
| 766 | 573 | array( |
| @@ -766,9 +573,9 @@ | ||
| 766 | 573 | array( |
| 767 | 574 | 'label' => 'Hide and show fields conditionally based on other fields or the user\'s role', |
| 768 | 575 | 'link' => array( |
| 769 | 576 | 'content' => 'conditional-logic', |
| 770 | - 'param' => 'conditional-logic-wordpress-forms', | |
| 577 | + 'anchor' => 'feature-conditional-logic-wordpress-forms', | |
| 771 | 578 | ), |
| 772 | 579 | 'lite' => false, |
| 773 | 580 | ), |
| 774 | 581 | array( |
| @@ -774,9 +581,9 @@ | ||
| 774 | 581 | array( |
| 775 | 582 | 'label' => 'Confirmation fields', |
| 776 | 583 | 'link' => array( |
| 777 | 584 | 'content' => 'confirmation-fields', |
| 778 | - 'param' => 'confirmation-fields-wordpress-forms', | |
| 585 | + 'anchor' => 'feature-confirm-email-address-password-wordpress-form', | |
| 779 | 586 | ), |
| 780 | 587 | 'lite' => false, |
| 781 | 588 | ), |
| 782 | 589 | array( |
| @@ -782,9 +589,9 @@ | ||
| 782 | 589 | array( |
| 783 | 590 | 'label' => 'Multi-paged forms', |
| 784 | 591 | 'link' => array( |
| 785 | 592 | 'content' => 'page-breaks', |
| 786 | - 'param' => 'wordpress-multi-page-forms', | |
| 593 | + 'anchor' => 'feature-wordpress-multi-step-form', | |
| 787 | 594 | ), |
| 788 | 595 | 'lite' => false, |
| 789 | 596 | ), |
| 790 | 597 | array( |
| @@ -798,9 +605,9 @@ | ||
| 798 | 605 | array( |
| 799 | 606 | 'label' => 'Drag & Drop Form building', |
| 800 | 607 | 'link' => array( |
| 801 | 608 | 'content' => 'drag-drop', |
| 802 | - 'param' => 'drag-drop-forms', | |
| 609 | + 'anchor' => 'feature-drag-drop-form-builder', | |
| 803 | 610 | ), |
| 804 | 611 | 'lite' => true, |
| 805 | 612 | ), |
| 806 | 613 | array( |
| @@ -806,9 +613,9 @@ | ||
| 806 | 613 | array( |
| 807 | 614 | 'label' => 'Create forms from Templates', |
| 808 | 615 | 'link' => array( |
| 809 | 616 | 'content' => 'form-templates', |
| 810 | - 'param' => 'wordpress-form-templates', | |
| 617 | + 'anchor' => 'feature-wordpress-form-templates', | |
| 811 | 618 | ), |
| 812 | 619 | 'lite' => true, |
| 813 | 620 | ), |
| 814 | 621 | array( |
| @@ -814,9 +621,9 @@ | ||
| 814 | 621 | array( |
| 815 | 622 | 'label' => 'Import and export forms with XML', |
| 816 | 623 | 'link' => array( |
| 817 | 624 | 'content' => 'import', |
| 818 | - 'param' => 'importing-exporting-wordpress-forms', | |
| 625 | + 'anchor' => 'feature-importing-exporting-wordpress-forms', | |
| 819 | 626 | ), |
| 820 | 627 | 'lite' => true, |
| 821 | 628 | ), |
| 822 | 629 | array( |
| @@ -828,8 +635,9 @@ | ||
| 828 | 635 | array( |
| 829 | 636 | 'label' => 'Conditionally send your email notifications based on values in your form', |
| 830 | 637 | 'link' => array( |
| 831 | 638 | 'content' => 'conditional-emails', |
| 639 | + 'anchor' => 'feature-conditional-logic-wordpress-forms', | |
| 832 | 640 | ), |
| 833 | 641 | 'lite' => false, |
| 834 | 642 | ), |
| 835 | 643 | array( |
| @@ -835,9 +643,9 @@ | ||
| 835 | 643 | array( |
| 836 | 644 | 'label' => 'Create and edit WordPress posts or custom posts from the front-end', |
| 837 | 645 | 'link' => array( |
| 838 | 646 | 'content' => 'create-posts', |
| 839 | - 'param' => 'create-posts-pages-wordpress-forms', | |
| 647 | + 'anchor' => 'feature-user-submitted-posts-wordpress-forms', | |
| 840 | 648 | ), |
| 841 | 649 | 'lite' => false, |
| 842 | 650 | ), |
| 843 | 651 | array( |
| @@ -843,9 +651,9 @@ | ||
| 843 | 651 | array( |
| 844 | 652 | 'label' => 'Send multiple emails and autoresponders', |
| 845 | 653 | 'link' => array( |
| 846 | 654 | 'content' => 'multiple-emails', |
| 847 | - 'param' => 'virtually-unlimited-emails', | |
| 655 | + 'anchor' => 'feature-email-autoresponders-wordpress', | |
| 848 | 656 | ), |
| 849 | 657 | 'lite' => true, |
| 850 | 658 | ), |
| 851 | 659 | ), |
| @@ -853,9 +661,9 @@ | ||
| 853 | 661 | array( |
| 854 | 662 | 'label' => 'Create Multiple styles for different forms', |
| 855 | 663 | 'link' => array( |
| 856 | 664 | 'content' => 'multiple-styles', |
| 857 | - 'param' => 'wordpress-visual-form-styler', | |
| 665 | + 'anchor' => 'feature-wordpress-visual-form-styler', | |
| 858 | 666 | ), |
| 859 | 667 | 'lite' => false, |
| 860 | 668 | ), |
| 861 | 669 | array( |
| @@ -861,9 +669,9 @@ | ||
| 861 | 669 | array( |
| 862 | 670 | 'label' => 'Customizable layout with CSS classes', |
| 863 | 671 | 'link' => array( |
| 864 | 672 | 'content' => 'form-layout', |
| 865 | - 'param' => 'wordpress-mobile-friendly-forms', | |
| 673 | + 'anchor' => 'feature-wordpress-mobile-friendly-responsive-forms', | |
| 866 | 674 | ), |
| 867 | 675 | 'lite' => true, |
| 868 | 676 | ), |
| 869 | 677 | array( |
| @@ -869,9 +677,9 @@ | ||
| 869 | 677 | array( |
| 870 | 678 | 'label' => 'Customize the HTML for your forms', |
| 871 | 679 | 'link' => array( |
| 872 | 680 | 'content' => 'custom-html', |
| 873 | - 'param' => 'customizable-html-wordpress-form', | |
| 681 | + 'anchor' => 'feature-customize-form-html-wordpress', | |
| 874 | 682 | ), |
| 875 | 683 | 'lite' => true, |
| 876 | 684 | ), |
| 877 | 685 | array( |
| @@ -884,94 +692,32 @@ | ||
| 884 | 692 | include( FrmAppHelper::plugin_path() . '/classes/views/addons/upgrade_to_pro.php' ); |
| 885 | 693 | } |
| 886 | 694 | |
| 887 | 695 | /** |
| 888 | - * Install Pro after connection with Formidable. | |
| 889 | - * | |
| 890 | - * @since 4.02.05 | |
| 891 | - * | |
| 892 | - * @return void | |
| 696 | + * @since 3.04.02 | |
| 893 | 697 | */ |
| 894 | - public static function connect_pro() { | |
| 895 | - FrmAppHelper::permission_check( 'install_plugins' ); | |
| 896 | - check_ajax_referer( 'frm_ajax', 'nonce' ); | |
| 698 | + public static function ajax_install_addon() { | |
| 897 | 699 | |
| 898 | - $url = self::get_current_plugin(); | |
| 899 | - if ( FrmAppHelper::pro_is_installed() || empty( $url ) ) { | |
| 900 | - wp_die(); | |
| 901 | - } | |
| 700 | + self::install_addon_permissions(); | |
| 902 | 701 | |
| 903 | - $response = array(); | |
| 702 | + // Set the current screen to avoid undefined notices. | |
| 703 | + global $hook_suffix; | |
| 704 | + set_current_screen(); | |
| 904 | 705 | |
| 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(); | |
| 917 | - } | |
| 918 | - | |
| 919 | - /** | |
| 920 | - * @since 5.5.2 | |
| 921 | - * | |
| 922 | - * @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. | |
| 927 | - */ | |
| 928 | - protected static function activate_plugin( $plugin, $redirect = '', $network_wide = false, $silent = false ) { | |
| 929 | - if ( ! function_exists( 'activate_plugin' ) ) { | |
| 930 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; | |
| 931 | - } | |
| 932 | - return activate_plugin( $plugin, $redirect, $network_wide, $silent ); | |
| 933 | - } | |
| 934 | - | |
| 935 | - /** | |
| 936 | - * @since 5.0.10 | |
| 937 | - * | |
| 938 | - * @return string | |
| 939 | - */ | |
| 940 | - protected static function get_current_plugin() { | |
| 941 | - if ( ! isset( self::$plugin ) ) { | |
| 942 | - self::$plugin = FrmAppHelper::get_param( 'plugin', '', 'post', 'esc_url_raw' ); | |
| 943 | - } | |
| 944 | - return self::$plugin; | |
| 945 | - } | |
| 946 | - | |
| 947 | - /** | |
| 948 | - * @since 4.08 | |
| 949 | - */ | |
| 950 | - protected static function download_and_activate() { | |
| 951 | - if ( is_admin() ) { | |
| 952 | - FrmAppHelper::set_current_screen_and_hook_suffix(); | |
| 953 | - } | |
| 954 | - | |
| 955 | 706 | self::maybe_show_cred_form(); |
| 956 | 707 | |
| 957 | 708 | $installed = self::install_addon(); |
| 958 | - if ( is_array( $installed ) && isset( $installed['message'] ) ) { | |
| 959 | - return $installed; | |
| 960 | - } | |
| 961 | 709 | self::maybe_activate_addon( $installed ); |
| 710 | + | |
| 711 | + // Send back a response. | |
| 712 | + echo json_encode( __( 'Your plugin has been installed. Please reload the page to see more options.', 'formidable' ) ); | |
| 713 | + wp_die(); | |
| 962 | 714 | } |
| 963 | 715 | |
| 964 | 716 | /** |
| 965 | 717 | * @since 3.04.02 |
| 966 | - * | |
| 967 | - * @return void | |
| 968 | 718 | */ |
| 969 | - protected static function maybe_show_cred_form() { | |
| 970 | - if ( ! function_exists( 'request_filesystem_credentials' ) ) { | |
| 971 | - include_once( ABSPATH . 'wp-admin/includes/file.php' ); | |
| 972 | - } | |
| 973 | - | |
| 719 | + private static function maybe_show_cred_form() { | |
| 974 | 720 | // Start output bufferring to catch the filesystem form if credentials are needed. |
| 975 | 721 | ob_start(); |
| 976 | 722 | |
| 977 | 723 | $show_form = false; |
| @@ -987,17 +733,12 @@ | ||
| 987 | 733 | $show_form = true; |
| 988 | 734 | } |
| 989 | 735 | |
| 990 | 736 | if ( $show_form ) { |
| 991 | - $form = ob_get_clean(); | |
| 992 | - $message = __( 'Sorry, your site requires FTP authentication. Please download plugins from FormidableForms.com and install them manually.', 'formidable' ); | |
| 993 | - $data = $form; | |
| 994 | - $response = array( | |
| 995 | - 'success' => false, | |
| 996 | - 'message' => $message, | |
| 997 | - 'form' => $form, | |
| 998 | - ); | |
| 999 | - wp_send_json( $response ); | |
| 737 | + //$form = ob_get_clean(); | |
| 738 | + //TODO: test this: echo json_encode( array( 'form' => $form ) ); | |
| 739 | + echo json_encode( array( 'form' => __( 'Sorry, you\'re site requires FTP authentication. Please install plugins manaully.', 'formidable' ) ) ); | |
| 740 | + wp_die(); | |
| 1000 | 741 | } |
| 1001 | 742 | |
| 1002 | 743 | ob_end_clean(); |
| 1003 | 744 | } |
| @@ -1002,42 +743,18 @@ | ||
| 1002 | 743 | ob_end_clean(); |
| 1003 | 744 | } |
| 1004 | 745 | |
| 1005 | 746 | /** |
| 1006 | - * Checks if an addon download url is allowed. | |
| 1007 | - * | |
| 1008 | - * @since 6.2 | |
| 1009 | - * | |
| 1010 | - * @param string $download_url | |
| 1011 | - * | |
| 1012 | - * @return bool | |
| 1013 | - */ | |
| 1014 | - public static function url_is_allowed( $download_url ) { | |
| 1015 | - return ( | |
| 1016 | - FrmAppHelper::validate_url_is_in_s3_bucket( $download_url, 'zip' ) || in_array( $download_url, self::allowed_external_urls(), true ) | |
| 1017 | - ); | |
| 1018 | - } | |
| 1019 | - | |
| 1020 | - /** | |
| 1021 | 747 | * We do not need any extra credentials if we have gotten this far, |
| 1022 | 748 | * so let's install the plugin. |
| 1023 | 749 | * |
| 1024 | 750 | * @since 3.04.02 |
| 1025 | 751 | */ |
| 1026 | - protected static function install_addon() { | |
| 1027 | - FrmAppHelper::permission_check( 'install_plugins' ); | |
| 752 | + private static function install_addon() { | |
| 753 | + require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' ); | |
| 1028 | 754 | |
| 1029 | - require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; | |
| 755 | + $download_url = FrmAppHelper::get_param( 'plugin', '', 'post', 'esc_url_raw' ); | |
| 1030 | 756 | |
| 1031 | - $download_url = self::get_current_plugin(); | |
| 1032 | - | |
| 1033 | - if ( ! self::url_is_allowed( $download_url ) ) { | |
| 1034 | - return array( | |
| 1035 | - 'message' => 'Plugin URL is not valid', | |
| 1036 | - 'success' => false, | |
| 1037 | - ); | |
| 1038 | - } | |
| 1039 | - | |
| 1040 | 757 | // Create the plugin upgrader with our custom skin. |
| 1041 | 758 | $installer = new Plugin_Upgrader( new FrmInstallerSkin() ); |
| 1042 | 759 | $installer->install( $download_url ); |
| 1043 | 760 | |
| @@ -1043,93 +760,45 @@ | ||
| 1043 | 760 | |
| 1044 | 761 | // Flush the cache and return the newly installed plugin basename. |
| 1045 | 762 | wp_cache_flush(); |
| 1046 | 763 | |
| 1047 | - $plugin = $installer->plugin_info(); | |
| 1048 | - if ( ! $plugin ) { | |
| 1049 | - return array( | |
| 1050 | - 'message' => 'Plugin was not installed. ' . $installer->result, | |
| 1051 | - 'success' => false, | |
| 1052 | - ); | |
| 1053 | - } | |
| 1054 | - return $plugin; | |
| 764 | + return $installer->plugin_info(); | |
| 1055 | 765 | } |
| 1056 | 766 | |
| 1057 | 767 | /** |
| 1058 | 768 | * @since 3.06.03 |
| 1059 | - * | |
| 1060 | - * @return void | |
| 1061 | 769 | */ |
| 1062 | 770 | public static function ajax_activate_addon() { |
| 1063 | 771 | |
| 1064 | 772 | self::install_addon_permissions(); |
| 1065 | 773 | |
| 1066 | - FrmAppHelper::set_current_screen_and_hook_suffix(); | |
| 774 | + // Set the current screen to avoid undefined notices. | |
| 775 | + global $hook_suffix; | |
| 776 | + set_current_screen(); | |
| 1067 | 777 | |
| 1068 | 778 | $plugin = FrmAppHelper::get_param( 'plugin', '', 'post', 'sanitize_text_field' ); |
| 1069 | 779 | self::maybe_activate_addon( $plugin ); |
| 1070 | 780 | |
| 1071 | - echo json_encode( self::get_addon_activation_response() ); | |
| 781 | + // Send back a response. | |
| 782 | + echo json_encode( __( 'Your plugin has been activated. Please reload the page to see more options.', 'formidable' ) ); | |
| 1072 | 783 | wp_die(); |
| 1073 | 784 | } |
| 1074 | 785 | |
| 1075 | 786 | /** |
| 1076 | - * @return array | |
| 1077 | - */ | |
| 1078 | - private static function get_addon_activation_response() { | |
| 1079 | - $activating_page = self::get_activating_page(); | |
| 1080 | - | |
| 1081 | - $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' ); | |
| 1082 | - | |
| 1083 | - $response = array( | |
| 1084 | - 'message' => $message, | |
| 1085 | - 'saveAndReload' => $activating_page, | |
| 1086 | - ); | |
| 1087 | - | |
| 1088 | - return $response; | |
| 1089 | - } | |
| 1090 | - | |
| 1091 | - /** | |
| 1092 | - * Return a string that reflects the page from which the addon is being activated on, | |
| 1093 | - * if it is from settings or form builder, otherwise return empty string. | |
| 1094 | - * | |
| 1095 | - * @return string | |
| 1096 | - */ | |
| 1097 | - private static function get_activating_page() { | |
| 1098 | - $referer = FrmAppHelper::get_server_value( 'HTTP_REFERER' ); | |
| 1099 | - if ( false !== strpos( $referer, 'frm_action=settings' ) ) { | |
| 1100 | - return 'settings'; | |
| 1101 | - } | |
| 1102 | - | |
| 1103 | - if ( false !== strpos( $referer, 'frm_action=edit' ) ) { | |
| 1104 | - return 'form_builder'; | |
| 1105 | - } | |
| 1106 | - | |
| 1107 | - return ''; | |
| 1108 | - } | |
| 1109 | - | |
| 1110 | - /** | |
| 1111 | 787 | * @since 3.04.02 |
| 1112 | - * | |
| 1113 | 788 | * @param string $installed The plugin folder name with file name |
| 1114 | 789 | */ |
| 1115 | - protected static function maybe_activate_addon( $installed ) { | |
| 790 | + private static function maybe_activate_addon( $installed ) { | |
| 1116 | 791 | if ( ! $installed ) { |
| 1117 | 792 | return; |
| 1118 | 793 | } |
| 1119 | 794 | |
| 1120 | - $activate = self::activate_plugin( $installed ); | |
| 795 | + $activate = activate_plugin( $installed ); | |
| 1121 | 796 | if ( is_wp_error( $activate ) ) { |
| 1122 | 797 | // Ignore the invalid header message that shows with nested plugins. |
| 1123 | 798 | if ( $activate->get_error_code() !== 'no_plugin_header' ) { |
| 1124 | - if ( wp_doing_ajax() ) { | |
| 1125 | - echo json_encode( array( 'error' => $activate->get_error_message() ) ); | |
| 1126 | - wp_die(); | |
| 1127 | - } | |
| 1128 | - return array( | |
| 1129 | - 'message' => $activate->get_error_message(), | |
| 1130 | - 'success' => false, | |
| 1131 | - ); | |
| 799 | + echo json_encode( array( 'error' => $activate->get_error_message() ) ); | |
| 800 | + wp_die(); | |
| 1132 | 801 | } |
| 1133 | 802 | } |
| 1134 | 803 | } |
| 1135 | 804 | |
| @@ -1136,15 +805,13 @@ | ||
| 1136 | 805 | /** |
| 1137 | 806 | * Run security checks before installing |
| 1138 | 807 | * |
| 1139 | 808 | * @since 3.04.02 |
| 1140 | - * | |
| 1141 | - * @return void | |
| 1142 | 809 | */ |
| 1143 | - protected static function install_addon_permissions() { | |
| 810 | + private static function install_addon_permissions() { | |
| 1144 | 811 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
| 1145 | 812 | |
| 1146 | - if ( ! current_user_can( 'activate_plugins' ) || ! self::get_current_plugin() ) { | |
| 813 | + if ( ! current_user_can( 'activate_plugins' ) || ! isset( $_POST['plugin'] ) ) { | |
| 1147 | 814 | echo json_encode( true ); |
| 1148 | 815 | wp_die(); |
| 1149 | 816 | } |
| 1150 | 817 | } |
| @@ -1149,259 +816,8 @@ | ||
| 1149 | 816 | } |
| 1150 | 817 | } |
| 1151 | 818 | |
| 1152 | 819 | /** |
| 1153 | - * @since 4.08 | |
| 1154 | - * | |
| 1155 | - * @return string | |
| 1156 | - */ | |
| 1157 | - public static function connect_link() { | |
| 1158 | - $auth = get_option( 'frm_connect_token' ); | |
| 1159 | - if ( empty( $auth ) ) { | |
| 1160 | - $auth = hash( 'sha512', wp_rand() ); | |
| 1161 | - update_option( 'frm_connect_token', $auth ); | |
| 1162 | - } | |
| 1163 | - $link = FrmAppHelper::admin_upgrade_link( 'connect', 'api-connect' ); | |
| 1164 | - $args = array( | |
| 1165 | - 'v' => 2, | |
| 1166 | - 'siteurl' => FrmAppHelper::site_url(), | |
| 1167 | - 'url' => get_rest_url(), | |
| 1168 | - 'token' => $auth, | |
| 1169 | - 'l' => self::get_pro_license(), | |
| 1170 | - ); | |
| 1171 | - | |
| 1172 | - return add_query_arg( $args, $link ); | |
| 1173 | - } | |
| 1174 | - | |
| 1175 | - /** | |
| 1176 | - * Check the auth value for install permission. | |
| 1177 | - * | |
| 1178 | - * @since 4.08 | |
| 1179 | - * | |
| 1180 | - * @return bool | |
| 1181 | - */ | |
| 1182 | - public static function can_install_addon_api() { | |
| 1183 | - if ( ! current_user_can( 'activate_plugins' ) ) { | |
| 1184 | - return false; | |
| 1185 | - } | |
| 1186 | - | |
| 1187 | - // Verify params present (auth & download link). | |
| 1188 | - $post_auth = FrmAppHelper::get_param( 'token', '', 'request', 'sanitize_text_field' ); | |
| 1189 | - $post_url = FrmAppHelper::get_param( 'file_url', '', 'request', 'sanitize_text_field' ); | |
| 1190 | - | |
| 1191 | - if ( empty( $post_auth ) || empty( $post_url ) ) { | |
| 1192 | - return false; | |
| 1193 | - } | |
| 1194 | - | |
| 1195 | - // Verify auth. | |
| 1196 | - $auth = get_option( 'frm_connect_token' ); | |
| 1197 | - if ( empty( $auth ) || ! hash_equals( $auth, $post_auth ) ) { | |
| 1198 | - return false; | |
| 1199 | - } | |
| 1200 | - | |
| 1201 | - return true; | |
| 1202 | - } | |
| 1203 | - | |
| 1204 | - /** | |
| 1205 | - * Install and/or activate the add-on file. | |
| 1206 | - * | |
| 1207 | - * @since 4.08 | |
| 1208 | - */ | |
| 1209 | - public static function install_addon_api() { | |
| 1210 | - self::$plugin = FrmAppHelper::get_param( 'file_url', '', 'request', 'esc_url_raw' ); | |
| 1211 | - | |
| 1212 | - $error = esc_html__( 'Could not install an upgrade. Please download from formidableforms.com and install manually.', 'formidable' ); | |
| 1213 | - | |
| 1214 | - // Delete so cannot replay. | |
| 1215 | - delete_option( 'frm_connect_token' ); | |
| 1216 | - | |
| 1217 | - // It's already installed and active. | |
| 1218 | - $active = self::activate_plugin( 'formidable-pro/formidable-pro.php', false, false, true ); | |
| 1219 | - if ( is_wp_error( $active ) ) { | |
| 1220 | - // Download plugin now. | |
| 1221 | - $response = self::download_and_activate(); | |
| 1222 | - if ( is_array( $response ) && isset( $response['success'] ) ) { | |
| 1223 | - return $response; | |
| 1224 | - } | |
| 1225 | - } | |
| 1226 | - | |
| 1227 | - // If empty license, save it now. | |
| 1228 | - if ( empty( self::get_pro_license() ) && function_exists( 'load_formidable_pro' ) ) { | |
| 1229 | - load_formidable_pro(); | |
| 1230 | - $license = stripslashes( FrmAppHelper::get_param( 'key', '', 'request', 'sanitize_text_field' ) ); | |
| 1231 | - if ( ! $license ) { | |
| 1232 | - return array( | |
| 1233 | - 'success' => false, | |
| 1234 | - 'error' => 'That site does not have a valid license key.', | |
| 1235 | - ); | |
| 1236 | - } | |
| 1237 | - | |
| 1238 | - $response = FrmAddon::activate_license_for_plugin( $license, 'formidable_pro' ); | |
| 1239 | - if ( ! $response['success'] ) { | |
| 1240 | - // Could not activate license. | |
| 1241 | - return $response; | |
| 1242 | - } | |
| 1243 | - } | |
| 1244 | - | |
| 1245 | - return array( | |
| 1246 | - 'success' => true, | |
| 1247 | - ); | |
| 1248 | - } | |
| 1249 | - | |
| 1250 | - /** | |
| 1251 | - * Render a conditional action button for a specified plugin | |
| 1252 | - * | |
| 1253 | - * @param string $plugin | |
| 1254 | - * @param array|string $upgrade_link_args | |
| 1255 | - * @since 4.09 | |
| 1256 | - */ | |
| 1257 | - public static function conditional_action_button( $plugin, $upgrade_link_args ) { | |
| 1258 | - if ( is_callable( 'FrmProAddonsController::conditional_action_button' ) ) { | |
| 1259 | - return FrmProAddonsController::conditional_action_button( $plugin, $upgrade_link_args ); | |
| 1260 | - } | |
| 1261 | - | |
| 1262 | - $addon = self::get_addon( $plugin ); | |
| 1263 | - $upgrade_link = FrmAppHelper::admin_upgrade_link( $upgrade_link_args ); | |
| 1264 | - | |
| 1265 | - $upgrade_link_args['link'] = $upgrade_link; | |
| 1266 | - self::addon_upgrade_link( $addon, $upgrade_link_args ); | |
| 1267 | - } | |
| 1268 | - | |
| 1269 | - /** | |
| 1270 | - * Render a conditional action button for an add on | |
| 1271 | - * | |
| 1272 | - * @since 4.09.01 | |
| 1273 | - * | |
| 1274 | - * @param array $addon | |
| 1275 | - * @param string|false $license_type | |
| 1276 | - * @param string $plan_required | |
| 1277 | - * @param string $upgrade_link | |
| 1278 | - */ | |
| 1279 | - public static function show_conditional_action_button( $atts ) { | |
| 1280 | - if ( is_callable( 'FrmProAddonsController::show_conditional_action_button' ) ) { | |
| 1281 | - return FrmProAddonsController::show_conditional_action_button( $atts ); | |
| 1282 | - } | |
| 1283 | - | |
| 1284 | - self::addon_upgrade_link( $atts['addon'], $atts['upgrade_link'] ); | |
| 1285 | - } | |
| 1286 | - | |
| 1287 | - /** | |
| 1288 | - * @since 4.09.01 | |
| 1289 | - * | |
| 1290 | - * @param array|false $addon | |
| 1291 | - * @param string|array $upgrade_link | |
| 1292 | - * | |
| 1293 | - * @return void | |
| 1294 | - */ | |
| 1295 | - protected static function addon_upgrade_link( $addon, $upgrade_link ) { | |
| 1296 | - $atts = is_array( $upgrade_link ) ? $upgrade_link : array(); | |
| 1297 | - $upgrade_link = is_array( $upgrade_link ) ? $upgrade_link['link'] : $upgrade_link; | |
| 1298 | - | |
| 1299 | - if ( $addon ) { | |
| 1300 | - $upgrade_link .= '&utm_content=' . $addon['slug']; | |
| 1301 | - } | |
| 1302 | - | |
| 1303 | - if ( $addon && isset( $addon['categories'] ) && in_array( 'Solution', $addon['categories'], true ) ) { | |
| 1304 | - // Solutions will go to a separate page. | |
| 1305 | - $upgrade_link = FrmAppHelper::admin_upgrade_link( 'addons', $addon['link'] ); | |
| 1306 | - } | |
| 1307 | - | |
| 1308 | - $class = ! empty( $atts['class'] ) ? $atts['class'] : ''; | |
| 1309 | - if ( strpos( $class, 'frm-button' ) === false ) { | |
| 1310 | - $class .= ' frm-button-secondary frm-button-sm'; | |
| 1311 | - } | |
| 1312 | - ?> | |
| 1313 | - <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' ); ?>"> | |
| 1314 | - <?php esc_html_e( 'Upgrade Now', 'formidable' ); ?> | |
| 1315 | - </a> | |
| 1316 | - <?php | |
| 1317 | - } | |
| 1318 | - | |
| 1319 | - /** | |
| 1320 | - * @since 3.04.02 | |
| 1321 | - * | |
| 1322 | - * @return void | |
| 1323 | - */ | |
| 1324 | - public static function ajax_install_addon() { | |
| 1325 | - self::install_addon_permissions(); | |
| 1326 | - | |
| 1327 | - $result = self::download_and_activate(); | |
| 1328 | - if ( isset( $result['success'] ) && ! $result['success'] ) { | |
| 1329 | - echo json_encode( $result ); | |
| 1330 | - wp_die(); | |
| 1331 | - } | |
| 1332 | - | |
| 1333 | - echo json_encode( self::get_addon_activation_response() ); | |
| 1334 | - wp_die(); | |
| 1335 | - } | |
| 1336 | - | |
| 1337 | - /** | |
| 1338 | - * Allowed URLs used for internal source of plugins installation. | |
| 1339 | - * | |
| 1340 | - * @since 6.3.1 | |
| 1341 | - * | |
| 1342 | - * @return array | |
| 1343 | - */ | |
| 1344 | - private static function allowed_external_urls() { | |
| 1345 | - $allowed_url_list = array( | |
| 1346 | - 'https://downloads.wordpress.org/plugin/formidable-gravity-forms-importer.zip', | |
| 1347 | - 'https://downloads.wordpress.org/plugin/formidable-import-pirate-forms.zip', | |
| 1348 | - 'https://downloads.wordpress.org/plugin/wp-mail-smtp.zip', | |
| 1349 | - ); | |
| 1350 | - | |
| 1351 | - /** | |
| 1352 | - * List of URLs used in plugin formidable internal installation. | |
| 1353 | - * | |
| 1354 | - * @since 6.3.1 | |
| 1355 | - * | |
| 1356 | - * @param array $allowed_url_list List of URLs. | |
| 1357 | - */ | |
| 1358 | - $allowed_url_list = apply_filters( 'frm_allowed_external_urls', $allowed_url_list ); | |
| 1359 | - | |
| 1360 | - if ( ! is_array( $allowed_url_list ) ) { | |
| 1361 | - _doing_it_wrong( __METHOD__, 'Only an array of URLs could be used within this filter.', '6.3.1' ); | |
| 1362 | - | |
| 1363 | - return array(); | |
| 1364 | - } | |
| 1365 | - | |
| 1366 | - return $allowed_url_list; | |
| 1367 | - } | |
| 1368 | - | |
| 1369 | - /** | |
| 1370 | - * Gets required plan for an addon. | |
| 1371 | - * | |
| 1372 | - * @since 6.4.2 | |
| 1373 | - * | |
| 1374 | - * @return string Empty string if no plan is required for active license. | |
| 1375 | - */ | |
| 1376 | - public static function get_addon_required_plan( $addon_id ) { | |
| 1377 | - $api = new FrmFormApi(); | |
| 1378 | - $addons = $api->get_api_info(); | |
| 1379 | - | |
| 1380 | - if ( is_array( $addons ) && array_key_exists( $addon_id, $addons ) ) { | |
| 1381 | - $dates = $addons[ $addon_id ]; | |
| 1382 | - $requires = FrmFormsHelper::get_plan_required( $dates ); | |
| 1383 | - } | |
| 1384 | - | |
| 1385 | - if ( ! isset( $requires ) || ! is_string( $requires ) ) { | |
| 1386 | - $requires = ''; | |
| 1387 | - } | |
| 1388 | - | |
| 1389 | - return $requires; | |
| 1390 | - } | |
| 1391 | - | |
| 1392 | - /** | |
| 1393 | - * @since 4.06.02 | |
| 1394 | - * | |
| 1395 | - * @deprecated 4.09.01 | |
| 1396 | - * | |
| 1397 | - * @return void | |
| 1398 | - */ | |
| 1399 | - public static function ajax_multiple_addons() { | |
| 1400 | - FrmDeprecated::ajax_multiple_addons(); | |
| 1401 | - } | |
| 1402 | - | |
| 1403 | - /** | |
| 1404 | 820 | * @since 3.04.03 |
| 1405 | 821 | * @deprecated 3.06 |
| 1406 | 822 | * @codeCoverageIgnore |
| 1407 | 823 | * @return array |
| @@ -1442,14 +858,10 @@ | ||
| 1442 | 858 | } |
| 1443 | 859 | |
| 1444 | 860 | /** |
| 1445 | 861 | * @since 3.04.03 |
| 1446 | - * | |
| 1447 | 862 | * @deprecated 3.06 |
| 1448 | - * | |
| 1449 | 863 | * @codeCoverageIgnore |
| 1450 | - * | |
| 1451 | - * @return void | |
| 1452 | 864 | */ |
| 1453 | 865 | public static function reset_cached_addons( $license = '' ) { |
| 1454 | 866 | FrmDeprecated::reset_cached_addons( $license ); |
| 1455 | 867 | } |
| @@ -1483,12 +895,9 @@ | ||
| 1483 | 895 | } |
| 1484 | 896 | |
| 1485 | 897 | /** |
| 1486 | 898 | * @deprecated 3.04.03 |
| 1487 | - * | |
| 1488 | 899 | * @codeCoverageIgnore |
| 1489 | - * | |
| 1490 | - * @return void | |
| 1491 | 900 | */ |
| 1492 | 901 | public static function get_licenses() { |
| 1493 | 902 | FrmDeprecated::get_licenses(); |
| 1494 | 903 | } |