function wppb_checkbox_handler($output, $form_location, $field, $user_id, $field_check_errors, $request_data) { if ($field['field'] == 'Checkbox') { $item_title = apply_filters('wppb_' . $form_location . '_checkbox_custom_field_' . $field['id'] . '_item_title', wppb_icl_t('plugin profile-builder-pro', 'custom_field_' . $field['id'] . '_title_translation', $field['field-title'])); $item_description = wppb_icl_t('plugin profile-builder-pro', 'custom_field_' . $field['id'] . '_description_translation', $field['description']); $item_option_labels = wppb_icl_t('plugin profile-builder-pro', 'custom_field_' . $field['id'] . '_option_labels_translation', $field['labels']); $checkbox_labels = explode(',', $item_option_labels); $checkbox_values = explode(',', $field['options']); if ($form_location != 'register') { $input_value = wppb_user_meta_exists($user_id, $field['meta-name']) != null ? array_map('trim', explode(',', stripslashes(get_user_meta($user_id, $field['meta-name'], true)))) : array_map('trim', explode(',', $field['default-options'])); } else { $input_value = !empty($field['default-options']) ? array_map('trim', explode(',', $field['default-options'])) : array(); } if ($form_location == 'register' && isset($request_data[wppb_handle_meta_name($field['meta-name'])]) && !empty($request_data[wppb_handle_meta_name($field['meta-name'])])) { $input_value = $request_data[wppb_handle_meta_name($field['meta-name'])]; } $extra_attr = apply_filters('wppb_extra_attribute', '', $field); if ($form_location != 'back_end') { $error_mark = $field['required'] == 'Yes' ? '<span class="wppb-required" title="' . wppb_required_field_error($field["field-title"]) . '">*</span>' : ''; if (array_key_exists($field['id'], $field_check_errors)) { $error_mark = '<img src="' . WPPB_PLUGIN_URL . 'assets/images/pencil_delete.png" title="' . wppb_required_field_error($field["field-title"]) . '"/>'; } $output = ' <label for="' . $field['meta-name'] . '">' . $item_title . $error_mark . '</label>'; $output .= '<ul class="wppb-checkboxes">'; foreach ($checkbox_values as $key => $value) { $output .= '<li><input value="' . esc_attr(trim($value)) . '" class="custom_field_checkbox" name="' . $field['meta-name'] . '[]" id="' . Wordpress_Creation_Kit_PB::wck_generate_slug(trim($value)) . '_' . $field['id'] . '" type="checkbox" ' . $extra_attr . ' '; if (in_array(trim($value), $input_value)) { $output .= ' checked'; } $output .= ' /><label for="' . Wordpress_Creation_Kit_PB::wck_generate_slug(trim($value)) . '_' . $field['id'] . '" class="wppb-rc-value">' . (!isset($checkbox_labels[$key]) || !$checkbox_labels[$key] ? trim($checkbox_values[$key]) : trim($checkbox_labels[$key])) . '</label></li>'; } $output .= '</ul>'; if (!empty($item_description)) { $output .= '<span class="wppb-description-delimiter">' . $item_description . '</span>'; } } else { $item_title = $field['required'] == 'Yes' ? $item_title . ' <span class="description">(' . __('required', 'profile-builder') . ')</span>' : $item_title; $output = ' <table class="form-table"> <tr> <th><label for="' . $field['meta-name'] . '">' . $item_title . '</label></th> <td>'; foreach ($checkbox_values as $key => $value) { $output .= '<li><input value="' . esc_attr(trim($value)) . '" class="custom_field_checkbox ' . apply_filters('wppb_fields_extra_css_class', '', $field) . '" name="' . $field['meta-name'] . '[]" id="' . Wordpress_Creation_Kit_PB::wck_generate_slug(trim($value)) . '_' . $field['id'] . '" type="checkbox"'; if (in_array(trim($value), $input_value)) { $output .= ' checked'; } $output .= ' /><label for="' . Wordpress_Creation_Kit_PB::wck_generate_slug(trim($value)) . '_' . $field['id'] . '" class="wppb-rc-value">' . (!isset($checkbox_labels[$key]) || !$checkbox_labels[$key] ? trim($checkbox_values[$key]) : trim($checkbox_labels[$key])) . '</label></li>'; } $output .= ' <span class="wppb-description-delimiter">' . $item_description . '</span> </td> </tr> </table>'; } return apply_filters('wppb_' . $form_location . '_checkbox_custom_field_' . $field['id'], $output, $form_location, $field, $user_id, $field_check_errors, $request_data, $input_value); } }
function wppb_autologin_after_password_changed() { if (isset($_POST['action']) && $_POST['action'] == 'edit_profile') { if (isset($_POST['passw1']) && !empty($_POST['passw1']) && !empty($_POST['form_name'])) { /* all the error checking filters are defined in each field file so we need them here */ if (file_exists(WPPB_PLUGIN_DIR . '/front-end/default-fields/default-fields.php')) { require_once WPPB_PLUGIN_DIR . '/front-end/default-fields/default-fields.php'; } if (file_exists(WPPB_PLUGIN_DIR . '/front-end/extra-fields/extra-fields.php')) { require_once WPPB_PLUGIN_DIR . '/front-end/extra-fields/extra-fields.php'; } /* we get the form_name through $_POST so we can apply correctly the filter so we generate the correct fields in the current form */ $form_fields = apply_filters('wppb_change_form_fields', get_option('wppb_manage_fields'), array('form_type' => 'edit_profile', 'form_fields' => array(), 'form_name' => $_POST['form_name'], 'role' => '', 'ID' => Profile_Builder_Form_Creator::wppb_get_form_id_from_form_name($_POST['form_name'], 'edit_profile'))); if (!empty($form_fields)) { /* check for errors in the form through the filters */ $output_field_errors = array(); foreach ($form_fields as $field) { $error_for_field = apply_filters('wppb_check_form_field_' . Wordpress_Creation_Kit_PB::wck_generate_slug($field['field']), '', $field, $_POST, 'edit_profile'); if (!empty($error_for_field)) { $output_field_errors[$field['id']] = '<span class="wppb-form-error">' . $error_for_field . '</span>'; } } /* if we have no errors change the password */ if (empty($output_field_errors)) { $user_id = get_current_user_id(); if (!is_multisite() && current_user_can('edit_users') || is_multisite() && current_user_can('manage_network')) { if (isset($_GET['edit_user']) && !empty($_GET['edit_user'])) { $user_id = $_GET['edit_user']; } } if (!isset($_GET['edit_user'])) { wp_clear_auth_cookie(); /* set the new password for the user */ wp_set_password($_POST['passw1'], $user_id); // Here we calculate the expiration length of the current auth cookie and compare it to the default expiration. // If it's greater than this, then we know the user checked 'Remember Me' when they logged in. $logged_in_cookie = wp_parse_auth_cookie('', 'logged_in'); /** This filter is documented in wp-includes/pluggable.php */ $default_cookie_life = apply_filters('auth_cookie_expiration', 2 * DAY_IN_SECONDS, $user_id, false); $remember = $logged_in_cookie['expiration'] - time() > $default_cookie_life; wp_set_auth_cookie($user_id, $remember); } else { wp_set_password($_POST['passw1'], $user_id); } } } } } }
function wppb_front_end_login($atts) { extract(shortcode_atts(array('display' => true, 'redirect' => '', 'redirect_url' => '', 'register_url' => '', 'lostpassword_url' => ''), $atts)); $wppb_generalSettings = get_option('wppb_general_settings'); if (!is_user_logged_in()) { // set up the form arguments $form_args = array('echo' => false, 'id_submit' => 'wppb-submit'); //Add support for "redirect_url" parameter for Login shortcode (will do the same thing as "redirect" - for consistency with Register, Edit Profile shortcodes) if (!empty($redirect_url)) { $redirect = $redirect_url; } // maybe set up the redirect argument if (empty($redirect)) { if (PROFILE_BUILDER == 'Profile Builder Pro') { $wppb_module_settings = get_option('wppb_module_settings'); if ($wppb_module_settings['wppb_customRedirect'] == 'show') { //check to see if the redirect location is not an empty string and is activated $login_redirect_settings = get_option('customRedirectSettings'); // set up the redirect argument to our redirect page if (trim($login_redirect_settings['afterLoginTarget']) != '' && $login_redirect_settings['afterLogin'] == 'yes') { $redirect_to = trim($login_redirect_settings['afterLoginTarget']); if (wppb_check_missing_http($redirect_to)) { $redirect_to = 'http://' . $redirect_to; } $form_args['redirect'] = $redirect_to; } } } } else { $form_args['redirect'] = trim($redirect); } // change the label argument for username is login with email is enabled if (isset($wppb_generalSettings['loginWith']) && $wppb_generalSettings['loginWith'] == 'email') { $form_args['label_username'] = __('Email', 'profile-builder'); } // change the label argument for username on login with username or email when Username and Email is enabled if (isset($wppb_generalSettings['loginWith']) && $wppb_generalSettings['loginWith'] == 'usernameemail') { $form_args['label_username'] = __('Username or Email', 'profile-builder'); } // initialize our form variable $login_form = ''; // display our login errors if (isset($_GET['loginerror']) || isset($_POST['loginerror'])) { $loginerror = isset($_GET['loginerror']) ? $_GET['loginerror'] : $_POST['loginerror']; $loginerror = '<p class="wppb-error">' . urldecode(base64_decode($loginerror)) . '</p><!-- .error -->'; if (isset($_GET['request_form_location'])) { if ($_GET['request_form_location'] == 'widget' && !in_the_loop()) { $login_form .= $loginerror; } elseif ($_GET['request_form_location'] == 'page' && in_the_loop()) { $login_form .= $loginerror; } } } // build our form $login_form .= '<div id="wppb-login-wrap" class="wppb-user-forms">'; $form_args['lostpassword_url'] = $lostpassword_url; $login_form .= wp_login_form(apply_filters('wppb_login_form_args', $form_args)); if (!empty($register_url) || !empty($lostpassword_url)) { $login_form .= '<p class="login-register-lost-password">'; $i = 0; if (!empty($register_url)) { if (wppb_check_missing_http($register_url)) { $register_url = "http://" . $register_url; } $login_form .= '<a href="' . esc_url($register_url) . '">' . apply_filters('wppb_login_register_text', __('Register', 'profile-builder')) . '</a>'; $i++; } if (!empty($lostpassword_url)) { if ($i != 0) { $login_form .= ' | '; } if (wppb_check_missing_http($lostpassword_url)) { $lostpassword_url = "http://" . $lostpassword_url; } $login_form .= '<a href="' . esc_url($lostpassword_url) . '">' . apply_filters('wppb_login_lostpass_text', __('Lost your password?', 'profile-builder')) . '</a>'; } $login_form .= '</p>'; } $login_form .= '</div>'; return $login_form; } else { $user_ID = get_current_user_id(); $wppb_user = get_userdata($user_ID); if (isset($wppb_generalSettings['loginWith']) && $wppb_generalSettings['loginWith'] == 'email') { $display_name = $wppb_user->user_email; } elseif ($wppb_user->display_name !== '') { $display_name = $wppb_user->user_login; } else { $display_name = $wppb_user->display_name; } if (isset($wppb_generalSettings['loginWith']) && $wppb_generalSettings['loginWith'] == 'usernameemail') { if ($wppb_user->user_login == Wordpress_Creation_Kit_PB::wck_generate_slug(trim($wppb_user->user_email))) { $display_name = $wppb_user->user_email; } elseif ($wppb_user->display_name !== '') { $display_name = $wppb_user->user_login; } else { $display_name = $wppb_user->display_name; } } $logged_in_message = '<p class="wppb-alert">'; $logout_url = '<a href="' . wp_logout_url($redirectTo = wppb_curpageurl()) . '" class="wppb-logout-url" title="' . __('Log out of this account', 'profile-builder') . '">' . __('Log out', 'profile-builder') . ' »</a>'; $logged_in_message .= sprintf(__('You are currently logged in as %1$s. %2$s', 'profile-builder'), $display_name, $logout_url); $logged_in_message .= '</p><!-- .wppb-alert-->'; return apply_filters('wppb_login_message', $logged_in_message, $wppb_user->ID, $display_name); } }
/** * Create a user. * * @param string $user_name The new user's login name. * @param string $password The new user's password. * @param string $email The new user's email address. * @return mixed Returns false on failure, or int $user_id on success */ function wppb_create_user($user_name, $password, $email) { if (is_email($user_name)) { $user_name = apply_filters('wppb_generated_random_username', Wordpress_Creation_Kit_PB::wck_generate_slug(trim($user_name)), $user_name); } else { $user_name = preg_replace('/\\s+/', '', sanitize_user($user_name, true)); } $user_id = wp_create_user($user_name, $password, $email); if (is_wp_error($user_id)) { return false; } // Newly created users have no roles or caps until they are added to a blog. delete_user_option($user_id, 'capabilities'); delete_user_option($user_id, 'user_level'); do_action('wppb_new_user', $user_id); return $user_id; }
} } else { $option_parts = explode('%', $option); if (!empty($option_parts)) { if (empty($option_parts[0]) && count($option_parts) == 3) { $label = $option_parts[1]; $value_attr = $option_parts[2]; if (in_array($option_parts[2], $values)) { $found = true; } } } } $element .= '<div><label><input type="checkbox" name="' . $single_prefix . esc_attr(Wordpress_Creation_Kit_PB::wck_generate_slug($details['title'], $details)); if ($this->args['single'] && $this->args['context'] != 'option') { $element .= '[]'; } $element .= '" id="'; if (!empty($frontend_prefix)) { $element .= $frontend_prefix; } /* since the slug below is generated from the value as well we need to determine here if we have a slug or not and not let the wck_generate_slug() function do that */ if (!empty($details['slug'])) { $slug_from = $details['slug']; } else { $slug_from = $details['title']; } $element .= esc_attr(Wordpress_Creation_Kit_PB::wck_generate_slug($slug_from . '_' . $value_attr)) . '" value="' . esc_attr($value_attr) . '" ' . checked($found, true, false) . 'class="mb-checkbox mb-field" />' . esc_html($label) . '</label></div>'; } $element .= '</div>'; }
<?php /* @param string $meta Meta name. * @param array $details Contains the details for the field. * @param string $value Contains input value; * @param string $context Context where the function is used. Depending on it some actions are preformed.; * @return string $element input element html string. */ $element .= '<input type="text" name="' . $single_prefix . esc_attr(Wordpress_Creation_Kit_PB::wck_generate_slug($details['title'], $details)) . '" id="'; if (!empty($frontend_prefix)) { $element .= $frontend_prefix; } $element .= esc_attr(Wordpress_Creation_Kit_PB::wck_generate_slug($details['title'], $details)) . '"'; if (!empty($details['readonly']) && $details['readonly']) { $element .= 'readonly="readonly"'; } $element .= ' value="' . esc_attr($value) . '" class="mb-text-input mb-field"/>';
<?php /* @param string $meta Meta name. * @param array $details Contains the details for the field. * @param string $value Contains input value; * @param string $context Context where the function is used. Depending on it some actions are preformed.; * @return string $element input element html string. */ $element .= '<textarea name="' . esc_attr(Wordpress_Creation_Kit_PB::wck_generate_slug($details['title'], $details)) . '" id="'; if (!empty($frontend_prefix)) { $element .= $frontend_prefix; } $element .= esc_attr(Wordpress_Creation_Kit_PB::wck_generate_slug($details['title'], $details)) . '" style="vertical-align:top;" class="mb-textarea mb-field">' . esc_html($value) . '</textarea>';
function wck_test_required($meta_array, $meta, $values, $id) { $fields = $meta_array; $required_fields = array(); $required_fields_with_errors = array(); $required_message = ''; $errors = ''; if (!empty($fields)) { foreach ($fields as $field) { if (!empty($field['required']) && $field['required']) { $required_fields[Wordpress_Creation_Kit_PB::wck_generate_slug($field['title'], $field)] = $field['title']; } } } if (!empty($values)) { foreach ($values as $key => $value) { if (array_key_exists($key, $required_fields) && apply_filters("wck_required_test_{$meta}_{$key}", empty($value), $value, $id)) { $required_message .= apply_filters("wck_required_message_{$meta}_{$key}", __("Please enter a value for the required field ", "wck") . "{$required_fields[$key]} \n", $value); $required_fields_with_errors[] = $key; } } } $required_message .= apply_filters("wck_extra_message", "", $fields, $required_fields, $meta, $values, $id); $required_fields_with_errors = apply_filters("wck_required_fields_with_errors", $required_fields_with_errors, $fields, $required_fields, $meta, $value, $id); if ($required_message != '') { $errors = array('error' => $required_message, 'errorfields' => $required_fields_with_errors); } return $errors; }
<?php /* @param string $meta Meta name. * @param array $details Contains the details for the field. * @param string $value Contains input value; * @param string $context Context where the function is used. Depending on it some actions are preformed.; * @return string $element input element html string. */ $element .= '<select name="' . $single_prefix . esc_attr(Wordpress_Creation_Kit_PB::wck_generate_slug($details['title'], $details)) . '" id="'; if (!empty($frontend_prefix)) { $element .= $frontend_prefix; } $element .= esc_attr(Wordpress_Creation_Kit_PB::wck_generate_slug($details['title'], $details)) . '" class="mb-select mb-field" >'; if (!empty($details['default-option']) && $details['default-option']) { $element .= '<option value="">' . __('...Choose', 'profilebuilder') . '</option>'; } $field_name = Wordpress_Creation_Kit_PB::wck_generate_slug($details['title'], $details); $options = ''; if (!empty($details['options'])) { $i = 0; foreach ($details['options'] as $option) { if (strpos($option, '%') === false) { $label = $option; if (!empty($details['values'])) { $value_attr = $details['values'][$i]; } else { $value_attr = $option; } } else { $option_parts = explode('%', $option); if (!empty($option_parts)) { if (empty($option_parts[0]) && count($option_parts) == 3) {
<?php /* @param string $meta Meta name. * @param array $details Contains the details for the field. * @param string $value Contains input value; * @param string $context Context where the function is used. Depending on it some actions are preformed.; * @return string $element input element html string. */ $element .= '<textarea name="' . $single_prefix . esc_attr(Wordpress_Creation_Kit_PB::wck_generate_slug($details['title'], $details)) . '" style="vertical-align:top;width:400px;height:200px" class="mb-textarea mb-field ' . esc_attr(Wordpress_Creation_Kit_PB::wck_generate_slug($details['title'], $details)) . '">' . esc_html($value) . '</textarea>'; $element .= '<script type="text/javascript">jQuery( function(){ if ( typeof wckInitTinyMCE == "function" ) wckInitTinyMCE("' . Wordpress_Creation_Kit_PB::wck_generate_slug($details['title'], $details) . '")});</script>';
if (preg_match('/^.*?\\.(\\w+)$/', get_attached_file($value), $matches)) { $file_type = esc_html(strtoupper($matches[1])); } else { $file_type = strtoupper(str_replace('image/', '', get_post_mime_type($value))); } } $element .= '<div id="' . esc_attr($upload_info_div_id) . '" class="upload-field-details">' . $thumbnail . '<p><span class="file-name">' . $file_name . '</span><span class="file-type">' . $file_type . '</span>'; if (!empty($value)) { $element .= '<span class="wck-remove-upload">' . __('Remove', 'wck') . '</span>'; } $element .= '</p></div>'; /* the upload link. we send through get the hidden input id, details div id and meta name */ if (!empty($details['attach_to_post'])) { $attach_to_post = 'post_id=' . $post_id . '&'; } else { $attach_to_post = ''; } if (empty($var_prefix)) { $var_prefix = ''; } if (empty($edit_class)) { $edit_class = ''; } $media_upload_url = 'media-upload.php?' . $attach_to_post . 'type=file&mb_type=' . $var_prefix . esc_js(strtolower($upload_input_id)) . '&mb_info_div=' . $var_prefix . esc_js(strtolower($upload_info_div_id)) . '&meta_name=' . $meta . '&TB_iframe=1'; $media_upload_url = admin_url($media_upload_url); $element .= '<a id="upload_' . esc_attr(Wordpress_Creation_Kit_PB::wck_generate_slug($details['title'])) . '_button" class="button" onclick="tb_show(\'\', \'' . $media_upload_url . '\');">' . __('Upload ', 'wck') . $details['title'] . ' </a>'; /* add js global var for the hidden input, and info container div */ $element .= '<script type="text/javascript">'; $element .= 'window.' . $var_prefix . strtolower($upload_input_id) . ' = jQuery(\'' . $edit_class . '#' . $upload_input_id . '\');'; $element .= 'window.' . $var_prefix . strtolower($upload_info_div_id) . ' = jQuery(\'' . $edit_class . '#' . $upload_info_div_id . '\');'; $element .= '</script>';
function wppb_make_upload_button($field, $input_value) { $upload_button = ''; $upload_input_id = str_replace('-', '_', Wordpress_Creation_Kit_PB::wck_generate_slug($field['meta-name'])); /* container for the image preview (or file ico) and name and file type */ if (!empty($input_value)) { /* it can hold multiple attachments separated by comma */ $values = explode(',', $input_value); foreach ($values as $value) { if (!empty($value)) { $thumbnail = wp_get_attachment_image($value, array(80, 80), true); $file_name = get_the_title($value); $file_type = get_post_mime_type($value); $attachment_url = wp_get_attachment_url($value); $upload_button .= '<div id="' . esc_attr($upload_input_id) . '_info_container" class="upload-field-details" data-attachment_id="' . $value . '">'; $upload_button .= '<div class="file-thumb">'; $upload_button .= "<a href='{$attachment_url}' target='_blank' class='wppb-attachment-link'>" . $thumbnail . "</a>"; $upload_button .= '</div>'; $upload_button .= '<p><span class="file-name">'; $upload_button .= $file_name; $upload_button .= '</span><span class="file-type">'; $upload_button .= $file_type; $upload_button .= '</span>'; $upload_button .= '<span class="wppb-remove-upload">' . __('Remove', 'profile-builder') . '</span>'; $upload_button .= '</p></div>'; } } $hide_upload_button = 'style="display:none;"'; } else { $hide_upload_button = ''; } $upload_button .= '<a href="#" class="button wppb_upload_button" id="upload_' . esc_attr(Wordpress_Creation_Kit_PB::wck_generate_slug($field['meta-name'], $field)) . '_button" ' . $hide_upload_button . ' data-uploader_title="' . $field["field-title"] . '" data-uploader_button_text="' . __('Select File', 'profile-builder') . '" data-upload_mn="' . $field['meta-name'] . '" data-upload_input="' . esc_attr($upload_input_id) . '"'; if (is_user_logged_in()) { $upload_button .= 'data-uploader_logged_in="true"'; } $upload_button .= ' data-multiple_upload="false"'; $upload_button .= '>' . __('Upload ', 'profile-builder') . '</a>'; $upload_button .= '<input id="' . esc_attr($upload_input_id) . '" type="hidden" size="36" name="' . esc_attr(Wordpress_Creation_Kit_PB::wck_generate_slug($field['meta-name'], $field)) . '" value="' . $input_value . '"/>'; return $upload_button; }
$element .= '<div id="' . esc_attr($upload_info_div_id) . '_info_container" class="upload-field-details" data-attachment_id="' . $value . '">'; $element .= '<div class="file-thumb">'; $element .= "<a href='{$attachment_url}' target='_blank' class='wck-attachment-link'>" . $thumbnail . "</a>"; $element .= '</div>'; $element .= '<p><span class="file-name">'; $element .= $file_name; $element .= '</span><span class="file-type">'; $element .= $file_type; $element .= '</span>'; if (!empty($value)) { $element .= '<span class="wck-remove-upload">' . __('Remove', 'core') . '</span>'; } $element .= '</p></div>'; } } $element .= '<a href="#" class="button wck_upload_button" id="upload_' . esc_attr(Wordpress_Creation_Kit_PB::wck_generate_slug($details['title'], $details)) . '_button" data-uploader_title="' . $details['title'] . '" data-uploader_button_text="Select Files" data-upload_input="' . esc_attr($upload_input_id) . '" '; if (is_user_logged_in()) { $element .= 'data-uploader_logged_in="true"'; } if (!empty($post_id)) { $element .= ' data-post_id="' . $post_id . '"'; } if (!empty($details['multiple_upload'])) { if ($details['multiple_upload'] == 'true') { $element .= ' data-multiple_upload="true"'; } else { $element .= ' data-multiple_upload="false"'; } } if (!empty($details['attach_to_post'])) { if ($details['attach_to_post'] == true) {
function wppb_validate_backend_fields(&$errors, $update, &$user) { $all_data = get_option('wppb_manage_fields'); $global_request = $_REQUEST; if (is_array($all_data)) { foreach ($all_data as $field) { $error_for_field = apply_filters('wppb_check_form_field_' . Wordpress_Creation_Kit_PB::wck_generate_slug($field['field']), '', $field, $global_request, 'back_end'); if (!empty($error_for_field)) { $errors->add($field['id'], '<strong>' . __('ERROR', 'profile-builder') . '</strong> ' . $field['field-title'] . ':' . $error_for_field); } } } }
/** * Function that adds a custom class to the existing element * * @since v.2.0 * * @param string $element_class - the new class name * @param string $meta - the name of the meta * @param array $results * @param integer $element_id - the ID of the element * * @return string */ function wppb_element_class($element_class, $meta, $results, $element_id) { $wppb_element_type = Wordpress_Creation_Kit_PB::wck_generate_slug($results[$element_id]["field"]); return "class='element_type_{$wppb_element_type} added_fields_list'"; }
<?php /* @param string $meta Meta name. * @param array $details Contains the details for the field. * @param string $value Contains input value; * @param string $context Context where the function is used. Depending on it some actions are preformed.; * @return string $element input element html string. */ $args = apply_filters('wck-user-select-args', array('orderby' => 'display_name')); $user_query = new WP_User_Query($args); if (!empty($user_query->results)) { $element .= '<select name="' . esc_attr(Wordpress_Creation_Kit_PB::wck_generate_slug($details['title'], $details)) . '" id="'; if (!empty($frontend_prefix)) { $element .= $frontend_prefix; } $element .= esc_attr(Wordpress_Creation_Kit_PB::wck_generate_slug($details['title'], $details)) . '" class="mb-user-select mb-field" >'; $element .= '<option value="">' . __('...Chose', 'wck') . '</option>'; foreach ($user_query->results as $user) { $element .= '<option value="' . esc_attr($user->ID) . '" ' . selected($user->ID, $value, false) . ' >' . esc_html($user->display_name) . '</option>'; } $element .= '</select>'; }
/** * Function that saves the entries for single forms on posts(no options). It is hooke on the 'save_post' hook * It is executed on each WCK object instance so we need to restrict it on only the ones that are present for that post */ function wck_save_single_metabox($post_id, $post) { if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return $post_id; } // check permissions if (!current_user_can('edit_page', $post_id)) { return $post_id; } /* only go through for metaboxes defined for this post type */ if (get_post_type($post_id) != $this->args['post_type']) { return $post_id; } if (!empty($_POST)) { /* for single metaboxes we save a hidden input that contains the meta_name attr as a key so we need to search for it */ foreach ($_POST as $request_key => $request_value) { if (strpos($request_key, '_wckmetaname_') !== false && strpos($request_key, '#wck') !== false) { /* found it so now retrieve the meta_name from the key formatted _wckmetaname_actuaname#wck */ $request_key = str_replace('_wckmetaname_', '', $request_key); $meta_name = str_replace('#wck', '', $request_key); /* we have it so go through only on the WCK object instance that has this meta_name */ if ($this->args['meta_name'] == $meta_name) { /* get the meta values from the $_POST and store them in an array */ $meta_values = array(); if (!empty($this->args['meta_array'])) { foreach ($this->args['meta_array'] as $meta_field) { /* in the $_POST the names for the fields are prefixed with the meta_name for the single metaboxes in case there are multiple metaboxes that contain fields wit hthe same name */ $single_field_name = $this->args['meta_name'] . '_' . Wordpress_Creation_Kit_PB::wck_generate_slug($meta_field['title'], $meta_field); if (isset($_POST[$single_field_name])) { /* checkbox needs to be stored as string not array */ if ($meta_field['type'] == 'checkbox') { $_POST[$single_field_name] = implode(', ', $_POST[$single_field_name]); } $meta_values[Wordpress_Creation_Kit_PB::wck_generate_slug($meta_field['title'], $meta_field)] = $_POST[$single_field_name]; } else { $meta_values[Wordpress_Creation_Kit_PB::wck_generate_slug($meta_field['title'], $meta_field)] = ''; } } } /* test if we have errors for the required fields */ $errors = self::wck_test_required($this->args['meta_array'], $meta_name, $meta_values, $post_id); if (!empty($errors)) { /* if we have errors then add them in the global. We do this so we get all errors from all single metaboxes that might be on that page */ global $wck_single_forms_errors; if (!empty($errors['errorfields'])) { foreach ($errors['errorfields'] as $key => $field_name) { $errors['errorfields'][$key] = $this->args['meta_name'] . '_' . $field_name; } } $wck_single_forms_errors[] = $errors; } else { /* no errors so we can save */ update_post_meta($post_id, $meta_name, array($meta_values)); /* handle unserialized fields */ if ($this->args['unserialize_fields']) { if (!empty($this->args['meta_array'])) { foreach ($this->args['meta_array'] as $meta_field) { update_post_meta($post_id, $meta_name . '_' . Wordpress_Creation_Kit_PB::wck_generate_slug($meta_field['title'], $meta_field) . '_1', $_POST[$this->args['meta_name'] . '_' . Wordpress_Creation_Kit_PB::wck_generate_slug($meta_field['title'], $meta_field)]); } } } } break; } } } } }
function wppb_add_custom_field_values($global_request, $meta, $form_properties) { if (!empty($this->args['form_fields'])) { foreach ($this->args['form_fields'] as $field) { if (!empty($field['meta-name'])) { $posted_value = !empty($global_request[$field['meta-name']]) ? $global_request[$field['meta-name']] : ''; $meta[$field['meta-name']] = apply_filters('wppb_add_to_user_signup_form_field_' . Wordpress_Creation_Kit_PB::wck_generate_slug($field['field']), $posted_value, $field, $global_request); } } } return apply_filters('wppb_add_to_user_signup_form_meta', $meta, $global_request); }
<?php /* @param string $meta Meta name. * @param array $details Contains the details for the field. * @param string $value Contains input value; * @param string $context Context where the function is used. Depending on it some actions are preformed.; * @return string $element input element html string. */ $element .= '<input type="text" name="' . $single_prefix . esc_attr(Wordpress_Creation_Kit_PB::wck_generate_slug($details['title'], $details)) . '" id="'; if (!empty($frontend_prefix)) { $element .= $frontend_prefix; } $element .= esc_attr(Wordpress_Creation_Kit_PB::wck_generate_slug($details['title'], $details)) . '" value="' . esc_attr($value) . '" class="mb-datepicker mb-field"/>'; $element .= '<script type="text/javascript">jQuery( function(){jQuery(".mb-datepicker").datepicker({' . apply_filters('wck-datepicker-args', 'dateFormat : "dd-mm-yy",changeMonth: true,changeYear: true') . '})});</script>';