Make WordPress User Name the Email Address - wordpress

Is it possible to make WordPress user name the Email Address?
So unername could be hidden or not required and is replaced with email address.
I know there are plugins that can allow users to use their email as the log in, but they still have to enter the username when they register. I want to try and do away with the username.

I know this thread is over a year old now, but I just tested creating an account where the username is an email address and it works. In theory, you could create a front-end signup form that saves the email variable to both the username and email fields in the database.
WordPress allows usernames with some special characters, so this is a completely valid way to sign people up: http://codex.wordpress.org/Function_Reference/sanitize_user

Yes it is possible. Even you can configure WordPress to Login, Register and Retrieve Password using Email only.
You can put the code below in your theme's functions.php file.
Step-1: Remove Username textfield
add_action('login_head', function(){
?>
<style>
#registerform > p:first-child{
display:none;
}
</style>
<script type="text/javascript" src="<?php echo site_url('/wp-includes/js/jquery/jquery.js'); ?>"></script>
<script type="text/javascript">
jQuery(document).ready(function($){
$('#registerform > p:first-child').css('display', 'none');
});
</script>
<?php
});
Step-2: Remove Username error
//Remove error for username, only show error for email only.
add_filter('registration_errors', function($wp_error, $sanitized_user_login, $user_email){
if(isset($wp_error->errors['empty_username'])){
unset($wp_error->errors['empty_username']);
}
if(isset($wp_error->errors['username_exists'])){
unset($wp_error->errors['username_exists']);
}
return $wp_error;
}, 10, 3);
Step-3: Manipulate Background Registration Functionality.
add_action('login_form_register', function(){
if(isset($_POST['user_login']) && isset($_POST['user_email']) && !empty($_POST['user_email'])){
$_POST['user_login'] = $_POST['user_email'];
}
});
There is also a plugin to achieve this functionality.
Plugin: https://wordpress.org/plugins/smart-wp-login/

The username is a core entity in the WordPress DB and philosophy and it can't be bypassed like that. Now if you want to let users login with their emails, use this plugin: http://wordpress.org/extend/plugins/wp-email-login/ It allows you to login with either email/pass or username/pass. Found it like a month ago, works like a charm.
Even plugins that use alternative means for registration and login (facebook, twitter and Google) create a username (for instance, one plugins I've tried creates usernames like fbX where X is the facebook ID. Unfortunately it is not something we can work around.
Hope this helps! :)

Related

How to create gated content using ACF + plugin

I'm looking to create gated content using some sort of plugin with ACF.
Do any of you have experience with this?
The Gated content should be hidden from people that are not signed in.
I would like to create the user accounts myself and send the account information to the users - the users should not be able to register themselves.
I would also like to hide specific content on the page, rather than a full page.
Just like if you read an online newspaper and are prompted with a payment wall.
However, I don't need a subscription or payments for this solution - I simply need to hide content for regular users and show it if the users are signed in.
Any help is much appreciated.
Thank you.
Within the template of the block you can use logic like this:
<p>content for everyone</p>
<?php
if (is_user_logged_in()) {
echo "<p>hello, logged in user</p>";
} else {
echo "<p>hello, guest</p>";
}
?>

change the template of e-mail message sent when admin changes password/e-mail adress

Lots of our users forgot e-mail adress details and passwords for our website and they are asking me to help them log in.
When I change their password/e-mail adress they receive an e-mail message like this:
Blockquote
From: WordPress <wordpress#example.com>
To: username#example.com
Subject: [WordPress] Password Changed
Hi username,
This notice confirms that your password was changed on WordPress.
If you did not change your password, please contact the Site Administrator at admin#example.com
This email has been sent to username#example.com
Regards,
All at WordPress
http://example.com/
I'd like to customize the message which is sent, but this template doesn't appear in the /wp-admin/Emails tab, like the message which is sent when users change their password themselves.
Could you help me, please?
The correct way to do it, following Wordpress guidelines is by using add_filer for the password_change_email hook.
Do not change wp-includes files as recommended above, as it will be overrun by future WP releases.
you can add the filter in your functions.php file of your theme, or in a plugin.
here's how it should look like roughly:
function my_theme_password_change_email($pass_change_email, $user, $userdata){
//do your changes here
}
add_filter( "password_change_email", "my_theme_password_change_email",10,3 )
See this - add to your functions file
<?php // << remove this
// https://developer.wordpress.org/reference/functions/wp_update_user/
add_filter('password_change_email', 'wpse207879_change_password_mail_message', 10, 3 );
function wpse207879_change_password_mail_message( $pass_change_mail, $user, $userdata) {
/* placeholders are:
'###USERNAME###'
'###ADMIN_EMAIL###'
'###EMAIL###'
'###SITENAME###'
'###SITEURL###'
*/
$new_message_txt = __( '
Hi ###USERNAME###,
This notice confirms that your password on ###SITENAME### was recently changed.
If you did not change your password, please contact us ASAP via our website contact page: ###SITEURL###.
This email has been sent to ###EMAIL###.
Regards,
All at ###SITENAME###
###SITEURL###'
);
$pass_change_mail[ 'message' ] = $new_message_txt;
return $pass_change_mail;
}
The file where these emails are handled are in the root of your wordpress installation. The exact file is wp-login.php. I hope this helps.
Just edit below file from root directory located in /wp-includes/user.php line no. 2009 or search for 'Hi ###USERNAME###, and you will find the message body as below that you can customize it as you would like.
$pass_change_text = __(
'Hi ###USERNAME###,
This notice confirms that your password was changed on ###SITENAME###.
If you did not change your password, please contact the Site Administrator at ###ADMIN_EMAIL###
This email has been sent to ###EMAIL###
Regards,
All at ###SITENAME###
###SITEURL###'
);

