| 1 |
<?php |
| 2 |
/** |
| 3 |
* Shortcode default-form ID resolution, and an unconditional |
| 4 |
* `wppb_change_form_fields` registration so per-form ordering works even when |
| 5 |
* the classic module gate is 'hide'. add_filter() de-duplicates if the bundled |
| 6 |
* conditional registration also runs. |
| 7 |
*/ |
| 8 |
|
| 9 |
if ( ! defined( 'ABSPATH' ) ) exit; |
| 10 |
|
| 11 |
// Safe before multiple-forms.php is included: add_filter() does not resolve the |
| 12 |
// callback until `wppb_change_form_fields` fires. |
| 13 |
add_filter( 'wppb_change_form_fields', 'wppb_multiple_forms_change_fields', 10, 2 ); |
| 14 |
|
| 15 |
/** |
| 16 |
* Force Multiple Registration / Edit Profile Forms module gates to 'show' on |
| 17 |
* every read so classic-mode WCK admin UI loads. Read-only — do not write back |
| 18 |
* (would persist the filtered value into a site option the user never set). |
| 19 |
*/ |
| 20 |
add_filter( 'option_wppb_module_settings', 'wppb_fb_force_multiple_forms_modules_active' ); |
| 21 |
// Absent option rows fire `default_option_*` instead of `option_*`. |
| 22 |
add_filter( 'default_option_wppb_module_settings', 'wppb_fb_force_multiple_forms_modules_active' ); |
| 23 |
function wppb_fb_force_multiple_forms_modules_active( $settings ) { |
| 24 |
if ( ! is_array( $settings ) ) $settings = array(); |
| 25 |
$settings['wppb_multipleRegistrationForms'] = 'show'; |
| 26 |
$settings['wppb_multipleEditProfileForms'] = 'show'; |
| 27 |
return $settings; |
| 28 |
} |
| 29 |
|
| 30 |
add_filter( 'wppb_form_args_after_init', 'wppb_fb_resolve_default_form_id', 10 ); |
| 31 |
|
| 32 |
/** |
| 33 |
* Bind a bare shortcode to the configured default form when no ID was passed. |
| 34 |
* |
| 35 |
* @param array $args Form render args from the `wppb_form_args_after_init` filter. |
| 36 |
* @return array |
| 37 |
*/ |
| 38 |
function wppb_fb_resolve_default_form_id( $args ) { |
| 39 |
if ( ! empty( $args['ID'] ) ) return $args; |
| 40 |
|
| 41 |
// Type is `$args['form_type']`, not a `context` key. |
| 42 |
$form_type = ( isset( $args['form_type'] ) && $args['form_type'] === 'edit_profile' ) |
| 43 |
? 'edit_profile' |
| 44 |
: 'register'; |
| 45 |
|
| 46 |
$defaults = get_option( 'wppb_default_form_ids', array() ); |
| 47 |
|
| 48 |
if ( ! empty( $defaults[ $form_type ] ) ) { |
| 49 |
$args['ID'] = $defaults[ $form_type ]; |
| 50 |
} |
| 51 |
|
| 52 |
return $args; |
| 53 |
} |
| 54 |
|