| @@ -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' ), |
| @@ -200,8 +210,107 @@ | ||
| 200 | 210 | return $sections; |
| 201 | 211 | } |
| 202 | 212 | |
| 203 | 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 | + ); | |
| 310 | + } | |
| 311 | + | |
| 312 | + /** | |
| 204 | 313 | * Remove the payments sections (PayPal, Square, Stripe, Authorize.Net) |
| 205 | 314 | * and show them all on the payments section in separate tabs. |
| 206 | 315 | * |
| 207 | 316 | * @since 6.22.1 |
| @@ -213,12 +322,14 @@ | ||
| 213 | 322 | private static function remove_payments_sections( &$sections ) { |
| 214 | 323 | $payment_section_keys = array( 'paypal', 'square', 'stripe', 'authorize_net' ); |
| 215 | 324 | |
| 216 | 325 | foreach ( $sections as $key => $section ) { |
| 217 | - if ( in_array( $key, $payment_section_keys, true ) ) { | |
| 218 | - self::$removed_payments_sections[ $key ] = $section; | |
| 219 | - unset( $sections[ $key ] ); | |
| 326 | + if ( ! in_array( $key, $payment_section_keys, true ) ) { | |
| 327 | + continue; | |
| 220 | 328 | } |
| 329 | + | |
| 330 | + self::$removed_payments_sections[ $key ] = $section; | |
| 331 | + unset( $sections[ $key ] ); | |
| 221 | 332 | } |
| 222 | 333 | |
| 223 | 334 | uksort( self::$removed_payments_sections, array( self::class, 'payment_sections_sort_callback' ) ); |
| 224 | 335 | } |
| @@ -260,9 +371,9 @@ | ||
| 260 | 371 | |
| 261 | 372 | if ( isset( $section['class'] ) ) { |
| 262 | 373 | call_user_func( array( $section['class'], $section['function'] ) ); |
| 263 | 374 | } else { |
| 264 | - call_user_func( ( $section['function'] ?? $section ) ); | |
| 375 | + call_user_func( $section['function'] ?? $section ); | |
| 265 | 376 | } |
| 266 | 377 | |
| 267 | 378 | wp_die(); |
| 268 | 379 | } |
| @@ -470,9 +581,9 @@ | ||
| 470 | 581 | public static function settings_cta_dismiss() { |
| 471 | 582 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
| 472 | 583 | FrmAppHelper::permission_check( 'frm_change_settings' ); |
| 473 | 584 | |
| 474 | - update_option( 'frm_lite_settings_upgrade', time(), 'no' ); | |
| 585 | + update_option( 'frm_lite_settings_upgrade', time(), false ); | |
| 475 | 586 | |
| 476 | 587 | wp_send_json_success(); |
| 477 | 588 | } |
| 478 | 589 | |