CRED plugin provides an API, making it easy to customize your post or user forms. The API includes hooks (actions and filters) to accomplish specific tasks using PHP code.
When you ask for help or report issues, make sure to tell us all related information about your form and what you want to achieve.
The customer was using the "save_post" hook to automatically fill lat/lon coordinates from a Toolset address type field into another custom field, but the values were not becoming available for new posts.
The customer asked how the WordPress user "Language" field can be set through the Toolset's user form.
Solution:
Informed that there is no built-in method available in the Toolset Forms for this, so it will require some workaround and custom code.
WordPress store's the ISO language code for the user's selected WordPress admin language as a value, in the user meta field with key 'locale'.
In a user registration form, one can include a hidden generic field and fill its value with the language code of the current page's language. After that, the 'cred_save_data' hook can be used to programmatically set that selected language value into the user's 'locale' meta field:
add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($user_id, $form_data)
{
// if a specific form
if ($form_data['id']==1234)
{
update_user_meta( $user_id, 'locale', $_POST['locale'] );
}
}
The user wanted the custom user field values from a user ID passed through the generic field in the form notification.
Solution:
Suggested to use the "cred_subject_notification_codes" and "cred_body_notification_codes" filters to register custom placeholders for form notifications.
Example:
add_filter('cred_subject_notification_codes', 'custom_generic_field_notification', 10, 1);
add_filter('cred_body_notification_codes', 'custom_generic_field_notification', 10, 1);
function custom_generic_field_notification( $defaultPlaceHolders ) {
// get the user ID from the generic field 'evaluatee-user-id'
$target_user_ID = $_REQUEST['evaluatee-user-id'];
// get the first name and last name from the $target_user_ID
$user_first_name = do_shortcode("[wpv-user field='user_firstname' id='".$target_user_ID."']");
$user_last_name = do_shortcode("[wpv-user field='user_lastname' id='".$target_user_ID."']");
// set those first name and last name values in the custom placeholders
$newPlaceHolders = array(
'%%evaluatee_first_name%%' => $user_first_name,
'%%evaluatee_last_name%%' => $user_last_name,
);
return array_merge($defaultPlaceHolders, $newPlaceHolders );
}