Viewed   304 times

I'm trying to get the current user info in my plugin using the func wp_get_current_user(). But am getting Call to undefined function wp_get_current_user()

Apparently this is happening because the file /wp-includes/pluggable which contains the function doesn't get loaded until after the plugins are loaded.

Anybody any ideas on how to get the user details in my plugin?

 Answers

3

Apparently this is happening because the file /wp-includes/pluggable which contains the function doesn't get loaded until after the plugins are loaded.

Indeed it is. So wrap whichever thing you're doing in a function, and hook it onto the plugins_loaded or init hook. (see the wp-settings.php file)

Example:

add_action('init','do_stuff');
function do_stuff(){
  $current_user = wp_get_current_user();
  // ...
}
Tuesday, August 23, 2022
4

I don't know how your code looks but this is how I just tested and it worked:

add_action('admin_menu', 'my_menu');

function my_menu() {
    add_menu_page('My Page Title', 'My Menu Title', 'manage_options', 'my-page-slug', 'my_function');
}

function my_function() {
    echo 'Hello world!';
}

Take a look here http://codex.wordpress.org/Administration_Menus

Friday, November 11, 2022
 
3

You can "remove" the parent theme function with remove_action(). This function removes a function which has been attached to a specified action hook, and is often used to replace functions with a substitute:

remove_action('wp_head', 'aaron_customize_css');

And then add your own function in place of it:

add_action('wp_head', 'aaron_customize_css_child');

So, in all, you'll have something like the following in your child theme:

function aaron_customize_css_child() {
    remove_action('wp_head', 'aaron_customize_css');
    // function contents
}
add_action('wp_head', 'aaron_customize_css_child', 100);
Friday, December 16, 2022
 
rog
 
rog
3

finfo_open is only available for php >= 5.3.0 http://www.php.net/manual/en/function.finfo-open.php

You may want to double check your server is up to date with php_info()

Thursday, November 3, 2022
 
2

I had the same issue,

I fixed it by making sure /var/lib/php/session folder was set 0777 for permissions, deleted all the session files and did a graceful restart of the server.

Sessions messages went away and voting worked.

Saturday, September 3, 2022
 
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :