| 1: | <?php |
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | if ( ! defined( 'ABSPATH' ) ) { |
| 14: | exit; |
| 15: | } |
| 16: | |
| 17: | |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: | |
| 23: | class EPL_Search_Fields { |
| 24: | |
| 25: | |
| 26: | |
| 27: | |
| 28: | |
| 29: | |
| 30: | |
| 31: | |
| 32: | public function init() { |
| 33: | |
| 34: | add_action( 'epl_frontend_search_field_text', array( $this, 'render_text' ), 10, 5 ); |
| 35: | add_action( 'epl_frontend_search_field_checkbox', array( $this, 'render_checkbox' ), 10, 5 ); |
| 36: | add_action( 'epl_frontend_search_field_select', array( $this, 'render_select' ), 10, 5 ); |
| 37: | add_action( 'epl_frontend_search_field_multiple_select', array( $this, 'render_multiple_select' ), 10, 5 ); |
| 38: | add_action( 'epl_frontend_search_field_number', array( $this, 'render_number' ), 10, 5 ); |
| 39: | add_action( 'epl_frontend_search_field_hidden', array( $this, 'render_hidden' ), 10, 5 ); |
| 40: | add_action( 'epl_frontend_search_field_radio', array( $this, 'render_radio' ), 10, 5 ); |
| 41: | add_action( 'epl_frontend_search_field_checkbox_multiple', array( $this, 'render_checkbox_multiple' ), 10, 5 ); |
| 42: | } |
| 43: | |
| 44: | |
| 45: | |
| 46: | |
| 47: | |
| 48: | |
| 49: | |
| 50: | |
| 51: | |
| 52: | |
| 53: | |
| 54: | |
| 55: | |
| 56: | |
| 57: | |
| 58: | public function render_text( array $field, $config = '', $value = '', $post_type = '', $property_status = '' ) { |
| 59: | if ( isset( $field['wrap_start'] ) ) { |
| 60: | echo '<div class="' . esc_attr( $field['wrap_start'] ) . '">'; |
| 61: | } |
| 62: | $placeholder = isset( $field['placeholder'] ) ? $field['placeholder'] : ''; |
| 63: | ?> |
| 64: | <div class="epl-search-row epl-search-row-text epl-<?php echo esc_attr( $field['meta_key'] ); ?> fm-block <?php echo isset( $field['class'] ) ? esc_attr( $field['class'] ) : ''; ?>"> |
| 65: | <label for="<?php echo esc_attr( $field['meta_key'] ); ?>" class="epl-search-label fm-label"> |
| 66: | <?php echo esc_attr( apply_filters( 'epl_search_widget_label_' . $field['meta_key'], $field['label'] ) ); ?> |
| 67: | </label> |
| 68: | <div class="field"> |
| 69: | <?php if ( ! empty( $field['icon'] ) ) : ?> |
| 70: | <i class="epl-icon <?php echo esc_attr( $field['icon'] ); ?>"></i> |
| 71: | <?php endif; ?> |
| 72: | <input |
| 73: | placeholder="<?php echo esc_attr( $placeholder ); ?>" |
| 74: | type="text" |
| 75: | class="in-field field-width <?php echo esc_attr( $field['meta_key'] ); ?>" |
| 76: | name="<?php echo esc_attr( $field['meta_key'] ); ?>" |
| 77: | id="<?php echo esc_attr( $field['meta_key'] ); ?>" |
| 78: | value="<?php echo esc_attr( $value ); ?>" |
| 79: | /> |
| 80: | </div> |
| 81: | </div> |
| 82: | <?php |
| 83: | if ( isset( $field['wrap_end'] ) ) { |
| 84: | echo '</div>'; |
| 85: | } |
| 86: | } |
| 87: | |
| 88: | |
| 89: | |
| 90: | |
| 91: | |
| 92: | |
| 93: | |
| 94: | |
| 95: | |
| 96: | |
| 97: | |
| 98: | |
| 99: | |
| 100: | |
| 101: | |
| 102: | public function render_checkbox( array $field, $config = '', $value = '', $post_type = '', $property_status = '' ) { |
| 103: | if ( isset( $field['wrap_start'] ) ) { |
| 104: | echo '<div class="' . esc_attr( $field['wrap_start'] ) . '">'; |
| 105: | } |
| 106: | ?> |
| 107: | <?php if ( ! empty( $field['icon'] ) ) : ?> |
| 108: | <i class="epl-icon <?php echo esc_attr( $field['icon'] ); ?>"></i> |
| 109: | <?php endif; ?> |
| 110: | <span class="epl-search-row epl-search-row-checkbox <?php echo isset( $field['class'] ) ? esc_attr( $field['class'] ) : ''; ?>"> |
| 111: | <input type="checkbox" name="<?php echo esc_attr( $field['meta_key'] ); ?>" id="<?php echo esc_attr( $field['meta_key'] ); ?>" class="in-field <?php echo esc_attr( $field['meta_key'] ); ?>" |
| 112: | <?php |
| 113: | if ( isset( $value ) && ! empty( $value ) ) { |
| 114: | echo 'checked="checked"'; } |
| 115: | ?> |
| 116: | /> |
| 117: | <label for="<?php echo esc_attr( $field['meta_key'] ); ?>" class="check-label"> |
| 118: | <?php echo esc_attr( apply_filters( 'epl_search_widget_label_' . $field['meta_key'], $field['label'] ) ); ?> |
| 119: | </label> |
| 120: | </span> |
| 121: | <?php |
| 122: | if ( isset( $field['wrap_end'] ) ) { |
| 123: | echo '</div>'; |
| 124: | } |
| 125: | } |
| 126: | |
| 127: | |
| 128: | |
| 129: | |
| 130: | |
| 131: | |
| 132: | |
| 133: | |
| 134: | |
| 135: | |
| 136: | |
| 137: | |
| 138: | |
| 139: | |
| 140: | |
| 141: | |
| 142: | public function render_select( array $field, $config = '', $value = '', $post_type = '', $property_status = '' ) { |
| 143: | |
| 144: | if ( isset( $field['wrap_start'] ) ) { |
| 145: | echo '<div class="' . esc_attr( $field['wrap_start'] ) . '">'; |
| 146: | } |
| 147: | |
| 148: | $has_min_max = false; |
| 149: | |
| 150: | if ( isset( $field['query']['type'] ) && 'numeric' === $field['query']['type'] && ! empty( $field['options'] ) && is_array( $field['options'] ) ) { |
| 151: | reset( $field['options'] ); |
| 152: | $opt_min = key( $field['options'] ); |
| 153: | end( $field['options'] ); |
| 154: | $opt_max = key( $field['options'] ); |
| 155: | $has_min_max = true; |
| 156: | } |
| 157: | |
| 158: | ?> |
| 159: | <div class="epl-search-row epl-search-row-select epl-<?php echo esc_attr( $field['meta_key'] ); ?> fm-block <?php echo isset( $field['class'] ) ? esc_attr( $field['class'] ) : ''; ?>"> |
| 160: | <label for="<?php echo esc_attr( $field['meta_key'] ); ?>" class="epl-search-label fm-label"> |
| 161: | <?php echo esc_attr( apply_filters( 'epl_search_widget_label_' . $field['meta_key'], $field['label'] ) ); ?> |
| 162: | </label> |
| 163: | <div class="field"> |
| 164: | <?php if ( ! empty( $field['icon'] ) ) : ?> |
| 165: | <i class="epl-icon <?php echo esc_attr( $field['icon'] ); ?>"></i> |
| 166: | <?php endif; ?> |
| 167: | <select |
| 168: | name="<?php echo esc_attr( $field['meta_key'] ); ?>" |
| 169: | id="<?php echo esc_attr( $field['meta_key'] ); ?>" |
| 170: | <?php if ( $has_min_max ) : ?> |
| 171: | data-min="<?php echo esc_attr( $opt_min ); ?>" |
| 172: | data-max="<?php echo esc_attr( $opt_max ); ?>" |
| 173: | <?php endif; ?> |
| 174: | class="in-field field-width <?php echo esc_attr( $field['meta_key'] ); ?>"> |
| 175: | <option value=""> |
| 176: | <?php echo esc_attr( apply_filters( 'epl_search_widget_option_label_' . $field['option_filter'], __( 'Any', 'easy-property-listings' ) ) ); ?> |
| 177: | </option> |
| 178: | <?php |
| 179: | if ( isset( $field['options'] ) && ! empty( $field['options'] ) ) { |
| 180: | foreach ( $field['options'] as $k => $v ) { |
| 181: | echo '<option value="' . esc_attr( $k ) . '"' . selected( $k, $value, false ) . '>' . esc_attr( $v ) . '</option>'; |
| 182: | } |
| 183: | } |
| 184: | ?> |
| 185: | </select> |
| 186: | </div> |
| 187: | </div> |
| 188: | <?php |
| 189: | if ( isset( $field['wrap_end'] ) ) { |
| 190: | echo '</div>'; |
| 191: | } |
| 192: | } |
| 193: | |
| 194: | |
| 195: | |
| 196: | |
| 197: | |
| 198: | |
| 199: | |
| 200: | |
| 201: | |
| 202: | |
| 203: | |
| 204: | |
| 205: | |
| 206: | |
| 207: | |
| 208: | |
| 209: | |
| 210: | public function render_multiple_select( array $field, $config = '', $value = '', $post_type = '', $property_status = '' ) { |
| 211: | if ( isset( $field['wrap_start'] ) ) { |
| 212: | echo '<div class="' . esc_attr( $field['wrap_start'] ) . '">'; |
| 213: | } |
| 214: | $field_label = apply_filters( 'epl_search_widget_label_' . $field['meta_key'], $field['label'] ); |
| 215: | ?> |
| 216: | <div class="epl-search-row epl-search-row-select epl-<?php echo esc_attr( $field['meta_key'] ); ?> fm-block <?php echo isset( $field['class'] ) ? esc_attr( $field['class'] ) : ''; ?>"> |
| 217: | <label for="<?php echo esc_attr( $field['meta_key'] ); ?>" class="epl-search-label fm-label"> |
| 218: | <?php echo esc_html( $field_label ); ?> |
| 219: | </label> |
| 220: | <div class="field"> |
| 221: | <?php if ( ! empty( $field['icon'] ) ) : ?> |
| 222: | <i class="epl-icon <?php echo esc_attr( $field['icon'] ); ?>"></i> |
| 223: | <?php endif; ?> |
| 224: | <select aria-label="<?php echo esc_attr( $field_label ); ?>" name="<?php echo esc_attr( $field['meta_key'] ); ?>[]" |
| 225: | id="<?php echo esc_attr( $field['meta_key'] ); ?>" |
| 226: | class="in-field field-width field-multiple <?php echo esc_attr( $field['meta_key'] ); ?>" multiple> |
| 227: | <option value=""> |
| 228: | <?php echo esc_attr( apply_filters( 'epl_search_widget_option_label_' . $field['option_filter'], __( 'Any', 'easy-property-listings' ) ) ); ?> |
| 229: | </option> |
| 230: | <?php |
| 231: | if ( isset( $field['options'] ) && ! empty( $field['options'] ) ) { |
| 232: | foreach ( $field['options'] as $k => $v ) { |
| 233: | $selected = in_array( $k, (array) $value, true ) ? true : false; |
| 234: | echo '<option value="' . esc_attr( $k ) . '"' . selected( $selected, true, false ) . '>' . esc_attr( $v ) . '</option>'; |
| 235: | } |
| 236: | } |
| 237: | ?> |
| 238: | </select> |
| 239: | </div> |
| 240: | </div> |
| 241: | <?php |
| 242: | if ( isset( $field['wrap_end'] ) ) { |
| 243: | echo '</div>'; |
| 244: | } |
| 245: | } |
| 246: | |
| 247: | |
| 248: | |
| 249: | |
| 250: | |
| 251: | |
| 252: | |
| 253: | |
| 254: | |
| 255: | |
| 256: | |
| 257: | |
| 258: | |
| 259: | |
| 260: | |
| 261: | public function render_number( array $field, $config = '', $value = '', $post_type = '', $property_status = '' ) { |
| 262: | if ( isset( $field['wrap_start'] ) ) { |
| 263: | echo '<div class="' . esc_attr( $field['wrap_start'] ) . '">'; |
| 264: | } |
| 265: | $placeholder = isset( $field['placeholder'] ) ? $field['placeholder'] : ''; |
| 266: | ?> |
| 267: | <div class="epl-search-row epl-search-row-number epl-<?php echo esc_attr( $field['meta_key'] ); ?> fm-block <?php echo isset( $field['class'] ) ? esc_attr( $field['class'] ) : ''; ?>"> |
| 268: | <label for="<?php echo esc_attr( $field['meta_key'] ); ?>" class="epl-search-label fm-label"> |
| 269: | <?php echo esc_attr( apply_filters( 'epl_search_widget_label_' . $field['meta_key'], $field['label'] ) ); ?> |
| 270: | </label> |
| 271: | <div class="field"> |
| 272: | <?php if ( ! empty( $field['icon'] ) ) : ?> |
| 273: | <i class="epl-icon <?php echo esc_attr( $field['icon'] ); ?>"></i> |
| 274: | <?php endif; ?> |
| 275: | <input type="number" class="in-field field-width <?php echo esc_attr( $field['meta_key'] ); ?>" |
| 276: | placeholder="<?php echo esc_attr( $placeholder ); ?>" |
| 277: | name="<?php echo esc_attr( $field['meta_key'] ); ?>" |
| 278: | id="<?php echo esc_attr( $field['meta_key'] ); ?>" |
| 279: | value="<?php echo esc_attr( $value ); ?>" |
| 280: | /> |
| 281: | </div> |
| 282: | </div> |
| 283: | <?php |
| 284: | if ( isset( $field['wrap_end'] ) ) { |
| 285: | echo '</div>'; |
| 286: | } |
| 287: | } |
| 288: | |
| 289: | |
| 290: | |
| 291: | |
| 292: | |
| 293: | |
| 294: | |
| 295: | |
| 296: | |
| 297: | |
| 298: | |
| 299: | |
| 300: | |
| 301: | |
| 302: | public function render_hidden( array $field, $config = '', $value = '', $post_type = '', $property_status = '' ) { |
| 303: | if ( isset( $field['wrap_start'] ) ) { |
| 304: | echo '<div class="' . esc_attr( $field['wrap_start'] ) . '">'; |
| 305: | } |
| 306: | ?> |
| 307: | <input type="hidden" class="in-field field-width <?php echo esc_attr( $field['meta_key'] ); ?>" |
| 308: | name="<?php echo esc_attr( $field['meta_key'] ); ?>" |
| 309: | id="<?php echo esc_attr( $field['meta_key'] ); ?>" |
| 310: | value="<?php echo esc_attr( $value ); ?>" |
| 311: | /> |
| 312: | <?php |
| 313: | if ( isset( $field['wrap_end'] ) ) { |
| 314: | echo '</div>'; |
| 315: | } |
| 316: | } |
| 317: | |
| 318: | |
| 319: | |
| 320: | |
| 321: | |
| 322: | |
| 323: | |
| 324: | |
| 325: | |
| 326: | |
| 327: | |
| 328: | |
| 329: | |
| 330: | |
| 331: | |
| 332: | public function render_radio( array $field, $config = '', $value = '', $post_type = '', $property_status = '' ) { |
| 333: | if ( isset( $field['wrap_start'] ) ) { |
| 334: | echo '<div class="' . esc_attr( $field['wrap_start'] ) . '">'; |
| 335: | } |
| 336: | ?> |
| 337: | <div class="epl-search-row epl-search-row-radio epl-<?php echo esc_attr( $field['meta_key'] ); ?> fm-block <?php echo isset( $field['class'] ) ? esc_attr( $field['class'] ) : ''; ?>"> |
| 338: | <label for="<?php echo esc_attr( $field['meta_key'] ); ?>" class="epl-search-label fm-label"> |
| 339: | <?php echo esc_attr( apply_filters( 'epl_search_widget_label_' . $field['meta_key'], $field['label'] ) ); ?> |
| 340: | </label> |
| 341: | <div class="field"> |
| 342: | <?php if ( ! empty( $field['icon'] ) ) : ?> |
| 343: | <i class="epl-icon <?php echo esc_attr( $field['icon'] ); ?>"></i> |
| 344: | <?php endif; ?> |
| 345: | <?php |
| 346: | if ( isset( $field['options'] ) && ! empty( $field['options'] ) ) { |
| 347: | foreach ( $field['options'] as $k => $v ) { |
| 348: | ?> |
| 349: | <input |
| 350: | type="radio" |
| 351: | <?php checked( $k, $value, true ); ?> |
| 352: | name="<?php echo esc_attr( $field['meta_key'] ); ?>" |
| 353: | id="<?php echo esc_attr( $field['meta_key'] ) . '_' . esc_attr( $k ); ?>" |
| 354: | value="<?php echo esc_attr( $k ); ?>" |
| 355: | class="in-field field-width <?php echo esc_attr( $field['meta_key'] ) . '_' . esc_attr( $k ); ?>" /> |
| 356: | <label class="epl-search-radio-label"><?php echo esc_attr( $v ); ?></label> |
| 357: | <?php |
| 358: | } |
| 359: | } |
| 360: | ?> |
| 361: | |
| 362: | </div> |
| 363: | </div> |
| 364: | <?php |
| 365: | if ( isset( $field['wrap_end'] ) ) { |
| 366: | echo '</div>'; |
| 367: | } |
| 368: | } |
| 369: | |
| 370: | |
| 371: | |
| 372: | |
| 373: | |
| 374: | |
| 375: | |
| 376: | |
| 377: | |
| 378: | |
| 379: | |
| 380: | |
| 381: | |
| 382: | |
| 383: | |
| 384: | |
| 385: | public function render_checkbox_multiple( array $field, $config = '', $value = '', $post_type = '', $property_status = '' ) { |
| 386: | if ( isset( $field['wrap_start'] ) ) { |
| 387: | echo '<div class="' . esc_attr( $field['wrap_start'] ) . '">'; |
| 388: | } |
| 389: | ?> |
| 390: | <div class="epl-search-row epl-search-row-checkbox-multiple epl-<?php echo esc_attr( $field['meta_key'] ); ?> fm-block <?php echo isset( $field['class'] ) ? esc_attr( $field['class'] ) : ''; ?>"> |
| 391: | <label for="<?php echo esc_attr( $field['meta_key'] ); ?>" class="epl-search-label fm-label"> |
| 392: | <?php echo esc_attr( apply_filters( 'epl_search_widget_label_' . $field['meta_key'], $field['label'] ) ); ?> |
| 393: | </label> |
| 394: | <div class="field"> |
| 395: | <?php if ( ! empty( $field['icon'] ) ) : ?> |
| 396: | <i class="epl-icon <?php echo esc_attr( $field['icon'] ); ?>"></i> |
| 397: | <?php endif; ?> |
| 398: | <?php |
| 399: | if ( isset( $field['options'] ) && ! empty( $field['options'] ) ) { |
| 400: | foreach ( $field['options'] as $k => $v ) { |
| 401: | $checked = in_array( $k, (array) $value, true ) ? 'checked' : ''; |
| 402: | ?> |
| 403: | <input |
| 404: | type="checkbox" |
| 405: | <?php echo ' ' . esc_attr( $checked ) . ' '; ?> |
| 406: | name="<?php echo esc_attr( $field['meta_key'] ); ?>[]" |
| 407: | id="<?php echo esc_attr( $field['meta_key'] ) . '_' . esc_attr( $k ); ?>" |
| 408: | value="<?php echo esc_attr( $k ); ?>" |
| 409: | class="in-field field-width <?php echo esc_attr( $field['meta_key'] ) . '_' . esc_attr( $k ); ?>" /> |
| 410: | <label for="<?php echo esc_attr( $field['meta_key'] ) . '_' . esc_attr( $k ); ?>" class="epl-search-checkbox-label"><?php echo esc_attr( $v ); ?></label> |
| 411: | <?php |
| 412: | } |
| 413: | } |
| 414: | ?> |
| 415: | </div> |
| 416: | </div> |
| 417: | <?php |
| 418: | if ( isset( $field['wrap_end'] ) ) { |
| 419: | echo '</div>'; |
| 420: | } |
| 421: | } |
| 422: | } |
| 423: | |