PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.5.2
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.5.2
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
formidable / classes / controllers / FrmWelcomeController.php

FrmWelcomeController.php in Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More 6.5.2, at classes/controllers/FrmWelcomeController.php

179 lines 4.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 * @return void
20 */
21 public static function load_hooks() {
22 add_action( 'admin_init', __CLASS__ . '::redirect' );
23
24 if ( ! FrmAppHelper::is_admin_page( self::$menu_slug ) ) {
25 return;
26 }
27
28 add_action( 'admin_menu', __CLASS__ . '::screen_page' );
29 add_action( 'admin_head', __CLASS__ . '::remove_menu' );
30 add_action( 'admin_enqueue_scripts', __CLASS__ . '::enqueue_styles' );
31 }
32
33 /**
34 * Performs a safe (local) redirect to the welcome screen
35 * when the plugin is activated
36 *
37 * @return void
38 */
39 public static function redirect() {
40 $current_page = FrmAppHelper::simple_get( 'page', 'sanitize_title' );
41 if ( $current_page === self::$menu_slug ) {
42 // Prevent endless loop.
43 return;
44 }
45
46 // Only do this for single site installs.
47 if ( isset( $_GET['activate-multi'] ) || is_network_admin() ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
48 return;
49 }
50
51 // Check if we should consider redirection.
52 if ( ! self::is_welcome_screen() ) {
53 return;
54 }
55
56 set_transient( self::$option_name, 'no', 60 );
57
58 // Prevent redirect with every activation.
59 if ( self::already_redirected() ) {
60 return;
61 }
62
63 // Initial install.
64 wp_safe_redirect( esc_url( self::settings_link() ) );
65 exit;
66 }
67
68 /**
69 * Don't redirect every time the plugin is activated.
70 *
71 * @return bool
72 */
73 private static function already_redirected() {
74 $last_redirect = get_option( self::$last_redirect );
75 if ( $last_redirect ) {
76 return true;
77 }
78
79 update_option( self::$last_redirect, FrmAppHelper::plugin_version(), 'no' );
80 return false;
81 }
82
83 /**
84 * Add a submenu welcome screen for the formidable parent menu
85 *
86 * @return void
87 */
88 public static function screen_page() {
89 if ( ! current_user_can( 'activate_plugins' ) ) {
90 return;
91 }
92 add_submenu_page( 'formidable', 'Formidable | ' . __( 'Welcome Screen', 'formidable' ), __( 'Welcome Screen', 'formidable' ), 'read', self::$menu_slug, __CLASS__ . '::screen_content' );
93 }
94
95 /**
96 * Include html content for the welcome screem
97 *
98 * @return void
99 */
100 public static function screen_content() {
101 FrmAppHelper::include_svg();
102 include FrmAppHelper::plugin_path() . '/classes/views/welcome/show.php';
103 }
104
105 /**
106 * Remove the welcome screen submenu page from the formidable parent menu
107 * since it is not necessary to show that link there
108 *
109 * @return void
110 */
111 public static function remove_menu() {
112 remove_submenu_page( 'formidable', self::$menu_slug );
113 }
114
115 /**
116 * Register the stylesheets for the welcome screen.
117 *
118 * @return void
119 */
120 public static function enqueue_styles() {
121 $version = FrmAppHelper::plugin_version();
122 wp_enqueue_style( 'frm-welcome-screen', FrmAppHelper::plugin_url() . '/css/welcome_screen.css', array( 'formidable-admin' ), $version );
123 }
124
125 /**
126 * Helps to confirm if the user is currently on the welcome screen
127 *
128 * @return bool
129 */
130 public static function is_welcome_screen() {
131 $to_redirect = get_transient( self::$option_name );
132 return $to_redirect === self::$menu_slug;
133 }
134
135 /**
136 * Build the admin URL link for the welcome screen
137 *
138 * @return string
139 */
140 public static function settings_link() {
141 return admin_url( 'admin.php?page=' . self::$menu_slug );
142 }
143
144 /**
145 * @return void
146 */
147 public static function upgrade_to_pro_button() {
148 if ( ! FrmAppHelper::pro_is_installed() ) {
149 ?>
150 <a href="<?php echo esc_url( FrmAppHelper::admin_upgrade_link( 'welcome' ) ); ?>" class="button-secondary frm-button-secondary frm-button-sm" target="_blank" rel="nofollow noopener">
151 <?php esc_html_e( 'Upgrade Now', 'formidable' ); ?>
152 </a>
153 <?php
154 }
155 }
156
157 /**
158 * @return void
159 */
160 public static function maybe_show_license_box() {
161 if ( ! FrmAppHelper::pro_is_installed() ) {
162 FrmSettingsController::license_box();
163 }
164 }
165
166 /**
167 * @param string $plugin
168 * @param string $upgrade_link_args
169 *
170 * @return void
171 */
172 public static function maybe_show_conditional_action_button( $plugin, $upgrade_link_args ) {
173 $is_installed = is_callable( 'FrmProAppHelper::views_is_installed' ) && FrmProAppHelper::views_is_installed();
174 if ( ! $is_installed ) {
175 FrmAddonsController::conditional_action_button( $plugin, $upgrade_link_args );
176 }
177 }
178 }
179