I want that in the registration form instead of writing label "Username", I shall write the label "Artist". I have referred to question But can't get it to work. I have shown my registration form in frontend using plugin theme my login.
Here is my code
if ($pagenow=='wp-login.php') {
add_filter( 'gettext', 'user_email_login_text', 20, 3 );
function user_email_login_text( $translated_text, $text, $domain ) {
if ($translated_text == 'Username') {
$translated_text = 'Artist Name';
}
return $translated_text;
}
}
Related
Is there a hook to change the Total title from the WooCommerce order received page's order overview? Please see the below image to understand better
Yes, you can use the gettext WordPress filter to "translate" (rename in your case) that string of text.
Your string is inside the thankyou.php WooCommerce template:
esc_html_e( 'Total:', 'woocommerce' );
Based on WooCommerce: How to Translate / Rename Any String tutorial, the right code should be the following:
add_filter( 'gettext', 'bbloomer_translate_woocommerce_strings', 9999, 3 );
function bbloomer_translate_woocommerce_strings( $translated, $untranslated, $domain ) {
if ( ! is_admin() && 'woocommerce' === $domain ) {
switch ( $translated ) {
case 'Total:':
$translated = 'Whatever:';
break;
}
}
return $translated;
}
I want to disable previous search suggestions in my site.
I use Elementor search form.
I can edit it from the plugin editor but I can't find the file where I can add the attribute.
Add this code into your theme function.php file it will add autocomplete='off' attribute
class Elementor_Forms_Input_Classes {
public function __construct() {
// Add class attribute to form field render
add_filter( 'elementor_pro/forms/render/item', [ $this, 'maybe_add_css_class' ], 10, 3 );
add_action( 'elementor/element/form/section_form_fields/before_section_end', [ $this, 'add_css_class_field_control' ], 100, 2 );
}
public function add_css_class_field_control( $element, $args ) {
$elementor = \Elementor\Plugin::instance();
$control_data = $elementor->controls_manager->get_control_from_stack( $element->get_name(), 'form_fields' );
if ( is_wp_error( $control_data ) ) {
return;
}
public function maybe_add_css_class( $field, $field_index, $form_widget ) {
$form_widget->add_render_attribute( 'input' . $field_index, 'autocomplete', 'off' );
$form_widget->add_render_attribute( 'select' . $field_index, 'autocomplete', 'off' );
return $field;
}
}
new Elementor_Forms_Input_Classes();
to do that you will need to follow these steps:
Give your search form an id or class name (for example i will give my form a class name: tho-auto-off)
Insert an HTML code element, and put in this code:
<script>
jQuery(".tho-auto-off input").focus(function(){
jQuery(this).attr('autocomplete', 'off');
});
</script>
Save and enjoy.
In case of this guide is not clearly enough for you - i have record a guide video for this here.
How can I disable the password change option for specific user in Wordpress?
I have a user where I set a new password each week for multiple users. But some tried to change the password for this user. I don't want that - but only for this specific user profile. All the other users should be able toi change their password.
I have tried different plugins but none of them work.
Thanks a lot if you can help on this!
Add this in your function.php file
class Password_Reset_Removed
{
function __construct()
{
add_filter( 'show_password_fields', array( $this, 'disable' ) );
add_filter( 'allow_password_reset', array( $this, 'disable' ) );
}
function disable()
{
if ( is_admin() ) {
$userdata = wp_get_current_user();
$user = new WP_User($userdata->ID);
if ( !empty( $user->roles ) && is_array( $user->roles ) && $user->roles[0] == 'administrator' )
return true;
}
return false;
}
}
$pass_reset_removed = new Password_Reset_Removed();
We have just removed the fields to change password from the back-end of the WordPress. Now, some users will also try to reset the password using the Lost your password? form from the log-in page.
In order to prevent them from doing that, we will remove lost password link and disable the lost password form by adding below code
function remove_lost_your_password($text)
{
return str_replace( array('Lost your password?', 'Lost your password'), '', trim($text, '?') );
}
add_filter( 'gettext', 'remove_lost_your_password' );
function disable_reset_lost_password()
{
return false;
}
add_filter( 'allow_password_reset', 'disable_reset_lost_password');
Note - you can update userid - as per your requirements
i want to update a custom user_meta field when a User changed/edit the xProfile field (width the ID 1542).
this does hook not work
function action_xprofile_data_after_save( $x )
{
print_r($x);
// if($field == 1542)
// {
// update_user_meta($user_id, 'field_1542', 'changed');
// }
}
add_action( 'xprofile_data_after_save', 'action_xprofile_data_after_save', 10, 1 );
I believe this approach works for edits made on both front-end and back-end. And it provides the $user_id:
function peter_xprofile_data_after_save( $data ) {
if ( $data->field_id == 1542 ) {
update_user_meta( $data->user_id, 'field_1542', 'changed');
}
}
add_action( 'xprofile_data_after_save', 'peter_xprofile_data_after_save' );
The above works fine in case of an edit, but not working when you "clean / remove" the text from the field. You should use something like this:
function peter_xprofile_data_after_save( $data ) {
$field_content = bp_get_member_profile_data('field=field_name'); // enter your field name here
if($field_content == '') {
update_user_meta( $data->user_id, 'field_1542', '' );
}
if ( $data->field_id == 1542 ) {
update_user_meta( $data->user_id, 'field_1542', $data->value);
}
}
add_action( 'xprofile_data_after_save', 'peter_xprofile_data_after_save' );
I'm trying to change the default label for the Wordpress lost password form which says "Username or E-mail". I need it to just read "Email" and I don't want to edit any core Wordpress files. I've already achieved this for the default login form using:
global $pagenow;
if ($pagenow==='wp-login.php') {
add_filter( 'gettext', 'user_email_login_text', 20, 3 );
function user_email_login_text( $translated_text, $text, $domain ) {
if ($translated_text === 'Username') {
echo $translated_text;
$translated_text = 'Email';
}
return $translated_text;
}
}
And this seems to also work on the other default forms for labels consisting of single words. However, if I augment the if condition to include | $translated_text === 'Username or e-mail' it doesn't work.
Any ideas? I really don't want to have to code a bespoke form as this doesn't fit in with how my system works.
Also, I wonder why Wordpress spells "Email" as "E-mail" on the lost password form, but without the dash on all other forms...
I dont know if you allready solved this. Anyway your code is allmost correct. You were only missing that the string is case sensitive and to include the colon. Like this: if ($translated_text === 'Username or E-mail:')
No need to echo $translated_text either
This works on my installation:
global $pagenow;
if ($pagenow==='wp-login.php') {
add_filter( 'gettext', 'user_email_login_text', 20, 3 );
function user_email_login_text( $translated_text, $text, $domain ) {
if ($translated_text === 'Username or E-mail:') {
$translated_text = 'Email';
}
return $translated_text;
}
}