| 1 |
<?php |
| 2 |
/** |
| 3 |
* WP-Members Installation Functions |
| 4 |
* |
| 5 |
* Functions to install and upgrade WP-Members. |
| 6 |
* |
| 7 |
* This file is part of the WP-Members plugin by Chad Butler |
| 8 |
* You can find out more about this plugin at https://rocketgeek.com |
| 9 |
* Copyright (c) 2006-2026 Chad Butler |
| 10 |
* WP-Members(tm) is a trademark of butlerblog.com |
| 11 |
* |
| 12 |
* @package WP-Members |
| 13 |
* @author Chad Butler |
| 14 |
* @copyright 2006-2026 |
| 15 |
*/ |
| 16 |
|
| 17 |
// Exit if accessed directly. |
| 18 |
if ( ! defined( 'ABSPATH' ) ) { |
| 19 |
exit(); |
| 20 |
} |
| 21 |
|
| 22 |
/** |
| 23 |
* Installs or upgrades the plugin. |
| 24 |
* |
| 25 |
* @since 2.2.2 |
| 26 |
* @since 3.1.6 Returns $wpmem_settings. |
| 27 |
* |
| 28 |
* @return array $wpmem_settings |
| 29 |
*/ |
| 30 |
function wpmem_do_install() { |
| 31 |
|
| 32 |
/* |
| 33 |
* If you need to force an install, set $chk_force = true. |
| 34 |
* |
| 35 |
* Important notes: |
| 36 |
* |
| 37 |
* 1. This will override any settings you already have for any of the plugin settings. |
| 38 |
* 2. This will not effect any WP settings or registered users. |
| 39 |
*/ |
| 40 |
|
| 41 |
$chk_force = false; |
| 42 |
|
| 43 |
// Existing settings are held in a separate array so we can update settings as we go. |
| 44 |
$existing_settings = get_option( 'wpmembers_settings' ); |
| 45 |
|
| 46 |
if ( false == $existing_settings || $chk_force == true ) { |
| 47 |
|
| 48 |
// New install. |
| 49 |
$wpmem_settings = wpmem_install_settings(); |
| 50 |
wpmem_install_fields(); |
| 51 |
wpmem_install_dialogs(); |
| 52 |
|
| 53 |
} else { |
| 54 |
|
| 55 |
// Upgrade. |
| 56 |
$wpmem_settings = wpmem_upgrade_settings(); |
| 57 |
|
| 58 |
if ( version_compare( $existing_settings['version'], '3.5.2', '<' ) ) { |
| 59 |
wpmem_update_autoload_options(); |
| 60 |
} |
| 61 |
|
| 62 |
if ( version_compare( $existing_settings['version'], '3.5.0', '<' ) ) { |
| 63 |
wpmem_add_profile_to_fields( $existing_settings ); |
| 64 |
wpmem_update_user_dirs(); |
| 65 |
wpmem_upgrade_user_search_crud_table(); // 3.4.7 fixes(?) a db collation issue with the user search CRUD table |
| 66 |
} |
| 67 |
|
| 68 |
if ( version_compare( $existing_settings['version'], '3.1.1', '<' ) ) { |
| 69 |
wpmem_upgrade_dialogs(); |
| 70 |
wpmem_upgrade_captcha(); |
| 71 |
} |
| 72 |
|
| 73 |
// Only run this if DB version < 2.3.0 |
| 74 |
if ( version_compare( $existing_settings['db_version'], '2.3.0', '<' ) ) { |
| 75 |
wpmem_upgrade_hidden_transient(); |
| 76 |
} |
| 77 |
|
| 78 |
// Only run this if DB version < 2.2.1 |
| 79 |
if ( version_compare( $existing_settings['db_version'], '2.2.1', '<' ) ) { |
| 80 |
wpmem_upgrade_woo_reg(); |
| 81 |
} |
| 82 |
|
| 83 |
// Only run these if DB version is < 2.2.0 |
| 84 |
if ( version_compare( $existing_settings['db_version'], '2.2.0', '<' ) ) { |
| 85 |
wpmem_upgrade_fields(); |
| 86 |
wpmem_upgrade_product_expiration(); |
| 87 |
} |
| 88 |
|
| 89 |
// Remove options no longer used or needed. |
| 90 |
delete_option( 'wpmembers_install_state' ); |
| 91 |
delete_option( 'wpmem_enable_field_sc' ); |
| 92 |
} |
| 93 |
|
| 94 |
return $wpmem_settings; |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
/** |
| 99 |
* Updates the existing settings if doing an update. |
| 100 |
* |
| 101 |
* @since 3.0.0 |
| 102 |
* @since 3.1.0 Changed from wpmem_update_settings() to wpmem_upgrade_settings(). |
| 103 |
* @since 3.5.0 Can only directly update 3.0.0 or higher (92% of installs are 3.2 or greater). |
| 104 |
* |
| 105 |
* @return array $wpmem_newsettings |
| 106 |
*/ |
| 107 |
function wpmem_upgrade_settings() { |
| 108 |
|
| 109 |
$wpmem_settings = get_option( 'wpmembers_settings' ); |
| 110 |
|
| 111 |
if ( ! isset( $wpmem_settings['enable_products'] ) ) { |
| 112 |
$wpmem_settings['enable_products'] = 0; |
| 113 |
} |
| 114 |
|
| 115 |
// reCAPTCHA v1 is obsolete. |
| 116 |
if ( isset( $wpmem_settings['captcha'] ) && 1 == $wpmem_settings['captcha'] ) { |
| 117 |
$wpmem_settings['captcha'] = 3; |
| 118 |
} |
| 119 |
|
| 120 |
// If old auto excerpt settings exists, update it. |
| 121 |
if ( isset( $wpmem_settings['autoex']['auto_ex'] ) ) { |
| 122 |
// Update Autoex setting. |
| 123 |
if ( $wpmem_settings['autoex']['auto_ex'] == 1 || $wpmem_settings['autoex']['auto_ex'] == "1" ) { |
| 124 |
// If Autoex is set, move it to posts/pages. |
| 125 |
$wpmem_settings['autoex']['post'] = array( 'enabled' => 1, 'length' => $wpmem_settings['autoex']['auto_ex_len'] ); |
| 126 |
$wpmem_settings['autoex']['page'] = array( 'enabled' => 1, 'length' => $wpmem_settings['autoex']['auto_ex_len'] ); |
| 127 |
} else { |
| 128 |
// If it is not turned on (!=1), set it to off in new setting (-1). |
| 129 |
$wpmem_settings['autoex']['post'] = array( 'enabled' => 0, 'length' => '' ); |
| 130 |
$wpmem_settings['autoex']['page'] = array( 'enabled' => 0, 'length' => '' ); |
| 131 |
} |
| 132 |
unset( $wpmem_settings['autoex']['auto_ex'] ); |
| 133 |
unset( $wpmem_settings['autoex']['auto_ex_len'] ); |
| 134 |
} |
| 135 |
|
| 136 |
// If post types settings does not exist, set as empty array. |
| 137 |
if ( ! isset( $wpmem_settings['post_types'] ) ) { |
| 138 |
$wpmem_settings['post_types'] = array(); |
| 139 |
} |
| 140 |
|
| 141 |
// If form tags is not set, add default. |
| 142 |
if ( ! isset( $wpmem_settings['form_tags'] ) ) { |
| 143 |
$wpmem_settings['form_tags'] = array( 'default' => 'Registration Default' ); |
| 144 |
} |
| 145 |
|
| 146 |
// If email is set in the settings array, change it back to the pre-3.1 option. |
| 147 |
if ( isset( $wpmem_settings['email'] ) ) { |
| 148 |
$from = ( is_array( $wpmem_settings['email'] ) ) ? $wpmem_settings['email']['from'] : ''; |
| 149 |
$name = ( is_array( $wpmem_settings['email'] ) ) ? $wpmem_settings['email']['from_name'] : ''; |
| 150 |
update_option( 'wpmembers_email_wpfrom', $from, false ); |
| 151 |
update_option( 'wpmembers_email_wpname', $name, false ); |
| 152 |
unset( $wpmem_settings['email'] ); |
| 153 |
} |
| 154 |
|
| 155 |
// @since 3.3.0 Upgrade stylesheet setting. |
| 156 |
// @since 3.5.0 Simplified. Only two options: default|use_custom. |
| 157 |
$wpmem_settings = wpmem_upgrade_style_setting( $wpmem_settings ); |
| 158 |
|
| 159 |
// Change 3.4.9 field shortcode option. |
| 160 |
$field_sc = get_option( 'wpmem_enable_field_sc' ); |
| 161 |
if ( $field_sc ) { |
| 162 |
$wpmem_settings['shortcodes']['enable_field'] = intval( $field_sc ); |
| 163 |
delete_option( 'wpmem_enable_field_sc' ); |
| 164 |
} |
| 165 |
|
| 166 |
// Version number should be updated no matter what. |
| 167 |
$wpmem_settings['version'] = WPMEM_VERSION; |
| 168 |
$wpmem_settings['db_version'] = WPMEM_DB_VERSION; |
| 169 |
|
| 170 |
$wpmem_settings['install_state'] = 'update_pending'; |
| 171 |
|
| 172 |
update_option( 'wpmembers_settings', $wpmem_settings, true ); |
| 173 |
return $wpmem_settings; |
| 174 |
} |
| 175 |
|
| 176 |
/** |
| 177 |
* Checks the dialogs array for necessary changes. |
| 178 |
* |
| 179 |
* @since 2.9.3 |
| 180 |
* @since 3.0.0 Changed from update_dialogs() to wpmem_update_dialogs(). |
| 181 |
* @since 3.1.0 Changed from wpmem_update_dialogs() to wpmem_upgrade_dialogs(). |
| 182 |
* @since 3.1.1 Converts numeric dialog array to associative. |
| 183 |
*/ |
| 184 |
function wpmem_upgrade_dialogs() { |
| 185 |
|
| 186 |
$wpmem_dialogs = get_option( 'wpmembers_dialogs' ); |
| 187 |
|
| 188 |
if ( ! array_key_exists( 'restricted_msg', $wpmem_dialogs ) ) { |
| 189 |
// Update is needed. |
| 190 |
$new_arr = array(); |
| 191 |
$new_keys = array( 'restricted_msg', 'user', 'email', 'success', 'editsuccess', 'pwdchangerr', 'pwdchangesuccess', 'pwdreseterr', 'pwdresetsuccess' ); |
| 192 |
foreach ( $wpmem_dialogs as $key => $val ) { |
| 193 |
$new_arr[ $new_keys[ $key ] ] = $val; |
| 194 |
} |
| 195 |
update_option( 'wpmembers_dialogs', $new_arr, false ); |
| 196 |
} |
| 197 |
|
| 198 |
return; |
| 199 |
} |
| 200 |
|
| 201 |
/** |
| 202 |
* Downgrades dialogs array for pre-3.1.1 version rollback. |
| 203 |
* |
| 204 |
* @since 3.1.1 |
| 205 |
*/ |
| 206 |
function wpmem_downgrade_dialogs() { |
| 207 |
|
| 208 |
$wpmem_dialogs = get_option( 'wpmembers_dialogs' ); |
| 209 |
|
| 210 |
if ( array_key_exists( 'restricted_msg', $wpmem_dialogs ) ) { |
| 211 |
// Update is needed. |
| 212 |
$new_arr = array(); |
| 213 |
$i = 0; |
| 214 |
foreach ( $wpmem_dialogs as $key => $val ) { |
| 215 |
$new_arr[ $i ] = $val; |
| 216 |
$i++; |
| 217 |
} |
| 218 |
update_option( 'wpmembers_dialogs', $new_arr, false ); |
| 219 |
} |
| 220 |
|
| 221 |
return; |
| 222 |
} |
| 223 |
|
| 224 |
/** |
| 225 |
* Checks the captcha settings and updates accordingly. |
| 226 |
* |
| 227 |
* Was update_captcha() since 2.9.5, changed to wpmem_update_captcha() in 3.0. |
| 228 |
* |
| 229 |
* @since 2.9.5 |
| 230 |
* @since 3.0.0 Changed from update_captcha() to wpmem_update_captcha(). |
| 231 |
* @since 3.1.0 Changed from wpmem_update_captcha() to wpmem_upgrade_captcha(). |
| 232 |
*/ |
| 233 |
function wpmem_upgrade_captcha() { |
| 234 |
|
| 235 |
$captcha_settings = get_option( 'wpmembers_captcha' ); |
| 236 |
|
| 237 |
// If there captcha settings, update them. |
| 238 |
if ( $captcha_settings && ! array_key_exists( 'recaptcha', $captcha_settings ) ) { |
| 239 |
|
| 240 |
// Check to see if the array keys are numeric. |
| 241 |
$is_numeric = false; |
| 242 |
foreach ( $captcha_settings as $key => $setting ) { |
| 243 |
$is_numeric = ( is_int( $key ) ) ? true : $is_numeric; |
| 244 |
} |
| 245 |
|
| 246 |
if ( $is_numeric ) { |
| 247 |
$new_captcha = array(); |
| 248 |
// These are old recaptcha settings. |
| 249 |
$new_captcha['recaptcha']['public'] = $captcha_settings[0]; |
| 250 |
$new_captcha['recaptcha']['private'] = $captcha_settings[1]; |
| 251 |
$new_captcha['recaptcha']['theme'] = $captcha_settings[2]; |
| 252 |
update_option( 'wpmembers_captcha', $new_captcha, false ); |
| 253 |
} |
| 254 |
} |
| 255 |
return; |
| 256 |
} |
| 257 |
|
| 258 |
/** |
| 259 |
* Does install of default settings. |
| 260 |
* |
| 261 |
* @since 3.1.5 |
| 262 |
* @since 3.1.6 Returns $wpmem_settings |
| 263 |
* |
| 264 |
* @return array $wpmem_settings |
| 265 |
*/ |
| 266 |
function wpmem_install_settings() { |
| 267 |
|
| 268 |
$wpmem_settings = array( |
| 269 |
'install_state' => 'new_install', |
| 270 |
'version' => WPMEM_VERSION, |
| 271 |
'db_version' => WPMEM_DB_VERSION, |
| 272 |
'block' => array( |
| 273 |
'post' => ( is_multisite() ) ? 0 : 1, |
| 274 |
'page' => 0, |
| 275 |
), |
| 276 |
'show_excerpt' => array( |
| 277 |
'post' => 0, |
| 278 |
'page' => 0, |
| 279 |
), |
| 280 |
'show_reg' => array( |
| 281 |
'post' => 1, |
| 282 |
'page' => 1, |
| 283 |
), |
| 284 |
'show_login' => array( |
| 285 |
'post' => 1, |
| 286 |
'page' => 1, |
| 287 |
), |
| 288 |
'autoex' => array( |
| 289 |
'post' => array( 'enabled' => 0, 'length' => '' ), |
| 290 |
'page' => array( 'enabled' => 0, 'length' => '' ), |
| 291 |
), |
| 292 |
'enable_products' => 0, |
| 293 |
'clone_menus' => 0, |
| 294 |
'notify' => 0, |
| 295 |
'mod_reg' => 0, |
| 296 |
'captcha' => 0, |
| 297 |
'use_exp' => 0, |
| 298 |
'use_trial' => 0, |
| 299 |
'warnings' => 0, |
| 300 |
'user_pages' => array( |
| 301 |
'profile' => '', |
| 302 |
'register' => '', |
| 303 |
'login' => '', |
| 304 |
), |
| 305 |
'cssurl' => '', |
| 306 |
'attrib' => 0, |
| 307 |
'post_types' => array(), |
| 308 |
'form_tags' => array( 'default' => 'Registration Default' ), |
| 309 |
'shortcodes' => array( 'enable_field' => 0 ), |
| 310 |
); |
| 311 |
|
| 312 |
// Using update_option to allow for forced update. |
| 313 |
update_option( 'wpmembers_settings', $wpmem_settings, true ); |
| 314 |
|
| 315 |
return $wpmem_settings; |
| 316 |
} |
| 317 |
|
| 318 |
/** |
| 319 |
* Installs default fields. |
| 320 |
* |
| 321 |
* @since 3.1.5 |
| 322 |
* |
| 323 |
* @return array $fields { |
| 324 |
* @type array { |
| 325 |
* order, |
| 326 |
* label, |
| 327 |
* meta key, |
| 328 |
* type, |
| 329 |
* display, |
| 330 |
* required, |
| 331 |
* native, |
| 332 |
* checked value, |
| 333 |
* checked by default, |
| 334 |
* } |
| 335 |
* } |
| 336 |
*/ |
| 337 |
function wpmem_install_fields() { |
| 338 |
$fields = array( |
| 339 |
array( 0, 'Choose a Username', 'username', 'text', 'y', 'y', 'y', 'profile'=>0 ), |
| 340 |
array( 1, 'First Name', 'first_name', 'text', 'y', 'y', 'y', 'profile'=>1 ), |
| 341 |
array( 2, 'Last Name', 'last_name', 'text', 'y', 'y', 'y', 'profile'=>1 ), |
| 342 |
array( 3, 'Address 1', 'billing_address_1', 'text', 'y', 'y', 'n', 'profile'=>1 ), |
| 343 |
array( 4, 'Address 2', 'billing_address_2', 'text', 'y', 'n', 'n', 'profile'=>1 ), |
| 344 |
array( 5, 'City', 'billing_city', 'text', 'y', 'y', 'n', 'profile'=>1 ), |
| 345 |
array( 6, 'State', 'billing_state', 'text', 'y', 'y', 'n', 'profile'=>1 ), |
| 346 |
array( 7, 'Zip', 'billing_postcode', 'text', 'y', 'y', 'n', 'profile'=>1 ), |
| 347 |
array( 8, 'Country', 'billing_country', 'text', 'y', 'y', 'n', 'profile'=>1 ), |
| 348 |
array( 9, 'Phone', 'billing_phone', 'text', 'y', 'y', 'n', 'profile'=>1 ), |
| 349 |
array( 10, 'Email', 'user_email', 'email', 'y', 'y', 'y', 'profile'=>1 ), |
| 350 |
array( 11, 'Confirm Email', 'confirm_email', 'email', 'n', 'n', 'n', 'profile'=>1 ), |
| 351 |
array( 12, 'Website', 'user_url', 'url', 'n', 'n', 'y', 'profile'=>1 ), |
| 352 |
array( 13, 'Biographical Info', 'description', 'textarea', 'n', 'n', 'y', 'profile'=>1 ), |
| 353 |
array( 14, 'Password', 'password', 'password', 'n', 'n', 'n', 'profile'=>0 ), |
| 354 |
array( 15, 'Confirm Password', 'confirm_password', 'password', 'n', 'n', 'n', 'profile'=>0 ), |
| 355 |
); |
| 356 |
update_option( 'wpmembers_fields', $fields, false ); // using update_option to allow for forced update |
| 357 |
return $fields; |
| 358 |
} |
| 359 |
|
| 360 |
/** |
| 361 |
* Installs default dialogs. |
| 362 |
* |
| 363 |
* @since 3.1.5 |
| 364 |
*/ |
| 365 |
function wpmem_install_dialogs() { |
| 366 |
$wpmem_dialogs_arr = array( |
| 367 |
'restricted_msg' => "This content is restricted to site members. If you are an existing user, please log in. New users may register below.", |
| 368 |
'user' => "Sorry, that username is taken, please try another.", |
| 369 |
'email' => "Sorry, that email address already has an account.<br />Please try another.", |
| 370 |
'success' => "Congratulations! Your registration was successful.<br /><br />You may now log in using the password that was emailed to you.", |
| 371 |
'editsuccess' => "Your information was updated!", |
| 372 |
'pwdchangerr' => "Passwords did not match.<br /><br />Please try again.", |
| 373 |
'pwdchangesuccess' => "Password successfully changed!", |
| 374 |
'pwdreseterr' => "Either the username or email address do not exist in our records.", |
| 375 |
'pwdresetsuccess' => "An email with instructions to update your password has been sent to the email address on file for your account.", |
| 376 |
); |
| 377 |
// Insert TOS dialog placeholder. |
| 378 |
$dummy_tos = "Put your TOS (Terms of Service) text here. You can use HTML markup."; |
| 379 |
update_option( 'wpmembers_tos', $dummy_tos, false ); |
| 380 |
update_option( 'wpmembers_dialogs', $wpmem_dialogs_arr, false ); // using update_option to allow for forced update |
| 381 |
} |
| 382 |
|
| 383 |
/** |
| 384 |
* Upgrades fields settings. |
| 385 |
* |
| 386 |
* @since 3.2.0 |
| 387 |
*/ |
| 388 |
function wpmem_upgrade_fields() { |
| 389 |
$fields = get_option( 'wpmembers_fields' ); |
| 390 |
$old_style = false; |
| 391 |
foreach ( $fields as $key => $val ) { |
| 392 |
if ( is_numeric( $key ) ) { |
| 393 |
$old_style = true; |
| 394 |
$check_array[] = $val[2]; |
| 395 |
} |
| 396 |
} |
| 397 |
if ( $old_style && ! in_array( 'username', $check_array ) ) { |
| 398 |
$username_array = array( 0, 'Choose a Username', 'username', 'text', 'y', 'y', 'y' ); |
| 399 |
array_unshift( $fields, $username_array ); |
| 400 |
update_option( 'wpmembers_fields', $fields, false ); |
| 401 |
} |
| 402 |
} |
| 403 |
|
| 404 |
/** |
| 405 |
* Upgrades the stylesheet setting from pre-3.0. |
| 406 |
* |
| 407 |
* This is a basic fix for users who have a WP-Members packaged stylesheet saved |
| 408 |
* with the full URL. I believe 90% or more users simply use the default stylesheet |
| 409 |
* so this should handle most updates. |
| 410 |
* |
| 411 |
* @since 3.2.7 |
| 412 |
* @since 3.5.0 Selector no longer available, so there's only one default, otherwise custom. |
| 413 |
* @since 3.5.4 Remove obsolete "select_style". |
| 414 |
* |
| 415 |
* @param array $settings |
| 416 |
*/ |
| 417 |
function wpmem_upgrade_style_setting( $settings ) { |
| 418 |
|
| 419 |
$url = plugin_dir_url ( __DIR__ ); |
| 420 |
|
| 421 |
if ( version_compare( $settings['version'], '3.5.0', '<' ) ) { |
| 422 |
|
| 423 |
switch ( $settings['select_style'] ) { |
| 424 |
case 'use_custom': |
| 425 |
$settings['cssurl'] = $settings['cssurl']; |
| 426 |
break; |
| 427 |
|
| 428 |
case 'generic-no-float': |
| 429 |
// This is the default style, so we can blank the custom setting. |
| 430 |
$settings['cssurl'] = ''; |
| 431 |
break; |
| 432 |
|
| 433 |
default: |
| 434 |
$settings['cssurl'] = trailingslashit( $url ) . 'assets/css/forms/' . $settings['select_style'] . '.min.css'; |
| 435 |
break; |
| 436 |
} |
| 437 |
} |
| 438 |
|
| 439 |
// Fix invalid style setting from previous upgrades (3.5.0 - 3.5.3) |
| 440 |
if ( $settings['cssurl'] == trailingslashit( $url ) . 'assets/css/forms/default.min.css' |
| 441 |
|| $settings['cssurl'] == trailingslashit( $url ) . 'assets/css/forms/default.css' |
| 442 |
|| $settings['cssurl'] == trailingslashit( $url ) . 'assets/css/forms/generic-no-float.min.css' |
| 443 |
|| $settings['cssurl'] == trailingslashit( $url ) . 'assets/css/forms/generic-no-float.css' ) { |
| 444 |
$settings['cssurl'] = ''; |
| 445 |
} |
| 446 |
|
| 447 |
unset( $settings['select_style'] ); |
| 448 |
|
| 449 |
return $settings; |
| 450 |
} |
| 451 |
|
| 452 |
/** |
| 453 |
* Upgrades product expiration meta from a single meta array |
| 454 |
* to individual meta for each product. Single meta array is |
| 455 |
* still maintained for legacy reasons and rollback possiblity. |
| 456 |
* |
| 457 |
* @since 3.3.0 |
| 458 |
*/ |
| 459 |
function wpmem_upgrade_product_expiration() { |
| 460 |
$users = get_users( array( 'fields'=>'ID' ) ); |
| 461 |
foreach ( $users as $user_id ) { |
| 462 |
$products = get_user_meta( $user_id, '_wpmem_products', true ); |
| 463 |
|
| 464 |
// If the user has legacy products, update to new single meta. |
| 465 |
if ( $products ) { |
| 466 |
// Update each product meta. |
| 467 |
foreach ( $products as $key => $product ) { |
| 468 |
// If it's an expiration product, |
| 469 |
if ( ! is_bool( $product ) ) { |
| 470 |
if ( DateTime::createFromFormat( 'Y-m-d H:i:s', $product ) !== FALSE ) { |
| 471 |
$value = strtotime( $product ); |
| 472 |
} |
| 473 |
} else { |
| 474 |
$value = $product; |
| 475 |
} |
| 476 |
|
| 477 |
// Save new meta |
| 478 |
if ( $key ) { |
| 479 |
update_user_meta( $user_id, '_wpmem_products_' . $key, $value ); |
| 480 |
} |
| 481 |
} |
| 482 |
} |
| 483 |
} |
| 484 |
} |
| 485 |
|
| 486 |
/** |
| 487 |
* Adds woo_reg settings. |
| 488 |
* |
| 489 |
* @since 3.3.8 |
| 490 |
*/ |
| 491 |
function wpmem_upgrade_woo_reg() { |
| 492 |
$wpmem_settings = get_option( 'wpmembers_settings' ); |
| 493 |
|
| 494 |
if ( ! isset( $wpmem_settings['woo'] ) ) { |
| 495 |
$wpmem_settings['woo'] = array( |
| 496 |
'add_my_account_fields' => 0, |
| 497 |
'add_checkout_fields' => 0, |
| 498 |
'add_update_fields' => 0, |
| 499 |
'product_restrict' => 0, |
| 500 |
); |
| 501 |
update_option( 'wpmembers_settings', $wpmem_settings, true ); |
| 502 |
} |
| 503 |
} |
| 504 |
|
| 505 |
function wpmem_upgrade_hidden_transient() { |
| 506 |
if ( ! class_exists( 'WP_Members' ) ) { |
| 507 |
require_once( 'class-wp-members.php' ); |
| 508 |
} |
| 509 |
$temp_obj = new WP_Members; |
| 510 |
$temp_obj->update_hidden_posts(); |
| 511 |
delete_transient( '_wpmem_hidden_posts' ); |
| 512 |
} |
| 513 |
|
| 514 |
function wpmem_upgrade_user_search_crud_table() { |
| 515 |
global $wpdb; |
| 516 |
// Drop old table if it exists. |
| 517 |
$wpdb->query( "DROP TABLE IF EXISTS " . $wpdb->prefix . "wpmembers_user_search_crud;" ); |
| 518 |
// If the table does not exist, create the table to store the meta keys. |
| 519 |
$wpdb->query( "CREATE TABLE IF NOT EXISTS " . $wpdb->prefix . "wpmembers_user_search_crud (meta_key VARCHAR(255) NOT NULL);" ); |
| 520 |
} |
| 521 |
|
| 522 |
function wpmem_add_profile_to_fields( $existing_settings ) { |
| 523 |
|
| 524 |
if ( ! function_exists( 'rktgk_wc_checkout_fields' ) ) { |
| 525 |
include_once( 'vendor/rocketgeek-utilities/loader.php' ); |
| 526 |
} |
| 527 |
|
| 528 |
$fields = get_option( 'wpmembers_fields' ); |
| 529 |
$skips = array( 'username', 'user_login', 'password', 'confirm_password', 'tos' ); |
| 530 |
$woo_skips = array_merge( rktgk_wc_checkout_fields(), array( 'username', 'user_login', 'user_email', 'confirm_email', 'password', 'confirm_password' ) ); |
| 531 |
$wpmem_fields_wcchkout = array(); |
| 532 |
$wpmem_fields_wcaccount = array(); |
| 533 |
|
| 534 |
foreach ( $fields as $key => $field ) { |
| 535 |
$meta_key = $field[2]; |
| 536 |
$reg_val = ( "y" == $field[4] ) ? true : false; |
| 537 |
$fields[ $key ]['profile'] = ( ! in_array( $meta_key, $skips ) ) ? $reg_val : false; |
| 538 |
|
| 539 |
if ( isset( $existing_settings['woo']['add_checkout_fields'] ) && 1 == $existing_settings['woo']['add_checkout_fields'] ) { |
| 540 |
if ( 'file' != $field[3] && 'image' != $field[3] && ! in_array( $meta_key, $woo_skips ) && $reg_val ) { |
| 541 |
$wpmem_fields_wcchkout[] = $meta_key; |
| 542 |
} |
| 543 |
} |
| 544 |
if ( isset( $existing_settings['woo']['add_my_account_fields'] ) && 1 == $existing_settings['woo']['add_my_account_fields'] ) { |
| 545 |
if ( 'file' != $field[3] && 'image' != $field[3] && ! in_array( $meta_key, $woo_skips ) && $reg_val ) { |
| 546 |
$wpmem_fields_wcaccount[] = $meta_key; |
| 547 |
} |
| 548 |
} |
| 549 |
} |
| 550 |
|
| 551 |
update_option( 'wpmembers_fields', $fields, false ); |
| 552 |
|
| 553 |
if ( ! empty( $wpmem_fields_wcchkout ) ) { |
| 554 |
update_option( 'wpmembers_wcchkout_fields', $wpmem_fields_wcchkout, false ); |
| 555 |
} |
| 556 |
|
| 557 |
if ( ! empty( $wpmem_fields_wcaccount ) ) { |
| 558 |
update_option( 'wpmembers_wcacct_fields', $wpmem_fields_wcaccount, false ); |
| 559 |
} |
| 560 |
} |
| 561 |
|
| 562 |
|
| 563 |
function wpmem_onboarding_init( $action ) { |
| 564 |
global $wpmem_onboarding; |
| 565 |
$settings = array( |
| 566 |
'product_action' => $action, |
| 567 |
); |
| 568 |
$wpmem_onboarding = new WP_Members_Installer( $settings ); |
| 569 |
} |
| 570 |
|
| 571 |
function wpmem_onboarding_new_install() { |
| 572 |
wpmem_onboarding_init( 'install' ); |
| 573 |
} |
| 574 |
|
| 575 |
function wpmem_onboarding_pending_update() { |
| 576 |
wpmem_onboarding_init( 'update' ); |
| 577 |
} |
| 578 |
|
| 579 |
function wpmem_onboarding_finalize() { |
| 580 |
global $wpmem, $wpmem_onboarding; |
| 581 |
if ( isset( $_POST['optin'] ) ) { |
| 582 |
if ( 'update_pending' == $wpmem->install_state ) { |
| 583 |
$wpmem_onboarding->deploy( 'wp-members', $wpmem->path . 'wp-members.php', 'update' ); |
| 584 |
} else { |
| 585 |
$wpmem_onboarding->deploy( 'wp-members', $wpmem->path . 'wp-members.php', 'activate' ); |
| 586 |
} |
| 587 |
update_option( 'wpmembers_optin', 1, false ); |
| 588 |
} else { |
| 589 |
update_option( 'wpmembers_optin', 0, false ); |
| 590 |
} |
| 591 |
|
| 592 |
$update_settings = get_option( 'wpmembers_settings' ); |
| 593 |
if ( 'update_pending' == $wpmem->install_state || 'finalize' == wpmem_get( 'wpmem_onboarding_action' ) ) { |
| 594 |
$wpmem->install_state = $update_settings['install_state'] = 'install_complete_' . $wpmem->version . '_' . time(); |
| 595 |
} |
| 596 |
update_option( 'wpmembers_settings', $update_settings, true ); |
| 597 |
} |
| 598 |
|
| 599 |
function wpmem_plugin_deactivate() { |
| 600 |
global $wpmem, $wpmem_onboarding; |
| 601 |
$optin = get_option( 'wpmembers_optin' ); |
| 602 |
if ( 1 == $optin ) { |
| 603 |
wpmem_onboarding_init( 'deactivate' ); |
| 604 |
$wpmem_onboarding->deploy( 'wp-members', $wpmem->path . 'wp-members.php', 'deactivate' ); |
| 605 |
} |
| 606 |
} |
| 607 |
|
| 608 |
function wpmem_update_user_dirs() { |
| 609 |
|
| 610 |
include_once 'api/api-utilities.php'; |
| 611 |
|
| 612 |
$upload_vars = wpmem_upload_dir(); |
| 613 |
|
| 614 |
// @todo See comments below. |
| 615 |
// $users_to_check = get_users( array( 'fields'=>'ID' )); |
| 616 |
|
| 617 |
if ( file_exists( $upload_vars['wpmem_user_files_dir'] ) ) { |
| 618 |
|
| 619 |
// Add indexes and htaccess |
| 620 |
wpmem_create_file( array( |
| 621 |
'path' => $upload_vars['wpmem_base_dir'], |
| 622 |
'name' => 'index.php', |
| 623 |
'contents' => "<?php // Silence is golden." |
| 624 |
) ); |
| 625 |
|
| 626 |
wpmem_create_file( array( |
| 627 |
'path' => $upload_vars['wpmem_user_files_dir'], |
| 628 |
'name' => '.htaccess', |
| 629 |
'contents' => "Options -Indexes" |
| 630 |
) ); |
| 631 |
} |
| 632 |
|
| 633 |
// User files are being moved in bulk and this will be handled in the move. |
| 634 |
// Left the above to create the new dir and setup. |
| 635 |
/* |
| 636 |
if ( file_exists( $upload_vars['wpmem_user_files_dir'] ) ) { |
| 637 |
|
| 638 |
// Loop through users to update user dirs. |
| 639 |
foreach ( $users_to_check as $user ) { |
| 640 |
$wpmem_user_dir = trailingslashit( $upload_vars['wpmem_user_files_dir'] ) . $user; |
| 641 |
if ( is_dir( $wpmem_user_dir ) ) { |
| 642 |
wpmem_create_file( array( |
| 643 |
'path' => $wpmem_user_dir, |
| 644 |
'name' => 'index.php', |
| 645 |
'contents' => "<?php // Silence is golden." |
| 646 |
) ); |
| 647 |
} |
| 648 |
} |
| 649 |
} |
| 650 |
*/ |
| 651 |
} |
| 652 |
|
| 653 |
function wpmem_update_autoload_options() { |
| 654 |
$wpmem_options = array( |
| 655 |
"wpmembers_settings" => true, |
| 656 |
"wpmem_hidden_posts" => true, |
| 657 |
"wpmem_memberships" => true, |
| 658 |
"wpmembers_optin" => false, |
| 659 |
"wpmembers_fields" => false, |
| 660 |
"wpmembers_dialogs" => false, |
| 661 |
"wpmembers_captcha" => false, |
| 662 |
"wpmembers_tos" => false, |
| 663 |
"wpmembers_export" => false, |
| 664 |
"wpmembers_dropins" => false, |
| 665 |
"wpmembers_wcchkout_fields" => false, |
| 666 |
"wpmembers_wcacct_fields" => false, |
| 667 |
"wpmembers_utfields" => false, |
| 668 |
"wpmembers_usfields" => false, |
| 669 |
"wpmembers_email_newreg" => false, |
| 670 |
"wpmembers_email_newmod" => false, |
| 671 |
"wpmembers_email_appmod" => false, |
| 672 |
"wpmembers_email_repass" => false, |
| 673 |
"wpmembers_email_footer" => false, |
| 674 |
"wpmembers_email_notify" => false, |
| 675 |
"wpmembers_email_wpfrom" => false, |
| 676 |
"wpmembers_email_wpname" => false, |
| 677 |
"wpmembers_email_html" => false, |
| 678 |
"wpmembers_email_getuser" => false, |
| 679 |
"wpmembers_email_validated" => false, |
| 680 |
); |
| 681 |
|
| 682 |
// Update wpmem options autoload values. |
| 683 |
wp_set_option_autoload_values( $wpmem_options ); |
| 684 |
|
| 685 |
// Delete pre-3.x options if they exist. |
| 686 |
delete_option( "wpmembers_msurl" ); |
| 687 |
delete_option( "wpmembers_regurl" ); |
| 688 |
delete_option( "wpmembers_logurl" ); |
| 689 |
delete_option( "wpmembers_cssurl" ); |
| 690 |
delete_option( "wpmembers_style" ); |
| 691 |
delete_option( "wpmembers_autoex" ); |
| 692 |
delete_option( "wpmembers_attrib" ); |
| 693 |
} |
| 694 |
|
| 695 |
class WP_Members_Installer { |
| 696 |
|
| 697 |
public $settings; |
| 698 |
public $product_action; |
| 699 |
public $opt_in_callback; |
| 700 |
public $opt_in_callback_args; |
| 701 |
|
| 702 |
public function __construct( $settings ) { |
| 703 |
$this->settings = $settings; |
| 704 |
|
| 705 |
foreach ( $settings as $key => $value ) { |
| 706 |
$this->{$key} = $value; |
| 707 |
} |
| 708 |
|
| 709 |
add_action( 'admin_notices', array( $this, 'onboarding_notice' ) ); |
| 710 |
} |
| 711 |
|
| 712 |
public function deploy( $slug, $product_file, $action ) { |
| 713 |
global $wpmem; |
| 714 |
require_once $wpmem->path . 'includes/vendor/rocketgeek-plugin-manager/class-rocketgeek-deploy-plugin.php'; |
| 715 |
//$rgut = new RocketGeek_Deploy_Plugin_v1( $slug, $product_file, $action, 'plugin' ); |
| 716 |
} |
| 717 |
|
| 718 |
public function onboarding_notice() { |
| 719 |
global $wpmem; |
| 720 |
|
| 721 |
$show_release_notes = true; |
| 722 |
$release_notes_link = "https://rocketgeek.com/release-announcements/wp-members-3-5-6/"; |
| 723 |
|
| 724 |
if ( 'new_install' == $wpmem->install_state ) { |
| 725 |
$notice_heading = __( 'Thank you for installing WP-Members, the original WordPress membership plugin.', 'wp-members' ); |
| 726 |
$notice_button = __( 'Complete plugin setup', 'wp-members' ); |
| 727 |
$show_release_notes = false; |
| 728 |
} |
| 729 |
|
| 730 |
if ( 'update_pending' == $wpmem->install_state ) { |
| 731 |
$notice_heading = __( 'Thank you for updating WP-Members, the original WordPress membership plugin.', 'wp-members' ); |
| 732 |
$notice_button = __( 'Complete the update', 'wp-members' ); |
| 733 |
} |
| 734 |
|
| 735 |
if ( 'finalize' == wpmem_get( 'wpmem_onboarding_action' ) ) { |
| 736 |
|
| 737 |
} |
| 738 |
|
| 739 |
include_once $wpmem->path . 'includes/admin/partials/onboarding_notice.php'; |
| 740 |
} |
| 741 |
|
| 742 |
public function has_user_opted_in() { |
| 743 |
global $wpmem; |
| 744 |
if ( 1 == $wpmem->optin ) { |
| 745 |
return true; |
| 746 |
} |
| 747 |
|
| 748 |
return false; |
| 749 |
} |
| 750 |
} |
| 751 |
// End of file. |