-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwpcasa-advanced-search.php
211 lines (171 loc) · 5.43 KB
/
wpcasa-advanced-search.php
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
<?php
/**
* WPCasa Advanced Search
*
* @package WPCasaAdvancedSearch
* @author WPSight
* @copyright 2024 Kybernetik Services GmbH
* @license GPL-2.0-or-later
*
* @wordpress-plugin
* Plugin Name: WPCasa Advanced Search
* Plugin URI: https://wpcasa.com/downloads/wpcasa-advanced-search
* Description: Display an expandable area with advanced options in WPCasa property search form.
* Version: 1.1.1
* Requires at least: 6.2
* Requires PHP: 7.2
* Requires Plugins: wpcasa
* Author: WPSight
* Author URI: https://wpcasa.com
* Text Domain: wpcasa-advanced-search
* License: GPL v2 or later
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) )
exit;
/**
* WPSight_Advanced_Search class
*/
class WPSight_Advanced_Search {
/**
* Constructor
*/
public function __construct() {
// Define constants
if ( ! defined( 'WPSIGHT_NAME' ) )
define( 'WPSIGHT_NAME', 'WPCasa' );
if ( ! defined( 'WPSIGHT_DOMAIN' ) )
define( 'WPSIGHT_DOMAIN', 'wpcasa' );
define( 'WPSIGHT_ADVANCED_SEARCH_NAME', 'WPCasa Advanced Search' );
define( 'WPSIGHT_ADVANCED_SEARCH_DOMAIN', 'wpcasa-advanced-search' );
define( 'WPSIGHT_ADVANCED_SEARCH_VERSION', '1.1.1' );
define( 'WPSIGHT_ADVANCED_SEARCH_PLUGIN_DIR', untrailingslashit( plugin_dir_path( __FILE__ ) ) );
define( 'WPSIGHT_ADVANCED_SEARCH_PLUGIN_URL', untrailingslashit( plugins_url( basename( plugin_dir_path( __FILE__ ) ), basename( __FILE__ ) ) ) );
// Cookie constants
define( 'WPSIGHT_COOKIE_SEARCH_ADVANCED', WPSIGHT_DOMAIN . '_advanced_search' );
// Actions
add_action( 'wp_enqueue_scripts', array( $this, 'frontend_scripts' ) );
// Filters
add_filter( 'wpsight_get_search_fields', array( $this, 'get_advanced_search_fields' ) );
}
/**
* init()
*
* Initialize the plugin when WPCasa is loaded.
*
* @param object $wpsight
* @uses do_action_ref_array()
* @return object $wpsight->advanced_search
*
* @since 1.0.0
*/
public static function init( $wpsight ) {
if ( ! isset( $wpsight->advanced_search ) )
$wpsight->advanced_search = new self();
do_action_ref_array( 'wpsight_init_advanced_search', array( &$wpsight ) );
return $wpsight->advanced_search;
}
/**
* frontend_scripts()
*
* Register and enqueue scripts and css.
*
* @uses wp_enqueue_style()
* @uses wp_localize_script()
*
* @since 1.0.0
*/
public function frontend_scripts() {
// Script debugging?
$suffix = SCRIPT_DEBUG ? '' : '.min';
wp_enqueue_script( 'wpsight-listings-search-advanced', WPSIGHT_ADVANCED_SEARCH_PLUGIN_URL . '/assets/js/listings-search-advanced' . $suffix . '.js', array( 'jquery' ), WPSIGHT_ADVANCED_SEARCH_VERSION, true );
// Localize scripts
$data = array(
'cookie_path' => COOKIEPATH,
'cookie_search_advanced' => WPSIGHT_COOKIE_SEARCH_ADVANCED
);
wp_localize_script( 'wpsight-listings-search-advanced', 'wpsight_localize', $data );
}
/**
* advanced_search_fields()
*
* Register and enqueue scripts and css.
*
* @uses wpsight_sort_array_by_priority()
*
* @since 1.0.0
*/
public function get_advanced_search_fields( $fields_default ) {
// Set advanced form fields
$fields_advanced = array(
'min' => array(
'label' => __( 'Price (min)', 'wpcasa-advanced-search' ),
'key' => '_price',
'type' => 'text',
'data_compare' => '>=',
'data_type' => 'numeric',
'advanced' => true,
'class' => 'width-1-4',
'priority' => 90
),
'max' => array(
'label' => __( 'Price (max)', 'wpcasa-advanced-search' ),
'key' => '_price',
'type' => 'text',
'data_compare' => '<=',
'data_type' => 'numeric',
'advanced' => true,
'class' => 'width-1-4',
'priority' => 100
),
'orderby' => array(
'label' => __( 'Order by', 'wpcasa-advanced-search' ),
'type' => 'select',
'data' => array(
'date' => __( 'Date', 'wpcasa-advanced-search' ),
'price' => __( 'Price', 'wpcasa-advanced-search' ),
'title' => __( 'Title', 'wpcasa-advanced-search' )
),
'default' => 'date',
'advanced' => true,
'class' => 'width-1-4',
'priority' => 110
),
'order' => array(
'label' => __( 'Order', 'wpcasa-advanced-search' ),
'type' => 'select',
'data' => array(
'asc' => __( 'asc', 'wpcasa-advanced-search' ),
'desc' => __( 'desc', 'wpcasa-advanced-search' )
),
'default' => 'desc',
'advanced' => true,
'class' => 'width-1-4',
'priority' => 120
),
'feature' => array(
'label' => '',
'data' => array(
// get_terms() options
'taxonomy' => 'feature',
'orderby' => 'count',
'order' => 'DESC',
'operator' => 'AND', // can be OR
'number' => 8
),
'type' => 'taxonomy_checkbox',
'advanced' => true,
'class' => 'width-auto',
'priority' => 130
)
);
$fields_advanced = apply_filters( 'wpsight_get_advanced_search_fields', $fields_advanced, $fields_default );
// Merge default and advanced search
$fields = array_merge( $fields_default, $fields_advanced );
// Apply filter and sort array by priority
return wpsight_sort_array_by_priority( $fields );
}
}
// Initialize plugin on wpsight_init
add_action( 'wpsight_init', array( 'WPSight_Advanced_Search', 'init' ) );