PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.3
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.3
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
← All changes | classes/controllers/FrmApplicationsController.php +17 -96 6.295.3 View file →
@@ -13,44 +13,14 @@
13 13 *
14 14 * @return void
15 15 */
16 16 public static function menu() {
17 - $label = __( 'Applications', 'formidable' );
18 - $cap = self::get_required_capability();
19 -
20 - if ( ! current_user_can( $cap ) && is_callable( 'FrmProApplicationsHelper::get_custom_applications_capability' ) ) {
21 - $custom_applications_cap = FrmProApplicationsHelper::get_custom_applications_capability();
22 -
23 - if ( current_user_can( $custom_applications_cap ) ) {
24 - $cap = $custom_applications_cap;
25 - $slug = 'edit-tags.php?taxonomy=frm_application';
26 - $callback = '';
27 - }
28 - }
29 -
30 - if ( ! isset( $slug ) ) {
31 - $slug = 'formidable-applications';
32 - $callback = array( self::class, 'landing_page' );
33 - }
34 -
35 - add_submenu_page( 'formidable', 'Formidable | ' . $label, $label, $cap, $slug, $callback );
17 + $label = __( 'Applications', 'formidable' );
18 + $new_pill = '<span class="frm-new-pill">NEW</span>';
19 + add_submenu_page( 'formidable', 'Formidable | ' . $label, $label . $new_pill, 'frm_edit_forms', 'formidable-applications', array( __CLASS__, 'landing_page' ) );
36 20 }
37 21
38 22 /**
39 - * Get the required capability for accessing the Applications dashboard.
40 - *
41 - * @since 5.3.1
42 - *
43 - * @return string
44 - */
45 - private static function get_required_capability() {
46 - if ( is_callable( 'FrmProApplicationsHelper::get_required_templates_capability' ) ) {
47 - return FrmProApplicationsHelper::get_required_templates_capability();
48 - }
49 - return 'frm_edit_forms';
50 - }
51 -
52 - /**
53 23 * Render Applications index page.
54 24 *
55 25 * @return void
56 26 */
@@ -72,20 +42,14 @@
72 42 *
73 43 * @return void
74 44 */
75 45 public static function get_applications_data() {
76 - FrmAppHelper::permission_check( 'frm_view_forms' );
77 - check_ajax_referer( 'frm_ajax', 'nonce' );
46 + FrmAppHelper::permission_check( 'frm_edit_forms' );
78 47
79 48 $view = FrmAppHelper::get_param( 'view', '', 'get', 'sanitize_text_field' );
80 49 $data = array();
81 -
82 - if ( 'applications' === $view ) {
83 - FrmAppHelper::permission_check( 'frm_edit_applications' );
84 - } else {
85 - FrmAppHelper::permission_check( self::get_required_capability() );
86 -
87 - // View may be 'applications', 'templates', or empty.
50 + if ( 'applications' !== $view ) {
51 + // view may be 'applications', 'templates', or empty.
88 52 $data['templates'] = self::get_prepared_template_data();
89 53 $data['categories'] = FrmApplicationTemplate::get_categories();
90 54 }
91 55
@@ -102,54 +66,26 @@
102 66 *
103 67 * @return array<array>
104 68 */
105 69 private static function get_prepared_template_data() {
106 - $api = new FrmApplicationApi();
107 - $applications = $api->get_api_info();
108 - $applications = array_filter( $applications, 'is_array' );
109 - $unlocked_templates = array();
110 - $locked_templates = array();
70 + $api = new FrmApplicationApi();
71 + $applications = $api->get_api_info();
72 + $applications = array_filter( $applications, 'is_array' );
73 + $applications = self::sort_templates( $applications );
111 74
112 - foreach ( $applications as $key => $application ) {
113 - if ( ! is_numeric( $key ) ) {
114 - // Skip "error" or any other non-numeric key.
115 - continue;
116 - }
117 -
118 - if ( ! empty( $application['url'] ) ) {
119 - $unlocked_templates[] = $application;
120 - } else {
121 - $locked_templates[] = $application;
122 - }
123 - }
124 -
125 - $unlocked_templates = self::sort_templates( $unlocked_templates );
126 - $applications = $unlocked_templates;
127 -
128 - if ( current_user_can( 'administrator' ) || current_user_can( 'frm_change_settings' ) ) {
129 - $locked_templates = self::sort_templates( $locked_templates );
130 - $applications = array_merge( $applications, $locked_templates );
131 - }
132 -
133 75 FrmApplicationTemplate::init();
134 76
135 - return array_reduce( $applications, array( self::class, 'reduce_template' ), array() );
77 + return array_reduce( $applications, array( __CLASS__, 'reduce_template' ), array() );
136 78 }
137 79
138 80 /**
139 81 * @param array $total the accumulated array of reduced application data.
140 82 * @param array $current data for the current template from the API.
141 - *
142 83 * @return array<array>
143 84 */
144 85 private static function reduce_template( $total, $current ) {
145 - $template = new FrmApplicationTemplate( $current );
146 - $js_object = $template->as_js_object();
147 -
148 - if ( $js_object ) {
149 - $total[] = $js_object;
150 - }
151 -
86 + $template = new FrmApplicationTemplate( $current );
87 + $total[] = $template->as_js_object();
152 88 return $total;
153 89 }
154 90
155 91 /**
@@ -155,15 +91,14 @@
155 91 /**
156 92 * Sort applications alphabetically.
157 93 *
158 94 * @param array<array> $applications
159 - *
160 95 * @return array<array>
161 96 */
162 97 private static function sort_templates( $applications ) {
163 98 usort(
164 99 $applications,
165 - function ( $a, $b ) {
100 + function( $a, $b ) {
166 101 return strcmp( $a['name'], $b['name'] );
167 102 }
168 103 );
169 104 return $applications;
@@ -169,21 +104,10 @@
169 104 return $applications;
170 105 }
171 106
172 107 /**
173 - * @usedby FrmAppController::admin_init().
174 - *
175 - * @since 6.8
176 - *
177 108 * @return void
178 109 */
179 - public static function load_page() {
180 - self::load_assets();
181 - }
182 -
183 - /**
184 - * @return void
185 - */
186 110 public static function load_assets() {
187 111 $plugin_url = FrmAppHelper::plugin_url();
188 112 $version = FrmAppHelper::plugin_version();
189 113
@@ -191,10 +115,8 @@
191 115 wp_enqueue_style( 'formidable-grids' );
192 116
193 117 $js_dependencies = array(
194 118 'wp-i18n',
195 - // This prevents a console error "wp.hooks is undefined" in WP versions older than 5.7.
196 - 'wp-hooks',
197 119 'formidable_dom',
198 120 );
199 121 wp_register_script( 'formidable_applications', $plugin_url . '/js/admin/applications.js', $js_dependencies, $version, true );
200 122 wp_register_style( 'formidable_applications', $plugin_url . '/css/admin/applications.css', array(), $version );
@@ -204,9 +126,8 @@
204 126 );
205 127 wp_localize_script( 'formidable_applications', 'frmApplicationsVars', $js_vars );
206 128
207 129 wp_enqueue_script( 'formidable_applications' );
208 - wp_set_script_translations( 'formidable_applications', 'formidable' );
209 130 wp_enqueue_style( 'formidable_applications' );
210 131
211 132 do_action( 'frm_applications_assets' );
212 133 }
@@ -215,9 +136,11 @@
215 136 * @return void
216 137 */
217 138 public static function dequeue_scripts() {
218 139 if ( 'formidable-applications' === FrmAppHelper::simple_get( 'page', 'sanitize_title' ) ) {
219 - FrmAppHelper::dequeue_extra_global_scripts();
140 + // Avoid extra scripts loading on applications index that aren't needed.
141 + wp_dequeue_script( 'frm-surveys-admin' );
142 + wp_dequeue_script( 'frm-quizzes-form-action' );
220 143 }
221 144 }
222 145
223 146 /**
@@ -222,12 +145,10 @@
222 145
223 146 /**
224 147 * @param string $title
225 148 * @param string $context values include 'index', 'list', and 'edit'.
226 - *
227 149 * @return void
228 150 */
229 151 public static function render_applications_header( $title, $context ) {
230 - FrmAppHelper::print_admin_banner( true );
231 152 require self::get_view_path() . 'header.php';
232 153 }
233 154 }