| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: WPLP Legal Pages |
| 4 |
* Plugin URI: https://club.wpeka.com/ |
| 5 |
* Description: WPLegalPages is a simple 1 click legal page management plugin. You can quickly add in legal pages to your WordPress sites. |
| 6 |
* Author: WPLP Legal Pages |
| 7 |
* Version: 3.7.3 |
| 8 |
* Author URI: https://wplegalpages.com |
| 9 |
* License: GPL2 |
| 10 |
* Text Domain: wplegalpages |
| 11 |
* Domain Path: /languages |
| 12 |
* |
| 13 |
* @package Wplegalpages |
| 14 |
*/ |
| 15 |
|
| 16 |
// If this file is called directly, abort. |
| 17 |
if ( ! defined( 'ABSPATH' ) ) { |
| 18 |
die; |
| 19 |
} |
| 20 |
|
| 21 |
if ( ! defined( 'WPL_LITE_PLUGIN_URL' ) ) { |
| 22 |
define( 'WPL_LITE_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); |
| 23 |
} |
| 24 |
if ( ! defined( 'WPL_LITE_PLUGIN_BASENAME' ) ) { |
| 25 |
define( 'WPL_LITE_PLUGIN_BASENAME', plugin_basename( __FILE__ ) ); |
| 26 |
} |
| 27 |
|
| 28 |
if ( ! defined( 'WPLEGAL_API_URL' ) ) { |
| 29 |
define( 'WPLEGAL_API_URL', 'https://app.wplegalpages.com/wp-json/wplegal/v2/' ); |
| 30 |
} |
| 31 |
if ( ! defined( 'WPLEGAL_API_ADMIN_URL' ) ) { |
| 32 |
define( 'WPLEGAL_API_ADMIN_URL', 'https://app.wplegalpages.com/wp-content/plugins/wplegal-api/admin/' ); |
| 33 |
} |
| 34 |
/** |
| 35 |
* Check if the constant GDPR_APP_URL is not already defined. |
| 36 |
*/ |
| 37 |
if ( ! defined( 'WPLEGAL_APP_URL' ) ) { |
| 38 |
define( 'WPLEGAL_APP_URL', 'https://app.wplegalpages.com' ); |
| 39 |
} |
| 40 |
|
| 41 |
if ( ! defined( 'APPWPLP_WPLP_SECRET_KEY_FEATURE_VERSION' ) ) { |
| 42 |
define( 'APPWPLP_WPLP_SECRET_KEY_FEATURE_VERSION', '3.7.3' ); |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* How long a successful bearer-token verdict stays cached, in seconds. |
| 47 |
* |
| 48 |
* Bounds how long a token revoked at the app can still be honoured here, so |
| 49 |
* keep it short. A cached entry is additionally capped by the token's own |
| 50 |
* `exp` claim, whichever comes first. |
| 51 |
*/ |
| 52 |
if ( ! defined( 'APPWPLP_JWT_CACHE_TTL' ) ) { |
| 53 |
define( 'APPWPLP_JWT_CACHE_TTL', 15 * MINUTE_IN_SECONDS ); |
| 54 |
} |
| 55 |
|
| 56 |
if ( ! defined( 'APPWPLP_SECRET_KEY_OPTION' ) ) { |
| 57 |
define( 'APPWPLP_SECRET_KEY_OPTION', 'appwplp_shared_secret_key' ); |
| 58 |
} |
| 59 |
|
| 60 |
if ( ! defined( 'APPWPLP_SECRET_KEY_STATUS_OPTION' ) ) { |
| 61 |
define( 'APPWPLP_SECRET_KEY_STATUS_OPTION', 'appwplp_shared_secret_key_status' ); // 'pending' | 'confirmed' |
| 62 |
} |
| 63 |
if ( ! defined( 'APPWPLP_WPLP_SECRET_KEY_VERSION_OPTION' ) ) { |
| 64 |
define( 'APPWPLP_WPLP_SECRET_KEY_VERSION_OPTION', 'APPWPLP_WPLP_SECRET_KEY_FEATURE_VERSION' ); |
| 65 |
} |
| 66 |
|
| 67 |
if ( ! defined( 'APPWPLP_SECRET_KEY_ATTEMPTS_OPTION' ) ) { |
| 68 |
define( 'APPWPLP_SECRET_KEY_ATTEMPTS_OPTION', 'appwplp_secret_key_retry_attempts' ); |
| 69 |
} |
| 70 |
|
| 71 |
/** |
| 72 |
* Total number of registration posts a site will make before giving up. |
| 73 |
* |
| 74 |
* Counted as posts, not as retries on top of a first try, so eight means eight |
| 75 |
* requests and then silence. On a 15 minute loop that is a two hour window. |
| 76 |
* |
| 77 |
* Verification runs inside the registration request on the server, so a post |
| 78 |
* from a site the server cannot reach holds a php-fpm worker there for the full |
| 79 |
* timeout. Without a cap an unreachable site pays that cost every 15 minutes |
| 80 |
* forever; with one, each site's total cost is bounded and the traffic stops on |
| 81 |
* its own. |
| 82 |
*/ |
| 83 |
if ( ! defined( 'APPWPLP_SECRET_KEY_MAX_ATTEMPTS' ) ) { |
| 84 |
define( 'APPWPLP_SECRET_KEY_MAX_ATTEMPTS', 8 ); |
| 85 |
} |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
/** |
| 90 |
* Load WC_AM_Client class if it exists. |
| 91 |
*/ |
| 92 |
if ( ! class_exists( 'WC_AM_Client_2_7_WPLegalPages' ) ) { |
| 93 |
require_once plugin_dir_path( __FILE__ ) . 'wc-am-client-legalpages.php'; |
| 94 |
} |
| 95 |
|
| 96 |
/* |
| 97 |
* Instantiate WC_AM_Client class object if the WC_AM_Client class is loaded. |
| 98 |
*/ |
| 99 |
if ( class_exists( 'WC_AM_Client_2_7_WPLegalPages' ) ) { |
| 100 |
|
| 101 |
$wcam_lib_legalpages = new WC_AM_Client_2_7_WPLegalPages( __FILE__, '', '3.1.0', 'plugin', WPLEGAL_APP_URL, 'WPLegalPages', 'wplegalpages' ); |
| 102 |
} |
| 103 |
|
| 104 |
if ( ! defined( 'WPLPP_SUFFIX' ) ) { |
| 105 |
define( 'WPLPP_SUFFIX', ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min' ); |
| 106 |
} |
| 107 |
|
| 108 |
if ( ! function_exists( 'activate_wp_legal_pages' ) ) { |
| 109 |
/** |
| 110 |
* The code that runs during WPLegalPages activation. |
| 111 |
* This action is documented in includes/class-wp-legal-pages-activator.php |
| 112 |
*/ |
| 113 |
function activate_wp_legal_pages() { |
| 114 |
require_once plugin_dir_path( __FILE__ ) . 'includes/class-wp-legal-pages-activator.php'; |
| 115 |
WP_Legal_Pages_Activator::activate(); |
| 116 |
add_option( 'analytics_activation_redirect_wplegalpages', true ); |
| 117 |
// Get redirect URL. |
| 118 |
add_option( 'redirect_after_activation_option_lp', true ); |
| 119 |
} |
| 120 |
} |
| 121 |
|
| 122 |
add_action( 'admin_init', 'activation_redirect_wplegalpages' ); |
| 123 |
|
| 124 |
/** |
| 125 |
* Generates a cryptographically strong 32-character secret key. |
| 126 |
* |
| 127 |
* @return string |
| 128 |
*/ |
| 129 |
if ( ! function_exists( 'appwplp_generate_secret_key' ) ) { |
| 130 |
function appwplp_generate_secret_key() { |
| 131 |
// random_bytes(16) -> 32 hex characters. Cryptographically secure. |
| 132 |
return bin2hex( random_bytes( 16 ) ); |
| 133 |
} |
| 134 |
} |
| 135 |
/** |
| 136 |
* Single-flight guard shared by WP Cookie Consent and WPLegalPages. |
| 137 |
* |
| 138 |
* Both plugins listen on `appwplp_secret_key_generated` and post the very same |
| 139 |
* key to the very same endpoint, and each one triggers the routine on its own |
| 140 |
* activation and version upgrade. Without a shared claim a single site ends up |
| 141 |
* registering the key several times over. |
| 142 |
* |
| 143 |
* Only the first caller wins - inside one request through the static flag, and |
| 144 |
* across requests through a lock that expires shortly before the 15 minute |
| 145 |
* retry cron is due, so a genuine retry is never blocked. |
| 146 |
* |
| 147 |
* The function is defined once, by whichever of the two plugins loads first, so |
| 148 |
* both share the same static flag and the same lock. |
| 149 |
* |
| 150 |
* @return bool True when the caller owns this registration attempt. |
| 151 |
*/ |
| 152 |
if ( ! function_exists( 'appwplp_claim_secret_key_registration' ) ) { |
| 153 |
function appwplp_claim_secret_key_registration() { |
| 154 |
static $claimed = false; |
| 155 |
|
| 156 |
// A second listener in the same request - the key is already going out. |
| 157 |
if ( $claimed ) { |
| 158 |
return false; |
| 159 |
} |
| 160 |
|
| 161 |
// An attempt from another request is still inside the current retry window. |
| 162 |
if ( get_transient( 'appwplp_secret_key_registration_lock' ) ) { |
| 163 |
return false; |
| 164 |
} |
| 165 |
|
| 166 |
$claimed = true; |
| 167 |
|
| 168 |
// One minute short of the retry interval so the cron tick always gets through. |
| 169 |
set_transient( 'appwplp_secret_key_registration_lock', time(), 14 * MINUTE_IN_SECONDS ); |
| 170 |
|
| 171 |
return true; |
| 172 |
} |
| 173 |
} |
| 174 |
|
| 175 |
/** |
| 176 |
* Generates and stores a local secret key for this site, if one doesn't |
| 177 |
* already exist. Does NOT register it with the server - that happens in |
| 178 |
* step 3, triggered separately after this runs. |
| 179 |
*/ |
| 180 |
if ( ! function_exists( 'appwplp_maybe_generate_secret_key' ) ) { |
| 181 |
function appwplp_maybe_generate_secret_key() { |
| 182 |
$existing_key = get_option( APPWPLP_SECRET_KEY_OPTION ); |
| 183 |
$existing_status = get_option( APPWPLP_SECRET_KEY_STATUS_OPTION ); |
| 184 |
|
| 185 |
if ( ! empty( $existing_key ) && 'confirmed' === $existing_status ) { |
| 186 |
$timestamp = wp_next_scheduled( 'appwplp_secret_key_retry_event' ); |
| 187 |
if ( $timestamp ) { |
| 188 |
wp_clear_scheduled_hook( 'appwplp_secret_key_retry_event' ); |
| 189 |
} |
| 190 |
delete_option( APPWPLP_SECRET_KEY_ATTEMPTS_OPTION ); |
| 191 |
return; |
| 192 |
} |
| 193 |
|
| 194 |
/* |
| 195 |
* Out of attempts - stop the loop for good. |
| 196 |
* |
| 197 |
* The counter is raised by the listener that actually posts, so an |
| 198 |
* attempt is never spent by the second plugin standing down on the |
| 199 |
* shared claim. Reactivating either plugin clears it and allows a fresh |
| 200 |
* set, which is the only way back for a site that was unreachable while |
| 201 |
* these ran out. |
| 202 |
*/ |
| 203 |
if ( (int) get_option( APPWPLP_SECRET_KEY_ATTEMPTS_OPTION, 0 ) >= APPWPLP_SECRET_KEY_MAX_ATTEMPTS ) { |
| 204 |
$timestamp = wp_next_scheduled( 'appwplp_secret_key_retry_event' ); |
| 205 |
if ( $timestamp ) { |
| 206 |
wp_clear_scheduled_hook( 'appwplp_secret_key_retry_event' ); |
| 207 |
} |
| 208 |
return; |
| 209 |
} |
| 210 |
|
| 211 |
if ( ! empty( $existing_key ) ) { |
| 212 |
update_option( APPWPLP_SECRET_KEY_STATUS_OPTION, 'pending', false ); |
| 213 |
do_action( 'appwplp_secret_key_generated', $existing_key ); |
| 214 |
} else { |
| 215 |
/* |
| 216 |
* First installation - generate the key. |
| 217 |
*/ |
| 218 |
$new_key = appwplp_generate_secret_key(); |
| 219 |
update_option( APPWPLP_SECRET_KEY_OPTION, $new_key, false ); |
| 220 |
update_option( APPWPLP_SECRET_KEY_STATUS_OPTION, 'pending', false ); |
| 221 |
|
| 222 |
do_action( 'appwplp_secret_key_generated', $new_key ); |
| 223 |
|
| 224 |
} |
| 225 |
if ( ! wp_next_scheduled( 'appwplp_secret_key_retry_event' ) ) { |
| 226 |
wp_schedule_event( time() + ( 15 * MINUTE_IN_SECONDS ), 'appwplp_fifteen_minutes', 'appwplp_secret_key_retry_event' ); |
| 227 |
} |
| 228 |
} |
| 229 |
} |
| 230 |
|
| 231 |
/** |
| 232 |
* Custom 15-minute cron schedule, used by the retry mechanism below. |
| 233 |
*/ |
| 234 |
add_filter( 'cron_schedules', function ( $schedules ) { |
| 235 |
$schedules['appwplp_fifteen_minutes'] = array( |
| 236 |
'interval' => 15 * MINUTE_IN_SECONDS, |
| 237 |
'display' => 'Every 15 Minutes', |
| 238 |
); |
| 239 |
return $schedules; |
| 240 |
} ); |
| 241 |
|
| 242 |
add_action( 'appwplp_secret_key_retry_event', 'appwplp_maybe_generate_secret_key' ); |
| 243 |
/** |
| 244 |
* Runs the secret key routine once on existing installs. |
| 245 |
* |
| 246 |
* register_activation_hook() does not fire when WordPress updates a plugin |
| 247 |
* in place, so sites upgrading from a version without this feature would |
| 248 |
* never get a key. A stored feature version is compared against the current |
| 249 |
* one so this runs exactly once per site after the update. |
| 250 |
* |
| 251 |
* @return void |
| 252 |
*/ |
| 253 |
if ( ! function_exists( 'wplp_appwplp_secret_key_version_check' ) ) { |
| 254 |
function wplp_appwplp_secret_key_version_check() { |
| 255 |
if ( APPWPLP_WPLP_SECRET_KEY_FEATURE_VERSION === get_option( APPWPLP_WPLP_SECRET_KEY_VERSION_OPTION ) ) { |
| 256 |
return; |
| 257 |
} |
| 258 |
delete_option( APPWPLP_SECRET_KEY_ATTEMPTS_OPTION ); |
| 259 |
appwplp_maybe_generate_secret_key(); |
| 260 |
update_option( APPWPLP_WPLP_SECRET_KEY_VERSION_OPTION, APPWPLP_WPLP_SECRET_KEY_FEATURE_VERSION, false ); |
| 261 |
} |
| 262 |
} |
| 263 |
add_action( 'admin_init', 'wplp_appwplp_secret_key_version_check' ); |
| 264 |
|
| 265 |
|
| 266 |
/** |
| 267 |
* It will redirect to the wizard page after plugin activation. |
| 268 |
* |
| 269 |
* @return void |
| 270 |
*/ |
| 271 |
function activation_redirect_wplegalpages() { |
| 272 |
if ( get_option( 'redirect_after_activation_option_lp', false ) ) { |
| 273 |
delete_option( 'redirect_after_activation_option_lp' ); |
| 274 |
exit( esc_html( wp_redirect( admin_url( 'admin.php?page=legal-pages' ) ) ) ); |
| 275 |
} |
| 276 |
} |
| 277 |
/** |
| 278 |
* The code that runs during WPLegalPages deactivation. |
| 279 |
* This action is documented in includes/class-plugin-name-deactivator.php |
| 280 |
*/ |
| 281 |
if ( ! function_exists( 'deactivate_wp_legal_pages' ) ) { |
| 282 |
/** |
| 283 |
* The code that runs during WPLegalPages deactivation. |
| 284 |
* This action is documented in includes/class-plugin-name-deactivator.php |
| 285 |
*/ |
| 286 |
function deactivate_wp_legal_pages() { |
| 287 |
require_once plugin_dir_path( __FILE__ ) . 'includes/class-wp-legal-pages-deactivator.php'; |
| 288 |
WP_Legal_Pages_Deactivator::deactivate(); |
| 289 |
} |
| 290 |
} |
| 291 |
if ( ! function_exists( 'delete_wp_legal_pages' ) ) { |
| 292 |
/** |
| 293 |
* The code that runs during WPLegalPages delete. |
| 294 |
* This action is documented in includes/class-plugin-name-delete.php |
| 295 |
*/ |
| 296 |
function delete_wp_legal_pages() { |
| 297 |
require_once plugin_dir_path( __FILE__ ) . 'includes/class-wp-legal-pages-delete.php'; |
| 298 |
WP_Legal_Pages_Delete::delete(); |
| 299 |
} |
| 300 |
} |
| 301 |
register_activation_hook( __FILE__, 'activate_wp_legal_pages' ); |
| 302 |
register_deactivation_hook( __FILE__, 'deactivate_wp_legal_pages' ); |
| 303 |
register_uninstall_hook( __FILE__, 'delete_wp_legal_pages' ); |
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
/** |
| 308 |
* The core WPLegalPages class that is used to define internationalization, |
| 309 |
* admin-specific hooks, and public-facing site hooks. |
| 310 |
*/ |
| 311 |
require plugin_dir_path( __FILE__ ) . 'includes/class-wp-legal-pages.php'; |
| 312 |
|
| 313 |
/** |
| 314 |
* Begins execution of the WPLegalPages. |
| 315 |
* |
| 316 |
* Since everything within the WPLegalPages is registered via hooks, |
| 317 |
* then kicking off the WPLegalPages from this point in the file does |
| 318 |
* not affect the page life cycle. |
| 319 |
* |
| 320 |
* @since 1.0.0 |
| 321 |
*/ |
| 322 |
function run_wp_legal_pages() { |
| 323 |
$legal_pages = new WP_Legal_Pages(); |
| 324 |
$legal_pages->run(); |
| 325 |
} |
| 326 |
run_wp_legal_pages(); |
| 327 |
|