-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathawpcp.php
More file actions
292 lines (243 loc) · 9.21 KB
/
awpcp.php
File metadata and controls
292 lines (243 loc) · 9.21 KB
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
<?php
/**
* @package AWPCP
*
* Plugin Name: AWP Classifieds
* Plugin URI: https://awpcp.com/
* Description: Run a free or paid classified ads service on your WordPress site.
* Version: 4.4.5
* Author: AWP Classifieds Team
* Author URI: https://awpcp.com/
* License: GPLv2 or later
* Text Domain: another-wordpress-classifieds-plugin
* Domain Path: /languages
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! function_exists( 'add_filter' ) ) {
header( 'Status: 403 Forbidden' );
header( 'HTTP/1.1 403 Forbidden' );
exit();
}
if ( ! defined( 'AWPCP_FILE' ) ) {
define( 'AWPCP_FILE', __FILE__ );
}
if ( ! defined( 'AWPCP_BASENAME' ) ) {
define( 'AWPCP_BASENAME', plugin_basename( AWPCP_FILE ) );
}
if ( ! defined( 'AWPCP_DIR' ) ) {
define( 'AWPCP_DIR', rtrim( plugin_dir_path( AWPCP_FILE ), '/' ) );
}
if ( ! defined( 'AWPCP_URL' ) ) {
define( 'AWPCP_URL', rtrim( plugin_dir_url( AWPCP_FILE ), '/' ) );
}
// TODO: Replace usage of this variable with the AWPCP_VERSION constant.
global $awpcp_db_version;
global $awpcp_imagesurl;
global $hascaticonsmodule;
global $hasregionsmodule;
global $hasextrafieldsmodule;
$awpcp_db_version = '4.4.5';
$awpcp_imagesurl = AWPCP_URL . '/resources/images';
$hascaticonsmodule = 0;
$hasextrafieldsmodule = $hasextrafieldsmodule ? true : false;
$hasregionsmodule = $hasregionsmodule ? true : false;
define( 'AWPCP_VERSION', $awpcp_db_version );
define( 'AWPCP_LISTING_POST_TYPE', 'awpcp_listing' );
define( 'AWPCP_CATEGORY_TAXONOMY', 'awpcp_listing_category' );
define( 'AWPCP_LOWEST_FILTER_PRIORITY', 1000000 );
if ( version_compare( phpversion(), '5.6.0', '<' ) ) {
add_action( 'admin_init', 'awpcp_outdated_php_version', 1 );
return;
}
$awpcp_autoload_file = AWPCP_DIR . '/vendor/autoload.php';
if ( ! is_readable( $awpcp_autoload_file ) ) {
add_action( 'admin_init', 'awpcp_missing_autoload', 1 );
return;
}
/**
* Legacy code that needs to be properly cleaned.
*/
if ( ! defined( 'AWPCP_REGION_CONTROL_MODULE' ) && file_exists( AWPCP_DIR . '/awpcp_region_control_module.php' ) ) {
require_once AWPCP_DIR . '/awpcp_region_control_module.php';
$hasregionsmodule = true;
}
if ( ! defined( 'AWPCP_EXTRA_FIELDS_MODULE' ) && file_exists( AWPCP_DIR . '/awpcp_extra_fields_module.php' ) ) {
require_once AWPCP_DIR . '/awpcp_extra_fields_module.php';
$hasextrafieldsmodule = true;
}
if ( file_exists( AWPCP_DIR . '/awpcp_category_icons_module.php' ) ) {
require_once AWPCP_DIR . '/awpcp_category_icons_module.php';
$hascaticonsmodule = 1;
}
/* End of legacy code. */
/**
* BuddyPress normally attaches bp_loaded to plugins_loaded with priority 10.
* When changing the priorities below, please make sure that modules are
* still loaded before bp_loaded so that they can register handlers for
* BuddyPress actions and filters.
*
* See bootstrap() and setup() methods that are called inside awpcp_load_main_plugin().
*/
add_action( 'plugins_loaded', 'awpcp_load_main_plugin', 5 );
// TODO: Configure this on plugin's main class?
add_filter( 'redirect_canonical', 'awpcp_redirect_canonical', 10, 2 );
require_once $awpcp_autoload_file;
// TODO: Remove constructor functions from class fields so that we don't
// have to require the files upfront and be able to take advantage of
// the autoloader.
require_once AWPCP_DIR . '/requires.php';
require_once ABSPATH . 'wp-admin/includes/plugin.php';
/**
* @since 4.0.0
*/
function awpcp_outdated_php_version() {
add_action( 'admin_notices', 'awpcp_render_plugin_required_php_version_notice' );
awpcp_self_deactivate();
}
/**
* @since 4.0.0
*/
function awpcp_render_plugin_required_php_version_notice() {
awpcp_required_php_version_notice( 'AWP Classifieds Plugin' );
}
/**
* Renders a notice if the Module Updater plugin is needed.
*
* @since 4.4
*/
function awpcp_maybe_render_module_updater_notice() {
if ( ! awpcp_is_module_updater_needed() ) {
return;
}
$message = __( 'The AWP Module Updater plugin is needed to for your premium modules to work properly. You can download it from the <a href="https://awpcp.com/account/downloads/">downloads page</a>.', 'another-wordpress-classifieds-plugin' );
echo '<div class="notice notice-error"><p>' . wp_kses_post( $message ) . '</p></div>';
}
add_action( 'admin_notices', 'awpcp_maybe_render_module_updater_notice' );
/**
* Check if the user has any premium licenses.
*
* @since 4.4
*/
function awpcp_is_module_updater_needed() {
if ( defined( 'AWP_MODULE_UPDATER_VERSION' ) ) {
return false;
}
$options = get_option( 'awpcp-options' );
foreach ( $options as $option_key => $option_value ) {
if ( str_contains( $option_key, '-license-status' ) ) {
return true;
}
}
return false;
}
/**
* @since 4.0.0
*/
function awpcp_required_php_version_notice( $product_name ) {
$content = '';
$content .= '<p><strong>';
$content .= str_replace( '{product_name}', $product_name, esc_html__( '{product_name} was deactivated because it requires PHP 5.6 or newer.', 'another-wordpress-classifieds-plugin' ) );
$content .= '</strong></p>';
$content .= '<p>';
$content .= esc_html__( 'Hi, we noticed that your site is running on an outdated version of PHP. New versions of PHP are faster, more secure and include the features our product requires.', 'another-wordpress-classifieds-plugin' );
$content .= '</p>';
$content .= '<p>';
$content .= wp_kses_post( __( 'You should upgrade to <strong>PHP 5.6</strong>, but if you want your site to also be considerable faster and even more secure, we recommend going up to <strong>PHP 7.2</strong>.', 'another-wordpress-classifieds-plugin' ) );
$content .= '</p>';
$content .= '<p>';
$content .= wp_kses_post( __( 'Please read <a href="https://wordpress.org/support/upgrade-php/">Upgrading PHP</a> to understand more about PHP and how to upgrade.', 'another-wordpress-classifieds-plugin' ) );
$content .= '</p>';
awpcp_activation_failed_notice( $content );
}
/**
* TODO: Organize functions to print/render flash messages, errors and notices.
* Right now we have too many ways to do the same thing and none of them seem
* to be good enough.
*
* @since 4.0.0
*/
function awpcp_activation_failed_notice( $content ) {
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo '<div class="notice notice-error">' . $content . '</div>';
}
/**
* @since 4.0.0
*/
function awpcp_self_deactivate() {
deactivate_plugins( plugin_basename( AWPCP_FILE ) );
if ( isset( $_GET['activate'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
unset( $_GET['activate'] );
}
}
/**
* @since 4.0.0
*/
function awpcp_missing_autoload() {
add_action( 'admin_notices', 'awpcp_missing_autoload_notice' );
awpcp_self_deactivate();
}
/**
* @since 4.0.0
*/
function awpcp_missing_autoload_notice() {
$message = esc_html__( 'AWP Classifieds Plugin installation is incomplete. Please {support_link}contact support{/support_link}.', 'another-wordpress-classifieds-plugin' );
$message = str_replace( '{support_link}', '<a href="https://awpcp.com/contact/">', $message );
$message = str_replace( '{/support_link}', '</a>', $message );
awpcp_activation_failed_notice( '<p>' . $message . '</p>' );
}
/**
* @since 4.0.0
*/
function awpcp_load_main_plugin() {
awpcp();
}
/**
* @since 4.0.0 Modified to instantiate the container directly.
* @return AWPCP
*/
function awpcp() {
global $awpcp;
if ( ! is_object( $awpcp ) ) {
$container = new AWPCP_Container(
[
'plugin_basename' => plugin_basename( AWPCP_FILE ),
'SettingsManager' => new AWPCP_SettingsManager(),
]
);
include AWPCP_DIR . '/includes/constructor-functions.php';
$awpcp = new AWPCP( $container );
$container['Plugin'] = $awpcp;
// bootstrap() was originally called as soon as the plugin was loaded and
// setup() was attached to plugins_loaded. Now both methods are called
// on plugins_loaded.
$awpcp->bootstrap();
$awpcp->setup();
}
return $awpcp;
}
// TODO: Remove this code after resolving the plugin activation issue. It's duplicated in AWPCP_Installer->activate().
register_activation_hook( __FILE__, function () {
if ( get_transient( AWPCP_OnboardingWizard::TRANSIENT_NAME ) !== 'no' ) {
set_transient(
AWPCP_OnboardingWizard::TRANSIENT_NAME,
AWPCP_OnboardingWizard::TRANSIENT_VALUE,
60
);
}
} );