1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
$epl_extensions = epl_get_new_admin_option_fields();
$active_tab = isset( $_GET['tab'] ) ? sanitize_title( wp_unslash( $_GET['tab'] ) ) : current( array_keys( $epl_extensions ) );
$active_sub_tab = isset( $_GET['sub_tab'] ) ? sanitize_title( wp_unslash( $_GET['sub_tab'] ) ) : '';
if ( isset( $_REQUEST['action'] ) && 'epl_settings' === $_REQUEST['action'] ) {
if (
! isset( $_POST['epl_nonce_extension_form'] ) ||
! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['epl_nonce_extension_form'] ) ), 'epl_nonce_extension_form' )
) {
wp_die( esc_html__( 'Sorry, your nonce did not verify.', 'easy-property-listings' ) );
}
if ( ! empty( $epl_extensions ) ) {
if ( array_key_exists( $active_tab, $epl_extensions ) ) {
$epl_settings = get_option( 'epl_settings' );
$ext_field_groups = $epl_extensions[ $active_tab ];
$ext_field_groups = apply_filters( 'epl_extension_settings_fields', $ext_field_groups, $active_tab );
foreach ( $ext_field_groups['fields'] as $ext_field_group ) {
foreach ( $ext_field_group['fields'] as $field ) {
if ( 'radio' === $field['type'] || 'checkbox' === $field['type'] ) {
if ( ! isset( $_REQUEST[ $field['name'] ] ) ) {
$_REQUEST[ $field['name'] ] = '';
} else {
if ( is_array( $_REQUEST[ $field['name'] ] ) ) {
$_REQUEST[ $field['name'] ] = array_map( 'sanitize_text_field', wp_unslash( $_REQUEST[ $field['name'] ] ) );
} else {
$_REQUEST[ $field['name'] ] = sanitize_text_field( wp_unslash( $_REQUEST[ $field['name'] ] ) );
}
}
}
if ( 'text' === $field['type'] ) {
if ( isset( $_REQUEST[ $field['name'] ] ) && is_array( $_REQUEST[ $field['name'] ] ) ) {
array_walk_recursive( wp_unslash( $_REQUEST[ $field['name'] ] ), 'sanitize_text_field' );
}
if ( isset( $_REQUEST[ $field['name'] ] ) && is_string( $_REQUEST[ $field['name'] ] ) ) {
$_REQUEST[ $field['name'] ] = sanitize_text_field( wp_unslash( $_REQUEST[ $field['name'] ] ) );
}
}
if ( isset( $_REQUEST[ $field['name'] ] ) ) {
$epl_settings[ $field['name'] ] = wp_unslash( $_REQUEST[ $field['name'] ] );
unset( $_REQUEST[ $field['name'] ] );
}
}
}
$page_params = apply_filters( 'epl_settings_page_params', array( 'tab', 'page', 'sub_tab', 'action', 'submit' ) );
foreach ( $page_params as $page_param ) {
if ( isset( $_REQUEST[ $page_param ] ) ) {
unset( $_REQUEST[ $page_param ] );
}
}
foreach ( $_REQUEST as $dynamic_key => $dynamic_value ) {
if ( ! empty( $dynamic_value ) ) {
$epl_settings[ $dynamic_key ] = $dynamic_value;
}
}
update_option( 'epl_settings', $epl_settings );
}
}
}
global $epl_settings;
$epl_settings = get_option( 'epl_settings' );
?>
<div class="wrap">
<h2><?php esc_html_e( 'Extensions Settings', 'easy-property-listings' ); ?></h2>
<p><?php esc_html_e( 'Configure your extension settings here. Visit the main settings page for more extension settings.', 'easy-property-listings' ); ?></p>
<h2 class="nav-tab-wrapper epl-nav-tab-wrapper">
<?php
foreach ( $epl_extensions as $ext_key => $epl_extension ) {
$nav_active = $active_tab === $ext_key ? 'nav-tab-active' : '';
?>
<a class="nav-tab <?php echo esc_attr( $nav_active ); ?>"
href="<?php echo esc_url( admin_url( 'admin.php?page=epl-extensions&tab=' . sanitize_title( $ext_key ) ) ); ?>">
<?php echo esc_attr( $epl_extension['label'] ); ?>
</a>
<?php
}
?>
</h2>
<?php
$epl_extensions = epl_get_new_admin_option_fields();
if ( array_key_exists( $active_tab, $epl_extensions ) ) :
$ext_field_groups = $epl_extensions[ $active_tab ];
?>
<div class="epl-content">
<?php
echo '<div class="epl-fields-help-content">';
foreach ( $ext_field_groups['fields'] as $ext_field_group ) {
if ( isset( $ext_field_group['intro'] ) && ! empty( $ext_field_group['intro'] ) ) {
echo '<div class="epl-field epl-field-intro" data-help="tab-menu-' . esc_attr( sanitize_title( $ext_field_group['label'] ) ) . '">';
echo wp_kses_post( $ext_field_group['intro'] );
echo '</div>';
}
}
echo '</div>';
?>
<form action="" method="post" id="epl_extension_settings_form">
<div class="epl-fields">
<?php
$counter = 1;
echo '
<div class="epl-fields-tab-menu">
<ul>';
foreach ( $ext_field_groups['fields'] as $ext_field_group ) {
$current_class = 'tab-menu-' . esc_attr( sanitize_title( $ext_field_group['label'] ) ) === $active_sub_tab ? 'epl-fields-menu-current' : '';
if ( empty( $active_sub_tab ) && 1 === $counter ) {
$current_class = 'epl-fields-menu-current';
}
if ( ! empty( $ext_field_group['label'] ) ) {
?>
<li class="<?php echo esc_attr( $current_class ); ?>" data-tab="<?php echo 'tab-menu-' . esc_attr( sanitize_title( $ext_field_group['label'] ) ); ?>">
<?php echo esc_attr( $ext_field_group['label'] ); ?>
</li>
<?php
}
++$counter;
}
echo '
</ul>
</div>
';
if ( ! empty( $ext_field_groups['fields'] ) ) {
echo '<div class="epl-fields-tab-content">';
$counter = 1;
foreach ( $ext_field_groups['fields'] as $field_group ) {
$current_class = 'tab-menu-' . sanitize_title( $field_group['label'] ) === $active_sub_tab ? 'epl-fields-field-current' : '';
if ( empty( $active_sub_tab ) && 1 === $counter ) {
$current_class = 'epl-fields-field-current';
}
?>
<div class="<?php echo esc_attr( $current_class ); ?> epl-fields-single-menu" id="<?php echo 'tab-menu-' . esc_attr( sanitize_title( $field_group['label'] ) ); ?>">
<?php foreach ( $field_group['fields'] as $field ) { ?>
<div id="epl-field-<?php echo esc_attr( $field['name'] ); ?>" class="epl-field epl-field-<?php echo esc_attr( $field['type'] ); ?> epl-field-<?php echo esc_attr( $field['name'] ); ?> <?php echo ! empty( $field['wrapper_class'] ) ? esc_attr( $field['wrapper_class'] ) : ''; ?>">
<div class="epl-help-entry-header">
<div class="epl_help_entry_content"></div>
</div>
<?php if ( 'help' !== $field['type'] ) { ?>
<div class="epl-half-left">
<label for="<?php echo esc_attr( $field['name'] ); ?>"><?php echo esc_attr( $field['label'] ); ?></label>
</div>
<?php } ?>
<div class="<?php echo 'help' === $field['type'] ? 'epl-full' : 'epl-half-right'; ?>">
<?php
$default_val = isset( $field['default'] ) ? $field['default'] : '';
$val = $default_val;
if ( isset( $epl_settings[ $field['name'] ] ) ) {
$val = $epl_settings[ $field['name'] ];
}
epl_render_html_fields( $field, $val );
?>
</div>
</div>
<?php } ?>
</div>
<?php ++$counter; ?>
<?php } ?>
</div>
<?php } ?>
<div class="epl-clear"></div>
<div class="epl-content-footer">
<input type="hidden" name="action" value="epl_settings" />
<?php wp_nonce_field( 'epl_nonce_extension_form', 'epl_nonce_extension_form' ); ?>
<input type="hidden" name="sub_tab" id="sub_tab" value="" />
<p class="submit">
<input type="submit" value="<?php esc_html_e( 'Save Changes', 'easy-property-listings' ); ?>" class="button button-primary" id="submit" name="submit">
</p>
</div>
</form>
</div>
<?php endif; ?>
</div>
<?php
function epl_get_new_admin_option_fields() {
$fields = array();
$fields = apply_filters( 'epl_extensions_options_filter_new', $fields );
return $fields;
}