forked from wpsight/wpcasa
-
Notifications
You must be signed in to change notification settings - Fork 1
/
wpcasa.php
449 lines (354 loc) · 15.4 KB
/
wpcasa.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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
<?php
/**
* WPCasa
*
* @package WPCasa
* @author WPSight
* @copyright 2024 Kybernetik Services GmbH
* @license GPL-2.0-or-later
*
* @wordpress-plugin
* Plugin Name: WPCasa
* Plugin URI: https://wordpress.org/plugins/wpcasa/
* Description: Flexible WordPress plugin to create professional real estate websites and manage property listings with ease.
* Version: 1.2.13
* Requires at least: 6.2
* Requires PHP: 5.6
* Author: WPSight
* Author URI: https://wpcasa.com
* Text Domain: wpcasa
* Domain Path: /languages
* License: GPL v2 or later
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
require __DIR__ . '/vendor/autoload.php';
/**
* WPSight_Framework class
*/
class WPSight_Framework {
// Variables
public $admin;
public $post_types;
public $agents;
public $general;
public $helpers;
public $search;
public $meta_boxes;
public $admin_map_ui;
public $listings_map;
public $ninja_forms;
/**
* Constructor - get the plugin hooked in and ready
*/
public function __construct() {
// Define constants
if ( ! defined( 'WPSIGHT_NAME' ) )
define( 'WPSIGHT_NAME', 'WPCasa' );
if ( ! defined( 'WPSIGHT_DOMAIN' ) )
define( 'WPSIGHT_DOMAIN', 'wpcasa' );
if ( ! defined( 'WPSIGHT_SHOP_URL' ) )
define( 'WPSIGHT_SHOP_URL', 'https://wpcasa.com' );
if ( ! defined( 'WPSIGHT_AUTHOR' ) )
define( 'WPSIGHT_AUTHOR', 'WPSight' );
if( ! function_exists( 'get_plugin_data' ) ) {
require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
}
$plugin_data = get_file_data(__FILE__, array( 'Version' => 'Version' ), false);
define( 'WPSIGHT_VERSION', $plugin_data[ 'Version' ] );
define( 'WPSIGHT_PLUGIN_DIR', untrailingslashit( plugin_dir_path( __FILE__ ) ) );
define( 'WPSIGHT_PLUGIN_URL', untrailingslashit( plugins_url( basename( plugin_dir_path( __FILE__ ) ), basename( __FILE__ ) ) ) );
// Cookie constants
define( 'WPSIGHT_COOKIE_SEARCH_QUERY', WPSIGHT_DOMAIN . '_search_query' );
define( 'WPSIGHT_COOKIE_SEARCH_MAP', WPSIGHT_DOMAIN . '_search_map' );
// Include functions
include( WPSIGHT_PLUGIN_DIR . '/functions/wpsight-general.php' );
include( WPSIGHT_PLUGIN_DIR . '/functions/wpsight-template.php' );
include( WPSIGHT_PLUGIN_DIR . '/functions/wpsight-listings.php' );
include( WPSIGHT_PLUGIN_DIR . '/functions/wpsight-agents.php' );
include( WPSIGHT_PLUGIN_DIR . '/functions/wpsight-search.php' );
include( WPSIGHT_PLUGIN_DIR . '/functions/wpsight-helpers.php' );
include( WPSIGHT_PLUGIN_DIR . '/functions/wpsight-admin.php' );
include( WPSIGHT_PLUGIN_DIR . '/functions/wpsight-meta-boxes.php' );
// Include classes
include( WPSIGHT_PLUGIN_DIR . '/includes/class-wpsight-post-types.php' );
include( WPSIGHT_PLUGIN_DIR . '/includes/class-wpsight-api.php' );
include( WPSIGHT_PLUGIN_DIR . '/includes/class-wpsight-geocode.php' );
include( WPSIGHT_PLUGIN_DIR . '/includes/class-wpsight-listings.php' );
include( WPSIGHT_PLUGIN_DIR . '/includes/class-wpsight-agents.php' );
include( WPSIGHT_PLUGIN_DIR . '/includes/class-wpsight-general.php' );
include( WPSIGHT_PLUGIN_DIR . '/includes/class-wpsight-helpers.php' );
include( WPSIGHT_PLUGIN_DIR . '/includes/class-wpsight-search.php' );
include( WPSIGHT_PLUGIN_DIR . '/includes/class-wpsight-meta-boxes.php' );
include( WPSIGHT_PLUGIN_DIR . '/includes/class-wpsight-template.php' );
// Include shortcodes
include( WPSIGHT_PLUGIN_DIR . '/includes/shortcodes/class-wpsight-shortcodes.php' );
// Include admin class
include( WPSIGHT_PLUGIN_DIR . '/includes/admin/class-wpsight-admin.php' );
require_once(ABSPATH . 'wp-admin/includes/plugin.php');
// TODO: delete till wpcasa 2.0
if ( is_plugin_active( 'wpcasa-admin-map-ui/wpcasa-admin-map-ui.php' ) ) {
deactivate_plugins( '/wpcasa-admin-map-ui/wpcasa-admin-map-ui.php' );
}
// TODO: delete check till wpcasa 2.0
if ( ! is_plugin_active( 'wpcasa-admin-map-ui/wpcasa-admin-map-ui.php' ) ) {
if ( ! class_exists( 'WPSight_Admin_Map_UI' ) ) {
include_once( WPSIGHT_PLUGIN_DIR . '/includes/admin-map-ui/class-wpsight-admin-map-ui.php' );
}
}
// TODO: delete till wpcasa 2.0
if ( is_plugin_active( 'wpcasa-listings-map/wpcasa-listings-map.php' ) ) {
deactivate_plugins( '/wpcasa-listings-map/wpcasa-listings-map.php' );
}
// TODO: delete check till wpcasa 2.0
if ( ! is_plugin_active( 'wpcasa-listings-map/wpcasa-listings-map.php' ) ) {
if ( ! class_exists( 'WPSight_Listings_Map' ) ) {
include( WPSIGHT_PLUGIN_DIR . '/includes/listings-map/class-wpsight-listings-map.php' );
}
}
// Only instantiate admin class when in admin area
if ( is_admin() )
$this->admin = new WPSight_Admin();
// Init classes
$this->post_types = new WPSight_Post_Type_Listing();
$this->agents = new WPSight_Agents();
$this->general = new WPSight_General();
$this->helpers = new WPSight_Helpers();
$this->search = new WPSight_Search();
$this->meta_boxes = new WPSight_Meta_Boxes();
// Activation
register_activation_hook( basename( dirname( __FILE__ ) ) . '/' . basename( __FILE__ ), [ $this->post_types, 'register_post_type_listing' ], 10 );
register_activation_hook( basename( dirname( __FILE__ ) ) . '/' . basename( __FILE__ ), function() { include_once('includes/class-wpsight-install.php'); }, 10 );
register_activation_hook( basename( dirname( __FILE__ ) ) . '/' . basename( __FILE__ ), 'flush_rewrite_rules', 15 );
register_activation_hook( basename( dirname( __FILE__ ) ) . '/' . basename( __FILE__ ), [ $this, 'activation' ] );
// Actions
add_action( 'plugins_loaded', [ $this, 'load_plugin_textdomain' ] );
add_action( 'switch_theme', [ $this->post_types, 'register_post_type_listing' ], 10 );
add_action( 'switch_theme', 'flush_rewrite_rules', 15 );
add_action( 'wp_enqueue_scripts', [ $this, 'frontend_scripts' ] );
// Init action for add-ons to hook in
do_action_ref_array( 'wpsight_init', [ &$this ] );
}
/**
* load_plugin_textdomain()
*
* Set up the text domain for the plugin
* and load language files.
*
* @uses plugin_basename()
* @uses load_plugin_textdomain()
*
* @since 1.0.0
*/
public function load_plugin_textdomain() {
load_plugin_textdomain( 'wpcasa', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
}
/**
* frontend_scripts()
*
* Register and enqueue scripts and css.
*
* @uses wp_enqueue_script()
* @uses wp_localize_script()
* @uses wp_enqueue_style()
* @uses wpsight_get_option()
*
* @since 1.0.0
*/
public function frontend_scripts() {
// Enqueue jQuery
wp_enqueue_script( 'jquery' );
// Script debugging?
$suffix = SCRIPT_DEBUG ? '' : '.min';
wp_enqueue_script( 'jquery-tiptip', WPSIGHT_PLUGIN_URL . '/assets/js/jquery.tipTip' . $suffix . '.js', [ 'jquery' ], '1.3', true );
wp_enqueue_script( 'jquery-cookie', WPSIGHT_PLUGIN_URL . '/assets/js/jquery.cookie.js', [ 'jquery' ], '1.4.1', true );
wp_enqueue_script( 'wpsight-listings-search', WPSIGHT_PLUGIN_URL . '/assets/js/wpsight-listings-search.js', [ 'jquery' ], WPSIGHT_VERSION, true );
// Localize scripts
$data = [
'cookie_path' => COOKIEPATH,
'cookie_search_query' => WPSIGHT_COOKIE_SEARCH_QUERY
];
wp_localize_script( 'wpsight-listings-search', 'wpsight_localize', $data );
// Enqueue Google Maps (optionally with API key)
if( true == apply_filters( 'wpsight_google_maps', true ) ) {
$api_key = wpsight_get_option( 'google_maps_api_key' );
$api_url = $api_key ? add_query_arg( [ 'key' => $api_key ], '//maps.googleapis.com/maps/api/js' ) : '//maps.googleapis.com/maps/api/js';
wp_enqueue_script( 'wpsight-map-googleapi', apply_filters( 'wpsight_google_maps_endpoint', esc_url( $api_url ), $api_key ), null, WPSIGHT_VERSION, array( 'in_footer' => false ) );
}
if( true == apply_filters('wpsight_css', true) && wpsight_get_option('listings_css' ) ) {
//if ( is_singular( 'listing' ) ) {
wp_enqueue_style( 'wpsight', WPSIGHT_PLUGIN_URL . '/assets/css/wpsight' . $suffix . '.css', '', WPSIGHT_VERSION);
if ( is_rtl() )
wp_enqueue_style( 'wpsight-rtl', WPSIGHT_PLUGIN_URL . '/assets/css/wpsight-rtl' . $suffix . '.css', '', WPSIGHT_VERSION );
//}
}
}
/**
* activation()
*
* Callback for register_activation_hook
* to create a default listings page with
* the [wpsight_listings] shortcode and
* to create some default options to be
* used by this plugin.
*
* @uses wpsight_get_option()
* @uses wp_insert_post()
* @uses wpsight_add_option()
*
* @since 1.0.0
*/
public function activation() {
// Create listings page
$page_data = [
'post_title' => _x( 'Listings', 'listings page title', 'wpcasa' ),
'post_content' => '[wpsight_listings]',
'post_type' => 'page',
'post_status' => 'publish',
'comment_status' => 'closed',
'ping_status' => 'closed'
];
$page_id = ! wpsight_get_option( 'listings_page' ) ? wp_insert_post( $page_data ) : false;
// Add some default options
$options = [
'listings_page' => $page_id,
'listing_id' => __( 'ID-', 'wpcasa' ),
'measurement_unit' => 'm2',
'currency' => 'usd',
'currency_symbol' => 'before',
'currency_separator' => 'comma',
'date_format' => get_option( 'date_format' ),
'listings_css' => '1'
];
// Add default standard features
foreach ( wpsight_details() as $option => $value )
$options[ $option ] = [ 'label' => $value['label'], 'unit' => $value['unit'] ];
// Add default rental periods
foreach ( wpsight_rental_periods() as $option => $value )
$options[ $option ] = $value;
foreach( $options as $option => $value ) {
if( wpsight_get_option( $option ) )
continue;
wpsight_add_option( $option, $value );
}
}
}
/**
* wpsight()
*
* The main function responsible for returning the one true wpsight Instance to functions everywhere.
* Use this function like you would use a global variable, except without needing to declare the global.
*
* Example: <?php $wpsight = wpsight(); ?>
*
* @return object|bool $wpsight
*/
function wpsight() {
global $wpsight;
// Don't activate plugin add-ons if theme still active
if( wp_get_theme()->template == 'wpcasa' ) {
remove_all_actions( 'wpsight_init' );
return false;
}
if ( ! isset( $wpsight ) )
$wpsight = new WPSight_Framework();
return $wpsight;
}
wpsight();
/**
* wpsight_admin_notice_wpcasa()
*
* Make sure users first deactivate
* the old WPCasa theme version.
* Display error message if it is
* still activated.
*
* @uses wp_get_theme()
*
* @since 1.0.0
*/
function wpsight_admin_notice_wpcasa() {
if( wp_get_theme()->template != 'wpcasa' )
return;
$error_notice = '<div class="error"><p>' . __( 'Please make sure to <strong>deactivate the WPCasa theme</strong> in order to use the WPCasa plugin version. For more information about how to switch please <a href="http://docs.wpsight.com/article/switching-from-theme-version/" target="_blank">read our docs</a>.', 'wpcasa' ) . '</p></div>';
echo wp_kses( $error_notice, array( 'div' => array( 'class' => array() ), 'p' => array(), 'strong' => array(), 'a' => array( 'href' => array() ) ) );
}
add_action( 'admin_notices', 'wpsight_admin_notice_wpcasa' );
/**
* wpsight_admin_plugins_delete_notice()
*
* Make sure users awera
* that WPCasa Listing Map and
* WPCasa admin map ui plugins
* can be deleted
*
* @since 1.2.0
*/
function wpsight_admin_plugins_delete_notice() {
$admin_map_ui = WP_PLUGIN_DIR . '/wpcasa-admin-map-ui/wpcasa-admin-map-ui.php';
$listing_map = WP_PLUGIN_DIR . '/wpcasa-listings-map/wpcasa-listings-map.php';
$plugin_name = '';
$count = 1;
if( file_exists( $admin_map_ui ) ) {
$plugin_name .= '<strong>WPCasa Admin Map UI</strong>';
}
if( file_exists( $listing_map ) ) {
if( !empty( $plugin_name ) ) {
$plugin_name .= ' ' . __( 'and' , 'wpcasa' ) . ' ';
$count = 2;
}
$plugin_name .= '<strong>WPCasa Listings Map</strong>';
}
if ( ! empty( $plugin_name ) ) {
$message = sprintf(
// Translators: %s is plugin name
_n(
'%s has been discontinued. Functionality of the plugin has been integrated in WPCasa as of 1.2.0.</br>Feel free to remove the plugin.',
'%s has been discontinued. Functionality of both plugins has been integrated in WPCasa as of 1.2.0.</br>Feel free to remove both of those plugins.',
$count, 'wpcasa' ),
$plugin_name );
echo wp_kses( '<div class="notice notice-warning my-dismiss-notice is-dismissible"><p>' . $message . '</p></div>', array( 'div' => array( 'class' => array() ), 'p' => array() ) );
}
}
add_action( 'admin_notices', 'wpsight_admin_plugins_delete_notice' );
/**
*
* Redirect after single wpcasa activatation
* Prevent multiple activation redirect
*
* @since 1.2.0
*/
register_activation_hook(__FILE__, 'wpcasa_plugin_activate');
function wpcasa_plugin_activate() {
add_option('wpcasa_do_activation_redirect', true);
}
function wpcasa_activation_redirect() {
if (get_option('wpcasa_do_activation_redirect', false)) {
delete_option('wpcasa_do_activation_redirect');
if ( !isset($_GET['activate-multi']) ) {
wp_safe_redirect( admin_url( 'index.php?page=wpsight-settings' ));
exit();
}
}
}
add_action('admin_init', 'wpcasa_activation_redirect');
/**
* Adds plugin upgrade notification
*
* @since 1.2.11
*/
function wpcasa_plugin_update_message( $data, $response ) {
if( isset( $data[ 'upgrade_notice'] ) ) {
$upgrade_notice = str_replace('<p>', '<span style="margin-top: 5px">', wpautop( $data['upgrade_notice'] ) );
$upgrade_notice = str_replace('</p>', '</span><br>', $upgrade_notice );
printf(
'</p><p style="background-color: #d63638; padding: 10px; color: #f9f9f9; margin-top: 10px"><span style="margin-left: -25px"><strong>%s:</strong></span><br>%s',
esc_html__( 'Important Upgrade Notice', 'wpcasa'),
$upgrade_notice
);
}
}
add_action( 'in_plugin_update_message-wpcasa/wpcasa.php', 'wpcasa_plugin_update_message', 10, 2 );