-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdispensary-age-verification.php
317 lines (286 loc) · 10.9 KB
/
dispensary-age-verification.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
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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
<?php
/**
* The plugin bootstrap file
*
* @package Age_Verification
* @author Devio Digital <[email protected]>
* @license GPL-2.0+ http://www.gnu.org/licenses/gpl-2.0.txt
* @link https://www.deviodigital.com
* @since 1.0.0
*
* @wordpress-plugin
* Plugin Name: Age Verification
* Plugin URI: https://www.deviodigital.com
* Description: Check a visitors age before allowing them to view your website. Brought to you by <a href="https://www.deviodigital.com/" target="_blank">Devio Digital</a>
* Version: 2.9.6
* Author: Devio Digital
* Author URI: https://www.deviodigital.com
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Text Domain: dispensary-age-verification
* Domain Path: /languages
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
wp_die();
}
require 'plugin-update-checker/plugin-update-checker.php';
use YahnisElsts\PluginUpdateChecker\v5\PucFactory;
$myUpdateChecker = PucFactory::buildUpdateChecker(
'https://github.com/deviodigital/dispensary-age-verification/',
__FILE__,
'dispensary-age-verification'
);
//Set the branch that contains the stable release.
$myUpdateChecker->setBranch( 'main' );
// Current plugin version.
define( 'AVWP_VERSION', '2.9.6' );
// Plugin folder name.
$pluginname = plugin_basename( __FILE__ );
/**
* The code that runs during plugin activation.
* This action is documented in includes/class-dispensary-age-verification-activator.php
*
* @return void
*/
function avwp_activate() {
require_once plugin_dir_path( __FILE__ ) . 'includes/class-dispensary-age-verification-activator.php';
Age_Verification_Activator::activate();
}
/**
* The code that runs during plugin deactivation.
* This action is documented in includes/class-dispensary-age-verification-deactivator.php
*
* @return void
*/
function avwp_deactivate() {
require_once plugin_dir_path( __FILE__ ) . 'includes/class-dispensary-age-verification-deactivator.php';
Age_Verification_Deactivator::deactivate();
}
register_activation_hook( __FILE__, 'avwp_activate' );
register_deactivation_hook( __FILE__, 'avwp_deactivate' );
/**
* The core plugin class that is used to define internationalization,
* admin-specific hooks, and public-facing site hooks.
*/
require plugin_dir_path( __FILE__ ) . 'includes/class-dispensary-age-verification.php';
/**
* Begins execution of the plugin.
*
* Since everything within the plugin is registered via hooks,
* then kicking off the plugin from this point in the file does
* not affect the page life cycle.
*
* @since 1.0.0
* @return void
*/
function run_avwp() {
$plugin = new Age_Verification();
$plugin->run();
}
run_avwp();
/**
* Add Go Pro link on plugin page
*
* @param array $links an array of links related to the plugin.
*
* @since 2.2
* @return array updatead array of links related to the plugin.
*/
function avwp_go_pro_link( $links ) {
// Pro link.
$pro_link = '<a href="https://deviodigital.com/product/age-verification-pro" target="_blank" style="font-weight:700;">' . esc_attr__( 'Go Pro', 'dispensary-age-verification' ) . '</a>';
if ( ! function_exists( 'run_avwp_pro' ) ) {
array_unshift( $links, $pro_link );
}
return $links;
}
add_filter( "plugin_action_links_$pluginname", 'avwp_go_pro_link' );
/**
* Check AVWP Pro version number.
*
* If the AVWP Pro version number is less than what's defined below, there will
* be a notice added to the admin screen letting the user know there's a new
* version of the AVWP Pro plugin available.
*
* @since 2.4
* @return void
*/
function avwp_check_pro_version() {
// Only run if AVWP Pro is active.
if ( function_exists( 'run_avwp_pro' ) ) {
// Check if AVWP Pro version is defined.
if ( ! defined( 'AVWP_PRO_VERSION' ) ) {
define( 'AVWP_PRO_VERSION', 0 ); // default to zero.
}
// Set pro version number.
$pro_version = AVWP_PRO_VERSION;
if ( '0' == $pro_version || $pro_version < '1.4' ) {
add_action( 'admin_notices', 'avwp_update_avwp_pro_notice' );
}
}
}
add_action( 'admin_init', 'avwp_check_pro_version' );
/**
* Error notice - Runs if AVWP Pro is out of date.
*
* @see avwp_check_pro_version()
* @since 2.9
* @return void
*/
function avwp_update_avwp_pro_notice() {
$avwp_orders = '<a href="https://www.deviodigital.com/my-account/orders/" target="_blank">' . esc_attr__( 'Orders', 'dispensary-age-verification' ) . '</a>';
$error = sprintf( esc_html__( 'There is a new version of AVWP Pro available. Download your copy from the %1$s page on Devio Digital.', 'dispensary-age-verification' ), $avwp_orders );
echo '<div class="notice notice-info"><p>' . $error . '</p></div>';
}
/**
* Display a custom admin notice to inform users about plugin update issues.
*
* This function displays a dismissible admin notice warning users about
* restrictions imposed by WordPress® leadership that may impact automatic
* plugin updates. It provides a link to a resource where users can learn how
* to continue receiving updates.
*
* @since 2.9.5
* @return void
*/
function avwp_custom_update_notice() {
// Check if the notice has been dismissed.
if ( get_option( 'avwp_custom_update_notice_dismissed' ) ) {
return;
}
// Translating the notice text using WordPress® translation functions.
$notice_text = sprintf(
__( 'Important Notice: Due to recent changes initiated by WordPress® leadership, access to the plugin repository is being restricted for certain hosting providers and developers. This may impact automatic updates for your plugins. To ensure you continue receiving updates and to learn about the next steps, please visit %s.', 'dispensary-age-verification' ),
'<a href="https://www.robertdevore.com" target="_blank">this page</a>'
);
// Display the admin notice.
echo '<div class="notice notice-warning is-dismissible" id="custom-update-notice">
<p>' . $notice_text . '</p>
</div>';
}
add_action( 'admin_notices', 'avwp_custom_update_notice' );
/**
* Enqueue the JavaScript to handle the dismissal of the notice.
*
* @since 2.9.5
* @return void
*/
function avwp_custom_update_notice_scripts() {
wp_enqueue_script( 'avwp-custom-notice-dismiss', plugin_dir_url( __FILE__ ) . 'public/js/custom-notice-dismiss.js', array( 'jquery' ), false, true );
wp_localize_script( 'avwp-custom-notice-dismiss', 'custom_notice', array(
'ajax_url' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( 'avwp_custom_notice_dismiss_nonce' ),
) );
}
add_action( 'admin_enqueue_scripts', 'avwp_custom_update_notice_scripts' );
/**
* AJAX handler to mark the notice as dismissed.
*/
function avwp_custom_dismiss_update_notice() {
check_ajax_referer( 'avwp_custom_notice_dismiss_nonce', 'nonce' );
update_option( 'avwp_custom_update_notice_dismissed', 1 );
wp_send_json_success();
}
add_action( 'wp_ajax_avwp_custom_dismiss_update_notice', 'avwp_custom_dismiss_update_notice' );
/**
* Helper function to handle WordPress.com environment checks.
*
* @param string $plugin_slug The plugin slug.
* @param string $learn_more_link The link to more information.
*
* @since 2.9.6
* @return bool
*/
function wp_com_plugin_check( $plugin_slug, $learn_more_link ) {
// Check if the site is hosted on WordPress.com.
if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
// Ensure the deactivate_plugins function is available.
if ( ! function_exists( 'deactivate_plugins' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
// Deactivate the plugin if in the admin area.
if ( is_admin() ) {
deactivate_plugins( $plugin_slug );
// Add a deactivation notice for later display.
add_option( 'wpcom_deactivation_notice', $learn_more_link );
// Prevent further execution.
return true;
}
}
return false;
}
/**
* Auto-deactivate the plugin if running in an unsupported environment.
*
* @since 2.9.6
* @return void
*/
function wpcom_auto_deactivation() {
if ( wp_com_plugin_check( plugin_basename( __FILE__ ), 'https://robertdevore.com/why-this-plugin-doesnt-support-wordpress-com-hosting/' ) ) {
return; // Stop execution if deactivated.
}
}
add_action( 'plugins_loaded', 'wpcom_auto_deactivation' );
/**
* Display an admin notice if the plugin was deactivated due to hosting restrictions.
*
* @since 2.9.6
* @return void
*/
function wpcom_admin_notice() {
$notice_link = get_option( 'wpcom_deactivation_notice' );
if ( $notice_link ) {
?>
<div class="notice notice-error">
<p>
<?php
echo wp_kses_post(
sprintf(
__( 'My Plugin has been deactivated because it cannot be used on WordPress.com-hosted websites. %s', 'dispensary-age-verification' ),
'<a href="' . esc_url( $notice_link ) . '" target="_blank" rel="noopener">' . __( 'Learn more', 'dispensary-age-verification' ) . '</a>'
)
);
?>
</p>
</div>
<?php
delete_option( 'wpcom_deactivation_notice' );
}
}
add_action( 'admin_notices', 'wpcom_admin_notice' );
/**
* Prevent plugin activation on WordPress.com-hosted sites.
*
* @since 2.9.6
* @return void
*/
function wpcom_activation_check() {
if ( wp_com_plugin_check( plugin_basename( __FILE__ ), 'https://robertdevore.com/why-this-plugin-doesnt-support-wordpress-com-hosting/' ) ) {
// Display an error message and stop activation.
wp_die(
wp_kses_post(
sprintf(
'<h1>%s</h1><p>%s</p><p><a href="%s" target="_blank" rel="noopener">%s</a></p>',
__( 'Plugin Activation Blocked', 'dispensary-age-verification' ),
__( 'This plugin cannot be activated on WordPress.com-hosted websites. It is restricted due to concerns about WordPress.com policies impacting the community.', 'dispensary-age-verification' ),
esc_url( 'https://robertdevore.com/why-this-plugin-doesnt-support-wordpress-com-hosting/' ),
__( 'Learn more', 'dispensary-age-verification' )
)
),
esc_html__( 'Plugin Activation Blocked', 'dispensary-age-verification' ),
[ 'back_link' => true ]
);
}
}
register_activation_hook( __FILE__, 'wpcom_activation_check' );
/**
* Add a deactivation flag when the plugin is deactivated.
*
* @since 2.9.6
* @return void
*/
function wpcom_deactivation_flag() {
add_option( 'wpcom_deactivation_notice', 'https://robertdevore.com/why-this-plugin-doesnt-support-wordpress-com-hosting/' );
}
register_deactivation_hook( __FILE__, 'wpcom_deactivation_flag' );