Admin Page Redirect

/** * Redirect admin pages. * * Redirect specific admin page to another specific admin page. * * @return void * @author Michael Ecklund * */ function disallowed_admin_pages() { global $pagenow; # Check current admin page. if ( $pagenow == ‘edit.php’ && isset( $_GET[‘post_type’] ) && $_GET[‘post_type’] == ‘page’ ) { wp_redirect( admin_url( ‘/post-new.php?post_type=page’ ) … Read more

How do I display logged-in username IF logged-in?

This seems to do what you need. <?php global $current_user; wp_get_current_user(); ?> <?php if ( is_user_logged_in() ) { echo ‘Username: ‘ . $current_user->user_login . “\n”; echo ‘User display name: ‘ . $current_user->display_name . “\n”; } else { wp_loginout(); } ?>

How to restrict dashboard access to Admins only?

We can hook to the admin_init action and check if the user is an administrator by using the current_user_can() function to see if the current user can manage_options, which is something only an administrator can do. This code, when pasted into your functions.php file, will display a message when a non-admin tries to access the … Read more

How to check if a user (not current user) is logged in?

I would use transients to do this: create a user-online-update function that you hook on init; it would look something like this: // get the user activity the list $logged_in_users = get_transient(‘online_status’); // get current user ID $user = wp_get_current_user(); // check if the current user needs to update his online status; // he does … Read more

How To Add Custom Form Fields To The User Profile Page?

You need to use the ‘show_user_profile’, ‘edit_user_profile’, ‘personal_options_update’ and ‘edit_user_profile_update’ hooks. Here’s some code to add a Phone number: add_action( ‘show_user_profile’, ‘yoursite_extra_user_profile_fields’ ); add_action( ‘edit_user_profile’, ‘yoursite_extra_user_profile_fields’ ); function yoursite_extra_user_profile_fields( $user ) { ?> <h3><?php _e(“Extra profile information”, “blank”); ?></h3> <table class=”form-table”> <tr> <th><label for=”phone”><?php _e(“Phone”); ?></label></th> <td> <input type=”text” name=”phone” id=”phone” class=”regular-text” value=”<?php echo esc_attr( … Read more

How do I add a field on the Users profile? For example, country, age etc

You need to use the show_user_profile, edit_user_profile, personal_options_update, and edit_user_profile_update hooks. You can use the following code for adding additional fields in User section Code for adding extra fields in Edit User Section: add_action( ‘show_user_profile’, ‘extra_user_profile_fields’ ); add_action( ‘edit_user_profile’, ‘extra_user_profile_fields’ ); function extra_user_profile_fields( $user ) { ?> <h3><?php _e(“Extra profile information”, “blank”); ?></h3> <table class=”form-table”> … Read more

Editor can create any new user except administrator

It’s actually pretty easy. You need to filter into map_meta_caps and stop editors from creating/editing admins, and remove the administrator role from the ‘editable roles’ array. This class, as a plugin or in your theme’s functions.php file would do it: class JPB_User_Caps { // Add our filters function __construct(){ add_filter( ‘editable_roles’, array($this, ‘editable_roles’)); add_filter( ‘map_meta_cap’, … Read more

Getting a List of Currently Available Roles on a WordPress Site?

Roles are stored in the global variable $wp_roles. The ideal function is get_editable_roles() from /wp-admin/includes/user.php function get_editable_roles() { global $wp_roles; $all_roles = $wp_roles->roles; $editable_roles = apply_filters(‘editable_roles’, $all_roles); return $editable_roles; } The “editable” part is because it offers other plugins a chance to filter the list in case someone other than admin has ‘edit_users’ privilege (and … Read more

How to change the default registration email ? (plugin and/or non-plugin)

The new user email is sent using the wp_new_user_notification() function. This function is pluggable, which means that you can overwrite it: // Redefine user notification function if ( !function_exists(‘wp_new_user_notification’) ) { function wp_new_user_notification( $user_id, $plaintext_pass=”” ) { $user = new WP_User($user_id); $user_login = stripslashes($user->user_login); $user_email = stripslashes($user->user_email); $message = sprintf(__(‘New user registration on your blog … Read more