| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 3 |
/** |
| 4 |
* Function which returns the same field-format over and over again. |
| 5 |
* |
| 6 |
* @since v.2.0 |
| 7 |
* |
| 8 |
* @param string $field |
| 9 |
* @param string $field_title |
| 10 |
* |
| 11 |
* @return string |
| 12 |
*/ |
| 13 |
function wppb_field_format ( $field_title, $field ){ |
| 14 |
|
| 15 |
return trim( $field_title ).' ( '.trim( $field ).' )'; |
| 16 |
} |
| 17 |
|
| 18 |
|
| 19 |
/** |
| 20 |
* Add a notification for either the Username or the Email field letting the user know that, even though it is there, it won't do anything |
| 21 |
* |
| 22 |
* @since v.2.0 |
| 23 |
* |
| 24 |
* @param string $form |
| 25 |
* @param integer $id |
| 26 |
* @param string $value |
| 27 |
* |
| 28 |
* @return string $form |
| 29 |
*/ |
| 30 |
|
| 31 |
function wppb_manage_fields_display_field_title_slug( $form ){ |
| 32 |
// add a notice to fields |
| 33 |
global $wppb_results_field; |
| 34 |
switch ($wppb_results_field){ |
| 35 |
case 'Default - Username': |
| 36 |
$wppb_generalSettings = get_option( 'wppb_general_settings', 'not_found' ); |
| 37 |
if ( $wppb_generalSettings != 'not_found' && $wppb_generalSettings['loginWith'] == 'email' ) { |
| 38 |
$form .= '<div id="wppb-login-email-nag" class="wppb-backend-notice">' . sprintf(__('Login is set to be done using the Email. This field will NOT appear in the front-end! ( you can change these settings under the "%s" tab )', 'profile-builder'), '<a href="' . admin_url('admin.php?page=profile-builder-general-settings') . '" target="_blank">' . __('General Settings', 'profile-builder') . '</a>') . '</div>'; |
| 39 |
} |
| 40 |
break; |
| 41 |
case 'Default - Display name publicly as': |
| 42 |
$form .= '<div id="wppb-display-name-nag" class="wppb-backend-notice">' . __( 'Display name publicly as - only appears on the Edit Profile page!', 'profile-builder' ) . '</div>'; |
| 43 |
break; |
| 44 |
case 'Default - Blog Details': |
| 45 |
$form .= '<div id="wppb-blog-details-nag" class="wppb-backend-notice">' . __( 'Blog Details - only appears on the Registration page!', 'profile-builder' ) . '</div>'; |
| 46 |
break; |
| 47 |
} |
| 48 |
|
| 49 |
return $form; |
| 50 |
} |
| 51 |
|
| 52 |
add_filter( 'wck_after_content_element', 'wppb_manage_fields_display_field_title_slug' ); |
| 53 |
|
| 54 |
/** |
| 55 |
* Check if field type is 'Default - Display name publicly as' so we can add a notification for it |
| 56 |
* |
| 57 |
* @since v.2.2 |
| 58 |
* |
| 59 |
* @param string $wck_element_class |
| 60 |
* @param string $meta |
| 61 |
* @param array $results |
| 62 |
* @param integer $element_id |
| 63 |
* |
| 64 |
*/ |
| 65 |
function wppb_manage_fields_display_name_notice( $wck_element_class, $meta, $results, $element_id ) { |
| 66 |
global $wppb_results_field; |
| 67 |
|
| 68 |
$wppb_results_field = $results[$element_id]['field']; |
| 69 |
} |
| 70 |
add_filter( 'wck_element_class_wppb_manage_fields', 'wppb_manage_fields_display_name_notice', 10, 4 ); |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
/** |
| 75 |
* Function that adds a custom class to the existing container |
| 76 |
* |
| 77 |
* @since v.2.0 |
| 78 |
* |
| 79 |
* @param string $update_container_class - the new class name |
| 80 |
* @param string $meta - the name of the meta |
| 81 |
* @param array $results |
| 82 |
* @param integer $element_id - the ID of the element |
| 83 |
* |
| 84 |
* @return string |
| 85 |
*/ |
| 86 |
function wppb_update_container_class( $update_container_class, $meta, $results, $element_id ) { |
| 87 |
$wppb_element_type = Wordpress_Creation_Kit_PB::wck_generate_slug( $results[$element_id]["field"] ); |
| 88 |
|
| 89 |
return "class='wck_update_container update_container_$meta update_container_$wppb_element_type element_type_$wppb_element_type'"; |
| 90 |
} |
| 91 |
add_filter( 'wck_update_container_class_wppb_manage_fields', 'wppb_update_container_class', 10, 4 ); |
| 92 |
|
| 93 |
|
| 94 |
/** |
| 95 |
* Function that adds a custom class to the existing element |
| 96 |
* |
| 97 |
* @since v.2.0 |
| 98 |
* |
| 99 |
* @param string $element_class - the new class name |
| 100 |
* @param string $meta - the name of the meta |
| 101 |
* @param array $results |
| 102 |
* @param integer $element_id - the ID of the element |
| 103 |
* |
| 104 |
* @return string |
| 105 |
*/ |
| 106 |
function wppb_element_class( $element_class, $meta, $results, $element_id ){ |
| 107 |
$wppb_element_type = Wordpress_Creation_Kit_PB::wck_generate_slug( $results[$element_id]["field"] ); |
| 108 |
|
| 109 |
return "class='element_type_$wppb_element_type added_fields_list'"; |
| 110 |
} |
| 111 |
add_filter( 'wck_element_class_wppb_manage_fields', 'wppb_element_class', 10, 4 ); |
| 112 |
|
| 113 |
/** |
| 114 |
* Functions to check password length and strength |
| 115 |
* |
| 116 |
* @since v.2.0 |
| 117 |
*/ |
| 118 |
/* on add user and update profile from WP admin area */ |
| 119 |
add_action( 'user_profile_update_errors', 'wppb_password_check_on_profile_update', 0, 3 ); |
| 120 |
function wppb_password_check_on_profile_update( $errors, $update, $user ){ |
| 121 |
wppb_password_check_extra_conditions( $errors, $user ); |
| 122 |
} |
| 123 |
|
| 124 |
/* on reset password */ |
| 125 |
add_action( 'validate_password_reset', 'wppb_password_check_extra_conditions', 10, 2 ); |
| 126 |
function wppb_password_check_extra_conditions( $errors, $user ){ |
| 127 |
$password = ( isset( $_POST[ 'pass1' ] ) && trim( $_POST[ 'pass1' ] ) ) ? $_POST[ 'pass1' ] : false; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.MissingUnslash |
| 128 |
|
| 129 |
if( $password ){ |
| 130 |
$wppb_generalSettings = get_option( 'wppb_general_settings' ); |
| 131 |
if( !empty( $wppb_generalSettings['minimum_password_length'] ) ){ |
| 132 |
if( strlen( $password ) < $wppb_generalSettings['minimum_password_length'] ) |
| 133 |
$errors->add( 'pass', sprintf( __( '<strong>ERROR</strong>: The password must have the minimum length of %s characters', 'profile-builder' ), $wppb_generalSettings['minimum_password_length'] ) ); |
| 134 |
} |
| 135 |
|
| 136 |
if( isset( $_POST['wppb_password_strength'] ) && !empty( $wppb_generalSettings['minimum_password_strength'] ) ){ |
| 137 |
$password_strength_array = array( 'short' => 0, 'bad' => 1, 'good' => 2, 'strong' => 3 ); |
| 138 |
$password_strength_text = array( 'short' => __( 'Very weak', 'profile-builder' ), 'bad' => __( 'Weak', 'profile-builder' ), 'good' => __( 'Medium', 'profile-builder' ), 'strong' => __( 'Strong', 'profile-builder' ) ); |
| 139 |
|
| 140 |
foreach( $password_strength_text as $psr_key => $psr_text ){ |
| 141 |
if( $psr_text == sanitize_text_field( $_POST['wppb_password_strength'] ) ){ |
| 142 |
$password_strength_result_slug = $psr_key; |
| 143 |
break; |
| 144 |
} |
| 145 |
} |
| 146 |
|
| 147 |
if( !empty( $password_strength_result_slug ) ){ |
| 148 |
if( $password_strength_array[$password_strength_result_slug] < $password_strength_array[$wppb_generalSettings['minimum_password_strength']] ) |
| 149 |
$errors->add( 'pass', sprintf( __( '<strong>ERROR</strong>: The password must have a minimum strength of %s', 'profile-builder' ), $password_strength_text[$wppb_generalSettings['minimum_password_strength']] ) ); |
| 150 |
} |
| 151 |
} |
| 152 |
} |
| 153 |
|
| 154 |
return $errors; |
| 155 |
} |
| 156 |
|
| 157 |
/* we need to create a hidden field that contains the results of the password strength from the js strength tester */ |
| 158 |
add_action( 'admin_footer', 'wppb_add_hidden_password_strength_on_backend' ); |
| 159 |
add_action( 'login_footer', 'wppb_add_hidden_password_strength_on_backend' ); |
| 160 |
function wppb_add_hidden_password_strength_on_backend(){ |
| 161 |
if( $GLOBALS['pagenow'] == 'profile.php' || $GLOBALS['pagenow'] == 'user-new.php' || ( $GLOBALS['pagenow'] == 'wp-login.php' && isset( $_GET['action'] ) && ( $_GET['action'] === 'rp' || $_GET['action'] === 'resetpass' ) ) ){ |
| 162 |
$wppb_generalSettings = get_option( 'wppb_general_settings' ); |
| 163 |
if( !empty( $wppb_generalSettings['minimum_password_strength'] ) ){ |
| 164 |
?> |
| 165 |
<script type="text/javascript"> |
| 166 |
jQuery( document ).ready( function() { |
| 167 |
var passswordStrengthResult = jQuery( '#pass-strength-result' ); |
| 168 |
// Check for password strength meter |
| 169 |
if ( passswordStrengthResult.length ) { |
| 170 |
// Attach submit event to form |
| 171 |
passswordStrengthResult.parents( 'form' ).on( 'submit', function() { |
| 172 |
// Store check results in hidden field |
| 173 |
jQuery( this ).append( '<input type="hidden" name="wppb_password_strength" value="' + passswordStrengthResult.text() + '">' ); |
| 174 |
}); |
| 175 |
} |
| 176 |
}); |
| 177 |
</script> |
| 178 |
<?php |
| 179 |
} |
| 180 |
} |
| 181 |
} |
| 182 |
|
| 183 |
|
| 184 |
/* Modify the Add Entry buttons for WCK metaboxes according to context */ |
| 185 |
add_filter( 'wck_add_entry_button', 'wppb_change_add_entry_button', 10, 2 ); |
| 186 |
function wppb_change_add_entry_button( $string, $meta ){ |
| 187 |
if( $meta == 'wppb_manage_fields' || $meta == 'wppb_epf_fields' || $meta == 'wppb_rf_fields' ){ |
| 188 |
return __( "Add Field", 'profile-builder' ); |
| 189 |
}elseif( $meta == 'wppb_epf_page_settings' || $meta == 'wppb_rf_page_settings' || $meta == 'wppb_ul_page_settings' ){ |
| 190 |
return __( "Save Settings", 'profile-builder' ); |
| 191 |
} |
| 192 |
|
| 193 |
return $string; |
| 194 |
} |
| 195 |
|
| 196 |
/** |
| 197 |
* add links on plugin page |
| 198 |
*/ |
| 199 |
add_filter( 'plugin_action_links', 'wppb_plugin_action_links', 10, 2 ); |
| 200 |
function wppb_plugin_action_links( $links, $file ) { |
| 201 |
if ( $file != WPPB_PLUGIN_BASENAME ) { |
| 202 |
return $links; |
| 203 |
} |
| 204 |
|
| 205 |
if ( ! current_user_can( 'manage_options' ) ) { |
| 206 |
return $links; |
| 207 |
} |
| 208 |
|
| 209 |
$settings_link = sprintf( '<a href="%1$s">%2$s</a>', |
| 210 |
menu_page_url( 'profile-builder-general-settings', false ), |
| 211 |
esc_html( __( 'Settings', 'profile-builder' ) ) ); |
| 212 |
|
| 213 |
array_unshift( $links, $settings_link ); |
| 214 |
|
| 215 |
return $links; |
| 216 |
} |
| 217 |
|
| 218 |
/** |
| 219 |
* add links on plugin page |
| 220 |
*/ |
| 221 |
add_filter( 'plugin_row_meta', 'wppb_plugin_row_meta', 10, 2 ); |
| 222 |
function wppb_plugin_row_meta( $links, $file ) { |
| 223 |
if ( WPPB_PLUGIN_BASENAME == $file ) { |
| 224 |
$row_meta = array( |
| 225 |
'docs' => '<a href="' . esc_url( 'https://www.cozmoslabs.com/docs/profile-builder-2/' ) . '" target="_blank" aria-label="' . esc_attr__( 'View Profile Builder documentation', 'profile-builder' ) . '">' . esc_html__( 'Docs', 'profile-builder' ) . '</a>', |
| 226 |
); |
| 227 |
|
| 228 |
return array_merge( $links, $row_meta ); |
| 229 |
} |
| 230 |
|
| 231 |
return (array) $links; |
| 232 |
} |
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
/* In plugin notifications */ |
| 237 |
add_action( 'admin_init', 'wppb_add_plugin_notifications' ); |
| 238 |
function wppb_add_plugin_notifications() { |
| 239 |
/* initiate the plugin notifications class */ |
| 240 |
$notifications = WPPB_Plugin_Notifications::get_instance(); |
| 241 |
/* this must be unique */ |
| 242 |
$notification_id = 'wppb_migrated_free_add_ons'; |
| 243 |
|
| 244 |
$message = '<p style="margin-top: 16px; font-size: 15px;">' . __( 'All the free add-ons have been migrated to the main plugin. Their old individual plugins have been disabled and you can delete them from your site if you were using them: <ul><li>Profile Builder - Custom CSS Classes on fields</li><li>Profile Builder - Customization Toolbox Add-On</li><li>Profile Builder - Email Confirmation Field</li><li>Profile Builder - GDPR Communication Preferences</li><li>Profile Builder - Import and Export Add-On</li><li>Profile Builder - Labels Edit Add-On</li><li>Profile Builder - Maximum Character Length Add-On</li><li>Profile Builder - Multiple Admin E-mails Add-On</li><li>Profile Builder - Placeholder Labels Add-On</li></ul>', 'profile-builder' ) . '</p>'; |
| 245 |
// be careful to use wppb_dismiss_admin_notification as query arg |
| 246 |
$message .= '<p><a href="https://www.cozmoslabs.com/277540-profile-builder-enhancements-free-addons-now-part-of-main-plugin/" target="_blank" class="button-primary">' . __( 'See details', 'profile-builder' ) . '</a></p>'; |
| 247 |
$message .= '<a href="' . add_query_arg( array( 'wppb_dismiss_admin_notification' => $notification_id ) ) . '" type="button" class="notice-dismiss"><span class="screen-reader-text">' . __( 'Dismiss this notice.', 'profile-builder' ) . '</span></a>'; |
| 248 |
|
| 249 |
$notifications->add_notification( $notification_id, $message, 'wppb-notice notice notice-info', false ); |
| 250 |
|
| 251 |
if ( did_action( 'elementor/loaded' ) ) { |
| 252 |
|
| 253 |
$notification_id = 'wppb_elementor_styling_notice'; |
| 254 |
|
| 255 |
$message = '<img style="float: left; margin: 10px 12px 10px 0; max-width: 100px;" src="'.WPPB_PLUGIN_URL.'assets/images/elementor_logo.png" alt="Elementor Logo"/>'; |
| 256 |
$message .= '<p style="margin-top: 16px; font-size: 15px;">' . sprintf( __( 'You can now style %s forms from the %s interface. To get started, add a form widget to a page through %s and go to the <strong>Style</strong> tab.', 'profile-builder' ), '<strong>Profile Builder</strong>', '<strong>Elementor</strong>', '<strong>Elementor</strong>') . '</p>'; |
| 257 |
// be careful to use wppb_dismiss_admin_notification as query arg |
| 258 |
$message .= '<p><a href="https://www.cozmoslabs.com/docs/profile-builder-2/integration-with-elementor/" target="_blank" class="button-primary">' . __( 'See details', 'profile-builder' ) . '</a></p>'; |
| 259 |
$message .= '<a href="' . add_query_arg( array( 'wppb_dismiss_admin_notification' => $notification_id ) ) . '" type="button" class="notice-dismiss"><span class="screen-reader-text">' . __( 'Dismiss this notice.', 'profile-builder' ) . '</span></a>'; |
| 260 |
|
| 261 |
$notifications->add_notification( $notification_id, $message, 'wppb-notice notice notice-info', false ); |
| 262 |
|
| 263 |
} |
| 264 |
} |
| 265 |
|
| 266 |
|
| 267 |
/* hook to create pages for out forms when a user press the create pages/setup button */ |
| 268 |
add_action( 'admin_init', 'wppb_create_form_pages' ); |
| 269 |
function wppb_create_form_pages(){ |
| 270 |
if( isset( $_GET['page'] ) && $_GET['page'] === 'profile-builder-basic-info' && isset( $_GET['wppb_create_pages'] ) && $_GET['wppb_create_pages'] === 'true' ){ |
| 271 |
|
| 272 |
$wppb_pages_created = get_option( 'wppb_pages_created' ); |
| 273 |
|
| 274 |
if( empty( $wppb_pages_created ) || ( isset( $_GET['wppb_force_create_pages'] ) && $_GET['wppb_force_create_pages'] === 'true' ) ) { |
| 275 |
$register_page = array( |
| 276 |
'post_title' => 'Register', |
| 277 |
'post_content' => '[wppb-register]', |
| 278 |
'post_status' => 'publish', |
| 279 |
'post_type' => 'page' |
| 280 |
); |
| 281 |
$register_id = wp_insert_post($register_page); |
| 282 |
|
| 283 |
$edit_page = array( |
| 284 |
'post_title' => 'Edit Profile', |
| 285 |
'post_content' => '[wppb-edit-profile]', |
| 286 |
'post_status' => 'publish', |
| 287 |
'post_type' => 'page' |
| 288 |
); |
| 289 |
$edit_id = wp_insert_post($edit_page); |
| 290 |
|
| 291 |
$login_page = array( |
| 292 |
'post_title' => 'Log In', |
| 293 |
'post_content' => '[wppb-login]', |
| 294 |
'post_status' => 'publish', |
| 295 |
'post_type' => 'page' |
| 296 |
); |
| 297 |
$login_id = wp_insert_post($login_page); |
| 298 |
|
| 299 |
update_option('wppb_pages_created', 'true' ); |
| 300 |
|
| 301 |
wp_safe_redirect( admin_url('edit.php?s=%5Bwppb-&post_status=all&post_type=page&action=-1&m=0&paged=1&action2=-1') ); |
| 302 |
} |
| 303 |
} |
| 304 |
} |
| 305 |
|
| 306 |
/** |
| 307 |
* Function that prepares labels to pass to the WCK api...we have a quirk in wck api that labels are wrapped |
| 308 |
* in %label%...so if we want to have % inside the label for example 25% off...we will have a bad time |
| 309 |
* @param string $label |
| 310 |
* @return string|string[] |
| 311 |
*/ |
| 312 |
function wppb_prepare_wck_labels( $label ){ |
| 313 |
return trim( str_replace( '%', '%', $label ) ); |
| 314 |
} |
| 315 |
|
| 316 |
/** |
| 317 |
* Function that returns the reserved meta name list |
| 318 |
*/ |
| 319 |
function wppb_get_reserved_meta_name_list( $all_fields, $posted_values ){ |
| 320 |
|
| 321 |
$unique_meta_name_list = array( 'first_name', 'last_name', 'nickname', 'description' ); |
| 322 |
|
| 323 |
// Default contact methods were removed in WP 3.6. A filter dictates contact methods. |
| 324 |
if ( apply_filters( 'wppb_remove_default_contact_methods', get_site_option( 'initial_db_version' ) < 23588 ) ){ |
| 325 |
$unique_meta_name_list[] = 'aim'; |
| 326 |
$unique_meta_name_list[] = 'yim'; |
| 327 |
$unique_meta_name_list[] = 'jabber'; |
| 328 |
} |
| 329 |
|
| 330 |
$add_reserved = true; |
| 331 |
|
| 332 |
$reserved_meta_names = array( 'attachment', 'attachment_id', 'author', 'author_name', 'calendar', 'cat', 'category', 'category__and', 'category__in', 'category__not_in', 'category_name', 'comments_per_page', |
| 333 |
'comments_popup', 'custom', 'customize_messenger_channel', 'customized', 'cpage', 'day', 'debug', 'embed', 'error', 'exact', 'feed', 'hour', 'link_category', 'm', 'map', 'minute', 'monthnum', 'more', |
| 334 |
'name', 'nav_menu', 'nonce', 'nopaging', 'offset', 'order', 'orderby', 'p', 'page', 'page_id', 'paged', 'pagename', 'pb', 'perm', 'post', 'post__in', 'post__not_in', 'post_format', 'post_mime_type', |
| 335 |
'post_status', 'post_tag', 'post_type', 'posts', 'posts_per_archive_page', 'posts_per_page', 'preview', 'robots', 's', 'search', 'second', 'sentence', 'showposts', 'static', 'status', 'subpost', |
| 336 |
'subpost_id', 'tag', 'tag__and', 'tag__in', 'tag__not_in', 'tag_id', 'tag_slug__and', 'tag_slug__in', 'taxonomy', 'tb', 'term', 'terms', 'theme', 'title', 'type', 'w', 'withcomments', 'withoutcomments', 'year' ); |
| 337 |
|
| 338 |
$args = array( |
| 339 |
'public' => true, |
| 340 |
'_builtin' => true |
| 341 |
); |
| 342 |
$post_types = get_post_types( $args, 'names', 'or' ); |
| 343 |
$taxonomies = get_taxonomies( $args, 'names', 'or' ); |
| 344 |
|
| 345 |
|
| 346 |
/*reserved meta names were added in PB 3.1.2 so to avoid the situation where someone updates an already existing field |
| 347 |
with a reserved name and gets an error check if it is an update or new field */ |
| 348 |
if( !empty( $all_fields ) && !empty($posted_values['id'] ) && !empty($posted_values['meta-name']) ){ |
| 349 |
foreach( $all_fields as $field ){ |
| 350 |
if( $field['id'] === $posted_values['id'] && $field['meta-name'] === $posted_values['meta-name'] ){//it is an update |
| 351 |
$add_reserved = false; |
| 352 |
} |
| 353 |
} |
| 354 |
} |
| 355 |
|
| 356 |
if( $add_reserved ) |
| 357 |
$unique_meta_name_list = array_merge( $unique_meta_name_list, $reserved_meta_names, $post_types, $taxonomies ); |
| 358 |
|
| 359 |
return apply_filters ( 'wppb_unique_meta_name_list', $unique_meta_name_list ); |
| 360 |
} |
| 361 |
|