Unlock content of other users in response to the owner's fb page is liked

I run a Wordpress website. I have many users who have content of their own.
I want to add this feature: if one user wants to see another user's content, then the user (who wants to see) has to Like the other user's Facebook page.
Is there any plugin to do this?
I am currently using this code by Patrik from Stack Overflow:
FB.api({
method: "pages.isFan",
page_id: page_id,
}, function(response) {
console.log(response);
if(response){
alert('You Likey');
} else {
alert('You not Likey :(');
}
}
);
But I actually need to also integrate user_id.
Note: I can get user id from get_the_user_id() function; I only need to integrate it.
Like-Gating is not allowed any more by Facebook – and therefor they have removed all easy means to check whether the user likes a certain page.
You must present the same content to all users, whether they liked a specific page or not.

Create a Dynamic Site Address in a Wordpress Menu

I'm doing some work on an existing site that is based on the Wordpress theme, but uses about 15 plugins (Including Buddypress). One in particular is the WP Sliding Login|Dashboard plugin, which has a link to the user's activity feed. I found the code that creates that link in the wp-sliding-login-dashboard.php file:
<?php
if ( is_user_logged_in() ) {
global $current_user;
$username = $current_user->user_login;
echo ' <li>Activity Feed</li>';
}
?>
I want to use this code to send the user to the same location, but using the a link at the top of the home page. Unfortunately, the home page links are all created using Wordpress menus, which as far as I can tell, only allow for the use of static links attached to existing pages.
Do I create a dummy page to link to that exits only to execute the above code? Is that even possible? Picture a five-year-old trying to read Shakespeare, and you have an idea of my ability as a coder, so feel free to engage me as such - i.e. if you say, "oh just create a scoping function instead of creating a global function", i would stare at you drooling and confused.
Images for clarity: The sliding login menu (WP-Sliding Login|Dashboard Plugin), showing the target URL in the status bar as www.ferrignofit.com/members/FerrignoFit/activity/ (the current logged in user is FerrignoFit):
http://i.imgur.com/NPvmCXU.jpg
The main page Wordpress-based menu, which i want to go to the above URL, but is currently going to www.ferrignofit.com/activity/, a different page:
http://i.imgur.com/dIiFpDC.jpg
So here's a jQuery solution for this specific issue. From seeing the images you have, what you want to do is target a specific anchor in your dynamic WordPress menu.
As you may be aware, you can create custom links for the WordPress menu function... it simply lets you set a label and a URL. You should create such item and just give it a hash for the URL for now.
Now set a class for that specific menu item so you can have a nice handle for jQuery to target it (otherwise you can use the dynamic class that WordPress creates for each specific menu-item).
One you have a class set or you know what you need to target then you can add this block of code before your menu.
<?php if (is_user_logged_in()){ ?>
<script>
$(document).ready(function(e) {
var targetNav = $('li.customClassName a');
var userName = '<?php $current_user = wp_get_current_user(); echo $current_user->display_name;?>';
var userUrl = 'http://www.mywebsitename.com/members/'+ userName +'/activity/';
targetNav.attr('href',userUrl);
});
</script>
<?php } else { ?>
<script>
$(document).ready(function(e) {
var targetNav = $('li.customClassName a');
targetNav.attr('href','http://www.stackoverflow.com');
});
</script>
<?php } ?>
Please not that I am using PHP to get the current username in WordPress, after I get the username and I store it in the userName variable I use it in the userUrl to set it with the path that I want.
On another note, I'm using is_user_logged_in() so you have the option of making the link something else if the user is in fact not logged in. So with this if statement one of the two blocks of code will be output by PHP.
As soon as my two variables are set, I simply target my menu item with jQuery and modify the href attribute to replace the hash with the path and dynamic username.
Though this is not very good practice to mix JS and PHP, I'd like to learn myself here what other solutions someone can suggest so I'm posting this as a solution for your very specific issue.
I tested this code with my own WordPress site and it works, just remember that this code NEEDS to be in a PHP file otherwise the PHP used in the <script> tags won't mean anything to the server if it's in a .js file.

Wordpress - Erase "Roles" on Profile Page

I'm new at Wordpress plugin creation and still trying to get the concept of action hook or filter hook.
I've created a custom role for "moderator". What I want for this role:
- in charge of users with specific role, e.g. subscribers.
- able to change users password.
- NOT able to change other users roles.
the problem is this: to be able to change other users password the moderators will need to have access to user profile page. But, on the user profile page, the moderators can change the other user role. I'm able to hide it by changing the wp-admin/user-edit.php but I think it's better done by plugin. So, how to hide / modify the "roles" selection with a plugin?
Thanks for the help.
To make it more clear, I'm attaching a picture for it.
There are no hooks to remove that. It has to be solved with CSS and/or jQuery.
Here, both CSS and jQuery do almost the same, you can choose one or another, or use both.
The current_user_can has to be adjusted to your roles/capabilities setup.
Note that the hook admin_head can have a suffix, so it'll only run in that specific /wp-admin/WP-PAGE.php address.
add_action( 'admin_head-user-edit.php', 'so_13598192_remove_roles_dropbox' );
function so_13598192_remove_roles_dropbox()
{
// Admins can edit that, exit without printing scripts
if ( current_user_can( 'administrator' ) )
return;
?>
<style>
label[for=role], #role
{
display:none;
}
</style>
<script>
jQuery(document).ready(function($)
{
$('label[for=role]').parent().parent().remove();
});
</script>
<?php
}

Resources