| @@ -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 | * |
| @@ -20,9 +29,9 @@ | ||
| 20 | 29 | public static function menu() { |
| 21 | 30 | // Make sure admins can see the menu items |
| 22 | 31 | FrmAppHelper::force_capability( 'frm_change_settings' ); |
| 23 | 32 | |
| 24 | - add_submenu_page( 'formidable', 'Formidable | ' . __( 'Global Settings', 'formidable' ), __( 'Global Settings', 'formidable' ), 'frm_change_settings', 'formidable-settings', 'FrmSettingsController::route' ); | |
| 33 | + add_submenu_page( 'formidable', 'Formidable | ' . __( 'Global Settings', 'formidable' ), __( 'Global Settings', 'formidable' ), 'frm_change_settings', 'formidable-settings', 'FrmSettingsController::route' ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong | |
| 25 | 34 | } |
| 26 | 35 | |
| 27 | 36 | /** |
| 28 | 37 | * Include license box template on demand. |
| @@ -45,15 +54,13 @@ | ||
| 45 | 54 | public static function display_form( $errors = array(), $message = '' ) { |
| 46 | 55 | global $frm_vars; |
| 47 | 56 | |
| 48 | 57 | $frm_settings = FrmAppHelper::get_settings(); |
| 58 | + $uploads = wp_upload_dir(); | |
| 59 | + $target_path = $uploads['basedir'] . '/formidable/css'; | |
| 60 | + $sections = self::get_settings_tabs(); | |
| 61 | + $current = FrmAppHelper::simple_get( 't', 'sanitize_title', 'general_settings' ); | |
| 49 | 62 | |
| 50 | - $uploads = wp_upload_dir(); | |
| 51 | - $target_path = $uploads['basedir'] . '/formidable/css'; | |
| 52 | - | |
| 53 | - $sections = self::get_settings_tabs(); | |
| 54 | - $current = FrmAppHelper::simple_get( 't', 'sanitize_title', 'general_settings' ); | |
| 55 | - | |
| 56 | 63 | if ( in_array( $current, array( 'stripe_settings', 'square_settings', 'authorize_net_settings', 'paypal_settings' ), true ) ) { |
| 57 | 64 | $current = 'payments_settings'; |
| 58 | 65 | } |
| 59 | 66 | |
| @@ -70,25 +77,25 @@ | ||
| 70 | 77 | 'general' => array( |
| 71 | 78 | 'class' => self::class, |
| 72 | 79 | 'function' => 'general_settings', |
| 73 | 80 | 'name' => __( 'General Settings', 'formidable' ), |
| 74 | - 'icon' => 'frm_icon_font frm_settings_icon', | |
| 81 | + 'icon' => 'frmfont frm_settings_icon', | |
| 75 | 82 | ), |
| 76 | 83 | 'messages' => array( |
| 77 | 84 | 'class' => self::class, |
| 78 | 85 | 'function' => 'message_settings', |
| 79 | 86 | 'name' => __( 'Message Defaults', 'formidable' ), |
| 80 | - 'icon' => 'frm_icon_font frm_stamp_icon', | |
| 87 | + 'icon' => 'frmfont frm_stamp_icon', | |
| 81 | 88 | ), |
| 82 | 89 | 'permissions' => array( |
| 83 | 90 | 'class' => self::class, |
| 84 | 91 | 'function' => 'permission_settings', |
| 85 | 92 | 'name' => __( 'Permissions', 'formidable' ), |
| 86 | - 'icon' => 'frm_icon_font frm_lock_icon', | |
| 93 | + 'icon' => 'frmfont frm_lock_icon', | |
| 87 | 94 | ), |
| 88 | 95 | 'payments' => array( |
| 89 | 96 | 'name' => __( 'Payments', 'formidable' ), |
| 90 | - 'icon' => 'frm_icon_font frm_simple_cc_icon', | |
| 97 | + 'icon' => 'frmfont frm_simple_cc_icon', | |
| 91 | 98 | 'class' => self::class, |
| 92 | 99 | 'function' => 'payments_settings', |
| 93 | 100 | ), |
| 94 | 101 | 'custom_css' => array( |
| @@ -94,31 +101,31 @@ | ||
| 94 | 101 | 'custom_css' => array( |
| 95 | 102 | 'class' => 'FrmStylesController', |
| 96 | 103 | 'function' => 'custom_css', |
| 97 | 104 | 'name' => __( 'Custom CSS', 'formidable' ), |
| 98 | - 'icon' => 'frm_icon_font frm_code_icon', | |
| 105 | + 'icon' => 'frmfont frm_code_icon', | |
| 99 | 106 | ), |
| 100 | 107 | 'manage_styles' => array( |
| 101 | 108 | 'class' => 'FrmStylesController', |
| 102 | 109 | 'function' => 'manage', |
| 103 | 110 | 'name' => __( 'Manage Styles', 'formidable' ), |
| 104 | - 'icon' => 'frm_icon_font frm_pallet_icon', | |
| 111 | + 'icon' => 'frmfont frm_pallet_icon', | |
| 105 | 112 | ), |
| 106 | 113 | 'captcha' => array( |
| 107 | 114 | 'class' => self::class, |
| 108 | 115 | 'function' => 'captcha_settings', |
| 109 | 116 | 'name' => __( 'Captcha/Spam', 'formidable' ), |
| 110 | - 'icon' => 'frm_icon_font frm_shield_check_icon', | |
| 117 | + 'icon' => 'frmfont frm_shield_check_icon', | |
| 111 | 118 | ), |
| 112 | 119 | 'email' => array( |
| 113 | 120 | 'class' => self::class, |
| 114 | 121 | 'function' => 'email_settings', |
| 115 | 122 | 'name' => __( 'Email', 'formidable' ), |
| 116 | - 'icon' => 'frm_icon_font frm_email_icon', | |
| 123 | + 'icon' => 'frmfont frm_email_icon', | |
| 117 | 124 | ), |
| 118 | 125 | 'white_label' => array( |
| 119 | 126 | 'name' => __( 'White Labeling', 'formidable' ), |
| 120 | - 'icon' => 'frm_icon_font frm_ghost_icon', | |
| 127 | + 'icon' => 'frmfont frm_ghost_icon', | |
| 121 | 128 | 'html_class' => 'frm_show_upgrade_tab frm_noallow', |
| 122 | 129 | 'data' => array( |
| 123 | 130 | 'medium' => 'white-label', |
| 124 | 131 | 'upgrade' => __( 'White labeling options', 'formidable' ), |
| @@ -127,9 +134,9 @@ | ||
| 127 | 134 | ), |
| 128 | 135 | ), |
| 129 | 136 | 'inbox' => array( |
| 130 | 137 | 'name' => __( 'Inbox', 'formidable' ), |
| 131 | - 'icon' => 'frm_icon_font frm_email_icon', | |
| 138 | + 'icon' => 'frmfont frm_email_icon', | |
| 132 | 139 | 'html_class' => 'frm_show_upgrade_tab frm_noallow', |
| 133 | 140 | 'data' => array( |
| 134 | 141 | 'medium' => 'inbox-settings', |
| 135 | 142 | 'upgrade' => __( 'Inbox settings', 'formidable' ), |
| @@ -144,9 +151,9 @@ | ||
| 144 | 151 | $show_licenses = false; |
| 145 | 152 | $installed_addons = apply_filters( 'frm_installed_addons', array() ); |
| 146 | 153 | |
| 147 | 154 | foreach ( $installed_addons as $installed_addon ) { |
| 148 | - if ( ! $installed_addon->is_parent_licence && $installed_addon->plugin_name != 'Formidable Pro' && $installed_addon->needs_license ) { | |
| 155 | + if ( ! $installed_addon->is_parent_licence && $installed_addon->plugin_name !== 'Formidable Pro' && $installed_addon->needs_license ) { | |
| 149 | 156 | $show_licenses = true; |
| 150 | 157 | break; |
| 151 | 158 | } |
| 152 | 159 | } |
| @@ -165,13 +172,14 @@ | ||
| 165 | 172 | /** |
| 166 | 173 | * @param array<array> $sections |
| 167 | 174 | */ |
| 168 | 175 | $sections = apply_filters( 'frm_add_settings_section', $sections ); |
| 176 | + self::add_inactive_addon_sections( $sections ); | |
| 169 | 177 | self::remove_payments_sections( $sections ); |
| 170 | 178 | |
| 171 | 179 | $sections['misc'] = array( |
| 172 | 180 | 'name' => __( 'Miscellaneous', 'formidable' ), |
| 173 | - 'icon' => 'frm_icon_font frm_shuffle_icon', | |
| 181 | + 'icon' => 'frmfont frm_shuffle_icon', | |
| 174 | 182 | 'class' => self::class, |
| 175 | 183 | 'function' => 'misc_settings', |
| 176 | 184 | ); |
| 177 | 185 | |
| @@ -179,9 +187,9 @@ | ||
| 179 | 187 | $original = $section; |
| 180 | 188 | $defaults = array( |
| 181 | 189 | 'html_class' => '', |
| 182 | 190 | 'name' => ucfirst( $key ), |
| 183 | - 'icon' => 'frm_icon_font frm_settings_icon', | |
| 191 | + 'icon' => 'frmfont frm_settings_icon', | |
| 184 | 192 | 'anchor' => $key . '_settings', |
| 185 | 193 | 'data' => array(), |
| 186 | 194 | ); |
| 187 | 195 | |
| @@ -202,8 +210,107 @@ | ||
| 202 | 210 | return $sections; |
| 203 | 211 | } |
| 204 | 212 | |
| 205 | 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 | + /** | |
| 206 | 313 | * Remove the payments sections (PayPal, Square, Stripe, Authorize.Net) |
| 207 | 314 | * and show them all on the payments section in separate tabs. |
| 208 | 315 | * |
| 209 | 316 | * @since 6.22.1 |
| @@ -215,12 +322,14 @@ | ||
| 215 | 322 | private static function remove_payments_sections( &$sections ) { |
| 216 | 323 | $payment_section_keys = array( 'paypal', 'square', 'stripe', 'authorize_net' ); |
| 217 | 324 | |
| 218 | 325 | foreach ( $sections as $key => $section ) { |
| 219 | - if ( in_array( $key, $payment_section_keys, true ) ) { | |
| 220 | - self::$removed_payments_sections[ $key ] = $section; | |
| 221 | - unset( $sections[ $key ] ); | |
| 326 | + if ( ! in_array( $key, $payment_section_keys, true ) ) { | |
| 327 | + continue; | |
| 222 | 328 | } |
| 329 | + | |
| 330 | + self::$removed_payments_sections[ $key ] = $section; | |
| 331 | + unset( $sections[ $key ] ); | |
| 223 | 332 | } |
| 224 | 333 | |
| 225 | 334 | uksort( self::$removed_payments_sections, array( self::class, 'payment_sections_sort_callback' ) ); |
| 226 | 335 | } |
| @@ -236,14 +345,15 @@ | ||
| 236 | 345 | * @return int |
| 237 | 346 | */ |
| 238 | 347 | private static function payment_sections_sort_callback( $a, $b ) { |
| 239 | 348 | $order = array( 'stripe', 'square', 'paypal', 'authorize_net' ); |
| 240 | - $first_key = array_search( $a, $order ); | |
| 241 | - $second_key = array_search( $b, $order ); | |
| 349 | + $first_key = array_search( $a, $order, true ); | |
| 350 | + $second_key = array_search( $b, $order, true ); | |
| 242 | 351 | |
| 243 | 352 | if ( false === $first_key || false === $second_key ) { |
| 244 | 353 | return 0; |
| 245 | 354 | } |
| 355 | + | |
| 246 | 356 | return $first_key - $second_key; |
| 247 | 357 | } |
| 248 | 358 | |
| 249 | 359 | public static function load_settings_tab() { |
| @@ -261,10 +371,11 @@ | ||
| 261 | 371 | |
| 262 | 372 | if ( isset( $section['class'] ) ) { |
| 263 | 373 | call_user_func( array( $section['class'], $section['function'] ) ); |
| 264 | 374 | } else { |
| 265 | - call_user_func( ( $section['function'] ?? $section ) ); | |
| 375 | + call_user_func( $section['function'] ?? $section ); | |
| 266 | 376 | } |
| 377 | + | |
| 267 | 378 | wp_die(); |
| 268 | 379 | } |
| 269 | 380 | |
| 270 | 381 | /** |
| @@ -285,13 +396,12 @@ | ||
| 285 | 396 | /** |
| 286 | 397 | * Render the global currency selector if Pro is up to date. |
| 287 | 398 | * |
| 288 | 399 | * @param FrmSettings $frm_settings |
| 289 | - * @param string $more_html | |
| 290 | 400 | * |
| 291 | 401 | * @return void |
| 292 | 402 | */ |
| 293 | - public static function maybe_render_currency_selector( $frm_settings, $more_html ) { | |
| 403 | + public static function maybe_render_currency_selector( $frm_settings ) { | |
| 294 | 404 | if ( is_callable( 'FrmProSettingsController::add_currency_settings' ) ) { |
| 295 | 405 | FrmProSettingsController::add_currency_settings(); |
| 296 | 406 | return; |
| 297 | 407 | } |
| @@ -306,9 +416,8 @@ | ||
| 306 | 416 | * @return void |
| 307 | 417 | */ |
| 308 | 418 | public static function message_settings() { |
| 309 | 419 | $frm_settings = FrmAppHelper::get_settings(); |
| 310 | - | |
| 311 | 420 | include FrmAppHelper::plugin_path() . '/classes/views/frm-settings/messages.php'; |
| 312 | 421 | } |
| 313 | 422 | |
| 314 | 423 | /** |
| @@ -331,9 +440,8 @@ | ||
| 331 | 440 | * @return void |
| 332 | 441 | */ |
| 333 | 442 | public static function email_settings() { |
| 334 | 443 | $frm_settings = FrmAppHelper::get_settings(); |
| 335 | - | |
| 336 | 444 | include FrmAppHelper::plugin_path() . '/classes/views/frm-settings/email/email-styles.php'; |
| 337 | 445 | } |
| 338 | 446 | |
| 339 | 447 | /** |
| @@ -352,11 +460,10 @@ | ||
| 352 | 460 | * @return void |
| 353 | 461 | */ |
| 354 | 462 | public static function payments_settings() { |
| 355 | 463 | $payment_sections = self::$removed_payments_sections; |
| 464 | + $tab = FrmAppHelper::simple_get( 't', 'sanitize_title', 'general_settings' ); | |
| 356 | 465 | |
| 357 | - $tab = FrmAppHelper::simple_get( 't', 'sanitize_title', 'general_settings' ); | |
| 358 | - | |
| 359 | 466 | if ( $tab && in_array( $tab, array( 'stripe_settings', 'square_settings', 'authorize_net_settings', 'paypal_settings' ), true ) ) { |
| 360 | 467 | $tab = str_replace( '_settings', '', $tab ); |
| 361 | 468 | } else { |
| 362 | 469 | $tab = 'stripe'; |
| @@ -371,9 +478,8 @@ | ||
| 371 | 478 | * @return void |
| 372 | 479 | */ |
| 373 | 480 | public static function misc_settings() { |
| 374 | 481 | $frm_settings = FrmAppHelper::get_settings(); |
| 375 | - | |
| 376 | 482 | include FrmAppHelper::plugin_path() . '/classes/views/frm-settings/misc.php'; |
| 377 | 483 | } |
| 378 | 484 | |
| 379 | 485 | /** |
| @@ -446,9 +552,9 @@ | ||
| 446 | 552 | FrmAppHelper::include_svg(); |
| 447 | 553 | |
| 448 | 554 | if ( $action === 'process-form' ) { |
| 449 | 555 | self::process_form( $stop_load ); |
| 450 | - } elseif ( $stop_load != 'stop_load' ) { | |
| 556 | + } elseif ( $stop_load !== 'stop_load' ) { | |
| 451 | 557 | self::display_form(); |
| 452 | 558 | } |
| 453 | 559 | } |
| 454 | 560 | |
| @@ -475,9 +581,9 @@ | ||
| 475 | 581 | public static function settings_cta_dismiss() { |
| 476 | 582 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
| 477 | 583 | FrmAppHelper::permission_check( 'frm_change_settings' ); |
| 478 | 584 | |
| 479 | - update_option( 'frm_lite_settings_upgrade', time(), 'no' ); | |
| 585 | + update_option( 'frm_lite_settings_upgrade', time(), false ); | |
| 480 | 586 | |
| 481 | 587 | wp_send_json_success(); |
| 482 | 588 | } |
| 483 | 589 | |
| @@ -505,10 +611,9 @@ | ||
| 505 | 611 | 'limit' => 25, |
| 506 | 612 | 'order_by' => 'post_title', |
| 507 | 613 | ); |
| 508 | 614 | |
| 509 | - $pages = FrmDb::get_results( $wpdb->posts, $where, 'ID, post_title', $atts ); | |
| 510 | - | |
| 615 | + $pages = FrmDb::get_results( $wpdb->posts, $where, 'ID, post_title', $atts ); | |
| 511 | 616 | $results = array(); |
| 512 | 617 | |
| 513 | 618 | foreach ( $pages as $page ) { |
| 514 | 619 | $results[] = array( |
| @@ -531,9 +636,9 @@ | ||
| 531 | 636 | */ |
| 532 | 637 | public static function fake_color_picker( $color ) { |
| 533 | 638 | ?> |
| 534 | 639 | <div class="wp-picker-container"> |
| 535 | - <button type="button" class="button wp-color-result" aria-expanded="false" aria-disabled="true" tabindex="-1" style="background-color:<?php echo esc_attr( $color ); ?>;"> | |
| 640 | + <button type="button" class="button wp-color-result" aria-expanded="false" aria-disabled="true" tabindex="-1" style="background-color:<?php echo esc_attr( $color ); ?>;"><?php // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong ?> | |
| 536 | 641 | <span class="wp-color-result-text" style="color:#a7aaad;"><?php esc_html_e( 'Select Color', 'formidable' ); ?></span> |
| 537 | 642 | </button> |
| 538 | 643 | </div> |
| 539 | 644 | <?php |