Remove users access to dashboard

Removing the dashboard: /* Remove the “Dashboard” from the admin menu for non-admin users */ function wpse54085_remove_dashboard () { global $current_user, $menu, $submenu; get_currentuserinfo(); if( ! in_array( ‘administrator’, $current_user->roles ) ) { reset( $menu ); $page = key( $menu ); while( ( __( ‘Dashboard’ ) != $menu[$page][0] ) && next( $menu ) ) { $page … Read more

Add number of members to “Right Now” dashboard widget

So here is the small snippet to show total number of users and all roles with user count. This code should go in the themes functions.php file. The code uses count_user function to fetch the array and show it up on Right Now dashboard screen. function wpse_60487_custom_right_now() { $users = count_users(); echo ‘<table><tbody>’; echo ‘<tr><td … Read more

Using my own user table

$wpdb is a global variable for the database class. In it $wpdb->users points to the name of the users table. As long as it’s the same database, you can use this to change the name of the table but it might create errors if the schema doesn’t match. Another way is to extend the wpdb … Read more

Need to exclude users with no posts from my contributors page

// retrieve latest 5(or all) posts of this user $query = new WP_Query(array( ‘author’ => $author, ‘posts_per_page’ => 5 )); // skip the user if the number of posts is 0 if($query->post_count < 1) continue; // loop through available posts & display the title while($query->have_posts()) : $query->the_post(); the_title(); endwhile; wp_reset_query(); This code should go inside … Read more

How to use `wp_insert_user` & `wp_insert_post` simultaneously without `headers already sent` error?

The header problem is actually this problem: Warning: mysql_real_escape_string() expects parameter 1 to be string, object given in /home/wp-includes/wp-db.php on line 885 Warning: mysql_real_escape_string() expects parameter 1 to be string, object given in /home/wp-includes/wp-db.php on line 885 You are getting those errors because somewhere you are sending an object when you shouldn’t be. When that … Read more

Using get_user in wordpress with sorting

I think modifying the default tables in your WordPress install is a bad idea. Generally you should never modify the database or the core code, but instead use API functions to get the desired functionality. In this case that you be using the user meta fields to store a sort order for each user. The … Read more

Get Authors Role

As an alternative to “current_user_can” WordPress provides “user_can” which will take a User object or ID as a parameter. Combining your top code and the bottom code with the new function it would look like this: $author_user = $wp_query->get_queried_object(); // the queried object in ‘author.php’ should be an author user if (user_can($author_user, ‘buyer’)) { get_template_part( … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)