PluginProbe
WPCasa – Real Estate for WordPress / 1.5.0
WPCasa – Real Estate for WordPress v1.5.0
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.0, at wpcasa.php

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