| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentForm\App\Modules\Registerer; |
| 4 |
|
| 5 |
defined('ABSPATH') or die; |
| 6 |
|
| 7 |
use FluentForm\App\Models\Form; |
| 8 |
use FluentForm\App\Http\Controllers\AdminNoticeController; |
| 9 |
use FluentForm\App\Helpers\Helper; |
| 10 |
|
| 11 |
class MigrationNotice |
| 12 |
{ |
| 13 |
public static function register() |
| 14 |
{ |
| 15 |
if (static::shouldRegister()) { |
| 16 |
add_action('fluentform/global_menu', [static::class, 'show'], 99); |
| 17 |
} |
| 18 |
} |
| 19 |
|
| 20 |
protected static function shouldRegister() |
| 21 |
{ |
| 22 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Checking admin page parameter |
| 23 |
if (isset($_GET['page']) && sanitize_text_field(wp_unslash($_GET['page'])) === 'fluent_forms_transfer') { |
| 24 |
return false; |
| 25 |
} |
| 26 |
|
| 27 |
if (Helper::isFluentAdminPage() && !wp_doing_ajax()) { |
| 28 |
return static::hasActiveCompatiblePlugins(); |
| 29 |
} |
| 30 |
|
| 31 |
return false; |
| 32 |
} |
| 33 |
|
| 34 |
public static function show() |
| 35 |
{ |
| 36 |
$notice = new AdminNoticeController(); |
| 37 |
$msg = static::getMessage(); |
| 38 |
$notice->addNotice($msg); |
| 39 |
$notice->showNotice(); |
| 40 |
} |
| 41 |
|
| 42 |
private static function hasActiveCompatiblePlugins() |
| 43 |
{ |
| 44 |
$activePlugins = static::getActiveCompatiblePlugins(); |
| 45 |
return !empty($activePlugins); |
| 46 |
} |
| 47 |
|
| 48 |
private static function getActiveCompatiblePlugins() |
| 49 |
{ |
| 50 |
$supportedPlugins = [ |
| 51 |
'wpforms/wpforms.php' => 'WPForms', |
| 52 |
'wpforms-lite/wpforms.php' => 'WPForms', |
| 53 |
'contact-form-7/wp-contact-form-7.php' => 'Contact Form 7', |
| 54 |
'ninja-forms/ninja-forms.php' => 'Ninja Forms', |
| 55 |
'gravityforms/gravityforms.php' => 'Gravity Forms', |
| 56 |
'caldera-forms/caldera-core.php' => 'Caldera Forms' |
| 57 |
]; |
| 58 |
|
| 59 |
$activePlugins = []; |
| 60 |
foreach ($supportedPlugins as $plugin => $name) { |
| 61 |
if (is_plugin_active($plugin)) { |
| 62 |
$activePlugins[] = $name; |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
return $activePlugins; |
| 67 |
} |
| 68 |
|
| 69 |
private static function getMessage() |
| 70 |
{ |
| 71 |
$activePlugins = static::getActiveCompatiblePlugins(); |
| 72 |
$pluginNames = implode(', ', $activePlugins); |
| 73 |
|
| 74 |
$message = sprintf( |
| 75 |
'We noticed you have <strong>%s</strong> installed. You can easily migrate your existing forms to <strong>Fluent Forms</strong> with just a few clicks.', |
| 76 |
$pluginNames ?: 'compatible plugins' |
| 77 |
); |
| 78 |
|
| 79 |
return [ |
| 80 |
'name' => 'migration_notice', //ff_notice_migration_notice |
| 81 |
'title' => '', |
| 82 |
'message' => $message, |
| 83 |
'links' => [ |
| 84 |
[ |
| 85 |
'href' => admin_url('admin.php?page=fluent_forms_transfer#migrator'), |
| 86 |
'btn_text' => 'Migrate Now', |
| 87 |
'btn_atts' => 'class="mr-1 el-button--success el-button--mini"', |
| 88 |
], |
| 89 |
[ |
| 90 |
'href' => admin_url('admin.php?page=fluent_forms'), |
| 91 |
'btn_text' => 'Maybe Later', |
| 92 |
'btn_atts' => 'class="mr-1 el-button--info el-button--soft el-button--mini ff_nag_cross" data-notice_type="temp" data-notice_name="migration_notice"', |
| 93 |
], |
| 94 |
[ |
| 95 |
'href' => admin_url('admin.php?page=fluent_forms'), |
| 96 |
'btn_text' => 'Don\'t show again', |
| 97 |
'btn_atts' => 'class="text-button el-button--mini ff_nag_cross" data-notice_type="permanent" data-notice_name="migration_notice"', |
| 98 |
], |
| 99 |
], |
| 100 |
]; |
| 101 |
} |
| 102 |
} |
| 103 |
|