PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.2.1
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.2.1
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.2.1, at classes/controllers/FrmWelcomeController.php

176 lines 4.4 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 add_submenu_page( 'formidable', 'Formidable | ' . __( 'Welcome Screen', 'formidable' ), __( 'Welcome Screen', 'formidable' ), 'read', self::$menu_slug, __CLASS__ . '::screen_content' );
90 }
91
92 /**
93 * Include html content for the welcome screem
94 *
95 * @return void
96 */
97 public static function screen_content() {
98 FrmAppHelper::include_svg();
99 include FrmAppHelper::plugin_path() . '/classes/views/welcome/show.php';
100 }
101
102 /**
103 * Remove the welcome screen submenu page from the formidable parent menu
104 * since it is not necessary to show that link there
105 *
106 * @return void
107 */
108 public static function remove_menu() {
109 remove_submenu_page( 'formidable', self::$menu_slug );
110 }
111
112 /**
113 * Register the stylesheets for the welcome screen.
114 *
115 * @return void
116 */
117 public static function enqueue_styles() {
118 $version = FrmAppHelper::plugin_version();
119 wp_enqueue_style( 'frm-welcome-screen', FrmAppHelper::plugin_url() . '/css/welcome_screen.css', array( 'formidable-admin' ), $version );
120 }
121
122 /**
123 * Helps to confirm if the user is currently on the welcome screen
124 *
125 * @return bool
126 */
127 public static function is_welcome_screen() {
128 $to_redirect = get_transient( self::$option_name );
129 return $to_redirect === self::$menu_slug;
130 }
131
132 /**
133 * Build the admin URL link for the welcome screen
134 *
135 * @return string
136 */
137 public static function settings_link() {
138 return admin_url( 'admin.php?page=' . self::$menu_slug );
139 }
140
141 /**
142 * @return void
143 */
144 public static function upgrade_to_pro_button() {
145 if ( ! FrmAppHelper::pro_is_installed() ) {
146 ?>
147 <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">
148 <?php esc_html_e( 'Upgrade Now', 'formidable' ); ?>
149 </a>
150 <?php
151 }
152 }
153
154 /**
155 * @return void
156 */
157 public static function maybe_show_license_box() {
158 if ( ! FrmAppHelper::pro_is_installed() ) {
159 FrmSettingsController::license_box();
160 }
161 }
162
163 /**
164 * @param string $plugin
165 * @param string $upgrade_link_args
166 *
167 * @return void
168 */
169 public static function maybe_show_conditional_action_button( $plugin, $upgrade_link_args ) {
170 $is_installed = is_callable( 'FrmProAppHelper::views_is_installed' ) && FrmProAppHelper::views_is_installed();
171 if ( ! $is_installed ) {
172 FrmAddonsController::conditional_action_button( $plugin, $upgrade_link_args );
173 }
174 }
175 }
176