forked from idxbroker/wordpress-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
idx-broker-platinum.php
199 lines (174 loc) · 5.83 KB
/
idx-broker-platinum.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
<?php
/**
Plugin Name: IMPress for IDX Broker
Plugin URI: https://idxbroker.com
Description: Over 600 IDX/MLS feeds serviced. The #1 IDX/MLS solution just got even better!
Version: 3.2.1
Author: IDX Broker
Contributors: IDX, LLC
Author URI: https://idxbroker.com
License: GPLv2 or later
*/
new Idx_Broker_Plugin();
/**
* Idx_Broker_Plugin class.
*/
class Idx_Broker_Plugin {
// Placed here for convenient updating.
const IDX_WP_PLUGIN_VERSION = '3.2.1';
const VUE_DEV_MODE = false;
/**
* __construct function.
*
* @access public
* @return void
*/
public function __construct() {
define( 'IMPRESS_IDX_URL', plugin_dir_url( __FILE__ ) );
define( 'IMPRESS_IDX_DIR', plugin_dir_path( __FILE__ ) );
define( 'IDX_API_DEFAULT_VERSION', '1.8.0' );
define( 'IDX_API_URL', 'https://api.idxbroker.com' );
if ( $this->php_version_check() ) {
// IDX Autoloader.
require_once 'idx' . DIRECTORY_SEPARATOR . 'autoloader.php';
// Composer autoload classes.
require_once 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
new IDX\Initiate_Plugin();
/** Function that is executed when plugin is activated. */
register_activation_hook( __FILE__, array( $this, 'idx_activate' ) );
register_deactivation_hook( __FILE__, array( $this, 'idx_deactivate' ) );
}
// IMPress Listings.
if ( boolval( get_option( 'idx_broker_listings_enabled', 0 ) ) && ! is_plugin_active( 'wp-listings/plugin.php' ) ) {
include_once 'add-ons/listings/plugin.php';
}
// IMPress Agents.
if ( boolval( get_option( 'idx_broker_agents_enabled', 0 ) ) && ! is_plugin_active( 'impress-agents/plugin.php' ) ) {
include_once 'add-ons/agents/plugin.php';
}
// Hide legacy widgets from the legacy block to prevent double-entries when searching for widgets.
add_filter( 'widget_types_to_hide_from_legacy_widget_block', [ $this, 'hide_from_legacy_block' ] );
}
/**
* Hide from legacy block.
* Prevents existing block widgets from appearing as an option in the legacy widget block.
*
* @access public
* @param array $widget_types - Array of widget handles.
* @return array
*/
public function hide_from_legacy_block( $widget_types ) {
$hidden_widget_list = [
'impress_showcase',
'impress_carousel',
'impress_idx_dashboard_widget',
'impress_city_links',
'impress_lead_login',
'impress_lead_signup',
'idx_omnibar_widget',
];
return array_merge( $widget_types, $hidden_widget_list );
}
/**
* Check for versions less than PHP7.0 and display error.
*/
public function php_version_check() {
if ( version_compare( PHP_VERSION, '7.1.8', '<' ) ) {
add_action( 'admin_init', array( $this, 'idx_deactivate_plugin' ) );
add_action( 'admin_notices', array( $this, 'incompatible_message' ) );
return false;
} else {
return true;
}
}
/**
* Incompatible Message.
*
* @access public
* @static
* @return void
*/
public static function incompatible_message() {
echo "<div class=\"error\"><br><div>You are using a deprecated version
of PHP. This is incompatable with the IDX Broker plugin.
For security reasons, please contact your host and upgrade to the
latest stable version of PHP they offer. We recommend a minimum
of PHP 7.0.<br>For more information on what versions of PHP are
supported with security updates, see <a
href=\"http://support.idxbroker.com/customer/en/portal/articles/1917460-wordpress-plugin\">
this knowledgebase article</a> and PHP.net's
<a href=\"http://php.net/supported-versions.php\"
target=\"_blank\">supported versions page.</a>
</div><br></div>";
}
/**
* IDX Deactivate.
*
* @access public
* @static
* @return void
*/
public static function idx_deactivate_plugin() {
deactivate_plugins( plugin_basename( __FILE__ ) );
}
/**
* IDX Activate.
*
* @access public
* @static
* @return void
*/
public static function idx_activate() {
if ( ! get_option( 'idx_results_url' ) ) {
add_option( 'idx_results_url' );
}
if ( get_site_option( 'idx_dismiss_review_prompt' ) !== false ) {
delete_option( 'idx_dismiss_review_prompt' );
}
if ( get_site_option( 'idx_review_prompt_time' ) !== false ) {
delete_option( 'idx_review_prompt_time' );
}
// Avoid 404 errors on custom posts such as wrappers by registering them then refreshing the permalink rules.
$idx_api = new \IDX\Idx_Api();
$wrappers = new \IDX\Wrappers( $idx_api );
$wrappers->register_wrapper_post_type();
// IMPress Listings.
if ( boolval( get_option( 'idx_broker_listings_enabled', 0 ) ) && ! is_plugin_active( 'wp-listings/plugin.php' ) ) {
wp_listings_init();
global $_wp_listings, $_wp_listings_taxonomies, $_wp_listings_templates;
$_wp_listings->create_post_type();
$_wp_listings_taxonomies->register_taxonomies();
}
$notice_keys = [ 'wpl_notice_idx', 'wpl_listing_notice_idx' ];
foreach ( $notice_keys as $notice ) {
delete_user_meta( get_current_user_id(), $notice );
}
// IMPress Agents.
if ( boolval( get_option( 'idx_broker_agents_enabled', 0 ) ) && ! is_plugin_active( 'impress-agents/plugin.php' ) ) {
impress_agents_init();
global $_impress_agents, $_impress_agents_taxonomies;
$_impress_agents->create_post_type();
$_impress_agents_taxonomies->register_taxonomies();
}
flush_rewrite_rules();
}
/**
* IDX Deactivate.
*
* @access public
* @static
* @return void
*/
public static function idx_deactivate() {
// Disable scheduled update for omnibar.
wp_clear_scheduled_hook( 'idx_omnibar_get_locations' );
// Disable scheduled IDX Page Update as well.
\IDX\Idx_Pages::unschedule_idx_page_update();
// IMPress Listings.
flush_rewrite_rules();
$notice_keys = [ 'wpl_notice_idx', 'wpl_listing_notice_idx' ];
foreach ( $notice_keys as $notice ) {
delete_user_meta( get_current_user_id(), $notice );
}
}
}