PluginProbe
WPCasa – Real Estate for WordPress / 1.5.3
WPCasa – Real Estate for WordPress v1.5.3
1.5.5 1.5.4 1.5.3 1.5.2 1.5.1 1.5.1.1 trunk 1.2.0 1.2.1 1.2.10 1.2.10.1 1.2.11 1.2.12 1.2.13 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.2.9.1 1.2.9.2 1.3.0 All 31 releases
wpcasa / wpcasa.php

wpcasa.php in WPCasa – Real Estate for WordPress 1.5.3, at wpcasa.php

513 lines 17.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * WPCasa
4 *
5 * @package WPCasa
6 * @author WPSight
7 * @copyright 2026 Kybernetik Services LLC
8 * @license GPL-2.0-or-later
9 *
10 * @wordpress-plugin
11 * Plugin Name: WPCasa - Real Estate for WordPress
12 * Plugin URI: https://wordpress.org/plugins/wpcasa/
13 * Description: Flexible WordPress plugin to create professional real estate websites and manage property listings with ease.
14 * Version: 1.5.3
15 * Requires at least: 6.2
16 * Requires PHP: 7.2
17 * Author: WPSight
18 * Author URI: https://wpcasa.com
19 * Text Domain: wpcasa
20 * License: GPL v2 or later
21 * License URI: http://www.gnu.org/licenses/gpl-2.0.txt
22 */
23
24 // Exit if accessed directly
25 if ( ! defined( 'ABSPATH' ) ) {
26 exit;
27 }
28
29 require __DIR__ . '/vendor/autoload.php';
30
31 /**
32 * WPSight_Framework class
33 */
34 class WPSight_Framework {
35
36 // Variables
37 public $admin;
38 public $post_types;
39 public $agents;
40 public $general;
41 public $helpers;
42 public $search;
43 public $meta_boxes;
44
45 // Add-ons
46 public $admin_map_ui;
47 public $listings_map;
48 public $ninja_forms;
49 public $advanced_search;
50 public $contact_form_7;
51 public $listing_pdf;
52 public $currency_converter;
53 public $dashboard;
54 public $expire_listings;
55 public $favorites;
56 public $featured_listings;
57 public $gravityforms;
58 public $legacy;
59 public $list_agents;
60 public $listing_labels;
61 public $polylang;
62 public $pricing_tables;
63 public $energy_efficiency;
64 public $mortgage_calculator;
65 public $elementor;
66 public $blocks;
67
68 /**
69 * Constructor - get the plugin hooked in and ready
70 */
71 public function __construct() {
72
73 // Define constants
74
75 if ( ! defined( 'WPSIGHT_NAME' ) )
76 define( 'WPSIGHT_NAME', 'WPCasa' );
77
78 if ( ! defined( 'WPSIGHT_DOMAIN' ) )
79 define( 'WPSIGHT_DOMAIN', 'wpcasa' );
80
81 if ( ! defined( 'WPSIGHT_SHOP_URL' ) )
82 define( 'WPSIGHT_SHOP_URL', 'https://wpcasa.com' );
83
84 if ( ! defined( 'WPSIGHT_AUTHOR' ) )
85 define( 'WPSIGHT_AUTHOR', 'WPSight' );
86
87 if( ! function_exists( 'get_plugin_data' ) ) {
88 require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
89 }
90 $plugin_data = get_plugin_data( __FILE__, false, false );
91
92 define( 'WPSIGHT_VERSION', $plugin_data[ 'Version' ] );
93 define( 'WPSIGHT_PLUGIN_DIR', untrailingslashit( plugin_dir_path( __FILE__ ) ) );
94 define( 'WPSIGHT_PLUGIN_URL', untrailingslashit( plugins_url( basename( plugin_dir_path( __FILE__ ) ), basename( __FILE__ ) ) ) );
95
96 // Cookie constants
97
98 define( 'WPSIGHT_COOKIE_SEARCH_QUERY', WPSIGHT_DOMAIN . '_search_query' );
99 define( 'WPSIGHT_COOKIE_SEARCH_MAP', WPSIGHT_DOMAIN . '_search_map' );
100
101 // Include functions
102
103 include( WPSIGHT_PLUGIN_DIR . '/functions/wpsight-general.php' );
104 include( WPSIGHT_PLUGIN_DIR . '/functions/wpsight-template.php' );
105 include( WPSIGHT_PLUGIN_DIR . '/functions/wpsight-listings.php' );
106 include( WPSIGHT_PLUGIN_DIR . '/functions/wpsight-agents.php' );
107 include( WPSIGHT_PLUGIN_DIR . '/functions/wpsight-search.php' );
108 include( WPSIGHT_PLUGIN_DIR . '/functions/wpsight-helpers.php' );
109 include( WPSIGHT_PLUGIN_DIR . '/functions/wpsight-admin.php' );
110 include( WPSIGHT_PLUGIN_DIR . '/functions/wpsight-meta-boxes.php' );
111
112 // Include classes
113
114 include( WPSIGHT_PLUGIN_DIR . '/includes/class-wpsight-post-types.php' );
115 include( WPSIGHT_PLUGIN_DIR . '/includes/class-wpsight-api.php' );
116 include( WPSIGHT_PLUGIN_DIR . '/includes/class-wpsight-geocode.php' );
117 include( WPSIGHT_PLUGIN_DIR . '/includes/class-wpsight-listings.php' );
118 include( WPSIGHT_PLUGIN_DIR . '/includes/class-wpsight-agents.php' );
119 include( WPSIGHT_PLUGIN_DIR . '/includes/class-wpsight-general.php' );
120 include( WPSIGHT_PLUGIN_DIR . '/includes/class-wpsight-helpers.php' );
121 include( WPSIGHT_PLUGIN_DIR . '/includes/class-wpsight-search.php' );
122 include( WPSIGHT_PLUGIN_DIR . '/includes/class-wpsight-meta-boxes.php' );
123 include( WPSIGHT_PLUGIN_DIR . '/includes/class-wpsight-template.php' );
124
125 // Include shortcodes
126 include( WPSIGHT_PLUGIN_DIR . '/includes/shortcodes/class-wpsight-shortcodes.php' );
127
128 // Include admin class
129 include( WPSIGHT_PLUGIN_DIR . '/includes/admin/class-wpsight-admin.php' );
130
131 require_once(ABSPATH . 'wp-admin/includes/plugin.php');
132
133 // TODO: delete till wpcasa 2.0
134 if ( is_plugin_active( 'wpcasa-admin-map-ui/wpcasa-admin-map-ui.php' ) ) {
135 deactivate_plugins( '/wpcasa-admin-map-ui/wpcasa-admin-map-ui.php' );
136 }
137
138 // TODO: delete check till wpcasa 2.0
139 if ( ! is_plugin_active( 'wpcasa-admin-map-ui/wpcasa-admin-map-ui.php' ) ) {
140 if ( ! class_exists( 'WPSight_Admin_Map_UI' ) ) {
141 include_once( WPSIGHT_PLUGIN_DIR . '/includes/admin-map-ui/class-wpsight-admin-map-ui.php' );
142 }
143 }
144
145 // TODO: delete till wpcasa 2.0
146 if ( is_plugin_active( 'wpcasa-listings-map/wpcasa-listings-map.php' ) ) {
147 deactivate_plugins( '/wpcasa-listings-map/wpcasa-listings-map.php' );
148 }
149
150 // TODO: delete check till wpcasa 2.0
151 if ( ! is_plugin_active( 'wpcasa-listings-map/wpcasa-listings-map.php' ) ) {
152 if ( ! class_exists( 'WPSight_Listings_Map' ) ) {
153 include( WPSIGHT_PLUGIN_DIR . '/includes/listings-map/class-wpsight-listings-map.php' );
154 }
155 }
156
157 // Only instantiate admin class when in admin area
158 if ( is_admin() )
159 $this->admin = new WPSight_Admin();
160
161 // Init classes
162 $this->post_types = new WPSight_Post_Type_Listing();
163 $this->agents = new WPSight_Agents();
164 $this->general = new WPSight_General();
165 $this->helpers = new WPSight_Helpers();
166 $this->search = new WPSight_Search();
167 $this->meta_boxes = new WPSight_Meta_Boxes();
168
169 // Activation
170
171 register_activation_hook( basename( dirname( __FILE__ ) ) . '/' . basename( __FILE__ ), [ $this->post_types, 'register_post_type_listing' ], 10 );
172 register_activation_hook( basename( dirname( __FILE__ ) ) . '/' . basename( __FILE__ ), array( 'WPSight_Agents', 'init_user_roles' ), 10 );
173 register_activation_hook( basename( dirname( __FILE__ ) ) . '/' . basename( __FILE__ ), function() { include_once('includes/class-wpsight-install.php'); }, 10 );
174 register_activation_hook( basename( dirname( __FILE__ ) ) . '/' . basename( __FILE__ ), 'flush_rewrite_rules', 15 );
175 register_activation_hook( basename( dirname( __FILE__ ) ) . '/' . basename( __FILE__ ), [ $this, 'activation' ] );
176 register_deactivation_hook( basename( dirname( __FILE__ ) ) . '/' . basename( __FILE__ ), array( 'WPSight_Agents', 'remove_user_roles' ) );
177
178 // Actions
179
180 add_action( 'switch_theme', [ $this->post_types, 'register_post_type_listing' ], 10 );
181 add_action( 'switch_theme', 'flush_rewrite_rules', 15 );
182 add_action( 'wp_enqueue_scripts', [ $this, 'frontend_scripts' ] );
183
184 // Init action for add-ons to hook in
185 do_action_ref_array( 'wpsight_init', [ &$this ] );
186
187 }
188
189 /**
190 * setChildClass()
191 *
192 * Set up the child plugin class
193 *
194 * @param $name
195 * @param $addon_object
196 *
197 * @since 1.2.13
198 */
199
200 public function setChildClass( $name, $addon_object ) {
201 $this->{$name} = $addon_object;
202 }
203
204 /**
205 * frontend_scripts()
206 *
207 * Register and enqueue scripts and css.
208 *
209 * @uses wp_enqueue_script()
210 * @uses wp_localize_script()
211 * @uses wp_enqueue_style()
212 * @uses wpsight_get_option()
213 *
214 * @since 1.0.0
215 */
216 public function frontend_scripts() {
217 // Enqueue jQuery
218 wp_enqueue_script( 'jquery' );
219
220 // Script debugging?
221 $suffix = SCRIPT_DEBUG ? '' : '.min';
222
223
224 wp_enqueue_script( 'jquery-tiptip', WPSIGHT_PLUGIN_URL . '/assets/js/jquery.tipTip' . $suffix . '.js', [ 'jquery' ], '1.3', true );
225 wp_enqueue_script( 'jquery-cookie', WPSIGHT_PLUGIN_URL . '/assets/js/jquery.cookie.js', [ 'jquery' ], '1.4.1', true );
226 wp_enqueue_script( 'wpsight-listings-search', WPSIGHT_PLUGIN_URL . '/assets/js/wpsight-listings-search.js', [ 'jquery' ], WPSIGHT_VERSION, true );
227
228 // Localize scripts
229 $data = [
230 'cookie_path' => COOKIEPATH,
231 'cookie_search_query' => WPSIGHT_COOKIE_SEARCH_QUERY
232 ];
233
234 wp_localize_script( 'wpsight-listings-search', 'wpsight_localize', $data );
235
236 // Register the Google Maps API loader when a key is available.
237 $api_key = wpsight_get_option( 'google_maps_api_key' );
238
239 if ( ! empty( $api_key ) && true === apply_filters( 'wpsight_google_maps', true ) ) {
240 $api_url = add_query_arg(
241 array(
242 'key' => $api_key,
243 'loading' => 'async',
244 'callback' => 'wpsightGoogleMapsApiReady',
245 ),
246 '//maps.googleapis.com/maps/api/js'
247 );
248
249 wp_register_script(
250 'wpsight-google-maps-api-loader',
251 WPSIGHT_PLUGIN_URL . '/assets/js/wpsight-google-maps-api-loader' . $suffix . '.js',
252 array(),
253 WPSIGHT_VERSION,
254 array( 'in_footer' => false )
255 );
256
257 wp_localize_script(
258 'wpsight-google-maps-api-loader',
259 'wpsightGoogleMapsApiLoader',
260 array(
261 'googleApiUrl' => apply_filters( 'wpsight_google_maps_endpoint', $api_url, $api_key ),
262 )
263 );
264
265 wp_enqueue_script( 'wpsight-google-maps-api-loader' );
266 }
267
268 if( true == apply_filters('wpsight_css', true) && wpsight_get_option('listings_css' ) ) {
269
270 //if ( is_singular( 'listing' ) ) {
271 wp_enqueue_style( 'wpsight', WPSIGHT_PLUGIN_URL . '/assets/css/wpsight' . $suffix . '.css', '', WPSIGHT_VERSION);
272
273 if ( is_rtl() )
274 wp_enqueue_style( 'wpsight-rtl', WPSIGHT_PLUGIN_URL . '/assets/css/wpsight-rtl' . $suffix . '.css', '', WPSIGHT_VERSION );
275 //}
276
277 }
278
279 }
280
281 /**
282 * activation()
283 *
284 * Callback for register_activation_hook
285 * to create a default listings page with
286 * the [wpsight_listings] shortcode and
287 * to create some default options to be
288 * used by this plugin.
289 *
290 * @uses wpsight_get_option()
291 * @uses wp_insert_post()
292 * @uses wpsight_add_option()
293 *
294 * @since 1.0.0
295 */
296
297 public function activation() {
298
299 // Create listings page
300
301 $page_data = [
302 'post_title' => _x( 'Listings', 'listings page title', 'wpcasa' ),
303 'post_content' => '[wpsight_listings]',
304 'post_type' => 'page',
305 'post_status' => 'publish',
306 'comment_status' => 'closed',
307 'ping_status' => 'closed'
308 ];
309
310 $page_id = ! wpsight_get_option( 'listings_page' ) ? wp_insert_post( $page_data ) : false;
311
312 // Add some default options
313
314 $options = [
315 'listings_page' => $page_id,
316 'listing_id' => __( 'ID-', 'wpcasa' ),
317 'measurement_unit' => 'm2',
318 'currency' => 'usd',
319 'currency_symbol' => 'before',
320 'currency_separator' => 'comma',
321 'date_format' => get_option( 'date_format' ),
322 'listings_css' => '1',
323 'review_notice_timestamp' => current_time( 'timestamp' ),
324 ];
325
326 // Add default standard features
327 foreach ( wpsight_details() as $option => $value )
328 $options[ $option ] = [ 'label' => $value['label'], 'unit' => $value['unit'] ];
329
330 // Add default rental periods
331 foreach ( wpsight_rental_periods() as $option => $value )
332 $options[ $option ] = $value;
333
334 foreach( $options as $option => $value ) {
335
336 if( wpsight_get_option( $option ) )
337 continue;
338
339 wpsight_add_option( $option, $value );
340
341 }
342
343 }
344 }
345
346 /**
347 * wpsight()
348 *
349 * The main function responsible for returning the one true wpsight Instance to functions everywhere.
350 * Use this function like you would use a global variable, except without needing to declare the global.
351 *
352 * Example: <?php $wpsight = wpsight(); ?>
353 *
354 * @return object|bool $wpsight
355 */
356 function wpsight() {
357 global $wpsight;
358
359 // Don't activate plugin add-ons if theme still active
360
361 if( wp_get_theme()->template == 'wpcasa' ) {
362 remove_all_actions( 'wpsight_init' );
363 return false;
364 }
365
366 if ( ! isset( $wpsight ) )
367 $wpsight = new WPSight_Framework();
368
369 return $wpsight;
370 }
371 wpsight();
372
373 /**
374 * wpsight_admin_notice_wpcasa()
375 *
376 * Make sure users first deactivate
377 * the old WPCasa theme version.
378 * Display error message if it is
379 * still activated.
380 *
381 * @uses wp_get_theme()
382 *
383 * @since 1.0.0
384 */
385 function wpsight_admin_notice_wpcasa() {
386
387 if( wp_get_theme()->template != 'wpcasa' )
388 return;
389
390 $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>';
391 echo wp_kses( $error_notice, array( 'div' => array( 'class' => array() ), 'p' => array(), 'strong' => array(), 'a' => array( 'href' => array() ) ) );
392 }
393 add_action( 'admin_notices', 'wpsight_admin_notice_wpcasa' );
394
395 /**
396 * wpsight_admin_plugins_delete_notice()
397 *
398 * Make sure users awera
399 * that WPCasa Listing Map and
400 * WPCasa admin map ui plugins
401 * can be deleted
402 *
403 * @since 1.2.0
404 */
405 function wpsight_admin_plugins_delete_notice() {
406
407 $admin_map_ui = WP_PLUGIN_DIR . '/wpcasa-admin-map-ui/wpcasa-admin-map-ui.php';
408 $listing_map = WP_PLUGIN_DIR . '/wpcasa-listings-map/wpcasa-listings-map.php';
409
410 $plugin_name = '';
411 $count = 1;
412
413 //if( file_exists( $admin_map_ui ) ) {
414 if( in_array( $admin_map_ui, apply_filters( 'active_plugins', get_option( 'active_plugins') ) ) ) {
415
416 $plugin_name .= '<strong>WPCasa Admin Map UI</strong>';
417
418 }
419
420 //if( file_exists( $listing_map ) ) {
421 if( in_array( $listing_map, apply_filters( 'active_plugins', get_option( 'active_plugins') ) ) ) {
422
423 if( !empty( $plugin_name ) ) {
424
425 $plugin_name .= ' ' . __( 'and' , 'wpcasa' ) . ' ';
426
427 $count = 2;
428
429 }
430
431 $plugin_name .= '<strong>WPCasa Listings Map</strong>';
432
433 }
434
435 if ( ! empty( $plugin_name ) ) {
436 $message = sprintf(
437 // Translators: %s is plugin name
438 _n(
439 '%s has been discontinued. The Functionality of the plugin has been integrated in WPCasa as of 1.2.0.</br>Feel free to remove the plugin.',
440 '%s has been discontinued. The Functionality of both plugins has been integrated in WPCasa as of 1.2.0.</br>Feel free to remove both of those plugins.',
441 $count, 'wpcasa' ),
442 $plugin_name );
443
444 echo wp_kses( '<div class="notice notice-warning my-dismiss-notice is-dismissible"><p>' . $message . '</p></div>', array( 'div' => array( 'class' => array() ), 'p' => array() ) );
445
446 }
447
448 }
449 add_action( 'admin_notices', 'wpsight_admin_plugins_delete_notice' );
450
451 /**
452 *
453 * Redirect after single wpcasa activatation
454 * Prevent multiple activation redirect
455 *
456 * @since 1.2.0
457 */
458 function wpcasa_plugin_activate() {
459 add_option('wpcasa_do_activation_redirect', true);
460 }
461 register_activation_hook(__FILE__, 'wpcasa_plugin_activate');
462
463 function wpcasa_activation_redirect() {
464 if (get_option('wpcasa_do_activation_redirect', false)) {
465 delete_option('wpcasa_do_activation_redirect');
466 if ( !isset($_GET['activate-multi']) ) {
467 wp_safe_redirect( admin_url( 'index.php?page=wpsight-settings' ));
468 exit();
469 }
470 }
471 }
472 add_action( 'admin_init', 'wpcasa_activation_redirect' );
473
474 /**
475 * Adds plugin upgrade notification
476 *
477 * @since 1.2.11
478 */
479 function wpcasa_plugin_update_message( $data, $response ) {
480
481 if( isset( $data[ 'upgrade_notice'] ) ) {
482
483 $upgrade_notice = str_replace('<p>', '<span style="margin-top: 5px">', wpautop( $data['upgrade_notice'] ) );
484 $upgrade_notice = str_replace('</p>', '</span><br>', $upgrade_notice );
485
486 printf(
487 '</p><p style="background-color: #d63638; padding: 10px; color: #f9f9f9; margin-top: 10px"><span style="margin-left: -25px"><strong>%s:</strong></span><br>%s',
488 esc_html__( 'Important Upgrade Notice', 'wpcasa'),
489 $upgrade_notice
490 );
491 }
492
493 }
494 add_action( 'in_plugin_update_message-wpcasa/wpcasa.php', 'wpcasa_plugin_update_message', 10, 2 );
495
496 function wpcasa_settings_value_change() {
497 $wpcasa_settings = get_option('wpcasa');
498 $thousand_separator = $wpcasa_settings['currency_separator'] ?? '';
499
500 if ( ( 'comma' === $thousand_separator ) || ( 'dot' === $thousand_separator ) ) {
501 switch ( $thousand_separator ) {
502 case 'comma':
503 $wpcasa_settings['currency_separator'] = ',';
504 break;
505 case 'dot':
506 $wpcasa_settings['currency_separator'] = '.';
507 break;
508 }
509 update_option( 'wpcasa', $wpcasa_settings );
510 }
511 }
512 add_action( 'admin_init', 'wpcasa_settings_value_change' );
513