| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 3 |
|
| 4 |
/** |
| 5 |
* Function that adds backwards compatibility starting from v1.3.15 for the email customizer |
| 6 |
* |
| 7 |
* @since v.1.3.15 |
| 8 |
* |
| 9 |
* @return void |
| 10 |
*/ |
| 11 |
function wppb_pro_v1_3_15(){ |
| 12 |
$email_customizer_array = get_option( 'emailCustomizer', 'not_found' ); |
| 13 |
|
| 14 |
if ( $email_customizer_array != 'not_found' ){ |
| 15 |
$new_email_customizer_array = array(); |
| 16 |
|
| 17 |
$new_email_customizer_array = wppb_copy_old_content( $email_customizer_array, $new_email_customizer_array, 'from', 'reply_to' ); |
| 18 |
$new_email_customizer_array = wppb_copy_old_content( $email_customizer_array, $new_email_customizer_array, 'settingsGroup1Option2', 'default_registration_email_subject' ); |
| 19 |
$new_email_customizer_array = wppb_copy_old_content( $email_customizer_array, $new_email_customizer_array, 'settingsGroup1Option3', 'default_registration_email_content' ); |
| 20 |
$new_email_customizer_array = wppb_copy_old_content( $email_customizer_array, $new_email_customizer_array, 'settingsGroup3Option2', 'registration_w_admin_approval_email_subject' ); |
| 21 |
$new_email_customizer_array = wppb_copy_old_content( $email_customizer_array, $new_email_customizer_array, 'settingsGroup3Option3', 'registration_w_admin_approval_email_content' ); |
| 22 |
$new_email_customizer_array = wppb_copy_old_content( $email_customizer_array, $new_email_customizer_array, 'settingsGroup4Option2', 'admin_approval_aproved_status_email_subject' ); |
| 23 |
$new_email_customizer_array = wppb_copy_old_content( $email_customizer_array, $new_email_customizer_array, 'settingsGroup4Option3', 'admin_approval_aproved_status_email_content' ); |
| 24 |
$new_email_customizer_array = wppb_copy_old_content( $email_customizer_array, $new_email_customizer_array, 'settingsGroup2Option2', 'registration_w_email_confirmation_email_subject' ); |
| 25 |
$new_email_customizer_array = wppb_copy_old_content( $email_customizer_array, $new_email_customizer_array, 'settingsGroup2Option3', 'registration_w_email_confirmation_email_content' ); |
| 26 |
$new_email_customizer_array = wppb_copy_old_content( $email_customizer_array, $new_email_customizer_array, 'settingsGroup4Option6', 'admin_approval_unaproved_status_email_subject' ); |
| 27 |
$new_email_customizer_array = wppb_copy_old_content( $email_customizer_array, $new_email_customizer_array, 'settingsGroup4Option7', 'admin_approval_unaproved_status_email_content' ); |
| 28 |
$new_email_customizer_array = wppb_copy_old_content( $email_customizer_array, $new_email_customizer_array, 'admin_settingsGroup1Option2', 'admin_default_registration_email_subject' ); |
| 29 |
$new_email_customizer_array = wppb_copy_old_content( $email_customizer_array, $new_email_customizer_array, 'admin_settingsGroup1Option3', 'admin_default_registration_email_content' ); |
| 30 |
$new_email_customizer_array = wppb_copy_old_content( $email_customizer_array, $new_email_customizer_array, 'admin_settingsGroup3Option2', 'admin_registration_w_admin_approval_email_subject' ); |
| 31 |
$new_email_customizer_array = wppb_copy_old_content( $email_customizer_array, $new_email_customizer_array, 'admin_settingsGroup3Option3', 'admin_registration_w_admin_approval_email_content' ); |
| 32 |
|
| 33 |
update_option( 'emailCustomizer', $new_email_customizer_array + $email_customizer_array ); |
| 34 |
} |
| 35 |
} |
| 36 |
|
| 37 |
function wppb_copy_old_content ( $email_customizer_array, $new_email_customizer_array, $old_index, $new_index ){ |
| 38 |
if ( isset( $email_customizer_array[$old_index] ) ){ |
| 39 |
$new_email_customizer_array[$new_index] = $email_customizer_array[$old_index]; |
| 40 |
unset( $email_customizer_array[$old_index] ); |
| 41 |
} |
| 42 |
|
| 43 |
return $new_email_customizer_array; |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* Function that adds backwards compatibility version 1.3.13 to version 1.3.14: we need to copy all data from item_options_values, and create the item_option_labels index for the checkbox, radio and select extra-fields, to reflect the front-end changes |
| 48 |
* |
| 49 |
* @since v.1.3.13 |
| 50 |
* |
| 51 |
* @return void |
| 52 |
*/ |
| 53 |
function wppb_pro_hobbyist_v1_3_13(){ |
| 54 |
$custom_fields = get_option( 'wppb_custom_fields','not_found' ); |
| 55 |
|
| 56 |
if ( $custom_fields != 'not_found' ){ |
| 57 |
foreach ( $custom_fields as $key => $value ){ |
| 58 |
if ( ( $value['item_type'] == 'checkbox' ) || ( $value['item_type'] == 'radio' ) || ( $value['item_type'] == 'select' ) ){ |
| 59 |
if ( isset( $custom_fields[$key]['item_option_values'] ) ){ |
| 60 |
$custom_fields[$key]['item_option_labels'] = $custom_fields[$key]['item_option_values']; |
| 61 |
unset( $custom_fields[$key]['item_option_values'] ); |
| 62 |
} |
| 63 |
|
| 64 |
}else |
| 65 |
unset( $custom_fields[$key]['item_option_values'] ); |
| 66 |
} |
| 67 |
|
| 68 |
update_option( 'wppb_custom_fields', $custom_fields ); |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
/** |
| 74 |
* Function that checks if there is at least one EP and/or R form. In the execution timeline this function runs faster than the wppb_prepopulate_fields function |
| 75 |
* |
| 76 |
* @since v.2.0 |
| 77 |
* |
| 78 |
* @return void |
| 79 |
*/ |
| 80 |
function wppb_pro_hobbyist_free_v2_0(){ |
| 81 |
$wppb_manage_fields = get_option( 'wppb_manage_fields', 'not_found' ); |
| 82 |
$backed_up_manage_fields = array(); |
| 83 |
|
| 84 |
// part that handles the manage fields |
| 85 |
if ( $wppb_manage_fields == 'not_found' ){ |
| 86 |
|
| 87 |
$old_default_fields = get_option( 'wppb_default_settings', 'not_found' ); |
| 88 |
|
| 89 |
if ( $old_default_fields != 'not_found' ){ |
| 90 |
$backed_up_manage_fields = wppb_add_existing_default_fields( $backed_up_manage_fields, 'Default - Name (Heading)', '', 'No' ); |
| 91 |
|
| 92 |
if ( $old_default_fields['username'] == 'show' ) |
| 93 |
$backed_up_manage_fields = wppb_add_existing_default_fields( $backed_up_manage_fields, 'Default - Username', '', ucfirst( trim( $old_default_fields['usernameRequired'] ) ), __( 'The usernames cannot be changed.', 'profile-builder' ) ); |
| 94 |
|
| 95 |
if ( $old_default_fields['firstname'] == 'show' ) |
| 96 |
$backed_up_manage_fields = wppb_add_existing_default_fields( $backed_up_manage_fields, 'Default - First Name', 'first_name', ucfirst( trim( $old_default_fields['firstnameRequired'] ) ) ); |
| 97 |
|
| 98 |
if ( $old_default_fields['lastname'] == 'show' ) |
| 99 |
$backed_up_manage_fields = wppb_add_existing_default_fields( $backed_up_manage_fields, 'Default - Last Name', 'last_name', ucfirst( trim( $old_default_fields['lastnameRequired'] ) ) ); |
| 100 |
|
| 101 |
if ( $old_default_fields['nickname'] == 'show' ) |
| 102 |
$backed_up_manage_fields = wppb_add_existing_default_fields( $backed_up_manage_fields, 'Default - Nickname', 'nickname', ucfirst( trim( $old_default_fields['nicknameRequired'] ) ) ); |
| 103 |
|
| 104 |
if ( $old_default_fields['dispname'] == 'show' ) |
| 105 |
$backed_up_manage_fields = wppb_add_existing_default_fields( $backed_up_manage_fields, 'Default - Display name publicly as', '', ucfirst( trim( $old_default_fields['dispnameRequired'] ) ) ); |
| 106 |
|
| 107 |
$backed_up_manage_fields = wppb_add_existing_default_fields( $backed_up_manage_fields, 'Default - Contact Info (Heading)', '', 'No' ); |
| 108 |
|
| 109 |
if ( $old_default_fields['email'] == 'show' ) |
| 110 |
$backed_up_manage_fields = wppb_add_existing_default_fields( $backed_up_manage_fields, 'Default - E-mail', '', ucfirst( trim( $old_default_fields['emailRequired'] ) ), '(required)' ); |
| 111 |
|
| 112 |
if ( $old_default_fields['website'] == 'show' ) |
| 113 |
$backed_up_manage_fields = wppb_add_existing_default_fields( $backed_up_manage_fields, 'Default - Website', '', ucfirst( trim( $old_default_fields['websiteRequired'] ) ) ); |
| 114 |
|
| 115 |
if ( $old_default_fields['aim'] == 'show' ) |
| 116 |
$backed_up_manage_fields = wppb_add_existing_default_fields( $backed_up_manage_fields, 'Default - AIM', 'aim', ucfirst( trim( $old_default_fields['aimRequired'] ) ) ); |
| 117 |
|
| 118 |
if ( $old_default_fields['yahoo'] == 'show' ) |
| 119 |
$backed_up_manage_fields = wppb_add_existing_default_fields( $backed_up_manage_fields, 'Default - Yahoo IM', 'yim', ucfirst( trim( $old_default_fields['yahooRequired'] ) ) ); |
| 120 |
|
| 121 |
if ( $old_default_fields['jabber'] == 'show' ) |
| 122 |
$backed_up_manage_fields = wppb_add_existing_default_fields( $backed_up_manage_fields, 'Default - Jabber / Google Talk', 'jabber', ucfirst( trim( $old_default_fields['jabberRequired'] ) ) ); |
| 123 |
|
| 124 |
$backed_up_manage_fields = wppb_add_existing_default_fields( $backed_up_manage_fields, 'Default - About Yourself (Heading)', '', 'No' ); |
| 125 |
|
| 126 |
if ( $old_default_fields['bio'] == 'show' ) |
| 127 |
$backed_up_manage_fields = wppb_add_existing_default_fields( $backed_up_manage_fields, 'Default - Biographical Info', 'description', ucfirst( trim( $old_default_fields['bioRequired'] ) ) ); |
| 128 |
|
| 129 |
if ( $old_default_fields['password'] == 'show' ){ |
| 130 |
$backed_up_manage_fields = wppb_add_existing_default_fields( $backed_up_manage_fields, 'Default - Password', '', ucfirst( trim( $old_default_fields['passwordRequired'] ) ) ); |
| 131 |
$backed_up_manage_fields = wppb_add_existing_default_fields( $backed_up_manage_fields, 'Default - Repeat Password', '', ucfirst( trim( $old_default_fields['passwordRequired'] ) ) ); |
| 132 |
} |
| 133 |
|
| 134 |
}else{ |
| 135 |
$backed_up_manage_fields = wppb_add_existing_default_fields( $backed_up_manage_fields, 'Default - Name (Heading)', '', 'No' ); |
| 136 |
$backed_up_manage_fields = wppb_add_existing_default_fields( $backed_up_manage_fields, 'Default - Username', '', 'Yes', __( 'The usernames cannot be changed.', 'profile-builder' ) ); |
| 137 |
$backed_up_manage_fields = wppb_add_existing_default_fields( $backed_up_manage_fields, 'Default - First Name', 'first_name', 'No' ); |
| 138 |
$backed_up_manage_fields = wppb_add_existing_default_fields( $backed_up_manage_fields, 'Default - Last Name', 'last_name', 'No' ); |
| 139 |
$backed_up_manage_fields = wppb_add_existing_default_fields( $backed_up_manage_fields, 'Default - Nickname', 'nickname', 'No' ); |
| 140 |
$backed_up_manage_fields = wppb_add_existing_default_fields( $backed_up_manage_fields, 'Default - Display name publicly as', '', 'No' ); |
| 141 |
$backed_up_manage_fields = wppb_add_existing_default_fields( $backed_up_manage_fields, 'Default - Contact Info (Heading)', '', 'No' ); |
| 142 |
$backed_up_manage_fields = wppb_add_existing_default_fields( $backed_up_manage_fields, 'Default - E-mail', '', 'Yes', '(required)' ); |
| 143 |
$backed_up_manage_fields = wppb_add_existing_default_fields( $backed_up_manage_fields, 'Default - Website', '', 'No' ); |
| 144 |
|
| 145 |
// Default contact methods were removed in WP 3.6. A filter dictates contact methods. |
| 146 |
if ( apply_filters( 'wppb_remove_default_contact_methods', get_site_option( 'initial_db_version' ) < 23588 ) ){ |
| 147 |
$backed_up_manage_fields = wppb_add_existing_default_fields( $backed_up_manage_fields, 'Default - AIM', 'aim', 'No' ); |
| 148 |
$backed_up_manage_fields = wppb_add_existing_default_fields( $backed_up_manage_fields, 'Default - Yahoo IM', 'yim', 'No' ); |
| 149 |
$backed_up_manage_fields = wppb_add_existing_default_fields( $backed_up_manage_fields, 'Default - Jabber / Google Talk', 'jabber', 'No' ); |
| 150 |
} |
| 151 |
|
| 152 |
$backed_up_manage_fields = wppb_add_existing_default_fields( $backed_up_manage_fields, 'Default - About Yourself (Heading)', '', 'No' ); |
| 153 |
$backed_up_manage_fields = wppb_add_existing_default_fields( $backed_up_manage_fields, 'Default - Biographical Info', 'description', 'No' ); |
| 154 |
$backed_up_manage_fields = wppb_add_existing_default_fields( $backed_up_manage_fields, 'Default - Password', '', 'Yes' ); |
| 155 |
$backed_up_manage_fields = wppb_add_existing_default_fields( $backed_up_manage_fields, 'Default - Repeat Password', '', 'Yes' ); |
| 156 |
} |
| 157 |
|
| 158 |
$old_custom_fields = get_option( 'wppb_custom_fields', 'not_found' ); |
| 159 |
if( $old_custom_fields != 'not_found' && count( $old_custom_fields ) != 0 ){ |
| 160 |
$existing_ids = array(); |
| 161 |
foreach ( $old_custom_fields as $key => $value ) { |
| 162 |
$local_array = array(); |
| 163 |
|
| 164 |
if( isset( $value['id'] ) ) |
| 165 |
$existing_ids[] = $value['id']; |
| 166 |
|
| 167 |
/* id will be set up at a later point */ |
| 168 |
$local_array['id'] = ( isset( $value['id'] ) ? trim( $value['id'] ) : '' ); |
| 169 |
$local_array['meta-name'] = ( isset( $value['item_metaName'] ) ? trim( $value['item_metaName'] ) : '' ); |
| 170 |
$local_array['field-title'] = ( isset( $value['item_title'] ) ? trim( $value['item_title'] ) : '' ); |
| 171 |
$local_array['description'] = ( isset( $value['item_desc'] ) ? $value['item_desc'] : '' ); |
| 172 |
$local_array['required'] = 'No'; |
| 173 |
$local_array['overwrite-existing'] = 'No'; |
| 174 |
$local_array['row-count'] = '5'; |
| 175 |
$local_array['allowed-image-extensions'] = '.*'; |
| 176 |
$local_array['allowed-upload-extensions'] = '.*'; |
| 177 |
$local_array['avatar-size'] = '100'; |
| 178 |
$local_array['date-format'] = 'mm/dd/yy'; |
| 179 |
$local_array['terms-of-agreement'] = ''; |
| 180 |
$local_array['options'] = ''; |
| 181 |
$local_array['labels'] = ''; |
| 182 |
$local_array['recaptcha-type'] = 'v2'; |
| 183 |
$local_array['public-key'] = ''; |
| 184 |
$local_array['private-key'] = ''; |
| 185 |
$local_array['default-value'] = ''; |
| 186 |
$local_array['default-option'] = ''; |
| 187 |
$local_array['default-options'] = ''; |
| 188 |
$local_array['default-content'] = ''; |
| 189 |
|
| 190 |
switch ( $value['item_type' ] ){ |
| 191 |
case "heading":{ |
| 192 |
$local_array['field'] = 'Heading'; |
| 193 |
$local_array['meta-name'] = ''; |
| 194 |
break; |
| 195 |
} |
| 196 |
case "input":{ |
| 197 |
$local_array['field'] = 'Input'; |
| 198 |
$local_array['required'] = ucfirst( trim( $value['item_required'] ) ); |
| 199 |
break; |
| 200 |
} |
| 201 |
case "hiddenInput":{ |
| 202 |
$local_array['field'] = 'Input (Hidden)'; |
| 203 |
$local_array['default-value'] = ( isset( $value['item_options'] ) ? trim( $value['item_options'] ) : '' ); |
| 204 |
break; |
| 205 |
} |
| 206 |
case "checkbox":{ |
| 207 |
$local_array['field'] = 'Checkbox'; |
| 208 |
$local_array['options'] = ( isset( $value['item_options'] ) ? trim( $value['item_options'] ) : '' ); |
| 209 |
$local_array['labels'] = ( isset( $value['item_option_labels'] ) ? trim( $value['item_option_labels'] ) : '' ); |
| 210 |
$local_array['required'] = ucfirst( trim( $value['item_required'] ) ); |
| 211 |
break; |
| 212 |
} |
| 213 |
case "agreeToTerms":{ |
| 214 |
$local_array['field'] = 'Checkbox (Terms and Conditions)'; |
| 215 |
$local_array['required'] = ucfirst( trim( "Yes" ) ); |
| 216 |
break; |
| 217 |
} |
| 218 |
case "radio":{ |
| 219 |
$local_array['field'] = 'Radio'; |
| 220 |
$local_array['options'] = ( isset( $value['item_options'] ) ? trim( $value['item_options'] ) : '' ); |
| 221 |
$local_array['labels'] = ( isset( $value['item_option_labels'] ) ? trim( $value['item_option_labels'] ) : '' ); |
| 222 |
$local_array['required'] = ucfirst( trim( $value['item_required'] ) ); |
| 223 |
break; |
| 224 |
} |
| 225 |
case "select":{ |
| 226 |
$local_array['field'] = 'Select'; |
| 227 |
$local_array['options'] = ( isset( $value['item_options'] ) ? trim( $value['item_options'] ) : '' ); |
| 228 |
$local_array['labels'] = ( isset( $value['item_option_labels'] ) ? trim( $value['item_option_labels'] ) : '' ); |
| 229 |
$local_array['required'] = ucfirst( trim( $value['item_required'] ) ); |
| 230 |
break; |
| 231 |
} |
| 232 |
case "countrySelect":{ |
| 233 |
$local_array['field'] = 'Select (Country)'; |
| 234 |
$local_array['required'] = ucfirst( trim( $value['item_required'] ) ); |
| 235 |
break; |
| 236 |
} |
| 237 |
case "timeZone":{ |
| 238 |
$local_array['field'] = 'Select (Timezone)'; |
| 239 |
$local_array['required'] = ucfirst( trim( $value['item_required'] ) ); |
| 240 |
break; |
| 241 |
} |
| 242 |
case "datepicker":{ |
| 243 |
$local_array['field'] = 'Datepicker'; |
| 244 |
$local_array['required'] = ucfirst( trim( $value['item_required'] ) ); |
| 245 |
break; |
| 246 |
} |
| 247 |
case "textarea":{ |
| 248 |
$local_array['field'] = 'Textarea'; |
| 249 |
$local_array['row-count'] = ( isset( $value['item_options'] ) ? trim( $value['item_options'] ) : '' ); |
| 250 |
$local_array['required'] = ucfirst( trim( $value['item_required'] ) ); |
| 251 |
break; |
| 252 |
} |
| 253 |
case "upload":{ |
| 254 |
$local_array['field'] = 'Upload'; |
| 255 |
$local_array['allowed-upload-extensions'] = ( isset( $value['item_options'] ) ? trim( $value['item_options'] ) : $local_array['allowed-upload-extensions'] ); |
| 256 |
$local_array['required'] = ucfirst( trim( $value['item_required'] ) ); |
| 257 |
break; |
| 258 |
} |
| 259 |
case "avatar":{ |
| 260 |
$local_array['field'] = 'Avatar'; |
| 261 |
$local_array['avatar-size'] = ( isset( $value['item_options'] ) ? trim( $value['item_options'] ) : $local_array['avatar-size'] ); |
| 262 |
$local_array['required'] = ucfirst( trim( $value['item_required'] ) ); |
| 263 |
break; |
| 264 |
} |
| 265 |
} |
| 266 |
|
| 267 |
array_push( $backed_up_manage_fields, $local_array ); |
| 268 |
} |
| 269 |
} |
| 270 |
} |
| 271 |
|
| 272 |
|
| 273 |
// part which handles the removal of the reCAPTCHA from the addon list |
| 274 |
$wppb_module_settings = get_option( 'wppb_addon_settings', 'not_found' ); |
| 275 |
if ( $wppb_module_settings != 'not_found' ){ |
| 276 |
if ( isset( $wppb_module_settings['wppb_reCaptcha'] ) && ( $wppb_module_settings['wppb_reCaptcha'] == 'show' ) ){ |
| 277 |
$recaptcha_settings = get_option( 'reCaptchaSettings' ); |
| 278 |
|
| 279 |
if ( ( $recaptcha_settings != 'no_found' ) || ( count( $recaptcha_settings ) != 0 ) ){ |
| 280 |
$backed_up_manage_fields = wppb_add_existing_default_fields( $backed_up_manage_fields, 'reCAPTCHA', '', 'Yes', '', trim( $recaptcha_settings['publicKey'] ), trim( $recaptcha_settings['privateKey'] ) ); |
| 281 |
} |
| 282 |
} |
| 283 |
|
| 284 |
unset( $wppb_module_settings['wppb_reCaptcha'] ); |
| 285 |
$wppb_module_settings['wppb_multipleEditProfileForms'] = 'hide'; |
| 286 |
$wppb_module_settings['wppb_multipleRegistrationForms'] = 'hide'; |
| 287 |
|
| 288 |
update_option( 'wppb_module_settings', $wppb_module_settings ); |
| 289 |
} |
| 290 |
|
| 291 |
/* set up start from index. it is set from the highest existing index + 1 */ |
| 292 |
if( !empty( $existing_ids ) ) { |
| 293 |
rsort($existing_ids, SORT_NUMERIC ); |
| 294 |
$start_from_index = $existing_ids[0] + 1; |
| 295 |
} |
| 296 |
else |
| 297 |
$start_from_index = 1; |
| 298 |
|
| 299 |
/* set up ids for each field */ |
| 300 |
if( !empty( $backed_up_manage_fields ) ){ |
| 301 |
foreach( $backed_up_manage_fields as $key => $backed_up_manage_field ){ |
| 302 |
if( empty( $backed_up_manage_fields[$key]['id'] ) ){ |
| 303 |
$backed_up_manage_fields[$key]['id'] = $start_from_index; |
| 304 |
$start_from_index ++; |
| 305 |
} |
| 306 |
} |
| 307 |
} |
| 308 |
add_option( 'wppb_manage_fields', $backed_up_manage_fields ); |
| 309 |
|
| 310 |
|
| 311 |
// part which handles the general settings select->checkbox backwards comp. |
| 312 |
$wppb_generalSettings = get_option( 'wppb_general_settings', 'not_found' ); |
| 313 |
if ( ( $wppb_generalSettings != 'not_found' ) && ( count( $wppb_generalSettings ) > 1 ) ){ |
| 314 |
if ( isset( $wppb_generalSettings['extraFieldsLayout'] ) && ( $wppb_generalSettings['extraFieldsLayout'] == 'no' ) ) |
| 315 |
unset( $wppb_generalSettings['extraFieldsLayout'] ); |
| 316 |
|
| 317 |
else |
| 318 |
$wppb_generalSettings['extraFieldsLayout'] = 'default'; |
| 319 |
|
| 320 |
update_option( 'wppb_general_settings', $wppb_generalSettings ); |
| 321 |
} |
| 322 |
} |
| 323 |
|
| 324 |
|
| 325 |
/** |
| 326 |
* Function that adds backwards compatibility for the userlisting |
| 327 |
* |
| 328 |
* @since v.2.0 |
| 329 |
* |
| 330 |
*/ |
| 331 |
function wppb_pro_userlisting_compatibility_upgrade(){ |
| 332 |
if ( wppb_default_form_already_present( 'Userlisting', 'wppb-ul-cpt' ) ) |
| 333 |
return ''; |
| 334 |
|
| 335 |
$old_userlisting_settings = get_option( 'customUserListingSettings', 'not_found' ); |
| 336 |
if ( $old_userlisting_settings == 'not_found' ) |
| 337 |
$old_userlisting_settings = get_option( 'userListingSettings', 'not_found' ); |
| 338 |
|
| 339 |
// Bail on fresh installs (and any install with no legacy user-listing data). |
| 340 |
// Without the 'not_found' default above, get_option() returned `false` and |
| 341 |
// `false == 'not_found'` is false in PHP 8, so this guard let fresh installs |
| 342 |
// fall through and create a phantom 'Userlisting' post — which trips the |
| 343 |
// license gate in wppb_filter_own_post_creation() and wp_die()'s on activation. |
| 344 |
if ( $old_userlisting_settings == 'not_found' || empty( $old_userlisting_settings ) ) |
| 345 |
return; |
| 346 |
|
| 347 |
$all_userlisting = ( isset( $old_userlisting_settings['allUserlisting'] ) ? wppb_replace_merge_tags( $old_userlisting_settings['allUserlisting'], true ) : '' ); |
| 348 |
$single_userlisting = ( isset( $old_userlisting_settings['singleUserlisting'] ) ? wppb_replace_merge_tags( $old_userlisting_settings['singleUserlisting'] ) : '' ); |
| 349 |
|
| 350 |
if( !empty( $old_userlisting_settings['sortingNumber'] ) ) |
| 351 |
$number_os_users_per_page = $old_userlisting_settings['sortingNumber']; |
| 352 |
else |
| 353 |
$number_os_users_per_page = '5'; |
| 354 |
|
| 355 |
if( !empty( $old_userlisting_settings['sortingCriteria'] ) ) |
| 356 |
$default_sorting_criteria = $old_userlisting_settings['sortingCriteria']; |
| 357 |
else |
| 358 |
$default_sorting_criteria = 'login'; |
| 359 |
|
| 360 |
if( !empty( $old_userlisting_settings['sortingOrder'] ) ) |
| 361 |
$default_sorting_order = $old_userlisting_settings['sortingOrder']; |
| 362 |
else |
| 363 |
$default_sorting_order = 'asc'; |
| 364 |
|
| 365 |
if( !empty( $old_userlisting_settings['avatarSize'] ) ) |
| 366 |
$avatar_size_all = $old_userlisting_settings['avatarSize']; |
| 367 |
else |
| 368 |
$avatar_size_all = '40'; |
| 369 |
|
| 370 |
if( !empty( $old_userlisting_settings['avatarSize'] ) ) |
| 371 |
$avatar_size_single = $old_userlisting_settings['avatarSize']; |
| 372 |
else |
| 373 |
$avatar_size_single = '60'; |
| 374 |
|
| 375 |
$userlisting_settings = array( array( 'roles-to-display' => '*', 'number-of-userspage' => $number_os_users_per_page, 'default-sorting-criteria' => $default_sorting_criteria, 'default-sorting-order' => $default_sorting_order, 'avatar-size-all-userlisting' => $avatar_size_all, 'avatar-size-single-userlisting' => $avatar_size_single ) ); |
| 376 |
|
| 377 |
$ul_post_id = wp_insert_post( array( 'post_title' => 'Userlisting', 'post_status' => 'publish', 'post_author' => get_current_user_id(), 'post_type' => 'wppb-ul-cpt', 'post_content' => 'Default Userlisting form placeholder' ), true ); |
| 378 |
|
| 379 |
add_post_meta( $ul_post_id, 'wppb-ul-templates', $all_userlisting ); |
| 380 |
add_post_meta( $ul_post_id, 'wppb-single-ul-templates', $single_userlisting ); |
| 381 |
add_post_meta( $ul_post_id, 'wppb_ul_page_settings', $userlisting_settings ); |
| 382 |
} |
| 383 |
|
| 384 |
|
| 385 |
/** |
| 386 |
* Function that replaces the individual merge-tags in the userlisting |
| 387 |
* |
| 388 |
* @since v.2.0 |
| 389 |
* |
| 390 |
* @param string $content |
| 391 |
* @param boolean $all_userlisting_form |
| 392 |
* |
| 393 |
* @return string |
| 394 |
* |
| 395 |
*/ |
| 396 |
function wppb_replace_merge_tags( $content, $all_userlisting_form = false ){ |
| 397 |
$content = trim( $content ); |
| 398 |
|
| 399 |
$content = wppb_old_backwards_compatibility( $content ); |
| 400 |
|
| 401 |
$content = str_replace( '%%meta_number_of_posts%%', '{{{meta_number_of_posts}}}', $content ); |
| 402 |
$content = str_replace( '%%extra_search_all_fields%%', '{{{extra_search_all_fields}}}', $content ); |
| 403 |
$content = str_replace( '%%extra_more_info_link%%', '{{{more_info}}}', $content ); |
| 404 |
$content = str_replace( '%%extra_while_users%%', '{{#users}}', $content ); |
| 405 |
$content = str_replace( '%%extra_end_while_users%%', '{{/users}}', $content ); |
| 406 |
$content = str_replace( '%%extra_avatar_or_gravatar%%', '{{{avatar_or_gravatar}}}', $content ); |
| 407 |
$content = str_replace( '%%extra_go_back_link%%', '{{{extra_go_back_link}}}', $content ); |
| 408 |
$content = str_replace( '%%meta_first_last_name%%', '{{meta_first_name}}{{meta_last_name}}', $content ); |
| 409 |
$content = str_replace( '%%sort_first_last_name%%', '{{{sort_first_name}}}', $content ); |
| 410 |
|
| 411 |
preg_match_all( '/%%([a-z0-9\_]+)%%/', $content, $matches, PREG_PATTERN_ORDER ); |
| 412 |
foreach ( $matches[0] as $key => $value ) |
| 413 |
$content = ( ( strpos( $value, 'sort_' ) !== false ) ? str_replace( $value, '{{{'.$matches[1][$key].'}}}', $content ) : str_replace( $value, '{{'.$matches[1][$key].'}}', $content ) ); |
| 414 |
|
| 415 |
if ( $all_userlisting_form ) |
| 416 |
$content .= '{{{pagination}}}'; |
| 417 |
|
| 418 |
return $content; |
| 419 |
} |
| 420 |
|
| 421 |
|
| 422 |
/** |
| 423 |
* Function that replaces the individual merge-tags which existed the very first time. These consisted of %%item_title%% instead of the (then) newer %%item_meta_name%% |
| 424 |
* |
| 425 |
* @since v.2.0 |
| 426 |
* |
| 427 |
* @param string $content |
| 428 |
* |
| 429 |
* @return string |
| 430 |
* |
| 431 |
*/ |
| 432 |
function wppb_old_backwards_compatibility( $content ){ |
| 433 |
$wppb_custom_fields = get_option( 'wppb_custom_fields', 'not_found' ); |
| 434 |
|
| 435 |
if ( ( $wppb_custom_fields == 'not_found' ) || ( count( $wppb_custom_fields ) < 1 ) ) |
| 436 |
return $content; |
| 437 |
|
| 438 |
foreach( $wppb_custom_fields as $key => $value ){ |
| 439 |
if ( ( isset( $value['item_type'] ) ) && ( trim( $value['item_type'] != '' ) ) ) |
| 440 |
if ( ( isset( $value['item_metaName'] ) ) && ( trim( $value['item_metaName'] != '' ) ) ){ |
| 441 |
/* TODO don't know what's supposed to be here and don't have time before launch */ |
| 442 |
$string = str_replace( '%%meta_'.$value['item_title'].'%%', '%%meta_'.$value['item_metaName'].'%%', $string ); |
| 443 |
$string = str_replace( '%%meta_description_'.$value['item_title'].'%%', '%%meta_description_'.$value['item_metaName'].'%%', $string ); |
| 444 |
$string = str_replace( '%%sort_'.$value['item_title'].'%%', '%%sort_'.$value['item_metaName'].'%%', $string ); |
| 445 |
} |
| 446 |
} |
| 447 |
|
| 448 |
return $content; |
| 449 |
} |
| 450 |
|
| 451 |
|
| 452 |
/** |
| 453 |
* Function that checks if a default userlisting-form is already present |
| 454 |
* |
| 455 |
* @since v.2.0 |
| 456 |
* |
| 457 |
* @param string $post_title |
| 458 |
* @param string $post_type |
| 459 |
* |
| 460 |
* @return boolean |
| 461 |
* |
| 462 |
*/ |
| 463 |
function wppb_default_form_already_present( $post_title, $post_type ){ |
| 464 |
$defaults = get_posts( array( 'posts_per_page' => -1, 'post_status' => array( 'publish' ), 'post_type' => $post_type, 'orderby' => 'post_date', 'order' => 'ASC' ) ); |
| 465 |
foreach ( $defaults as $default ){ |
| 466 |
if ( $default->post_content == 'Default '.$post_title.' form placeholder' ) |
| 467 |
return true; |
| 468 |
} |
| 469 |
|
| 470 |
return false; |
| 471 |
} |
| 472 |
|
| 473 |
|
| 474 |
/** |
| 475 |
* Function that assures backwards compatibility for the email customizer |
| 476 |
* |
| 477 |
* @since v.2.0 |
| 478 |
* |
| 479 |
*/ |
| 480 |
function wppb_pro_email_customizer_compatibility_upgrade(){ |
| 481 |
$email_customizer_array = get_option( 'emailCustomizer', 'not_found' ); |
| 482 |
|
| 483 |
if ( $email_customizer_array != 'not_found' ){ |
| 484 |
wppb_replace_and_save( $email_customizer_array['from_name'], 'wppb_emailc_common_settings_from_name' ); |
| 485 |
wppb_replace_and_save( $email_customizer_array['reply_to'], 'wppb_emailc_common_settings_from_reply_to_email' ); |
| 486 |
wppb_replace_and_save( $email_customizer_array['default_registration_email_subject'], 'wppb_user_emailc_default_registration_email_subject' ); |
| 487 |
wppb_replace_and_save( $email_customizer_array['default_registration_email_content'], 'wppb_user_emailc_default_registration_email_content' ); |
| 488 |
wppb_replace_and_save( $email_customizer_array['registration_w_admin_approval_email_subject'], 'wppb_user_emailc_registration_with_admin_approval_email_subject' ); |
| 489 |
wppb_replace_and_save( $email_customizer_array['registration_w_admin_approval_email_content'], 'wppb_user_emailc_registration_with_admin_approval_email_content' ); |
| 490 |
wppb_replace_and_save( $email_customizer_array['admin_approval_aproved_status_email_subject'], 'wppb_user_emailc_admin_approval_notif_approved_email_subject' ); |
| 491 |
wppb_replace_and_save( $email_customizer_array['admin_approval_aproved_status_email_content'], 'wppb_user_emailc_admin_approval_notif_approved_email_content' ); |
| 492 |
wppb_replace_and_save( $email_customizer_array['admin_approval_unaproved_status_email_subject'], 'wppb_user_emailc_admin_approval_notif_unapproved_email_subject' ); |
| 493 |
wppb_replace_and_save( $email_customizer_array['admin_approval_unaproved_status_email_content'], 'wppb_user_emailc_admin_approval_notif_unapproved_email_content' ); |
| 494 |
wppb_replace_and_save( $email_customizer_array['registration_w_email_confirmation_email_subject'], 'wppb_user_emailc_registr_w_email_confirm_email_subject' ); |
| 495 |
wppb_replace_and_save( $email_customizer_array['registration_w_email_confirmation_email_content'], 'wppb_user_emailc_registr_w_email_confirm_email_content' ); |
| 496 |
wppb_replace_and_save( $email_customizer_array['admin_default_registration_email_subject'], 'wppb_admin_emailc_default_registration_email_subject' ); |
| 497 |
wppb_replace_and_save( $email_customizer_array['admin_default_registration_email_content'], 'wppb_admin_emailc_default_registration_email_content' ); |
| 498 |
wppb_replace_and_save( $email_customizer_array['admin_registration_w_admin_approval_email_subject'], 'wppb_admin_emailc_registration_with_admin_approval_email_subject' ); |
| 499 |
wppb_replace_and_save( $email_customizer_array['admin_registration_w_admin_approval_email_content'], 'wppb_admin_emailc_registration_with_admin_approval_email_content' ); |
| 500 |
} |
| 501 |
} |
| 502 |
|
| 503 |
|
| 504 |
/** |
| 505 |
* Function that checks if a default userlisting-form is already present |
| 506 |
* |
| 507 |
* @since v.2.0 |
| 508 |
* |
| 509 |
* @param string $old_content |
| 510 |
* @param string $option_name |
| 511 |
* |
| 512 |
*/ |
| 513 |
function wppb_replace_and_save( $content, $option_name ){ |
| 514 |
preg_match_all( '/%%([a-z0-9\_]+)%%/', $content, $matches, PREG_PATTERN_ORDER ); |
| 515 |
|
| 516 |
foreach ( $matches[0] as $key => $value ) |
| 517 |
$content = str_replace( $value, '{{'.$matches[1][$key].'}}', $content ); |
| 518 |
|
| 519 |
update_option( $option_name, $content ); |
| 520 |
} |
| 521 |
|
| 522 |
|
| 523 |
/** |
| 524 |
* Function that adds backwards compatibility for the default fields only |
| 525 |
* |
| 526 |
* @since v.2.0 |
| 527 |
* |
| 528 |
* @param array $backed_up_manage_fields |
| 529 |
* @param string $field |
| 530 |
* @param string $meta_name |
| 531 |
* @param string $required |
| 532 |
* @param string $description |
| 533 |
* @param string $recaptcha_public_key |
| 534 |
* @param string $recaptcha_private_key |
| 535 |
* |
| 536 |
* @return array |
| 537 |
*/ |
| 538 |
function wppb_add_existing_default_fields ( $backed_up_manage_fields, $field, $meta_name, $required, $description = '', $recaptcha_public_key = '', $recaptcha_private_key = '' ){ |
| 539 |
if ( !is_array($backed_up_manage_fields) ){ |
| 540 |
$backed_up_manage_fields = empty($backed_up_manage_fields) ? array(): array($backed_up_manage_fields); |
| 541 |
} |
| 542 |
|
| 543 |
$local_array = array(); |
| 544 |
|
| 545 |
$local_array['id'] = ''; |
| 546 |
$local_array['field'] = $field; |
| 547 |
$local_array['meta-name'] = $meta_name; |
| 548 |
$local_array['field-title'] = str_replace( array( 'Default - ', ' (Heading)' ), '', $field ); |
| 549 |
$local_array['description'] = ''; |
| 550 |
$local_array['required'] = $required; |
| 551 |
$local_array['overwrite-existing'] = 'No'; |
| 552 |
$local_array['row-count'] = '5'; |
| 553 |
$local_array['allowed-image-extensions'] = '.*'; |
| 554 |
$local_array['allowed-upload-extensions'] = '.*'; |
| 555 |
$local_array['avatar-size'] = '100'; |
| 556 |
$local_array['date-format'] = 'mm/dd/yy'; |
| 557 |
$local_array['terms-of-agreement'] = ''; |
| 558 |
$local_array['options'] = ''; |
| 559 |
$local_array['labels'] = ''; |
| 560 |
$local_array['public-key'] = $recaptcha_public_key; |
| 561 |
$local_array['private-key'] = $recaptcha_private_key; |
| 562 |
$local_array['default-value'] = ''; |
| 563 |
$local_array['default-option'] = ''; |
| 564 |
$local_array['default-options'] = ''; |
| 565 |
$local_array['default-content'] = ''; |
| 566 |
|
| 567 |
array_push( $backed_up_manage_fields, $local_array ); |
| 568 |
|
| 569 |
return $backed_up_manage_fields; |
| 570 |
} |
| 571 |
|
| 572 |
|
| 573 |
/** |
| 574 |
* Function that assures compatibility for the old Custom Redirects settings with the new Custom Redirects module |
| 575 |
* |
| 576 |
* @since v.2.2.5 |
| 577 |
* |
| 578 |
*/ |
| 579 |
function wppb_new_custom_redirects_compatibility() { |
| 580 |
$wppb_old_cr = get_option( 'customRedirectSettings', 'not_found' ); |
| 581 |
|
| 582 |
$wppb_new_cr_global = array(); |
| 583 |
$wppb_new_cr_wp_default = array(); |
| 584 |
|
| 585 |
if( $wppb_old_cr != 'not_found' ) { |
| 586 |
// new Custom Redirect -> Global Redirects |
| 587 |
if( $wppb_old_cr['afterRegister'] == 'yes' ) { |
| 588 |
$wppb_new_cr_global[] = array( |
| 589 |
'type' => 'after_registration', |
| 590 |
'url' => $wppb_old_cr['afterRegisterTarget'], |
| 591 |
'id' => 1, |
| 592 |
); |
| 593 |
} |
| 594 |
|
| 595 |
if( $wppb_old_cr['afterLogin'] == 'yes' ) { |
| 596 |
$wppb_new_cr_global[] = array( |
| 597 |
'type' => 'after_login', |
| 598 |
'url' => $wppb_old_cr['afterLoginTarget'], |
| 599 |
'id' => 1, |
| 600 |
); |
| 601 |
} |
| 602 |
|
| 603 |
if( $wppb_old_cr['loginRedirectLogout'] == 'yes' ) { |
| 604 |
$wppb_new_cr_global[] = array( |
| 605 |
'type' => 'after_logout', |
| 606 |
'url' => $wppb_old_cr['loginRedirectTargetLogout'], |
| 607 |
'id' => 1, |
| 608 |
); |
| 609 |
} |
| 610 |
|
| 611 |
if( $wppb_old_cr['dashboardRedirect'] == 'yes' ) { |
| 612 |
$wppb_new_cr_global[] = array( |
| 613 |
'type' => 'dashboard_redirect', |
| 614 |
'url' => $wppb_old_cr['dashboardRedirectTarget'], |
| 615 |
'id' => 1, |
| 616 |
); |
| 617 |
} |
| 618 |
|
| 619 |
// new Custom Redirect -> Redirect Default WordPress Forms and Pages |
| 620 |
if( $wppb_old_cr['loginRedirect'] == 'yes' ) { |
| 621 |
$wppb_new_cr_wp_default[] = array( |
| 622 |
'type' => 'login', |
| 623 |
'url' => $wppb_old_cr['loginRedirectTarget'], |
| 624 |
'id' => 1, |
| 625 |
); |
| 626 |
} |
| 627 |
|
| 628 |
if( $wppb_old_cr['registerRedirect'] == 'yes' ) { |
| 629 |
$wppb_new_cr_wp_default[] = array( |
| 630 |
'type' => 'register', |
| 631 |
'url' => $wppb_old_cr['registerRedirectTarget'], |
| 632 |
'id' => 1, |
| 633 |
); |
| 634 |
} |
| 635 |
|
| 636 |
if( $wppb_old_cr['recoverRedirect'] == 'yes' ) { |
| 637 |
$wppb_new_cr_wp_default[] = array( |
| 638 |
'type' => 'lostpassword', |
| 639 |
'url' => $wppb_old_cr['recoverRedirectTarget'], |
| 640 |
'id' => 1, |
| 641 |
); |
| 642 |
} |
| 643 |
|
| 644 |
// add new Custom Redirect database options |
| 645 |
if( isset( $wppb_new_cr_global ) && ! empty( $wppb_new_cr_global ) ) { |
| 646 |
update_option( 'wppb_cr_global', $wppb_new_cr_global ); |
| 647 |
} |
| 648 |
|
| 649 |
if( isset( $wppb_new_cr_wp_default ) && ! empty( $wppb_new_cr_wp_default ) ) { |
| 650 |
update_option( 'wppb_cr_default_wp_pages', $wppb_new_cr_wp_default ); |
| 651 |
} |
| 652 |
} |
| 653 |
} |
| 654 |
|
| 655 |
/** |
| 656 |
* Check if an addon was active as a slug before it was programmatically deactivated by us |
| 657 |
* On the plugin updates, where we transitioned add-ons we save the status in an option 'wppb_old_add_ons_status' |
| 658 |
* @param $slug |
| 659 |
* @return false |
| 660 |
*/ |
| 661 |
function wppb_was_addon_active_as_plugin( $slug ){ |
| 662 |
$old_add_ons_status = get_option( 'wppb_old_add_ons_status' ); |
| 663 |
if( isset( $old_add_ons_status[$slug] ) ) |
| 664 |
return $old_add_ons_status[$slug]; |
| 665 |
else |
| 666 |
return false; |
| 667 |
} |
| 668 |
|
| 669 |
/** |
| 670 |
* Function that returns the slugs of old addons that were plugins |
| 671 |
* @return string[] |
| 672 |
*/ |
| 673 |
function wppb_get_old_addons_slug_list(){ |
| 674 |
$old_addon_list = array( |
| 675 |
'pd-add-on-multiple-admin-e-mails/index.php', |
| 676 |
'pb-add-on-customization-toolbox/index.php', |
| 677 |
'pb-add-on-email-confirmation-field/index.php', |
| 678 |
'pb-add-on-placeholder-labels/pbpl.php', |
| 679 |
'pb-add-on-gdpr-communication-preferences/pb-gdpr-communication-preferences.php', |
| 680 |
'pb-add-on-labels-edit/pble.php', |
| 681 |
'pb-add-on-maximum-character-length/index.php', |
| 682 |
'pb-add-on-custom-css-classes-on-fields/index.php', |
| 683 |
'pb-add-on-import-export/pbie.php', |
| 684 |
'pb-add-on-buddypress/index.php', |
| 685 |
'pb-add-on-social-connect/index.php', |
| 686 |
'pb-add-on-woocommerce/index.php', |
| 687 |
'pb-add-on-multi-step-forms/index.php', |
| 688 |
'pb-add-on-mailchimp-integration/index.php', |
| 689 |
'pb-add-on-bbpress/index.php', |
| 690 |
'pb-add-on-campaign-monitor/index.php', |
| 691 |
'pb-add-on-field-visibility/index.php', |
| 692 |
'pb-add-on-edit-profile-approved-by-admin/index.php', |
| 693 |
'pb-add-on-custom-profile-menus/index.php', |
| 694 |
'pb-add-on-mailpoet-integration/index.php', |
| 695 |
); |
| 696 |
|
| 697 |
if( PROFILE_BUILDER !== 'Profile Builder Free' ) |
| 698 |
$old_addon_list[] = 'pb-add-on-select2/index.php';//don't disable select 2 for people who already had it in free |
| 699 |
|
| 700 |
return $old_addon_list; |
| 701 |
} |