| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 3 |
|
| 4 |
include_once ( WPPB_PLUGIN_DIR.'/features/upgrades/upgrades-functions.php' ); |
| 5 |
|
| 6 |
/** |
| 7 |
* Function that assures backwards compatibility for all future versions, where this is needed |
| 8 |
* |
| 9 |
* @since v.1.3.13 |
| 10 |
* |
| 11 |
* @return void |
| 12 |
*/ |
| 13 |
function wppb_update_patch(){ |
| 14 |
if ( !get_option( 'wppb_version' ) ) { |
| 15 |
add_option( 'wppb_version', '1.3.13' ); |
| 16 |
|
| 17 |
do_action( 'wppb_set_initial_version_number', PROFILE_BUILDER_VERSION ); |
| 18 |
} |
| 19 |
|
| 20 |
$wppb_version = get_option( 'wppb_version' ); |
| 21 |
|
| 22 |
do_action( 'wppb_before_default_changes', PROFILE_BUILDER_VERSION, $wppb_version ); |
| 23 |
|
| 24 |
if ( version_compare( PROFILE_BUILDER_VERSION, $wppb_version, '>' ) ) { |
| 25 |
$paid_versions = array( 'Profile Builder Pro', 'Profile Builder Hobbyist', 'Profile Builder Agency', 'Profile Builder Unlimited', 'Profile Builder Basic' ); |
| 26 |
|
| 27 |
if ( in_array( PROFILE_BUILDER, $paid_versions ) ){ |
| 28 |
|
| 29 |
/* stopped creating them on 01.02.2016 */ |
| 30 |
/*$upload_dir = wp_upload_dir(); |
| 31 |
wp_mkdir_p( $upload_dir['basedir'].'/profile_builder' ); |
| 32 |
wp_mkdir_p( $upload_dir['basedir'].'/profile_builder/attachments/' ); |
| 33 |
wp_mkdir_p( $upload_dir['basedir'].'/profile_builder/avatars/' );*/ |
| 34 |
|
| 35 |
// Flush the rewrite rules and add them, if need be, the proper way. |
| 36 |
if ( function_exists( 'wppb_flush_rewrite_rules' ) ) |
| 37 |
wppb_flush_rewrite_rules(); |
| 38 |
|
| 39 |
wppb_pro_hobbyist_v1_3_13(); |
| 40 |
} |
| 41 |
|
| 42 |
$pro_versions = array( 'Profile Builder Pro', 'Profile Builder Agency', 'Profile Builder Unlimited' ); |
| 43 |
|
| 44 |
if ( in_array( PROFILE_BUILDER, $pro_versions ) ){ |
| 45 |
wppb_pro_v1_3_15(); |
| 46 |
} |
| 47 |
|
| 48 |
update_option( 'wppb_version', PROFILE_BUILDER_VERSION ); |
| 49 |
} |
| 50 |
|
| 51 |
//this should run only once, mainly if the old version is < 2.0 (can be anything) |
| 52 |
if ( version_compare( $wppb_version, 2.0, '<' ) ) { |
| 53 |
$all_versions = array( 'Profile Builder Pro', 'Profile Builder Hobbyist', 'Profile Builder Agency', 'Profile Builder Unlimited', 'Profile Builder Basic', 'Profile Builder Free' ); |
| 54 |
|
| 55 |
if ( in_array( PROFILE_BUILDER, $all_versions ) ){ |
| 56 |
wppb_pro_hobbyist_free_v2_0(); |
| 57 |
} |
| 58 |
|
| 59 |
$pro_versions = array( 'Profile Builder Pro', 'Profile Builder Agency', 'Profile Builder Unlimited' ); |
| 60 |
|
| 61 |
if ( in_array( PROFILE_BUILDER, $pro_versions ) ){ |
| 62 |
wppb_pro_userlisting_compatibility_upgrade(); |
| 63 |
wppb_pro_email_customizer_compatibility_upgrade(); |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
// this should run only once, mainly if the old version is < 2.2.5 (can be anything) |
| 68 |
if ( version_compare( $wppb_version, '2.2.5', '<' ) ) { |
| 69 |
$pro_versions = array( 'Profile Builder Pro', 'Profile Builder Agency', 'Profile Builder Unlimited' ); |
| 70 |
|
| 71 |
if ( in_array( PROFILE_BUILDER, $pro_versions ) ){ |
| 72 |
wppb_new_custom_redirects_compatibility(); |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
if ( version_compare( $wppb_version, '2.2.5', '<=' ) ) { |
| 77 |
if( is_multisite() ){ |
| 78 |
$wppb_general_settings = get_option( 'wppb_general_settings', 'not_set' ); |
| 79 |
if ( $wppb_general_settings != 'not_set' ) { |
| 80 |
$wppb_general_settings['emailConfirmation'] = 'yes'; |
| 81 |
update_option('wppb_general_settings', $wppb_general_settings); |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
} |
| 86 |
|
| 87 |
do_action ( 'wppb_after_default_changes', PROFILE_BUILDER_VERSION, $wppb_version ); |
| 88 |
} |
| 89 |
add_action ( 'init', 'wppb_update_patch' ); |
| 90 |
|
| 91 |
|
| 92 |
/** |
| 93 |
* before disabling the old plugin addons save their status in the db |
| 94 |
*/ |
| 95 |
add_action( 'plugins_loaded', 'wppb_save_old_add_ons_status', 11 ); |
| 96 |
function wppb_save_old_add_ons_status(){ |
| 97 |
$old_addon_list = wppb_get_old_addons_slug_list(); |
| 98 |
$old_addons_status = get_option( 'wppb_old_add_ons_status', array() ); |
| 99 |
|
| 100 |
//if it's triggered in the frontend we need this include |
| 101 |
if( !function_exists('is_plugin_active') ) |
| 102 |
include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
| 103 |
|
| 104 |
foreach( $old_addon_list as $addon_slug ){ |
| 105 |
if( !isset( $old_addons_status[$addon_slug] ) ) {//don't change the status, just take the first run through |
| 106 |
if ( is_plugin_active($addon_slug) ) |
| 107 |
$old_addons_status[$addon_slug] = true; |
| 108 |
else |
| 109 |
$old_addons_status[$addon_slug] = false; |
| 110 |
} |
| 111 |
} |
| 112 |
|
| 113 |
update_option( 'wppb_old_add_ons_status', $old_addons_status ); |
| 114 |
} |
| 115 |
|
| 116 |
|
| 117 |
/** |
| 118 |
* Deactivate the old addons as plugins |
| 119 |
*/ |
| 120 |
add_action( 'plugins_loaded', 'wppb_disable_old_add_ons', 12 ); |
| 121 |
function wppb_disable_old_add_ons(){ |
| 122 |
|
| 123 |
//if it's triggered in the frontend we need this include |
| 124 |
if( !function_exists('is_plugin_active') ) |
| 125 |
include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
| 126 |
|
| 127 |
$old_addons_list = wppb_get_old_addons_slug_list(); |
| 128 |
$deactivated_addons = 0; |
| 129 |
foreach( $old_addons_list as $addon_slug ){ |
| 130 |
if( is_plugin_active($addon_slug) ){ |
| 131 |
if( is_multisite() ){ |
| 132 |
if( is_plugin_active_for_network($addon_slug) ) |
| 133 |
deactivate_plugins($addon_slug, true); |
| 134 |
else |
| 135 |
deactivate_plugins($addon_slug, true, false); |
| 136 |
} |
| 137 |
else { |
| 138 |
deactivate_plugins($addon_slug, true); |
| 139 |
} |
| 140 |
$deactivated_addons++; |
| 141 |
} |
| 142 |
} |
| 143 |
if ( isset( $_GET['activate'] ) && $deactivated_addons === 1 ){ |
| 144 |
add_action( 'load-plugins.php', |
| 145 |
function(){ |
| 146 |
add_action( 'in_admin_header', |
| 147 |
function(){ |
| 148 |
add_filter( 'gettext', 'wppb_disable_old_add_ons_notice', 99, 3 ); |
| 149 |
} |
| 150 |
); |
| 151 |
} |
| 152 |
); |
| 153 |
} elseif ( isset( $_GET['activate-multi'] ) && $deactivated_addons !== 0 ){ |
| 154 |
add_action( 'admin_notices', 'wppb_disable_old_add_ons_notice_multi' ); |
| 155 |
} |
| 156 |
} |
| 157 |
|
| 158 |
function wppb_disable_old_add_ons_notice( $translated_text, $untranslated_text, $domain ) |
| 159 |
{ |
| 160 |
$old = array( |
| 161 |
"Plugin activated." |
| 162 |
); |
| 163 |
|
| 164 |
$new = "This Profile Builder add-on has been migrated to the main plugin and is no longer used. You can delete it."; |
| 165 |
|
| 166 |
if ( in_array( $untranslated_text, $old, true ) ) |
| 167 |
{ |
| 168 |
$translated_text = $new; |
| 169 |
remove_filter( current_filter(), __FUNCTION__, 99 ); |
| 170 |
} |
| 171 |
return $translated_text; |
| 172 |
} |
| 173 |
|
| 174 |
function wppb_disable_old_add_ons_notice_multi() { |
| 175 |
?> |
| 176 |
<div id="message" class="updated notice is-dismissible"> |
| 177 |
<p><?php esc_html_e( 'This Profile Builder add-on has been migrated to the main plugin and is no longer used. You can delete it.', 'profile-builder' ); ?></p> |
| 178 |
</div> |
| 179 |
<?php |
| 180 |
} |
| 181 |
|
| 182 |
add_action( 'plugins_loaded', 'wppb_generate_new_free_add_ons_setting', 13 ); |
| 183 |
function wppb_generate_new_free_add_ons_setting(){ |
| 184 |
$wppb_free_add_ons_settings = get_option( 'wppb_free_add_ons_settings', array() ); |
| 185 |
if( empty( $wppb_free_add_ons_settings ) ){ |
| 186 |
|
| 187 |
$old_addons_list = wppb_get_old_addons_slug_list(); |
| 188 |
foreach( $old_addons_list as $addon_slug ){ |
| 189 |
|
| 190 |
switch ($addon_slug) { |
| 191 |
case 'pb-add-on-customization-toolbox/index.php': |
| 192 |
if( !wppb_was_addon_active_as_plugin( $addon_slug ) ){ |
| 193 |
//it might have been active at some point and we need to remove the settings so they don't get activated in Advance Settings |
| 194 |
$toolbox_settings = array( 'wppb_toolbox_forms_settings', 'wppb_toolbox_fields_settings', 'wppb_toolbox_userlisting_settings', 'wppb_toolbox_shortcodes_settings', 'wppb_toolbox_admin_settings' ); |
| 195 |
foreach( $toolbox_settings as $toolbox_setting ){ |
| 196 |
delete_option( $toolbox_setting ); |
| 197 |
} |
| 198 |
} |
| 199 |
break; |
| 200 |
case 'pb-add-on-gdpr-communication-preferences/pb-gdpr-communication-preferences.php': |
| 201 |
if( wppb_was_addon_active_as_plugin( $addon_slug ) ) |
| 202 |
$wppb_free_add_ons_settings['gdpr-communication-preferences'] = true; |
| 203 |
else |
| 204 |
$wppb_free_add_ons_settings['gdpr-communication-preferences'] = false; |
| 205 |
break; |
| 206 |
case 'pb-add-on-labels-edit/pble.php': |
| 207 |
if( wppb_was_addon_active_as_plugin( $addon_slug ) ) |
| 208 |
$wppb_free_add_ons_settings['labels-edit'] = true; |
| 209 |
else |
| 210 |
$wppb_free_add_ons_settings['labels-edit'] = false; |
| 211 |
break; |
| 212 |
case 'pb-add-on-maximum-character-length/index.php': |
| 213 |
if( wppb_was_addon_active_as_plugin( $addon_slug ) ) |
| 214 |
$wppb_free_add_ons_settings['maximum-character-length'] = true; |
| 215 |
else |
| 216 |
$wppb_free_add_ons_settings['maximum-character-length'] = false; |
| 217 |
break; |
| 218 |
case 'pb-add-on-custom-css-classes-on-fields/index.php': |
| 219 |
if( wppb_was_addon_active_as_plugin( $addon_slug ) ) |
| 220 |
$wppb_free_add_ons_settings['custom-css-classes-on-fields'] = true; |
| 221 |
else |
| 222 |
$wppb_free_add_ons_settings['custom-css-classes-on-fields'] = false; |
| 223 |
break; |
| 224 |
case 'pb-add-on-import-export/pbie.php': |
| 225 |
if( wppb_was_addon_active_as_plugin( $addon_slug ) ) |
| 226 |
$wppb_free_add_ons_settings['import-export'] = true; |
| 227 |
else |
| 228 |
$wppb_free_add_ons_settings['import-export'] = false; |
| 229 |
break; |
| 230 |
} |
| 231 |
|
| 232 |
|
| 233 |
} |
| 234 |
|
| 235 |
add_option( 'wppb_free_add_ons_settings', $wppb_free_add_ons_settings ); |
| 236 |
} |
| 237 |
|
| 238 |
// Add an option for the new User Profile Picture add-on |
| 239 |
if ( !array_key_exists( 'user-profile-picture', $wppb_free_add_ons_settings ) ) { |
| 240 |
|
| 241 |
$wppb_free_add_ons_settings['user-profile-picture'] = false; |
| 242 |
} |
| 243 |
|
| 244 |
update_option( 'wppb_free_add_ons_settings', $wppb_free_add_ons_settings ); |
| 245 |
|
| 246 |
} |
| 247 |
|
| 248 |
add_action( 'plugins_loaded', 'wppb_generate_new_advanced_add_ons_setting', 13 ); |
| 249 |
function wppb_generate_new_advanced_add_ons_setting(){ |
| 250 |
$wppb_advanced_add_ons_settings = get_option( 'wppb_advanced_add_ons_settings', array() ); |
| 251 |
if( empty( $wppb_advanced_add_ons_settings ) ){ |
| 252 |
|
| 253 |
$old_addons_list = wppb_get_old_addons_slug_list(); |
| 254 |
foreach( $old_addons_list as $addon_slug ){ |
| 255 |
|
| 256 |
switch ($addon_slug) { |
| 257 |
case 'pb-add-on-buddypress/index.php': |
| 258 |
if( wppb_was_addon_active_as_plugin( $addon_slug ) ) |
| 259 |
$wppb_advanced_add_ons_settings['buddypress'] = true; |
| 260 |
else |
| 261 |
$wppb_advanced_add_ons_settings['buddypress'] = false; |
| 262 |
break; |
| 263 |
case 'pb-add-on-social-connect/index.php': |
| 264 |
if( wppb_was_addon_active_as_plugin( $addon_slug ) ) |
| 265 |
$wppb_advanced_add_ons_settings['social-connect'] = true; |
| 266 |
else |
| 267 |
$wppb_advanced_add_ons_settings['social-connect'] = false; |
| 268 |
break; |
| 269 |
case 'pb-add-on-woocommerce/index.php': |
| 270 |
if( wppb_was_addon_active_as_plugin( $addon_slug ) ) |
| 271 |
$wppb_advanced_add_ons_settings['woocommerce'] = true; |
| 272 |
else |
| 273 |
$wppb_advanced_add_ons_settings['woocommerce'] = false; |
| 274 |
break; |
| 275 |
case 'pb-add-on-multi-step-forms/index.php': |
| 276 |
if( wppb_was_addon_active_as_plugin( $addon_slug ) ) |
| 277 |
$wppb_advanced_add_ons_settings['multi-step-forms'] = true; |
| 278 |
else |
| 279 |
$wppb_advanced_add_ons_settings['multi-step-forms'] = false; |
| 280 |
break; |
| 281 |
case 'pb-add-on-mailchimp-integration/index.php': |
| 282 |
if( wppb_was_addon_active_as_plugin( $addon_slug ) ) |
| 283 |
$wppb_advanced_add_ons_settings['mailchimp-integration'] = true; |
| 284 |
else |
| 285 |
$wppb_advanced_add_ons_settings['mailchimp-integration'] = false; |
| 286 |
break; |
| 287 |
case 'pb-add-on-bbpress/index.php': |
| 288 |
if( wppb_was_addon_active_as_plugin( $addon_slug ) ) |
| 289 |
$wppb_advanced_add_ons_settings['bbpress'] = true; |
| 290 |
else |
| 291 |
$wppb_advanced_add_ons_settings['bbpress'] = false; |
| 292 |
break; |
| 293 |
case 'pb-add-on-campaign-monitor/index.php': |
| 294 |
if( wppb_was_addon_active_as_plugin( $addon_slug ) ) |
| 295 |
$wppb_advanced_add_ons_settings['campaign-monitor'] = true; |
| 296 |
else |
| 297 |
$wppb_advanced_add_ons_settings['campaign-monitor'] = false; |
| 298 |
break; |
| 299 |
case 'pb-add-on-field-visibility/index.php': |
| 300 |
if( wppb_was_addon_active_as_plugin( $addon_slug ) ) |
| 301 |
$wppb_advanced_add_ons_settings['field-visibility'] = true; |
| 302 |
else |
| 303 |
$wppb_advanced_add_ons_settings['field-visibility'] = false; |
| 304 |
break; |
| 305 |
case 'pb-add-on-edit-profile-approved-by-admin/index.php': |
| 306 |
if( wppb_was_addon_active_as_plugin( $addon_slug ) ) |
| 307 |
$wppb_advanced_add_ons_settings['edit-profile-approved-by-admin'] = true; |
| 308 |
else |
| 309 |
$wppb_advanced_add_ons_settings['edit-profile-approved-by-admin'] = false; |
| 310 |
break; |
| 311 |
case 'pb-add-on-custom-profile-menus/index.php': |
| 312 |
if( wppb_was_addon_active_as_plugin( $addon_slug ) ) |
| 313 |
$wppb_advanced_add_ons_settings['custom-profile-menus'] = true; |
| 314 |
else |
| 315 |
$wppb_advanced_add_ons_settings['custom-profile-menus'] = false; |
| 316 |
break; |
| 317 |
case 'pb-add-on-mailpoet-integration/index.php': |
| 318 |
if( wppb_was_addon_active_as_plugin( $addon_slug ) ) |
| 319 |
$wppb_advanced_add_ons_settings['mailpoet-integration'] = true; |
| 320 |
else |
| 321 |
$wppb_advanced_add_ons_settings['mailpoet-integration'] = false; |
| 322 |
break; |
| 323 |
} |
| 324 |
|
| 325 |
|
| 326 |
} |
| 327 |
|
| 328 |
add_option( 'wppb_advanced_add_ons_settings', $wppb_advanced_add_ons_settings ); |
| 329 |
} |
| 330 |
} |