| 1 |
<?php |
| 2 |
/** |
| 3 |
* Functions Load |
| 4 |
* |
| 5 |
*/ |
| 6 |
|
| 7 |
// whitelist options, you can add more register_settings changing the second parameter |
| 8 |
function wppb_register_settings() { |
| 9 |
register_setting( 'wppb_option_group', 'wppb_default_settings' ); |
| 10 |
register_setting( 'wppb_general_settings', 'wppb_general_settings', 'wppb_general_settings_sanitize' ); |
| 11 |
register_setting( 'wppb_display_admin_settings', 'wppb_display_admin_settings' ); |
| 12 |
register_setting( 'wppb_profile_builder_pro_serial', 'wppb_profile_builder_pro_serial' ); |
| 13 |
register_setting( 'wppb_profile_builder_hobbyist_serial', 'wppb_profile_builder_hobbyist_serial' ); |
| 14 |
register_setting( 'wppb_module_settings', 'wppb_module_settings' ); |
| 15 |
register_setting( 'wppb_module_settings_description', 'wppb_module_settings_description' ); |
| 16 |
register_setting( 'customRedirectSettings', 'customRedirectSettings' ); |
| 17 |
register_setting( 'customUserListingSettings', 'customUserListingSettings' ); |
| 18 |
register_setting( 'reCaptchaSettings', 'reCaptchaSettings' ); |
| 19 |
register_setting( 'emailCustomizer', 'emailCustomizer' ); |
| 20 |
register_setting( 'wppb_content_restriction_settings', 'wppb_content_restriction_settings' ); |
| 21 |
} |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
// WPML support |
| 27 |
function wppb_icl_t($context, $name, $value){ |
| 28 |
if( function_exists( 'icl_t' ) ) |
| 29 |
return icl_t( $context, $name, $value ); |
| 30 |
|
| 31 |
else |
| 32 |
return $value; |
| 33 |
} |
| 34 |
|
| 35 |
|
| 36 |
function wppb_add_plugin_stylesheet() { |
| 37 |
$wppb_generalSettings = get_option( 'wppb_general_settings' ); |
| 38 |
|
| 39 |
if ( ( file_exists( WPPB_PLUGIN_DIR . '/assets/css/style-front-end.css' ) ) && ( isset( $wppb_generalSettings['extraFieldsLayout'] ) && ( $wppb_generalSettings['extraFieldsLayout'] == 'default' ) ) ){ |
| 40 |
wp_register_style( 'wppb_stylesheet', WPPB_PLUGIN_URL . 'assets/css/style-front-end.css', array(), PROFILE_BUILDER_VERSION ); |
| 41 |
wp_enqueue_style( 'wppb_stylesheet' ); |
| 42 |
} |
| 43 |
if( is_rtl() ) { |
| 44 |
if ( ( file_exists( WPPB_PLUGIN_DIR . '/assets/css/rtl.css' ) ) && ( isset( $wppb_generalSettings['extraFieldsLayout'] ) && ( $wppb_generalSettings['extraFieldsLayout'] == 'default' ) ) ){ |
| 45 |
wp_register_style( 'wppb_stylesheet_rtl', WPPB_PLUGIN_URL . 'assets/css/rtl.css', array(), PROFILE_BUILDER_VERSION ); |
| 46 |
wp_enqueue_style( 'wppb_stylesheet_rtl' ); |
| 47 |
} |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
function wppb_show_admin_bar($content){ |
| 53 |
global $current_user; |
| 54 |
|
| 55 |
$adminSettingsPresent = get_option('wppb_display_admin_settings','not_found'); |
| 56 |
$show = null; |
| 57 |
|
| 58 |
if ($adminSettingsPresent != 'not_found' && $current_user->ID) |
| 59 |
foreach ($current_user->roles as $role_key) { |
| 60 |
if (empty($GLOBALS['wp_roles']->roles[$role_key])) |
| 61 |
continue; |
| 62 |
$role = $GLOBALS['wp_roles']->roles[$role_key]; |
| 63 |
if (isset($adminSettingsPresent[$role['name']])) { |
| 64 |
if ($adminSettingsPresent[$role['name']] == 'show') |
| 65 |
$show = true; |
| 66 |
if ($adminSettingsPresent[$role['name']] == 'hide' && $show === null) |
| 67 |
$show = false; |
| 68 |
} |
| 69 |
} |
| 70 |
return $show === null ? $content : $show; |
| 71 |
} |
| 72 |
|
| 73 |
|
| 74 |
if(!function_exists('wppb_curpageurl')){ |
| 75 |
function wppb_curpageurl() { |
| 76 |
$pageURL = 'http'; |
| 77 |
|
| 78 |
if ((isset($_SERVER["HTTPS"])) && ($_SERVER["HTTPS"] == "on")) |
| 79 |
$pageURL .= "s"; |
| 80 |
|
| 81 |
$pageURL .= "://"; |
| 82 |
|
| 83 |
if( strpos( $_SERVER["HTTP_HOST"], $_SERVER["SERVER_NAME"] ) !== false ){ |
| 84 |
$pageURL .=$_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"]; |
| 85 |
} |
| 86 |
else { |
| 87 |
if ($_SERVER["SERVER_PORT"] != "80") |
| 88 |
$pageURL .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"]; |
| 89 |
else |
| 90 |
$pageURL .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"]; |
| 91 |
} |
| 92 |
|
| 93 |
if ( function_exists('apply_filters') ) $pageURL = apply_filters('wppb_curpageurl', $pageURL); |
| 94 |
|
| 95 |
return $pageURL; |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
|
| 100 |
if ( is_admin() ){ |
| 101 |
|
| 102 |
// register the settings for the menu only display sidebar menu for a user with a certain capability, in this case only the "admin" |
| 103 |
add_action( 'admin_init', 'wppb_register_settings' ); |
| 104 |
|
| 105 |
// display the same extra profile fields in the admin panel also |
| 106 |
if ( file_exists ( WPPB_PLUGIN_DIR.'/front-end/extra-fields/extra-fields.php' ) ){ |
| 107 |
require_once( WPPB_PLUGIN_DIR.'/front-end/extra-fields/extra-fields.php' ); |
| 108 |
|
| 109 |
add_action( 'show_user_profile', 'display_profile_extra_fields_in_admin', 10 ); |
| 110 |
add_action( 'edit_user_profile', 'display_profile_extra_fields_in_admin', 10 ); |
| 111 |
global $pagenow; |
| 112 |
if( $pagenow != 'user-new.php' ) |
| 113 |
add_action( 'user_profile_update_errors', 'wppb_validate_backend_fields', 10, 3 ); |
| 114 |
add_action( 'personal_options_update', 'save_profile_extra_fields_in_admin', 10 ); |
| 115 |
add_action( 'edit_user_profile_update', 'save_profile_extra_fields_in_admin', 10 ); |
| 116 |
} |
| 117 |
|
| 118 |
}else if ( !is_admin() ){ |
| 119 |
// include the stylesheet |
| 120 |
add_action( 'wp_print_styles', 'wppb_add_plugin_stylesheet' ); |
| 121 |
|
| 122 |
// include the menu file for the profile informations |
| 123 |
include_once( WPPB_PLUGIN_DIR.'/front-end/edit-profile.php' ); |
| 124 |
include_once( WPPB_PLUGIN_DIR.'/front-end/class-formbuilder.php' ); |
| 125 |
add_shortcode( 'wppb-edit-profile', 'wppb_front_end_profile_info' ); |
| 126 |
|
| 127 |
// include the menu file for the login screen |
| 128 |
include_once( WPPB_PLUGIN_DIR.'/front-end/login.php' ); |
| 129 |
add_shortcode( 'wppb-login', 'wppb_front_end_login' ); |
| 130 |
|
| 131 |
// include the menu file for the logout screen |
| 132 |
include_once( WPPB_PLUGIN_DIR.'/front-end/logout.php' ); |
| 133 |
add_shortcode( 'wppb-logout', 'wppb_front_end_logout' ); |
| 134 |
|
| 135 |
// include the menu file for the register screen |
| 136 |
include_once( WPPB_PLUGIN_DIR.'/front-end/register.php' ); |
| 137 |
add_shortcode( 'wppb-register', 'wppb_front_end_register_handler' ); |
| 138 |
|
| 139 |
// include the menu file for the recover password screen |
| 140 |
include_once( WPPB_PLUGIN_DIR.'/front-end/recover.php' ); |
| 141 |
add_shortcode( 'wppb-recover-password', 'wppb_front_end_password_recovery' ); |
| 142 |
|
| 143 |
// set the front-end admin bar to show/hide |
| 144 |
add_filter( 'show_admin_bar' , 'wppb_show_admin_bar'); |
| 145 |
|
| 146 |
// Shortcodes used for the widget area |
| 147 |
add_filter( 'widget_text', 'do_shortcode', 11 ); |
| 148 |
} |
| 149 |
|
| 150 |
|
| 151 |
/** |
| 152 |
* Function that overwrites the default wp_mail function and sends out emails |
| 153 |
* |
| 154 |
* @since v.2.0 |
| 155 |
* |
| 156 |
* @param string $to |
| 157 |
* @param string $subject |
| 158 |
* @param string $message |
| 159 |
* @param string $message_from |
| 160 |
* |
| 161 |
*/ |
| 162 |
function wppb_mail( $to, $subject, $message, $message_from = null, $context = null, $headers = '' ) { |
| 163 |
$to = apply_filters( 'wppb_send_email_to', $to ); |
| 164 |
$send_email = apply_filters( 'wppb_send_email', true, $to, $subject, $message, $context ); |
| 165 |
|
| 166 |
$message = apply_filters( 'wppb_email_message', $message, $context ); |
| 167 |
|
| 168 |
do_action( 'wppb_before_sending_email', $to, $subject, $message, $send_email, $context ); |
| 169 |
|
| 170 |
if ( $send_email ) { |
| 171 |
//we add this filter to enable html encoding |
| 172 |
add_filter( 'wp_mail_content_type', create_function( '', 'return "text/html"; ' ) ); |
| 173 |
|
| 174 |
$atts = apply_filters( 'wppb_mail', compact( 'to', 'subject', 'message', 'headers' ), $context ); |
| 175 |
|
| 176 |
$sent = wp_mail( $atts['to'] , html_entity_decode( htmlspecialchars_decode( $atts['subject'], ENT_QUOTES ), ENT_QUOTES ), $atts['message'], $atts['headers'] ); |
| 177 |
|
| 178 |
do_action( 'wppb_after_sending_email', $sent, $to, $subject, $message, $send_email, $context ); |
| 179 |
|
| 180 |
return $sent; |
| 181 |
} |
| 182 |
|
| 183 |
return ''; |
| 184 |
} |
| 185 |
|
| 186 |
function wppb_activate_account_check(){ |
| 187 |
if ( ( isset( $_GET['activation_key'] ) ) && ( trim( $_GET['activation_key'] ) != '' ) ){ |
| 188 |
global $post; |
| 189 |
$activation_key = sanitize_text_field( $_GET['activation_key'] ); |
| 190 |
|
| 191 |
$wppb_generalSettings = get_option( 'wppb_general_settings' ); |
| 192 |
$activation_landing_page_id = ( ( isset( $wppb_generalSettings['activationLandingPage'] ) && ( trim( $wppb_generalSettings['activationLandingPage'] ) != '' ) ) ? $wppb_generalSettings['activationLandingPage'] : 'not_set' ); |
| 193 |
|
| 194 |
if ( $activation_landing_page_id != 'not_set' ){ |
| 195 |
//an activation page was selected, but we still need to check if the current page doesn't already have the registration shortcode |
| 196 |
if ( strpos( $post->post_content, '[wppb-register' ) === false ) |
| 197 |
add_filter( 'the_content', 'wppb_add_activation_message' ); |
| 198 |
|
| 199 |
}elseif ( strpos( $post->post_content, '[wppb-register' ) === false ){ |
| 200 |
//no activation page was selected, and the sent link pointed to the home url |
| 201 |
wp_redirect( apply_filters( 'wppb_activatate_account_redirect_url', WPPB_PLUGIN_URL.'assets/misc/fallback-page.php?activation_key='.urlencode( $activation_key ).'&site_name='.urlencode( get_bloginfo( 'name' ) ).'&site_url='.urlencode( get_bloginfo( 'url' ) ).'&message='.urlencode( $activation_message = wppb_activate_signup( $activation_key ) ), $activation_key, $activation_message ) ); |
| 202 |
exit; |
| 203 |
} |
| 204 |
} |
| 205 |
} |
| 206 |
add_action( 'template_redirect', 'wppb_activate_account_check' ); |
| 207 |
|
| 208 |
|
| 209 |
function wppb_add_activation_message( $content ){ |
| 210 |
|
| 211 |
return wppb_activate_signup( sanitize_text_field( $_GET['activation_key'] ) ) . $content; |
| 212 |
} |
| 213 |
|
| 214 |
|
| 215 |
// Create a new, top-level page |
| 216 |
$args = array( |
| 217 |
'page_title' => 'Profile Builder', |
| 218 |
'menu_title' => 'Profile Builder', |
| 219 |
'capability' => 'manage_options', |
| 220 |
'menu_slug' => 'profile-builder', |
| 221 |
'page_type' => 'menu_page', |
| 222 |
'position' => '70,69', |
| 223 |
'priority' => 1, |
| 224 |
'icon_url' => WPPB_PLUGIN_URL . 'assets/images/pb-menu-icon.png' |
| 225 |
); |
| 226 |
new WCK_Page_Creator_PB( $args ); |
| 227 |
|
| 228 |
/** |
| 229 |
* Remove the automatically created submenu page |
| 230 |
* |
| 231 |
* @since v.2.0 |
| 232 |
* |
| 233 |
* @return void |
| 234 |
*/ |
| 235 |
function wppb_remove_main_menu_page(){ |
| 236 |
remove_submenu_page( 'profile-builder', 'profile-builder' ); |
| 237 |
} |
| 238 |
add_action( 'admin_menu', 'wppb_remove_main_menu_page', 11 ); |
| 239 |
|
| 240 |
/** |
| 241 |
* Add scripts to the back-end CPT's to remove the slug from the edit page |
| 242 |
* |
| 243 |
* @since v.2.0 |
| 244 |
* |
| 245 |
* @return void |
| 246 |
*/ |
| 247 |
function wppb_print_cpt_script( $hook ){ |
| 248 |
wp_enqueue_script( 'jquery-ui-dialog' ); |
| 249 |
wp_enqueue_style( 'wp-jquery-ui-dialog' ); |
| 250 |
|
| 251 |
if ( $hook == 'profile-builder_page_manage-fields' ){ |
| 252 |
wp_enqueue_script( 'wppb-manage-fields-live-change', WPPB_PLUGIN_URL . 'assets/js/jquery-manage-fields-live-change.js', array(), PROFILE_BUILDER_VERSION, true ); |
| 253 |
} |
| 254 |
|
| 255 |
if (( $hook == 'profile-builder_page_manage-fields' ) || |
| 256 |
( $hook == 'profile-builder_page_profile-builder-basic-info' ) || |
| 257 |
( $hook == 'profile-builder_page_profile-builder-modules' ) || |
| 258 |
( $hook == 'profile-builder_page_profile-builder-general-settings' ) || |
| 259 |
( $hook == 'profile-builder_page_profile-builder-admin-bar-settings' ) || |
| 260 |
( $hook == 'profile-builder_page_profile-builder-register' ) || |
| 261 |
( $hook == 'profile-builder_page_profile-builder-wppb_userListing' ) || |
| 262 |
( $hook == 'profile-builder_page_custom-redirects' ) || |
| 263 |
( $hook == 'profile-builder_page_profile-builder-wppb_emailCustomizer' ) || |
| 264 |
( $hook == 'profile-builder_page_profile-builder-wppb_emailCustomizerAdmin' ) || |
| 265 |
( $hook == 'profile-builder_page_profile-builder-add-ons' ) || |
| 266 |
( $hook == 'profile-builder_page_profile-builder-woocommerce-sync' ) || |
| 267 |
( $hook == 'profile-builder_page_profile-builder-bbpress') || |
| 268 |
( $hook == 'admin_page_profile-builder-pms-promo') ) { |
| 269 |
wp_enqueue_style( 'wppb-back-end-style', WPPB_PLUGIN_URL . 'assets/css/style-back-end.css', false, PROFILE_BUILDER_VERSION ); |
| 270 |
} |
| 271 |
|
| 272 |
if ( $hook == 'profile-builder_page_profile-builder-general-settings' ) |
| 273 |
wp_enqueue_script( 'wppb-manage-fields-live-change', WPPB_PLUGIN_URL . 'assets/js/jquery-email-confirmation.js', array(), PROFILE_BUILDER_VERSION, true ); |
| 274 |
|
| 275 |
if( ($hook == 'profile-builder_page_profile-builder-add-ons' ) || |
| 276 |
($hook == 'admin_page_profile-builder-pms-promo' ) ) { |
| 277 |
wp_enqueue_script('wppb-add-ons', WPPB_PLUGIN_URL . 'assets/js/jquery-pb-add-ons.js', array(), PROFILE_BUILDER_VERSION, true); |
| 278 |
wp_enqueue_style( 'thickbox' ); |
| 279 |
wp_enqueue_script( 'thickbox' ); |
| 280 |
} |
| 281 |
|
| 282 |
if ( isset( $_GET['post_type'] ) || isset( $_GET['post'] ) ){ |
| 283 |
if ( isset( $_GET['post_type'] ) ) |
| 284 |
$post_type = sanitize_text_field( $_GET['post_type'] ); |
| 285 |
|
| 286 |
elseif ( isset( $_GET['post'] ) ) |
| 287 |
$post_type = get_post_type( absint( $_GET['post'] ) ); |
| 288 |
|
| 289 |
if ( ( 'wppb-epf-cpt' == $post_type ) || ( 'wppb-rf-cpt' == $post_type ) || ( 'wppb-ul-cpt' == $post_type ) ){ |
| 290 |
wp_enqueue_style( 'wppb-back-end-style', WPPB_PLUGIN_URL . 'assets/css/style-back-end.css', false, PROFILE_BUILDER_VERSION ); |
| 291 |
wp_enqueue_script( 'wppb-epf-rf', WPPB_PLUGIN_URL . 'assets/js/jquery-epf-rf.js', array(), PROFILE_BUILDER_VERSION, true ); |
| 292 |
} |
| 293 |
} |
| 294 |
if ( file_exists ( WPPB_PLUGIN_DIR.'/update/update-checker.php' ) ) { |
| 295 |
wp_enqueue_script( 'wppb-sitewide', WPPB_PLUGIN_URL . 'assets/js/jquery-pb-sitewide.js', array(), PROFILE_BUILDER_VERSION, true ); |
| 296 |
} |
| 297 |
wp_enqueue_style( 'wppb-serial-notice-css', WPPB_PLUGIN_URL . 'assets/css/serial-notice.css', false, PROFILE_BUILDER_VERSION ); |
| 298 |
} |
| 299 |
add_action( 'admin_enqueue_scripts', 'wppb_print_cpt_script' ); |
| 300 |
|
| 301 |
|
| 302 |
//the function used to overwrite the avatar across the wp installation |
| 303 |
function wppb_changeDefaultAvatar( $avatar, $id_or_email, $size, $default, $alt ){ |
| 304 |
/* Get user info. */ |
| 305 |
if(is_object($id_or_email)){ |
| 306 |
$my_user_id = $id_or_email->user_id; |
| 307 |
|
| 308 |
}elseif(is_numeric($id_or_email)){ |
| 309 |
$my_user_id = $id_or_email; |
| 310 |
|
| 311 |
}elseif(!is_integer($id_or_email)){ |
| 312 |
$user_info = get_user_by( 'email', $id_or_email ); |
| 313 |
$my_user_id = ( is_object( $user_info ) ? $user_info->ID : '' ); |
| 314 |
}else |
| 315 |
$my_user_id = $id_or_email; |
| 316 |
|
| 317 |
$wppb_manage_fields = get_option( 'wppb_manage_fields', 'not_found' ); |
| 318 |
if ( $wppb_manage_fields != 'not_found' ){ |
| 319 |
foreach( $wppb_manage_fields as $value ){ |
| 320 |
if ( $value['field'] == 'Avatar'){ |
| 321 |
$avatar_field = $value; |
| 322 |
} |
| 323 |
} |
| 324 |
} |
| 325 |
|
| 326 |
/* for multisite if we don't have an avatar try to get it from the main blog */ |
| 327 |
if( is_multisite() && empty( $avatar_field ) ){ |
| 328 |
switch_to_blog(1); |
| 329 |
$wppb_switched_blog = true; |
| 330 |
$wppb_manage_fields = get_option( 'wppb_manage_fields', 'not_found' ); |
| 331 |
if ( $wppb_manage_fields != 'not_found' ){ |
| 332 |
foreach( $wppb_manage_fields as $value ){ |
| 333 |
if ( $value['field'] == 'Avatar'){ |
| 334 |
$avatar_field = $value; |
| 335 |
} |
| 336 |
} |
| 337 |
} |
| 338 |
} |
| 339 |
|
| 340 |
if ( !empty( $avatar_field ) ){ |
| 341 |
|
| 342 |
$customUserAvatar = get_user_meta( $my_user_id, Wordpress_Creation_Kit_PB::wck_generate_slug( $avatar_field['meta-name'] ), true ); |
| 343 |
if( !empty( $customUserAvatar ) ){ |
| 344 |
if( is_numeric( $customUserAvatar ) ){ |
| 345 |
$img_attr = wp_get_attachment_image_src( $customUserAvatar, 'wppb-avatar-size-'.$size ); |
| 346 |
if( $img_attr[3] === false ){ |
| 347 |
$img_attr = wp_get_attachment_image_src( $customUserAvatar, 'thumbnail' ); |
| 348 |
$avatar = "<img alt='{$alt}' src='{$img_attr[0]}' class='avatar avatar-{$size} photo avatar-default' height='{$size}' width='{$size}' />"; |
| 349 |
} |
| 350 |
else |
| 351 |
$avatar = "<img alt='{$alt}' src='{$img_attr[0]}' class='avatar avatar-{$size} photo avatar-default' height='{$img_attr[2]}' width='{$img_attr[1]}' />"; |
| 352 |
} |
| 353 |
else { |
| 354 |
$customUserAvatar = get_user_meta($my_user_id, 'resized_avatar_' . $avatar_field['id'], true); |
| 355 |
$customUserAvatarRelativePath = get_user_meta($my_user_id, 'resized_avatar_' . $avatar_field['id'] . '_relative_path', true); |
| 356 |
|
| 357 |
if ((($customUserAvatar != '') || ($customUserAvatar != null)) && file_exists($customUserAvatarRelativePath)) { |
| 358 |
$avatar = "<img alt='{$alt}' src='{$customUserAvatar}' class='avatar avatar-{$size} photo avatar-default' height='{$size}' width='{$size}' />"; |
| 359 |
} |
| 360 |
} |
| 361 |
} |
| 362 |
|
| 363 |
} |
| 364 |
|
| 365 |
/* if we switched the blog restore it */ |
| 366 |
if( is_multisite() && !empty( $wppb_switched_blog ) && $wppb_switched_blog ) |
| 367 |
restore_current_blog(); |
| 368 |
|
| 369 |
return $avatar; |
| 370 |
} |
| 371 |
add_filter( 'get_avatar', 'wppb_changeDefaultAvatar', 21, 5 ); |
| 372 |
|
| 373 |
|
| 374 |
//the function used to resize the avatar image; the new function uses a user ID as parameter to make pages load faster |
| 375 |
function wppb_resize_avatar( $userID, $userlisting_size = null, $userlisting_crop = null ){ |
| 376 |
// include the admin image API |
| 377 |
require_once( ABSPATH . '/wp-admin/includes/image.php' ); |
| 378 |
|
| 379 |
// retrieve first a list of all the current custom fields |
| 380 |
$wppb_manage_fields = get_option( 'wppb_manage_fields', 'not_found' ); |
| 381 |
if ( $wppb_manage_fields != 'not_found' ){ |
| 382 |
foreach( $wppb_manage_fields as $value ){ |
| 383 |
if ( $value['field'] == 'Avatar'){ |
| 384 |
$avatar_field = $value; |
| 385 |
} |
| 386 |
} |
| 387 |
} |
| 388 |
|
| 389 |
/* for multisite if we don't have an avatar try to get it from the main blog */ |
| 390 |
if( is_multisite() && empty( $avatar_field ) ){ |
| 391 |
switch_to_blog(1); |
| 392 |
$wppb_switched_blog = true; |
| 393 |
$wppb_manage_fields = get_option( 'wppb_manage_fields', 'not_found' ); |
| 394 |
if ( $wppb_manage_fields != 'not_found' ){ |
| 395 |
foreach( $wppb_manage_fields as $value ){ |
| 396 |
if ( $value['field'] == 'Avatar'){ |
| 397 |
$avatar_field = $value; |
| 398 |
} |
| 399 |
} |
| 400 |
} |
| 401 |
} |
| 402 |
|
| 403 |
|
| 404 |
if ( !empty( $avatar_field ) ){ |
| 405 |
|
| 406 |
// retrieve width and height of the image |
| 407 |
$width = $height = ''; |
| 408 |
|
| 409 |
//this checks if it only has 1 component |
| 410 |
if ( is_numeric( $avatar_field['avatar-size'] ) ){ |
| 411 |
$width = $height = $avatar_field['avatar-size']; |
| 412 |
|
| 413 |
}else{ |
| 414 |
//this checks if the entered value has 2 components |
| 415 |
$sentValue = explode( ',', $avatar_field['avatar-size'] ); |
| 416 |
$width = $sentValue[0]; |
| 417 |
$height = $sentValue[1]; |
| 418 |
} |
| 419 |
|
| 420 |
$width = ( !empty( $userlisting_size ) ? $userlisting_size : $width ); |
| 421 |
$height = ( !empty( $userlisting_size ) ? $userlisting_size : $height ); |
| 422 |
|
| 423 |
if( !strpos( get_user_meta( $userID, 'resized_avatar_'.$avatar_field['id'], true ), $width . 'x' . $height ) ) { |
| 424 |
// retrieve the original image (in original size) |
| 425 |
$avatar_directory_path = get_user_meta( $userID, 'avatar_directory_path_'.$avatar_field['id'], true ); |
| 426 |
|
| 427 |
$image = wp_get_image_editor( $avatar_directory_path ); |
| 428 |
if ( !is_wp_error( $image ) ) { |
| 429 |
do_action( 'wppb_before_avatar_resizing', $image, $userID, Wordpress_Creation_Kit_PB::wck_generate_slug( $avatar_field['meta-name'] ), $avatar_field['avatar-size'] ); |
| 430 |
|
| 431 |
$crop = apply_filters( 'wppb_avatar_crop_resize', ( !empty( $userlisting_crop ) ? $userlisting_crop : false ) ); |
| 432 |
|
| 433 |
$resize = $image->resize( $width, $height, $crop ); |
| 434 |
|
| 435 |
if ($resize !== FALSE) { |
| 436 |
do_action( 'wppb_avatar_resizing', $image, $resize ); |
| 437 |
|
| 438 |
$fileType = apply_filters( 'wppb_resized_file_extension', 'png' ); |
| 439 |
|
| 440 |
$wp_upload_array = wp_upload_dir(); // Array of key => value pairs |
| 441 |
|
| 442 |
//create file(name); both with directory and url |
| 443 |
$fileName_dir = $image->generate_filename( NULL, $wp_upload_array['basedir'].'/profile_builder/avatars/', $fileType ); |
| 444 |
|
| 445 |
if ( PHP_OS == "WIN32" || PHP_OS == "WINNT" ) |
| 446 |
$fileName_dir = str_replace( '\\', '/', $fileName_dir ); |
| 447 |
|
| 448 |
$fileName_url = str_replace( str_replace( '\\', '/', $wp_upload_array['basedir'] ), $wp_upload_array['baseurl'], $fileName_dir ); |
| 449 |
|
| 450 |
//save the newly created (resized) avatar on the disc |
| 451 |
$saved_image = $image->save( $fileName_dir ); |
| 452 |
|
| 453 |
if ( !is_wp_error( $saved_image ) ) { |
| 454 |
/* the image save sometimes doesn't save with the desired extension so we need to see with what extension it saved it with and |
| 455 |
if it differs replace the extension in the path and url that we save as meta */ |
| 456 |
$validate_saved_image = wp_check_filetype_and_ext( $saved_image['path'], $saved_image['path'] ); |
| 457 |
$ext = substr( $fileName_dir,strrpos( $fileName_dir, '.', -1 ), strlen($fileName_dir) ); |
| 458 |
if( !empty( $validate_saved_image['ext'] ) && $validate_saved_image['ext'] != $ext ){ |
| 459 |
$fileName_url = str_replace( $ext, '.'.$validate_saved_image['ext'], $fileName_url ); |
| 460 |
$fileName_dir = str_replace( $ext, '.'.$validate_saved_image['ext'], $fileName_dir ); |
| 461 |
} |
| 462 |
|
| 463 |
update_user_meta( $userID, 'resized_avatar_'.$avatar_field['id'], $fileName_url ); |
| 464 |
update_user_meta( $userID, 'resized_avatar_'.$avatar_field['id'].'_relative_path', $fileName_dir ); |
| 465 |
|
| 466 |
do_action( 'wppb_after_avatar_resizing', $image, $fileName_dir, $fileName_url ); |
| 467 |
} |
| 468 |
} |
| 469 |
} |
| 470 |
} |
| 471 |
} |
| 472 |
|
| 473 |
/* if we switched the blog restore it */ |
| 474 |
if( is_multisite() && !empty( $wppb_switched_blog ) && $wppb_switched_blog ) |
| 475 |
restore_current_blog(); |
| 476 |
|
| 477 |
} |
| 478 |
|
| 479 |
|
| 480 |
if ( is_admin() ){ |
| 481 |
// add a hook to delete the user from the _signups table if either the email confirmation is activated, or it is a wpmu installation |
| 482 |
function wppb_delete_user_from_signups_table($user_id) { |
| 483 |
global $wpdb; |
| 484 |
|
| 485 |
$userLogin = $wpdb->get_var( $wpdb->prepare( "SELECT user_login, user_email FROM " . $wpdb->users . " WHERE ID = %d LIMIT 1", $user_id ) ); |
| 486 |
if ( is_multisite() ) |
| 487 |
$delete = $wpdb->delete( $wpdb->signups, array( 'user_login' => $userLogin ) ); |
| 488 |
else |
| 489 |
$delete = $wpdb->delete( $wpdb->prefix.'signups', array( 'user_login' => $userLogin ) ); |
| 490 |
} |
| 491 |
|
| 492 |
$wppb_generalSettings = get_option( 'wppb_general_settings' ); |
| 493 |
if ( !empty( $wppb_generalSettings['emailConfirmation'] ) && ( $wppb_generalSettings['emailConfirmation'] == 'yes' ) ) { |
| 494 |
if( is_multisite() ) |
| 495 |
add_action( 'wpmu_delete_user', 'wppb_delete_user_from_signups_table' ); |
| 496 |
else |
| 497 |
add_action('delete_user', 'wppb_delete_user_from_signups_table'); |
| 498 |
} |
| 499 |
} |
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
// This function offers compatibility with the all in one event calendar plugin |
| 504 |
function wppb_aioec_compatibility(){ |
| 505 |
|
| 506 |
wp_deregister_script( 'jquery.tools-form'); |
| 507 |
} |
| 508 |
add_action('admin_print_styles-users_page_ProfileBuilderOptionsAndSettings', 'wppb_aioec_compatibility'); |
| 509 |
|
| 510 |
|
| 511 |
function wppb_user_meta_exists( $id, $meta_name ){ |
| 512 |
global $wpdb; |
| 513 |
|
| 514 |
return $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->usermeta WHERE user_id = %d AND meta_key = %s", $id, $meta_name ) ); |
| 515 |
} |
| 516 |
|
| 517 |
|
| 518 |
// function to check if there is a need to add the http:// prefix |
| 519 |
function wppb_check_missing_http( $redirectLink ) { |
| 520 |
return preg_match( '#^(?:[a-z\d]+(?:-+[a-z\d]+)*\.)+[a-z]+(?::\d+)?(?:/|$)#i', $redirectLink ); |
| 521 |
} |
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
//function to output the password strength checker on frontend forms |
| 526 |
function wppb_password_strength_checker_html(){ |
| 527 |
$wppb_generalSettings = get_option( 'wppb_general_settings' ); |
| 528 |
if( !empty( $wppb_generalSettings['minimum_password_strength'] ) ){ |
| 529 |
$password_strength = '<span id="pass-strength-result">'.__('Strength indicator', 'profile-builder' ).'</span> |
| 530 |
<input type="hidden" value="" name="wppb_password_strength" id="wppb_password_strength"/>'; |
| 531 |
return $password_strength; |
| 532 |
} |
| 533 |
return ''; |
| 534 |
} |
| 535 |
|
| 536 |
//function to check password length check |
| 537 |
function wppb_check_password_length( $password ){ |
| 538 |
$wppb_generalSettings = get_option( 'wppb_general_settings' ); |
| 539 |
if( !empty( $wppb_generalSettings['minimum_password_length'] ) ){ |
| 540 |
if( strlen( $password ) < $wppb_generalSettings['minimum_password_length'] ){ |
| 541 |
return true; |
| 542 |
} |
| 543 |
else |
| 544 |
return false; |
| 545 |
} |
| 546 |
return false; |
| 547 |
} |
| 548 |
|
| 549 |
//function to check password strength |
| 550 |
function wppb_check_password_strength(){ |
| 551 |
$wppb_generalSettings = get_option( 'wppb_general_settings' ); |
| 552 |
if( isset( $_POST['wppb_password_strength'] ) && !empty( $wppb_generalSettings['minimum_password_strength'] ) ){ |
| 553 |
$wppb_password_strength = sanitize_text_field( $_POST['wppb_password_strength'] ); |
| 554 |
$password_strength_array = array( 'short' => 0, 'bad' => 1, 'good' => 2, 'strong' => 3 ); |
| 555 |
$password_strength_text = array( 'short' => __( 'Very Weak', 'profile-builder' ), 'bad' => __( 'Weak', 'profile-builder' ), 'good' => __( 'Medium', 'profile-builder' ), 'strong' => __( 'Strong', 'profile-builder' ) ); |
| 556 |
if( $password_strength_array[$wppb_password_strength] < $password_strength_array[$wppb_generalSettings['minimum_password_strength']] ){ |
| 557 |
return $password_strength_text[$wppb_generalSettings['minimum_password_strength']]; |
| 558 |
} |
| 559 |
else |
| 560 |
return false; |
| 561 |
} |
| 562 |
return false; |
| 563 |
} |
| 564 |
|
| 565 |
/* function to output password length requirements text */ |
| 566 |
function wppb_password_length_text(){ |
| 567 |
$wppb_generalSettings = get_option( 'wppb_general_settings' ); |
| 568 |
if( !empty( $wppb_generalSettings['minimum_password_length'] ) ){ |
| 569 |
return sprintf(__('Minimum length of %d characters.', 'profile-builder'), $wppb_generalSettings['minimum_password_length']); |
| 570 |
} |
| 571 |
return ''; |
| 572 |
} |
| 573 |
|
| 574 |
/* function to output password strength requirements text */ |
| 575 |
function wppb_password_strength_description() { |
| 576 |
$wppb_generalSettings = get_option( 'wppb_general_settings' ); |
| 577 |
|
| 578 |
if( ! empty( $wppb_generalSettings['minimum_password_strength'] ) ) { |
| 579 |
$password_strength_text = array( 'short' => __( 'Very Weak', 'profile-builder' ), 'bad' => __( 'Weak', 'profile-builder' ), 'good' => __( 'Medium', 'profile-builder' ), 'strong' => __( 'Strong', 'profile-builder' ) ); |
| 580 |
$password_strength_description = '<br>'. sprintf( __( 'The password must have a minimum strength of %s.', 'profile-builder' ), $password_strength_text[$wppb_generalSettings['minimum_password_strength']] ); |
| 581 |
|
| 582 |
return $password_strength_description; |
| 583 |
} else { |
| 584 |
return ''; |
| 585 |
} |
| 586 |
} |
| 587 |
|
| 588 |
/** |
| 589 |
* Include password strength check scripts on frontend where we have shortoces present |
| 590 |
*/ |
| 591 |
add_action( 'wp_footer', 'wppb_enqueue_password_strength_check' ); |
| 592 |
function wppb_enqueue_password_strength_check() { |
| 593 |
global $wppb_shortcode_on_front; |
| 594 |
if( $wppb_shortcode_on_front ){ |
| 595 |
$wppb_generalSettings = get_option( 'wppb_general_settings' ); |
| 596 |
if( !empty( $wppb_generalSettings['minimum_password_strength'] ) ){ |
| 597 |
wp_enqueue_script( 'password-strength-meter' ); |
| 598 |
} |
| 599 |
} |
| 600 |
} |
| 601 |
add_action( 'wp_footer', 'wppb_password_strength_check', 102 ); |
| 602 |
function wppb_password_strength_check(){ |
| 603 |
global $wppb_shortcode_on_front; |
| 604 |
if( $wppb_shortcode_on_front ){ |
| 605 |
$wppb_generalSettings = get_option( 'wppb_general_settings' ); |
| 606 |
if( !empty( $wppb_generalSettings['minimum_password_strength'] ) ){ |
| 607 |
?> |
| 608 |
<script type="text/javascript"> |
| 609 |
function check_pass_strength() { |
| 610 |
var pass1 = jQuery('#passw1').val(), pass2 = jQuery('#passw2').val(), strength; |
| 611 |
|
| 612 |
jQuery('#pass-strength-result').removeClass('short bad good strong'); |
| 613 |
if ( ! pass1 ) { |
| 614 |
jQuery('#pass-strength-result').html( pwsL10n.empty ); |
| 615 |
return; |
| 616 |
} |
| 617 |
|
| 618 |
strength = wp.passwordStrength.meter( pass1, wp.passwordStrength.userInputBlacklist(), pass2 ); |
| 619 |
|
| 620 |
switch ( strength ) { |
| 621 |
case 2: |
| 622 |
jQuery('#pass-strength-result').addClass('bad').html( pwsL10n.bad ); |
| 623 |
jQuery('#wppb_password_strength').val('bad'); |
| 624 |
break; |
| 625 |
case 3: |
| 626 |
jQuery('#pass-strength-result').addClass('good').html( pwsL10n.good ); |
| 627 |
jQuery('#wppb_password_strength').val('good'); |
| 628 |
break; |
| 629 |
case 4: |
| 630 |
jQuery('#pass-strength-result').addClass('strong').html( pwsL10n.strong ); |
| 631 |
jQuery('#wppb_password_strength').val('strong'); |
| 632 |
break; |
| 633 |
case 5: |
| 634 |
jQuery('#pass-strength-result').addClass('short').html( pwsL10n.mismatch ); |
| 635 |
jQuery('#wppb_password_strength').val('short'); |
| 636 |
break; |
| 637 |
default: |
| 638 |
jQuery('#pass-strength-result').addClass('short').html( pwsL10n['short'] ); |
| 639 |
jQuery('#wppb_password_strength').val('short'); |
| 640 |
} |
| 641 |
} |
| 642 |
jQuery( document ).ready( function() { |
| 643 |
// Binding to trigger checkPasswordStrength |
| 644 |
jQuery('#passw1').val('').keyup( check_pass_strength ); |
| 645 |
jQuery('#passw2').val('').keyup( check_pass_strength ); |
| 646 |
jQuery('#pass-strength-result').show(); |
| 647 |
}); |
| 648 |
</script> |
| 649 |
<?php |
| 650 |
} |
| 651 |
} |
| 652 |
} |
| 653 |
/** |
| 654 |
* Create functions for repeating error messages in front-end forms |
| 655 |
*/ |
| 656 |
function wppb_required_field_error($field_title='') { |
| 657 |
$required_error = apply_filters('wppb_required_error' , __('This field is required','profile-builder') , $field_title); |
| 658 |
|
| 659 |
return $required_error; |
| 660 |
|
| 661 |
} |
| 662 |
|
| 663 |
/** |
| 664 |
* Function that returns a certain field (from manage_fields) by a given id or meta_name |
| 665 |
*/ |
| 666 |
function wppb_get_field_by_id_or_meta( $id_or_meta ){ |
| 667 |
|
| 668 |
$id = 0; |
| 669 |
$meta = ''; |
| 670 |
|
| 671 |
if ( is_numeric($id_or_meta) ) |
| 672 |
$id = $id_or_meta; |
| 673 |
else |
| 674 |
$meta = $id_or_meta; |
| 675 |
|
| 676 |
$fields = get_option('wppb_manage_fields', 'not_found'); |
| 677 |
|
| 678 |
if ($fields != 'not_found') { |
| 679 |
|
| 680 |
foreach ($fields as $key => $field) { |
| 681 |
if ( (!empty($id)) && ($field['id'] == $id) ) |
| 682 |
return $field; |
| 683 |
if ( (!empty($meta)) && ($field['meta-name'] == $meta) ) |
| 684 |
return $field; |
| 685 |
} |
| 686 |
|
| 687 |
} |
| 688 |
|
| 689 |
return ''; |
| 690 |
} |
| 691 |
|
| 692 |
|
| 693 |
/* Function for displaying reCAPTCHA error on Login and Recover Password forms */ |
| 694 |
function wppb_recaptcha_field_error($field_title='') { |
| 695 |
$recaptcha_error = apply_filters('wppb_recaptcha_error' , __('Please enter a (valid) reCAPTCHA value','profile-builder') , $field_title); |
| 696 |
|
| 697 |
return $recaptcha_error; |
| 698 |
|
| 699 |
} |
| 700 |
/* Function for displaying phone field error */ |
| 701 |
function wppb_phone_field_error( $field_title = '' ) { |
| 702 |
$phone_error = apply_filters( 'wppb_phone_error' , __( 'Incorrect phone number', 'profile-builder' ) , $field_title ); |
| 703 |
|
| 704 |
return $phone_error; |
| 705 |
} |
| 706 |
|
| 707 |
/* Create a wrapper function for get_query_var */ |
| 708 |
function wppb_get_query_var( $varname ){ |
| 709 |
return apply_filters( 'wppb_get_query_var_'.$varname, get_query_var( $varname ) ); |
| 710 |
} |
| 711 |
|
| 712 |
/* Filter the "Save Changes" button text, to make it translatable */ |
| 713 |
function wppb_change_save_changes_button($value){ |
| 714 |
$value = __('Save Changes','profile-builder'); |
| 715 |
return $value; |
| 716 |
} |
| 717 |
add_filter( 'wck_save_changes_button', 'wppb_change_save_changes_button', 10, 2); |
| 718 |
|
| 719 |
/* Filter the "Cancel" button text, to make it translatable */ |
| 720 |
function wppb_change_cancel_button($value){ |
| 721 |
$value = __('Cancel','profile-builder'); |
| 722 |
return $value; |
| 723 |
} |
| 724 |
add_filter( 'wck_cancel_button', 'wppb_change_cancel_button', 10, 2); |
| 725 |
|
| 726 |
/* ilter the "Delete" button text, to make it translatable */ |
| 727 |
function wppb_change_delete_button($value){ |
| 728 |
$value = __('Delete','profile-builder'); |
| 729 |
return $value; |
| 730 |
} |
| 731 |
add_filter( 'wck_delete_button', 'wppb_change_delete_button', 10, 2); |
| 732 |
|
| 733 |
/*Filter the "Edit" button text, to make it translatable*/ |
| 734 |
function wppb_change_edit_button($value){ |
| 735 |
$value = __('Edit','profile-builder'); |
| 736 |
return $value; |
| 737 |
} |
| 738 |
add_filter( 'wck_edit_button', 'wppb_change_edit_button', 10, 2); |
| 739 |
|
| 740 |
/*Filter the User Listing, Register Forms and Edit Profile forms metabox header content, to make it translatable*/ |
| 741 |
function wppb_change_metabox_content_header(){ |
| 742 |
return '<thead><tr><th class="wck-number">#</th><th class="wck-content">'. __( 'Content', 'profile-builder' ) .'</th><th class="wck-edit">'. __( 'Edit', 'profile-builder' ) .'</th><th class="wck-delete">'. __( 'Delete', 'profile-builder' ) .'</th></tr></thead>'; |
| 743 |
} |
| 744 |
add_filter('wck_metabox_content_header_wppb_ul_page_settings', 'wppb_change_metabox_content_header', 1); |
| 745 |
add_filter('wck_metabox_content_header_wppb_rf_page_settings', 'wppb_change_metabox_content_header', 1); |
| 746 |
add_filter('wck_metabox_content_header_wppb_epf_page_settings', 'wppb_change_metabox_content_header', 1); |
| 747 |
|
| 748 |
|
| 749 |
/* Add a notice if people are not able to register via Profile Builder; Membership -> "Anyone can register" checkbox is not checked under WordPress admin UI -> Settings -> General tab */ |
| 750 |
if ( (get_option('users_can_register') == false) && (!class_exists('PMS_Add_General_Notices')) ) { |
| 751 |
if( is_multisite() ) { |
| 752 |
new WPPB_Add_General_Notices('wppb_anyone_can_register', |
| 753 |
sprintf(__('To allow users to register for your website via Profile Builder, you first must enable user registration. Go to %1$sNetwork Settings%2$s, and under Registration Settings make sure to check “User accounts may be registered”. %3$sDismiss%4$s', 'profile-builder'), "<a href='" . network_admin_url('settings.php') . "'>", "</a>", "<a href='" . esc_url( add_query_arg('wppb_anyone_can_register_dismiss_notification', '0') ) . "'>", "</a>"), |
| 754 |
'update-nag'); |
| 755 |
}else{ |
| 756 |
new WPPB_Add_General_Notices('wppb_anyone_can_register', |
| 757 |
sprintf(__('To allow users to register for your website via Profile Builder, you first must enable user registration. Go to %1$sSettings -> General%2$s tab, and under Membership make sure to check “Anyone can register”. %3$sDismiss%4$s', 'profile-builder'), "<a href='" . admin_url('options-general.php') . "'>", "</a>", "<a href='" . esc_url( add_query_arg('wppb_anyone_can_register_dismiss_notification', '0') ) . "'>", "</a>"), |
| 758 |
'update-nag'); |
| 759 |
} |
| 760 |
} |
| 761 |
|
| 762 |
/*Filter default WordPress notices ("Post published. Post updated."), add post type name for User Listing, Registration Forms and Edit Profile Forms*/ |
| 763 |
function wppb_change_default_post_updated_messages($messages){ |
| 764 |
global $post; |
| 765 |
$post_type = get_post_type($post->ID); |
| 766 |
$object = get_post_type_object($post_type); |
| 767 |
|
| 768 |
if ( ($post_type == 'wppb-rf-cpt')||($post_type == 'wppb-epf-cpt')||($post_type == 'wppb-ul-cpt') ){ |
| 769 |
$messages['post'][1] = $object->labels->name . ' updated.'; |
| 770 |
$messages['post'][6] = $object->labels->name . ' published.'; |
| 771 |
} |
| 772 |
return $messages; |
| 773 |
} |
| 774 |
add_filter('post_updated_messages','wppb_change_default_post_updated_messages', 2); |
| 775 |
|
| 776 |
|
| 777 |
/* for meta-names with spaces in them PHP converts the space to underline in the $_POST */ |
| 778 |
function wppb_handle_meta_name( $meta_name ){ |
| 779 |
$meta_name = str_replace( ' ', '_', $meta_name ); |
| 780 |
$meta_name = str_replace( '.', '_', $meta_name ); |
| 781 |
return $meta_name; |
| 782 |
} |
| 783 |
|
| 784 |
|
| 785 |
// change User Registered date and time according to timezone selected in WordPress settings |
| 786 |
function wppb_get_date_by_timezone() { |
| 787 |
$wppb_wp_timezone = get_option( 'timezone_string' ); |
| 788 |
|
| 789 |
if( ! empty( $wppb_wp_timezone ) ) { |
| 790 |
date_default_timezone_set( $wppb_wp_timezone ); |
| 791 |
$wppb_get_date = date( "Y-m-d G:i:s" ); |
| 792 |
} else { |
| 793 |
$wppb_wp_gmt_offset = get_option( 'gmt_offset' ); |
| 794 |
$wppb_gmt_offset = $wppb_wp_gmt_offset * 60 * 60; |
| 795 |
$wppb_get_date = gmdate( "Y-m-d G:i:s", time() + $wppb_gmt_offset ); |
| 796 |
} |
| 797 |
|
| 798 |
return $wppb_get_date; |
| 799 |
} |
| 800 |
|
| 801 |
/** |
| 802 |
* Add HTML tag 'required' to fields |
| 803 |
* |
| 804 |
* Add HTML tag 'required' for each field if the field is required. For browsers that don't support this HTML tag, we will still have the fallback. |
| 805 |
* Field type 'Checkbox' is explicitly excluded because there is no HTML support to check if at least one option is selected. |
| 806 |
* Other fields excluded are Avatar, Upload, Heading, ReCaptcha, WYSIWYG, Map. |
| 807 |
* |
| 808 |
* @since |
| 809 |
* |
| 810 |
* @param string $extra_attributes Extra attributes attached to the field HTML tag. |
| 811 |
* @param array $field Field description. |
| 812 |
* @return string $extra_attributes |
| 813 |
*/ |
| 814 |
function wppb_add_html_tag_required_to_fields( $extra_attributes, $field, $form_location ) { |
| 815 |
if ( $field['field'] != "Checkbox" && isset( $field['required'] ) && $field['required'] == 'Yes' ){ |
| 816 |
if( !( ( $field['field'] == "Default - Password" || $field['field'] == "Default - Repeat Password" ) && $form_location == 'edit_profile' ) ) |
| 817 |
$extra_attributes .= ' required '; |
| 818 |
} |
| 819 |
return $extra_attributes; |
| 820 |
} |
| 821 |
add_filter( 'wppb_extra_attribute', 'wppb_add_html_tag_required_to_fields', 10, 3 ); |
| 822 |
|
| 823 |
/** |
| 824 |
* Add HTML tag 'required' to WooCommerce fields |
| 825 |
* |
| 826 |
* Add HTML tag 'required' for each WooCommerce field if the field is required. For browsers that don't support this HTML tag, we will still have the fallback. |
| 827 |
* Does not work on 'State / County' field, if it becomes required later depending on the Country Value |
| 828 |
* |
| 829 |
* @since |
| 830 |
* |
| 831 |
* @param string $extra_attributes Extra attributes attached to the field HTML tag. |
| 832 |
* @param array $field Field description. |
| 833 |
* @return string $extra_attributes |
| 834 |
*/ |
| 835 |
function wppb_add_html_tag_required_to_woo_fields( $extra_attributes, $field ) { |
| 836 |
if ( isset( $field['required'] ) && $field['required'] == 'Yes' ){ |
| 837 |
$extra_attributes .= ' required '; |
| 838 |
} |
| 839 |
return $extra_attributes; |
| 840 |
} |
| 841 |
add_filter( 'wppb_woo_extra_attribute', 'wppb_add_html_tag_required_to_woo_fields', 10, 2 ); |
| 842 |
|
| 843 |
|
| 844 |
/** |
| 845 |
* Add jQuery script to remove required attribute for hidden fields |
| 846 |
* |
| 847 |
* If a field is hidden dynamically via conditional fields or WooSync 'Ship to a different address' checkbox, then the required field needs to be removed. |
| 848 |
* If a field is made visible again, add the required field back again. |
| 849 |
* |
| 850 |
* @since |
| 851 |
* |
| 852 |
* @param string $extra_attributes Extra attributes attached to the field HTML tag. |
| 853 |
* @param array $field Field description. |
| 854 |
* @return string $extra_attributes |
| 855 |
*/ |
| 856 |
function wppb_manage_required_attribute() { |
| 857 |
global $wppb_shortcode_on_front; |
| 858 |
if ($wppb_shortcode_on_front) { |
| 859 |
?> |
| 860 |
<script type="text/javascript"> |
| 861 |
jQuery(document).on( "wppbAddRequiredAttributeEvent", wppbAddRequired ); |
| 862 |
function wppbAddRequired(event) { |
| 863 |
var element = wppbEventTargetRequiredElement( event.target ); |
| 864 |
if( jQuery( element ).attr( "wppb_cf_temprequired" ) ){ |
| 865 |
jQuery( element ).removeAttr( "wppb_cf_temprequired" ); |
| 866 |
jQuery( element ).attr( "required", "required" ); |
| 867 |
} |
| 868 |
} |
| 869 |
|
| 870 |
jQuery(document).on( "wppbRemoveRequiredAttributeEvent", wppbRemoveRequired ); |
| 871 |
function wppbRemoveRequired(event) { |
| 872 |
var element = wppbEventTargetRequiredElement( event.target ); |
| 873 |
if ( jQuery( element ).attr( "required" ) ) { |
| 874 |
jQuery( element ).removeAttr( "required" ); |
| 875 |
jQuery( element ).attr( "wppb_cf_temprequired", "wppb_cf_temprequired" ); |
| 876 |
} |
| 877 |
} |
| 878 |
|
| 879 |
jQuery(document).on( "wppbToggleRequiredAttributeEvent", wppbToggleRequired ); |
| 880 |
function wppbToggleRequired(event) { |
| 881 |
if ( jQuery( event.target ).attr( "required" ) ) { |
| 882 |
jQuery( event.target ).removeAttr( "required" ); |
| 883 |
jQuery( event.target ).attr( "wppb_cf_temprequired", "wppb_cf_temprequired" ); |
| 884 |
}else if( jQuery( event.target ).attr( "wppb_cf_temprequired" ) ){ |
| 885 |
jQuery( event.target ).removeAttr( "wppb_cf_temprequired" ); |
| 886 |
jQuery( event.target ).attr( "required", "required" ); |
| 887 |
} |
| 888 |
} |
| 889 |
|
| 890 |
function wppbEventTargetRequiredElement( htmlElement ){ |
| 891 |
if ( htmlElement.nodeName == "OPTION" ){ |
| 892 |
// <option> is the target element, so we need to get the parent <select>, in order to apply the required attribute |
| 893 |
return htmlElement.parentElement; |
| 894 |
}else{ |
| 895 |
return htmlElement; |
| 896 |
} |
| 897 |
} |
| 898 |
|
| 899 |
</script> |
| 900 |
<?php |
| 901 |
} |
| 902 |
} |
| 903 |
add_action( 'wp_footer', 'wppb_manage_required_attribute' ); |
| 904 |
|
| 905 |
function wpbb_specify_blog_details_on_signup_email( $message, $user_email, $user, $activation_key, $registration_page_url, $meta, $from_name, $context ){ |
| 906 |
$meta = unserialize($meta); |
| 907 |
|
| 908 |
if ( is_multisite() && isset( $meta['wppb_create_new_site_checkbox'] ) && $meta['wppb_create_new_site_checkbox'] == 'yes' ) { |
| 909 |
$blog_details = wpmu_validate_blog_signup( $meta['wppb_blog_url'], $meta['wppb_blog_title'] ); |
| 910 |
|
| 911 |
if ( empty($blog_details['errors']->errors['blogname']) && empty($blog_details['errors']->errors['blog_title'])) { |
| 912 |
$blog_path = $blog_details['domain'] . $blog_details['path']; |
| 913 |
$message .= __( '<br><br>Also, you will be able to visit your site at ', 'profile-builder' ) . '<a href="' . $blog_path . '">' . $blog_path . '</a>.'; |
| 914 |
} |
| 915 |
} |
| 916 |
return $message; |
| 917 |
} |
| 918 |
add_filter( 'wppb_signup_user_notification_email_content', 'wpbb_specify_blog_details_on_signup_email', 5, 8 ); |
| 919 |
|
| 920 |
function wpbb_specify_blog_details_on_registration_email( $user_message_content, $email, $password, $user_message_subject, $context ){ |
| 921 |
|
| 922 |
if ( is_multisite() ) { |
| 923 |
$user = get_user_by( 'email', $email ); |
| 924 |
$blog_path = wppb_get_blog_url_of_user_id( $user->ID ); |
| 925 |
if ( ! empty ( $blog_path ) ) { |
| 926 |
$user_message_content .= __( '<br><br>You can visit your site at ', 'profile-builder' ) . '<a href="' . $blog_path . '">' . $blog_path . '</a>.'; |
| 927 |
} |
| 928 |
} |
| 929 |
return $user_message_content; |
| 930 |
|
| 931 |
} |
| 932 |
add_filter( 'wppb_register_user_email_message_without_admin_approval', 'wpbb_specify_blog_details_on_registration_email', 5, 5 ); |
| 933 |
add_filter( 'wppb_register_user_email_message_with_admin_approval', 'wpbb_specify_blog_details_on_registration_email', 5, 5 ); |
| 934 |
|
| 935 |
|
| 936 |
function wppb_get_blog_url_of_user_id( $user_id, $ignore_privacy = true ){ |
| 937 |
$blog_id = get_user_meta( $user_id, 'primary_blog', true ); |
| 938 |
if ( is_multisite() && !empty( $blog_id ) ){ |
| 939 |
$blog_details = get_blog_details( $blog_id ); |
| 940 |
if ( $ignore_privacy || $blog_details->public ) { |
| 941 |
return $blog_details->domain . $blog_details->path; |
| 942 |
} |
| 943 |
} |
| 944 |
return ''; |
| 945 |
} |
| 946 |
|
| 947 |
function wppb_can_users_signup_blog(){ |
| 948 |
if ( ! is_multisite() ) |
| 949 |
return false; |
| 950 |
global $wpdb; |
| 951 |
$current_site = get_current_site(); |
| 952 |
$sitemeta_options_query = $wpdb->prepare( "SELECT meta_value FROM {$wpdb->sitemeta} WHERE meta_key = 'registration' AND site_id = %d", $current_site->id ); |
| 953 |
$network_options_meta = $wpdb->get_results( $sitemeta_options_query ); |
| 954 |
|
| 955 |
if ( $network_options_meta[0]->meta_value == 'all' ){ |
| 956 |
return true; |
| 957 |
} |
| 958 |
return false; |
| 959 |
} |
| 960 |
|
| 961 |
/** |
| 962 |
* Function that handle redirect URL |
| 963 |
* |
| 964 |
* @param string $redirect_priority - it can be normal or top priority |
| 965 |
* @param string $redirect_type - type of the redirect |
| 966 |
* @param null|string $redirect_url - redirect URL if already set |
| 967 |
* @param null|string|object $user - username, user email or user data |
| 968 |
* @param null|string $user_role - user role |
| 969 |
* |
| 970 |
* @return null|string $redirect_url |
| 971 |
*/ |
| 972 |
function wppb_get_redirect_url( $redirect_priority = 'normal', $redirect_type, $redirect_url = NULL, $user = NULL, $user_role = NULL ) { |
| 973 |
if( PROFILE_BUILDER == 'Profile Builder Pro' ) { |
| 974 |
$wppb_module_settings = get_option( 'wppb_module_settings' ); |
| 975 |
|
| 976 |
if( isset( $wppb_module_settings['wppb_customRedirect'] ) && $wppb_module_settings['wppb_customRedirect'] == 'show' && $redirect_priority != 'top' && function_exists( 'wppb_custom_redirect_url' ) ) { |
| 977 |
$redirect_url = wppb_custom_redirect_url( $redirect_type, $redirect_url, $user, $user_role ); |
| 978 |
} |
| 979 |
} |
| 980 |
|
| 981 |
if( ! empty( $redirect_url ) ) { |
| 982 |
$redirect_url = ( wppb_check_missing_http( $redirect_url ) ? 'http://'. $redirect_url : $redirect_url ); |
| 983 |
} |
| 984 |
|
| 985 |
return $redirect_url; |
| 986 |
} |
| 987 |
|
| 988 |
/** |
| 989 |
* Function that builds the redirect |
| 990 |
* |
| 991 |
* @param string $redirect_url - redirect URL |
| 992 |
* @param int $redirect_delay - redirect delay in seconds |
| 993 |
* @param null|string $redirect_type - the type of the redirect |
| 994 |
* @param null|array $form_args - form args if set |
| 995 |
* |
| 996 |
* @return string $redirect_message |
| 997 |
*/ |
| 998 |
function wppb_build_redirect( $redirect_url, $redirect_delay, $redirect_type = NULL, $form_args = NULL ) { |
| 999 |
if( isset( $redirect_type ) ) { |
| 1000 |
$redirect_url = apply_filters( 'wppb_'. $redirect_type .'_redirect', $redirect_url ); |
| 1001 |
} |
| 1002 |
|
| 1003 |
$redirect_message = ''; |
| 1004 |
|
| 1005 |
if( ! empty( $redirect_url ) ) { |
| 1006 |
$redirect_url = ( wppb_check_missing_http( $redirect_url ) ? 'http://'. $redirect_url : $redirect_url ); |
| 1007 |
|
| 1008 |
if( $redirect_delay == 0 ) { |
| 1009 |
$redirect_message = '<meta http-equiv="Refresh" content="'. $redirect_delay .';url='. $redirect_url .'" />'; |
| 1010 |
} else { |
| 1011 |
$redirect_url_href = apply_filters( 'wppb_redirect_url', '<a href="'. $redirect_url .'">'. __( 'here', 'profile-builder' ) .'</a>', $redirect_url, $redirect_type, $form_args ); |
| 1012 |
$redirect_message = apply_filters( 'wppb_redirect_message_before_returning', '<p class="redirect_message">'. sprintf( wp_slash( __( 'You will soon be redirected automatically. If you see this page for more than %1$d seconds, please click %2$s.%3$s', 'profile-builder' ) ), $redirect_delay, $redirect_url_href, '<meta http-equiv="Refresh" content="'. $redirect_delay .';url='. $redirect_url .'" />' ) .'</p>', $redirect_url, $redirect_delay, $redirect_url_href, $redirect_type, $form_args ); |
| 1013 |
} |
| 1014 |
} |
| 1015 |
|
| 1016 |
return $redirect_message; |
| 1017 |
} |
| 1018 |
|
| 1019 |
/** |
| 1020 |
* Function that strips the script tags from an input |
| 1021 |
* @param $string |
| 1022 |
* @return mixed |
| 1023 |
*/ |
| 1024 |
function wppb_sanitize_value( $string ){ |
| 1025 |
return preg_replace( '/<script\b[^>]*>(.*?)<\/script>/is', '', $string ); |
| 1026 |
} |
| 1027 |
|
| 1028 |
/** |
| 1029 |
* Function that receives a user role and returns it's label. |
| 1030 |
* Returns the original role if not found. |
| 1031 |
* |
| 1032 |
* @since v.2.7.1 |
| 1033 |
* |
| 1034 |
* @param string $role |
| 1035 |
* |
| 1036 |
* @return string |
| 1037 |
*/ |
| 1038 |
function wppb_get_role_name($role){ |
| 1039 |
global $wp_roles; |
| 1040 |
|
| 1041 |
if ( array_key_exists( $role, $wp_roles->role_names ) ) |
| 1042 |
return $wp_roles->role_names[$role]; |
| 1043 |
|
| 1044 |
return $role; |
| 1045 |
} |