| 1 |
<?php |
| 2 |
/** |
| 3 |
* Render the WPCasa settings form. |
| 4 |
* |
| 5 |
* A section keeps the existing two-element structure for its label and |
| 6 |
* fields. Add-ons can opt into a second navigation level by registering a |
| 7 |
* `tabs` map in the optional third element and assigning fields with `tab`. |
| 8 |
* |
| 9 |
* @package WPCasa |
| 10 |
* @updated 1.5.4 |
| 11 |
*/ |
| 12 |
|
| 13 |
if ( ! defined( 'ABSPATH' ) ) { |
| 14 |
exit; |
| 15 |
} |
| 16 |
|
| 17 |
$settings = isset( $settings ) && is_array( $settings ) ? $settings : array(); |
| 18 |
$settings_group = isset( $settings_group ) ? $settings_group : ''; |
| 19 |
?> |
| 20 |
|
| 21 |
<form method="post" action="options.php"> |
| 22 |
|
| 23 |
<?php settings_fields( $settings_group ); ?> |
| 24 |
|
| 25 |
<?php |
| 26 |
foreach ( $settings as $key => $section ) { |
| 27 |
if ( ! is_array( $section ) ) { |
| 28 |
continue; |
| 29 |
} |
| 30 |
|
| 31 |
// Normalize the optional tab metadata while preserving legacy sections. |
| 32 |
$section_id = sanitize_title( $key ); |
| 33 |
$section_tabs = $this->get_section_tabs( $section ); |
| 34 |
$section_tab_options = $this->get_section_tab_options( $section, $section_tabs ); |
| 35 |
?> |
| 36 |
|
| 37 |
<div id="settings-<?php echo esc_attr( $section_id ); ?>" class="settings_panel"> |
| 38 |
<div class="wpsight-admin-ui-container"> |
| 39 |
<div class="wpsight-admin-ui-grid"> |
| 40 |
<div class="wpsight-admin-ui-grid-col wpsight-admin-ui-grid-1-1"> |
| 41 |
<div class="wpsight-admin-ui-panel wpsight-admin-ui-panel-large"> |
| 42 |
|
| 43 |
<?php |
| 44 |
if ( empty( $section_tabs ) ) { |
| 45 |
// Render legacy sections through the shared field view. |
| 46 |
$settings_options = isset( $section[1] ) && is_array( $section[1] ) |
| 47 |
? $section[1] |
| 48 |
: array(); |
| 49 |
|
| 50 |
require WPSIGHT_PLUGIN_DIR . '/includes/admin/views/settings-fields.php'; |
| 51 |
} else { |
| 52 |
if ( ! empty( $section_tab_options['common'] ) ) { |
| 53 |
$settings_options = $section_tab_options['common']; |
| 54 |
|
| 55 |
require WPSIGHT_PLUGIN_DIR . '/includes/admin/views/settings-fields.php'; |
| 56 |
} |
| 57 |
?> |
| 58 |
|
| 59 |
<div |
| 60 |
class="wpsight-settings-subtabs" |
| 61 |
data-wpsight-settings-section="<?php echo esc_attr( $section_id ); ?>" |
| 62 |
> |
| 63 |
<?php $tab_select_id = 'settings-' . $section_id . '-subtab-select'; ?> |
| 64 |
|
| 65 |
<?php // The mobile select mirrors the desktop tab list and is synchronized in JavaScript. ?> |
| 66 |
<div class="wpsight-settings-subtab-select-wrap"> |
| 67 |
<label |
| 68 |
class="wpsight-settings-subtab-select-label" |
| 69 |
for="<?php echo esc_attr( $tab_select_id ); ?>" |
| 70 |
> |
| 71 |
<?php echo esc_html__( 'Select section', 'wpcasa' ); ?> |
| 72 |
</label> |
| 73 |
|
| 74 |
<select |
| 75 |
id="<?php echo esc_attr( $tab_select_id ); ?>" |
| 76 |
class="wpsight-settings-subtab-select" |
| 77 |
data-wpsight-settings-subtab-select |
| 78 |
> |
| 79 |
<?php |
| 80 |
$is_first_option = true; |
| 81 |
|
| 82 |
foreach ( $section_tabs as $tab_id => $tab_label ) { |
| 83 |
?> |
| 84 |
|
| 85 |
<option |
| 86 |
value="<?php echo esc_attr( $tab_id ); ?>" |
| 87 |
<?php selected( $is_first_option ); ?> |
| 88 |
> |
| 89 |
<?php echo esc_html( $tab_label ); ?> |
| 90 |
</option> |
| 91 |
|
| 92 |
<?php |
| 93 |
$is_first_option = false; |
| 94 |
} |
| 95 |
?> |
| 96 |
</select> |
| 97 |
</div> |
| 98 |
|
| 99 |
<?php // The desktop control follows the ARIA tabs pattern. ?> |
| 100 |
<div |
| 101 |
class="wpsight-settings-subtab-nav" |
| 102 |
role="tablist" |
| 103 |
aria-label="<?php echo esc_attr__( 'Settings sections', 'wpcasa' ); ?>" |
| 104 |
> |
| 105 |
<?php |
| 106 |
$is_first_tab = true; |
| 107 |
|
| 108 |
foreach ( $section_tabs as $tab_id => $tab_label ) { |
| 109 |
$tab_button_id = 'settings-' . $section_id . '-subtab-' . $tab_id; |
| 110 |
$tab_panel_id = 'settings-' . $section_id . '-subpanel-' . $tab_id; |
| 111 |
$tab_class = $is_first_tab ? 'nav-tab nav-tab-active' : 'nav-tab'; |
| 112 |
?> |
| 113 |
|
| 114 |
<button |
| 115 |
type="button" |
| 116 |
id="<?php echo esc_attr( $tab_button_id ); ?>" |
| 117 |
class="<?php echo esc_attr( $tab_class ); ?>" |
| 118 |
role="tab" |
| 119 |
aria-controls="<?php echo esc_attr( $tab_panel_id ); ?>" |
| 120 |
aria-selected="<?php echo esc_attr( $is_first_tab ? 'true' : 'false' ); ?>" |
| 121 |
tabindex="<?php echo esc_attr( $is_first_tab ? '0' : '-1' ); ?>" |
| 122 |
data-wpsight-settings-subtab="<?php echo esc_attr( $tab_id ); ?>" |
| 123 |
> |
| 124 |
<?php echo esc_html( $tab_label ); ?> |
| 125 |
</button> |
| 126 |
|
| 127 |
<?php |
| 128 |
$is_first_tab = false; |
| 129 |
} |
| 130 |
?> |
| 131 |
</div> |
| 132 |
|
| 133 |
<?php |
| 134 |
$is_first_tab = true; |
| 135 |
|
| 136 |
// Render every panel so hooks can populate tabs without registered fields. |
| 137 |
foreach ( array_keys( $section_tabs ) as $tab_id ) { |
| 138 |
$tab_button_id = 'settings-' . $section_id . '-subtab-' . $tab_id; |
| 139 |
$tab_panel_id = 'settings-' . $section_id . '-subpanel-' . $tab_id; |
| 140 |
$tab_panel_class = $is_first_tab ? 'wpsight-settings-subpanel is-active' : 'wpsight-settings-subpanel'; |
| 141 |
$settings_options = $section_tab_options['tabs'][ $tab_id ]; |
| 142 |
?> |
| 143 |
|
| 144 |
<div |
| 145 |
id="<?php echo esc_attr( $tab_panel_id ); ?>" |
| 146 |
class="<?php echo esc_attr( $tab_panel_class ); ?>" |
| 147 |
role="tabpanel" |
| 148 |
aria-labelledby="<?php echo esc_attr( $tab_button_id ); ?>" |
| 149 |
data-wpsight-settings-subpanel="<?php echo esc_attr( $tab_id ); ?>" |
| 150 |
> |
| 151 |
<?php |
| 152 |
/** |
| 153 |
* Fires before a WPCasa settings subtab is rendered. |
| 154 |
* |
| 155 |
* @since 1.5.4 |
| 156 |
* |
| 157 |
* @param string $section_id Sanitized settings section ID. |
| 158 |
* @param string $tab_id Sanitized settings tab ID. |
| 159 |
* @param array $section Complete settings section data. |
| 160 |
*/ |
| 161 |
do_action( 'wpsight_settings_subtab_before', $section_id, $tab_id, $section ); |
| 162 |
|
| 163 |
if ( ! empty( $settings_options ) ) { |
| 164 |
require WPSIGHT_PLUGIN_DIR . '/includes/admin/views/settings-fields.php'; |
| 165 |
} |
| 166 |
|
| 167 |
/** |
| 168 |
* Fires after a WPCasa settings subtab is rendered. |
| 169 |
* |
| 170 |
* @since 1.5.4 |
| 171 |
* |
| 172 |
* @param string $section_id Sanitized settings section ID. |
| 173 |
* @param string $tab_id Sanitized settings tab ID. |
| 174 |
* @param array $section Complete settings section data. |
| 175 |
*/ |
| 176 |
do_action( 'wpsight_settings_subtab_after', $section_id, $tab_id, $section ); |
| 177 |
?> |
| 178 |
</div> |
| 179 |
|
| 180 |
<?php |
| 181 |
$is_first_tab = false; |
| 182 |
} |
| 183 |
?> |
| 184 |
</div> |
| 185 |
|
| 186 |
<?php |
| 187 |
} |
| 188 |
?> |
| 189 |
|
| 190 |
</div> |
| 191 |
</div> |
| 192 |
</div> |
| 193 |
</div> |
| 194 |
</div> |
| 195 |
|
| 196 |
<?php |
| 197 |
} |
| 198 |
?> |
| 199 |
|
| 200 |
</form> |
| 201 |
|