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