| 1: | <?php |
| 2: | /** |
| 3: | * SHORTCODE :: Listing Search [listing_search] |
| 4: | * |
| 5: | * @package EPL |
| 6: | * @subpackage Shortcode/ListingSearch |
| 7: | * @copyright Copyright (c) 2020, Merv Barrett |
| 8: | * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 9: | * @since 1.2 |
| 10: | */ |
| 11: | |
| 12: | // Exit if accessed directly. |
| 13: | if ( ! defined( 'ABSPATH' ) ) { |
| 14: | exit; |
| 15: | } |
| 16: | |
| 17: | /** |
| 18: | * Listing Search Shortcode [listing_search] This shortcode allows for you to specify the property type(s) using |
| 19: | * [listing_search title="" post_type="property" property_status="current/sold/leased" search_house_category="on/off" search_price="on/off" search_bed="on/off" search_bath="on/off" search_car="on/off" search_other="on/off"] option |
| 20: | * |
| 21: | * @param array $atts Shortcode attributes. |
| 22: | * |
| 23: | * @return false|string |
| 24: | * |
| 25: | * @since 1.2 |
| 26: | * @since 3.4.45 Tweak: Pass user provided attributes to the [listing_search] Shortcode template. |
| 27: | * @since 3.5 Support for instance ID, fallback generates unique instance ID automatically, added support for 'status' in shortcodes. |
| 28: | * @since 3.5.3 Filter to disable default template & action to add custom template. |
| 29: | */ |
| 30: | function epl_shortcode_listing_search_callback( $atts ) { |
| 31: | |
| 32: | $defaults = epl_search_get_defaults(); |
| 33: | $attributes = shortcode_atts( $defaults, $atts ); |
| 34: | |
| 35: | if ( empty( $attributes['instance_id'] ) ) { |
| 36: | $attributes['instance_id'] = epl_generate_search_instance_counter(); |
| 37: | } |
| 38: | |
| 39: | if ( isset( $atts['status'] ) ) { |
| 40: | $attributes['property_status'] = $atts['status']; |
| 41: | } |
| 42: | ob_start(); |
| 43: | if ( apply_filters( 'epl_search_should_load_default_template', true, $attributes, $atts ) ) { |
| 44: | // Rendering view of listing search shortcode. |
| 45: | epl_get_template_part( |
| 46: | 'shortcodes/listing-search/' . ( ! empty( $attributes['view'] ) ? trim( $attributes['view'] ) . '.php' : 'default.php' ), |
| 47: | array( |
| 48: | 'atts' => $attributes, |
| 49: | 'user_atts' => $atts, |
| 50: | ) |
| 51: | ); |
| 52: | } else { |
| 53: | do_action( 'epl_search_load_template', $attributes, $atts ); |
| 54: | } |
| 55: | return ob_get_clean(); |
| 56: | } |
| 57: | add_shortcode( 'listing_search', 'epl_shortcode_listing_search_callback' ); |
| 58: |