PluginProbe
WPCasa – Real Estate for WordPress / 1.4.3
WPCasa – Real Estate for WordPress v1.4.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.4.3, at wpcasa.php

488 lines 16.2 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 2025 Kybernetik Services GmbH
8 * @license GPL-2.0-or-later
9 *
10 * @wordpress-plugin
11 * Plugin Name: WPCasa
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.4.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
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__ ), function() { include_once('includes/class-wpsight-install.php'); }, 10 );
172 register_activation_hook( basename( dirname( __FILE__ ) ) . '/' . basename( __FILE__ ), 'flush_rewrite_rules', 15 );
173 register_activation_hook( basename( dirname( __FILE__ ) ) . '/' . basename( __FILE__ ), [ $this, 'activation' ] );
174
175 // Actions
176
177 add_action( 'switch_theme', [ $this->post_types, 'register_post_type_listing' ], 10 );
178 add_action( 'switch_theme', 'flush_rewrite_rules', 15 );
179 add_action( 'wp_enqueue_scripts', [ $this, 'frontend_scripts' ] );
180
181 // Init action for add-ons to hook in
182 do_action_ref_array( 'wpsight_init', [ &$this ] );
183
184 }
185
186 /**
187 * setChildClass()
188 *
189 * Set up the child plugin class
190 *
191 * @param $name
192 * @param $addon_object
193 *
194 * @since 1.2.13
195 */
196
197 public function setChildClass( $name, $addon_object ) {
198 $this->{$name} = $addon_object;
199 }
200
201 /**
202 * frontend_scripts()
203 *
204 * Register and enqueue scripts and css.
205 *
206 * @uses wp_enqueue_script()
207 * @uses wp_localize_script()
208 * @uses wp_enqueue_style()
209 * @uses wpsight_get_option()
210 *
211 * @since 1.0.0
212 */
213 public function frontend_scripts() {
214 // Enqueue jQuery
215 wp_enqueue_script( 'jquery' );
216
217 // Script debugging?
218 $suffix = SCRIPT_DEBUG ? '' : '.min';
219
220
221 wp_enqueue_script( 'jquery-tiptip', WPSIGHT_PLUGIN_URL . '/assets/js/jquery.tipTip' . $suffix . '.js', [ 'jquery' ], '1.3', true );
222 wp_enqueue_script( 'jquery-cookie', WPSIGHT_PLUGIN_URL . '/assets/js/jquery.cookie.js', [ 'jquery' ], '1.4.1', true );
223 wp_enqueue_script( 'wpsight-listings-search', WPSIGHT_PLUGIN_URL . '/assets/js/wpsight-listings-search.js', [ 'jquery' ], WPSIGHT_VERSION, true );
224
225 // Localize scripts
226 $data = [
227 'cookie_path' => COOKIEPATH,
228 'cookie_search_query' => WPSIGHT_COOKIE_SEARCH_QUERY
229 ];
230
231 wp_localize_script( 'wpsight-listings-search', 'wpsight_localize', $data );
232
233 // Enqueue Google Maps (optionally with API key)
234
235 if( true == apply_filters( 'wpsight_google_maps', true ) ) {
236
237 $api_key = wpsight_get_option( 'google_maps_api_key' );
238 $api_url = $api_key ? add_query_arg( [ 'key' => $api_key ], '//maps.googleapis.com/maps/api/js' ) : '//maps.googleapis.com/maps/api/js';
239
240 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 ) );
241
242 }
243
244 if( true == apply_filters('wpsight_css', true) && wpsight_get_option('listings_css' ) ) {
245
246 //if ( is_singular( 'listing' ) ) {
247 wp_enqueue_style( 'wpsight', WPSIGHT_PLUGIN_URL . '/assets/css/wpsight' . $suffix . '.css', '', WPSIGHT_VERSION);
248
249 if ( is_rtl() )
250 wp_enqueue_style( 'wpsight-rtl', WPSIGHT_PLUGIN_URL . '/assets/css/wpsight-rtl' . $suffix . '.css', '', WPSIGHT_VERSION );
251 //}
252
253 }
254
255 }
256
257 /**
258 * activation()
259 *
260 * Callback for register_activation_hook
261 * to create a default listings page with
262 * the [wpsight_listings] shortcode and
263 * to create some default options to be
264 * used by this plugin.
265 *
266 * @uses wpsight_get_option()
267 * @uses wp_insert_post()
268 * @uses wpsight_add_option()
269 *
270 * @since 1.0.0
271 */
272
273 public function activation() {
274
275 // Create listings page
276
277 $page_data = [
278 'post_title' => _x( 'Listings', 'listings page title', 'wpcasa' ),
279 'post_content' => '[wpsight_listings]',
280 'post_type' => 'page',
281 'post_status' => 'publish',
282 'comment_status' => 'closed',
283 'ping_status' => 'closed'
284 ];
285
286 $page_id = ! wpsight_get_option( 'listings_page' ) ? wp_insert_post( $page_data ) : false;
287
288 // Add some default options
289
290 $options = [
291 'listings_page' => $page_id,
292 'listing_id' => __( 'ID-', 'wpcasa' ),
293 'measurement_unit' => 'm2',
294 'currency' => 'usd',
295 'currency_symbol' => 'before',
296 'currency_separator' => 'comma',
297 'date_format' => get_option( 'date_format' ),
298 'listings_css' => '1'
299 ];
300
301 // Add default standard features
302 foreach ( wpsight_details() as $option => $value )
303 $options[ $option ] = [ 'label' => $value['label'], 'unit' => $value['unit'] ];
304
305 // Add default rental periods
306 foreach ( wpsight_rental_periods() as $option => $value )
307 $options[ $option ] = $value;
308
309 foreach( $options as $option => $value ) {
310
311 if( wpsight_get_option( $option ) )
312 continue;
313
314 wpsight_add_option( $option, $value );
315
316 }
317
318 }
319 }
320
321 /**
322 * wpsight()
323 *
324 * The main function responsible for returning the one true wpsight Instance to functions everywhere.
325 * Use this function like you would use a global variable, except without needing to declare the global.
326 *
327 * Example: <?php $wpsight = wpsight(); ?>
328 *
329 * @return object|bool $wpsight
330 */
331 function wpsight() {
332 global $wpsight;
333
334 // Don't activate plugin add-ons if theme still active
335
336 if( wp_get_theme()->template == 'wpcasa' ) {
337 remove_all_actions( 'wpsight_init' );
338 return false;
339 }
340
341 if ( ! isset( $wpsight ) )
342 $wpsight = new WPSight_Framework();
343
344 return $wpsight;
345 }
346 wpsight();
347
348 /**
349 * wpsight_admin_notice_wpcasa()
350 *
351 * Make sure users first deactivate
352 * the old WPCasa theme version.
353 * Display error message if it is
354 * still activated.
355 *
356 * @uses wp_get_theme()
357 *
358 * @since 1.0.0
359 */
360 function wpsight_admin_notice_wpcasa() {
361
362 if( wp_get_theme()->template != 'wpcasa' )
363 return;
364
365 $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>';
366 echo wp_kses( $error_notice, array( 'div' => array( 'class' => array() ), 'p' => array(), 'strong' => array(), 'a' => array( 'href' => array() ) ) );
367 }
368 add_action( 'admin_notices', 'wpsight_admin_notice_wpcasa' );
369
370 /**
371 * wpsight_admin_plugins_delete_notice()
372 *
373 * Make sure users awera
374 * that WPCasa Listing Map and
375 * WPCasa admin map ui plugins
376 * can be deleted
377 *
378 * @since 1.2.0
379 */
380 function wpsight_admin_plugins_delete_notice() {
381
382 $admin_map_ui = WP_PLUGIN_DIR . '/wpcasa-admin-map-ui/wpcasa-admin-map-ui.php';
383 $listing_map = WP_PLUGIN_DIR . '/wpcasa-listings-map/wpcasa-listings-map.php';
384
385 $plugin_name = '';
386 $count = 1;
387
388 if( file_exists( $admin_map_ui ) ) {
389
390 $plugin_name .= '<strong>WPCasa Admin Map UI</strong>';
391
392 }
393
394 if( file_exists( $listing_map ) ) {
395
396 if( !empty( $plugin_name ) ) {
397
398 $plugin_name .= ' ' . __( 'and' , 'wpcasa' ) . ' ';
399
400 $count = 2;
401
402 }
403
404 $plugin_name .= '<strong>WPCasa Listings Map</strong>';
405
406 }
407
408 if ( ! empty( $plugin_name ) ) {
409 $message = sprintf(
410 // Translators: %s is plugin name
411 _n(
412 '%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.',
413 '%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.',
414 $count, 'wpcasa' ),
415 $plugin_name );
416
417 echo wp_kses( '<div class="notice notice-warning my-dismiss-notice is-dismissible"><p>' . $message . '</p></div>', array( 'div' => array( 'class' => array() ), 'p' => array() ) );
418
419 }
420
421 }
422 add_action( 'admin_notices', 'wpsight_admin_plugins_delete_notice' );
423
424 /**
425 *
426 * Redirect after single wpcasa activatation
427 * Prevent multiple activation redirect
428 *
429 * @since 1.2.0
430 */
431 function wpcasa_plugin_activate() {
432 add_option('wpcasa_do_activation_redirect', true);
433 }
434 register_activation_hook(__FILE__, 'wpcasa_plugin_activate');
435
436 function wpcasa_activation_redirect() {
437 if (get_option('wpcasa_do_activation_redirect', false)) {
438 delete_option('wpcasa_do_activation_redirect');
439 if ( !isset($_GET['activate-multi']) ) {
440 wp_safe_redirect( admin_url( 'index.php?page=wpsight-settings' ));
441 exit();
442 }
443 }
444 }
445 add_action( 'admin_init', 'wpcasa_activation_redirect' );
446
447 /**
448 * Adds plugin upgrade notification
449 *
450 * @since 1.2.11
451 */
452 function wpcasa_plugin_update_message( $data, $response ) {
453
454 if( isset( $data[ 'upgrade_notice'] ) ) {
455
456 $upgrade_notice = str_replace('<p>', '<span style="margin-top: 5px">', wpautop( $data['upgrade_notice'] ) );
457 $upgrade_notice = str_replace('</p>', '</span><br>', $upgrade_notice );
458
459 printf(
460 '</p><p style="background-color: #d63638; padding: 10px; color: #f9f9f9; margin-top: 10px"><span style="margin-left: -25px"><strong>%s:</strong></span><br>%s',
461 esc_html__( 'Important Upgrade Notice', 'wpcasa'),
462 $upgrade_notice
463 );
464 }
465
466 }
467 add_action( 'in_plugin_update_message-wpcasa/wpcasa.php', 'wpcasa_plugin_update_message', 10, 2 );
468
469 function wpcasa_settings_value_change() {
470 $wpcasa_settings = get_option('wpcasa');
471 $thousand_separator = $wpcasa_settings['currency_separator'] ?? '';
472
473 if ( ( 'comma' === $thousand_separator ) || ( 'dot' === $thousand_separator ) ) {
474 switch ( $thousand_separator ) {
475 case 'comma':
476 $wpcasa_settings['currency_separator'] = ',';
477 break;
478 case 'dot':
479 $wpcasa_settings['currency_separator'] = '.';
480 break;
481 }
482 update_option( 'wpcasa', $wpcasa_settings );
483 }
484 }
485 add_action( 'admin_init', 'wpcasa_settings_value_change' );
486
487
488