PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / trunk
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More vtrunk
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/FrmSettingsController.php +109 -0 6.29 → trunk View file →
@@ -5,8 +5,17 @@
5 5
6 6 class FrmSettingsController {
7 7
8 8 /**
9 + * Icon for the API section, used whether the add-on is active or only a placeholder.
10 + *
11 + * @since 6.35
12 + *
13 + * @var string
14 + */
15 + private static $api_section_icon = 'frmfont frm_cloud_icon';
16 +
17 + /**
9 18 * Payments sections are removed from the top level and added to a payments section.
10 19 *
11 20 * @since 6.22.1
12 21 *
@@ -163,8 +172,9 @@
163 172 /**
164 173 * @param array<array> $sections
165 174 */
166 175 $sections = apply_filters( 'frm_add_settings_section', $sections );
176 + self::add_inactive_addon_sections( $sections );
167 177 self::remove_payments_sections( $sections );
168 178
169 179 $sections['misc'] = array(
170 180 'name' => __( 'Miscellaneous', 'formidable' ),
@@ -197,8 +207,107 @@
197 207 $sections[ $key ] = $section;
198 208 }//end foreach
199 209
200 210 return $sections;
211 + }
212 +
213 + /**
214 + * Add a placeholder section for each add-on that owns a Global Settings
215 + * section but is not active.
216 + *
217 + * A placeholder reads as disabled and opens a page offering to activate the
218 + * add-on or to upgrade, depending on what the license allows. It goes at the
219 + * head of the add-on sections, right after Inbox, so it sits with the rest of
220 + * the add-on settings instead of trailing them. A section already claimed by
221 + * an active plugin is left alone, so nothing stands in for a section that is
222 + * really there.
223 + *
224 + * @since 6.35
225 + *
226 + * @param array<array> $sections Sections registered for the Global Settings page so far.
227 + *
228 + * @return void
229 + */
230 + private static function add_inactive_addon_sections( &$sections ) {
231 + if ( isset( $sections['api'] ) ) {
232 + // The add-on is active, so it owns the section. Only the icon is taken over,
233 + // so the tab looks the same whether or not the add-on is installed.
234 + $sections['api']['icon'] = self::$api_section_icon;
235 + return;
236 + }
237 +
238 + self::insert_section_after( $sections, 'inbox', 'api', self::get_api_placeholder_section() );
239 + }
240 +
241 + /**
242 + * Insert a section directly after another one, leaving the rest of the order alone.
243 + *
244 + * Assigning a new key lands the section at the end of the array, so the array
245 + * is rebuilt to put it where it belongs.
246 + *
247 + * @since 6.35
248 + *
249 + * @param array<array> $sections Sections registered for the Global Settings page so far.
250 + * @param string $after Key of the section the new one follows. The new section goes last when this key is not there.
251 + * @param string $key Key for the new section.
252 + * @param array $section The section to insert.
253 + *
254 + * @return void
255 + */
256 + private static function insert_section_after( &$sections, $after, $key, $section ) {
257 + if ( ! isset( $sections[ $after ] ) ) {
258 + $sections[ $key ] = $section;
259 + return;
260 + }
261 +
262 + $ordered = array();
263 +
264 + foreach ( $sections as $section_key => $existing_section ) {
265 + $ordered[ $section_key ] = $existing_section;
266 +
267 + if ( $section_key === $after ) {
268 + $ordered[ $key ] = $section;
269 + }
270 + }
271 +
272 + $sections = $ordered;
273 + }
274 +
275 + /**
276 + * Get the placeholder that stands in for the API add-on's section.
277 + *
278 + * The upgrade data decides which call to action the page shows. When the
279 + * license covers the add-on, it carries the one click install or activate
280 + * link. Otherwise it carries the plan the add-on needs, and the page asks
281 + * the user to upgrade to it, on a gradient button that sets the upgrade
282 + * apart from a one click install.
283 + *
284 + * @since 6.35
285 + *
286 + * @return array
287 + */
288 + private static function get_api_placeholder_section() {
289 + $data = FrmAppHelper::get_upgrade_data_params(
290 + 'api',
291 + array(
292 + 'medium' => 'api-settings',
293 + 'upgrade' => __( 'API settings', 'formidable' ),
294 + 'message' => __( 'Send entries to any site with a REST API, and let AI assistants build your forms. Upgrade to get the API add-on.', 'formidable' ),
295 + 'learn-more' => FrmAppHelper::get_doc_url( 'formidable-api', 'api-global-settings' ),
296 + 'upsell-images' => 'api-settings-1.png,api-settings-2.png,api-settings-3.png',
297 + )
298 + );
299 +
300 + if ( ! FrmAppHelper::pro_is_installed() ) {
301 + $data['gradient-upgrade'] = 1;
302 + }
303 +
304 + return array(
305 + 'name' => __( 'API', 'formidable' ),
306 + 'icon' => self::$api_section_icon,
307 + 'html_class' => 'frm_show_upgrade_tab frm_noallow',
308 + 'data' => $data,
309 + );
201 310 }
202 311
203 312 /**
204 313 * Remove the payments sections (PayPal, Square, Stripe, Authorize.Net)