I need more information about this filter, I’m trying to set up a selection of the language by the user in his preferences on my site.
I save the language code in a user meta
I would like to use this filter so that the language is defined by this meta in priority but I can’t get this filter to work
here is my code:
add_filter('pll_preferred_language', 'set_preferred_language_to_user_meta', 10, 2);
function set_preferred_language_to_user_meta($slug, $languages) {?
if(current_user_is_logged()){
? ? $locale = get_user_meta(get_current_user_id(), 'locale', true);
? ? return empty($locale) ? ($slug === false ? 'en' : $slug) : $locale;
? }
return $slug === false ? 'en' : $slug;
}
The meta contains “fr” or “en” but the result is that the language defaults to “fr” no matter what is in my meta
]]>The code I use is based on this – https://docs.ultimatemember.com/article/128-add-a-hidden-field-to-your-register-form
I can see that the fields are there, but they just aren’t being added to the database anymore – is this a bug since the last update???
]]>However, I’m curious about the possibility of working with user meta data.
Specifically, I’m wondering if it’s possible to display metadata from the database table “wp_usermeta” in mail templates. Do you have a solution for achieving this?
Is it can work like shorcode example: [yaymail_order_meta:_billing_your_age] ?
Thank you for any answers
{product_name} contains {acf user_{user_ID} fieldname}
Kind regards, Malinka
]]>I have a custom code/plugin where I get the follower count for a specific social media platform. Now I want to display these numbers on the people profiles.
Is there a way to save them in some kinda of meta values?
This values will be updated once every day and not on the site refresh of a profile.
Otherwise I would save them in the wp_option table.
]]>This is my code – what am I doing wrong?
function your_before_member_register ( $posted_data, $user_id ) {
$posted_data['lname'] = 'test';
return ( $posted_data );
}
//add_filter ( 'arm_before_member_register', 'your_before_member_register', 10, 1 );
add_filter ( 'arm_change_user_meta_before_save', 'your_before_member_register', 10, 2 );
]]>I am trying to send the usermeta values from a site to another, the user in created, and everything is fine, but the usermeta value is not getting stored.
$s=array(
"billing_phone"=> "00000000000",
"billing_address_1"=> "adress",
"billing_postcode"=> "0000000"
);
$data=array(
"username"=> "username-tests",
"user_login"=> "username-tests",
"first_name"=> "username",
"last_name"=> "tests",
"email"=> "[email protected]",
"password"=> '000000',
'AUTH_KEY' => 'the-key',
'user_meta'=> $s,
);
this is a sample code that I am using. I also tried using json_encode($s)
but it is not working.
I am new to JSON and REST API, so I am pretty sure I am getting something basic wrong.
Please let me know how the metadata should be sent, possibly with a sample code in php.
Thanks.
My woocommerce checkout page has a wp_dropdown_users() where the customer can select who they want their recipient to be.
From that result I am looking up the user meta using get_user_meta() to retrieve all the shipping details.
I want to use that to fill the shipping checkout fields which I have previously accessed using woocommerce_checkout_fields but I cannot anywhere find a way to set those fields (there only seems to be instructions on how to unset or change the placeholder)
Please can someone help me with how to set those fields using the retrieved data.
I would like to do this in functions.php which should be possible but is not clear how.
If not I can try another solution but this would (/should) be the most straightforward I feel.
Many thanks
]]>update_user_meta()
and update the meta data with a dropdown list, it updates the record with the index number (e.g. 12, meaning I have selected the 13th option from the dropdown) instead of the actual string value (e.g. ‘United States’). How can I fix this with the string value actually be saved?wp_usermeta table in MySQL record is originally like this,
+----------+---------+----------+-----------------------+
| umeta_id | user_id | meta_key | meta_value |
+----------+---------+----------+-----------------------+
| 519 | 11 | country | Canada |
+----------+---------+----------+-----------------------+
but when I go to the account.php page and update my field, using the dropdown and select ‘United States’, my meta_value is updated based on the index (int value 12, representing the 13th option), not the selected text.
+----------+---------+----------+-----------------------+
| umeta_id | user_id | meta_key | meta_value |
+----------+---------+----------+-----------------------+
| 519 | 11 | country | 12 |
+----------+---------+----------+-----------------------+
Here is the code I have on my functions.php
add_action('um_after_account_general', 'showUMExtraFields', 100);
function showUMExtraFields() {
$id = um_user('ID');
$output = '';
$names = array(
"country",
"office"
);
$fields = array();
foreach( $names as $name )
$fields[ $name ] = UM()->builtin()->get_specific_field( $name );
$fields = apply_filters('um_account_secure_fields', $fields, $id);
foreach( $fields as $key => $data )
$output .= UM()->fields()->edit_field( $key, $data );
echo $output;
}
add_action('um_account_pre_update_profile', 'getUMFormData', 100);
function getUMFormData(){
$id = um_user('ID');
$names = array(
"country",
"office"
);
foreach( $names as $name )
update_user_meta( $id, $name, $_POST[ $name ] );
}
This also relates to this topic:
https://gist.github.com/champsupertramp/c1f6d83406e9e0425e9e98aaa36fed7d#gistcomment-3520506
I am trying to add a custom field to registration form.
I have done following changes in page-signup.php file
// CUSTOM FIELD VIEW
// Added a custom field $cf_org
function show_user_form( $user_name = '', $user_email = '', $cf_org = '', $errors = '' ) {
if ( ! is_wp_error( $errors ) ) {
$errors = new WP_Error();
}
// User name
echo '<label for="user_name">' . __( 'Username:' ) . '</label>';
$errmsg = $errors->get_error_message( 'user_name' );
if ( $errmsg ) {
echo '<p class="error">' . $errmsg . '</p>';
}
echo '<input name="user_name" type="text" id="user_name" value="' . esc_attr( $user_name ) . '" autocapitalize="none" autocorrect="off" maxlength="60" /><br />';
_e( '(Must be at least 4 characters using lowercase letters and numbers only.)' );
?>
<label for="user_email"><?php _e( 'Email Address:' ); ?></label>
<?php
$errmsg = $errors->get_error_message( 'user_email' );
if ( $errmsg ) {
?>
<p class="error"><?php echo $errmsg; ?></p>
<?php } ?>
<input name="user_email" type="email" id="user_email" value="<?php echo esc_attr( $user_email ); ?>" maxlength="200" /><br /><?php _e( 'We send your registration email to this address. (Double-check your email address before continuing.)' ); ?>
<?php
$errmsg = $errors->get_error_message( 'generic' );
if ( $errmsg ) {
echo '<p class="error">' . $errmsg . '</p>';
}
// CU FIELD
$team_posts = get_posts([
'post_type' => 'wc_memberships_team',
'post_status' => 'publish',
'numberposts' => -1,
'orderby'=> 'title',
'order' => 'ASC'
]);
$teams = [];
$team_posts = check_duplicate_teams($team_posts);
?>
<label for="cf_org "><?php _e( 'Organization:' ); ?></label>
<?php
$errmsg = $errors->get_error_message( 'cf_org ' );
if ( $errmsg ) {
?>
<p class="error"><?php echo $errmsg; ?></p>
<?php } ?>
<select name="cf_org " id="cf_org ">
<option value=""> -- Select your Organization -- </option>
<?php
// An array coming from PHP with values
foreach( $team_posts as $team){ ?>
<option value="<?php echo $team ?>"> <?php echo $team ?> </option>
<?php } ?>
</select>
<?php
$errmsg = $errors->get_error_message( 'generic' );
if ( $errmsg ) {
echo '<p class="error">' . $errmsg . '</p>';
}
/**
* Fires at the end of the user registration form on the site sign-up form.
*
* @since 3.0.0
*
* @param WP_Error $errors A WP_Error object containing 'user_name' or 'user_email' errors.
*/
do_action( 'signup_extra_fields', $errors );
}
After adding above code, i am able to see a custom field in User Registraion form. But data is not saving into database.
I have further elaborated the code and found that data is being saved using wpmu_signup_user() So i have added custom field value but still it is not saving. see below code.
function validate_user_signup() {
$result = validate_user_form();
$user_name = $result['user_name'];
$user_email = $result['user_email'];
$cf_org = $_POST['cf_org '];
$errors = $result['errors'];
if ( $errors->has_errors() ) {
signup_user( $user_name, $user_email, $cf_org , $errors );
return false;
}
if ( 'blog' == $_POST['signup_for'] ) {
signup_blog( $user_name, $user_email );
return false;
}
//echo 'cu';
//print_r($cf_org );
//die('');
/** This filter is documented in wp-signup.php */
wpmu_signup_user( $user_name, $user_email, apply_filters( 'add_signup_meta', array('cf_org ' => $cf_org ) ) );
confirm_user_signup( $user_name, $user_email );
return true;
}
Please confirm, what steps do i need to do to save this value in Database or where i am doing wrong.
Thank you
]]>