What is the proper way to get logged in user id in a plugin?

If you’re inside a plugin, WordPress is already loaded. You don’t need to load it yourself. Inside whatever function needs the user ID, you need to do two things: Globalize the user data variable Populate the user data variable Here’s some pseudocode: function some_function_that_needs_user_info() { global $current_user; get_currentuserinfo(); // Now reference $current_user->ID in your code. … Read more

if user role is then echo text

You are passing a role name, administrator, to current_user_can. Looking at the Codex page this is supported but not guaranteed to work, and should generally be avoided: Passing role names to current_user_can() is discouraged as this is not guaranteed to work correctly (see #22624). Instead, you should use a capability: if ( current_user_can( ‘manage_options’ ) … Read more

Getting the age of a users account

The answer from @Ralf912 (the second ‘here’ in my comment!) is all you need/want. This little function should help you out: (please make a backup of functions.php before adding this code snippet in that file. /** * Display Members registration year * * @author @Ralf912 * @return date(year) * @uses echo do_shortcode( ‘[memberSince]’ ); * … Read more

Calling User Nickname

Try echo the_author_meta( ‘nickname’, $current_user->ID ); or you can also use; $current_user = wp_get_current_user(); echo $current_user->nickname;

WordPress SQL Issue not returning correct reselts

Here is my answer in code form: <?php // Customer Details $args = array( ‘blog_id’ => $GLOBALS[‘blog_id’], ‘role’ => ‘customer’, ‘meta_key’ => ‘last_name’, ‘meta_value’ => ”, ‘meta_compare’ => ”, ‘meta_query’ => array(), ‘date_query’ => array(), ‘include’ => array(), ‘exclude’ => array(), ‘orderby’ => ‘last_name’, ‘order’ => ‘ASC’, ‘offset’ => ”, ‘search’ => ”, ‘number’ => … Read more

Role can edit just one page [closed]

Adminimize does not remove menu items etc, it just keeps them visually hidden. In other words, your admin pages is still accessible. Add this code to your functions.php file: add_action(‘admin_menu’, ‘edit_trustees_page’); function edit_trustees_page() { global $submenu; $trustees_page_id = 1; //change this value $url = get_admin_url() . ‘post.php?post=” . $trustees_page_id . “&action=edit’; $submenu[‘index.php’][] = array( ‘Edit … Read more

Replace Gravatar with UserPhoto in All Users Coulmn view

Not tested, but much probably this works: Instead of trying to add/change the columns, change the get_avatar behavior. For one, it is a pluggable function, so it can be overridden. And second, there are many Questions in this Stack on how to modify/customize the avatars. Check this two: Upload gravatar in WP profile? Removing Gravatar.com … Read more

Call to undefined function get_userdata() in plugin

Solution found: the reason was that the code including those lines were included in plug-in’s main file and were wrapped in the shortcode launch anymore. I had to put things in another file,like for example function load_shortcode( $atts ){ require_once(getPluginPath().(‘my-project.start.php’)); } add_shortcode( ‘my-project’, ‘load_shortcode’ ); and lines had to be in my-project.start.php getPluginPath() is NOT … Read more