|
1
|
|
|
<?php |
|
2
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
|
3
|
|
|
die( 'You are not allowed to call this page directly.' ); |
|
4
|
|
|
} |
|
5
|
|
|
|
|
6
|
|
|
class FrmWelcomeController { |
|
7
|
|
|
|
|
8
|
|
|
public static $menu_slug = 'formidable-welcome'; |
|
9
|
|
|
|
|
10
|
|
|
public static $option_name = 'frm_activation_redirect'; |
|
11
|
|
|
|
|
12
|
|
|
private static $last_redirect = 'frm_welcome_redirect'; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Register all of the hooks related to the welcome screen functionality |
|
16
|
|
|
* |
|
17
|
|
|
* @access public |
|
18
|
|
|
*/ |
|
19
|
|
|
public static function load_hooks() { |
|
20
|
|
|
add_action( 'admin_init', __CLASS__ . '::redirect' ); |
|
21
|
|
|
|
|
22
|
|
|
if ( ! FrmAppHelper::is_admin_page( self::$menu_slug ) ) { |
|
23
|
|
|
return; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
add_action( 'admin_menu', __CLASS__ . '::screen_page' ); |
|
27
|
|
|
add_action( 'admin_head', __CLASS__ . '::remove_menu' ); |
|
28
|
|
|
add_action( 'admin_enqueue_scripts', __CLASS__ . '::enqueue_styles' ); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Performs a safe (local) redirect to the welcome screen |
|
33
|
|
|
* when the plugin is activated |
|
34
|
|
|
* |
|
35
|
|
|
* @return void |
|
36
|
|
|
*/ |
|
37
|
|
|
public static function redirect() { |
|
38
|
|
|
$current_page = FrmAppHelper::simple_get( 'page', 'sanitize_title' ); |
|
39
|
|
|
if ( $current_page === self::$menu_slug ) { |
|
40
|
|
|
// Prevent endless loop. |
|
41
|
|
|
return; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
// Only do this for single site installs. |
|
45
|
|
|
if ( isset( $_GET['activate-multi'] ) || is_network_admin() ) { // WPCS: CSRF ok. |
|
46
|
|
|
return; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
// Check if we should consider redirection. |
|
50
|
|
|
if ( ! self::is_welcome_screen() ) { |
|
51
|
|
|
return; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
set_transient( self::$option_name, 'no', 60 ); |
|
55
|
|
|
|
|
56
|
|
|
// Prevent redirect with every activation. |
|
57
|
|
|
if ( self::already_redirected() ) { |
|
58
|
|
|
return; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
// Initial install. |
|
62
|
|
|
wp_safe_redirect( esc_url( self::settings_link() ) ); |
|
63
|
|
|
exit; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Don't redirect every time the plugin is activated. |
|
68
|
|
|
*/ |
|
69
|
|
|
private static function already_redirected() { |
|
70
|
|
|
$last_redirect = get_option( self::$last_redirect ); |
|
71
|
|
|
if ( $last_redirect ) { |
|
72
|
|
|
return true; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
update_option( self::$last_redirect, FrmAppHelper::plugin_version(), 'no' ); |
|
76
|
|
|
return false; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Add a submenu welcome screen for the formidable parent menu |
|
81
|
|
|
* |
|
82
|
|
|
* @return void |
|
83
|
|
|
*/ |
|
84
|
|
|
public static function screen_page() { |
|
85
|
|
|
add_submenu_page( 'formidable', 'Formidable | ' . __( 'Welcome Screen', 'formidable' ), __( 'Welcome Screen', 'formidable' ), 'read', self::$menu_slug, __CLASS__ . '::screen_content' ); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Include html content for the welcome screem |
|
90
|
|
|
* |
|
91
|
|
|
* @return void |
|
92
|
|
|
*/ |
|
93
|
|
|
public static function screen_content() { |
|
94
|
|
|
FrmAppHelper::include_svg(); |
|
95
|
|
|
include FrmAppHelper::plugin_path() . '/classes/views/welcome/show.php'; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* Remove the welcome screen submenu page from the formidable parent menu |
|
100
|
|
|
* since it is not necessary to show that link there |
|
101
|
|
|
* |
|
102
|
|
|
* @return void |
|
103
|
|
|
*/ |
|
104
|
|
|
public static function remove_menu() { |
|
105
|
|
|
remove_submenu_page( 'formidable', self::$menu_slug ); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* Register the stylesheets for the welcome screen. |
|
110
|
|
|
* |
|
111
|
|
|
* @return void |
|
112
|
|
|
*/ |
|
113
|
|
|
public static function enqueue_styles() { |
|
114
|
|
|
$version = FrmAppHelper::plugin_version(); |
|
115
|
|
|
wp_enqueue_style( 'frm-welcome-screen', FrmAppHelper::plugin_url() . '/css/welcome_screen.css', array( 'formidable-admin' ), $version ); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* Helps to confirm if the user is currently on the welcome screen |
|
120
|
|
|
* |
|
121
|
|
|
* @return bool |
|
122
|
|
|
*/ |
|
123
|
|
|
public static function is_welcome_screen() { |
|
124
|
|
|
$to_redirect = get_transient( self::$option_name ); |
|
125
|
|
|
return $to_redirect === self::$menu_slug; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* Build the admin URL link for the welcome screen |
|
130
|
|
|
* |
|
131
|
|
|
* @return string |
|
132
|
|
|
*/ |
|
133
|
|
|
public static function settings_link() { |
|
134
|
|
|
return admin_url( 'admin.php?page=' . self::$menu_slug ); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
public static function upgrade_to_pro_button() { |
|
138
|
|
View Code Duplication |
if ( ! FrmAppHelper::pro_is_installed() ) { |
|
|
|
|
|
|
139
|
|
|
?> |
|
140
|
|
|
<a href="<?php echo esc_url( FrmAppHelper::admin_upgrade_link( 'settings-license' ) ); ?>" class="button-secondary frm-button-secondary" target="_blank" rel="nofollow noopener"> |
|
141
|
|
|
<?php esc_html_e( 'Upgrade Now', 'formidable' ); ?> |
|
142
|
|
|
</a> |
|
143
|
|
|
<?php |
|
144
|
|
|
} |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
public static function maybe_show_license_box() { |
|
148
|
|
|
if ( ! FrmAppHelper::pro_is_installed() ) { |
|
149
|
|
|
FrmSettingsController::license_box(); |
|
150
|
|
|
} |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
public static function maybe_show_conditional_action_button( $plugin, $upgrade_link_args ) { |
|
154
|
|
|
$is_installed = is_callable( 'FrmProAppHelper::views_is_installed' ) && FrmProAppHelper::views_is_installed(); |
|
155
|
|
|
if ( ! $is_installed ) { |
|
156
|
|
|
FrmAddonsController::conditional_action_button( $plugin, $upgrade_link_args ); |
|
157
|
|
|
} |
|
158
|
|
|
} |
|
159
|
|
|
} |
|
160
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.