plugin de wordpress - > Llamar a undefined función wp obtener usuario actual()


Estoy tratando de obtener la información del usuario actual en mi plugin usando el func wp_get_current_user(). Pero estoy recibiendo Call to undefined function wp_get_current_user()

Aparentemente esto está sucediendo porque el archivo /wp-includes/pluggable que contiene la función no se carga hasta después de que se cargan los complementos.

¿Alguien tiene alguna idea sobre cómo obtener los detalles del usuario en mi plugin?

Author: madhead, 2011-05-25

8 answers

Aparentemente esto está sucediendo porque el archivo /wp-includes/pluggable que contiene la función no se carga hasta después de que se cargan los complementos.

De hecho lo es. Así que envuelva lo que está haciendo en una función, y engancharlo en el plugins_loaded o gancho init. (consulte la configuración de wp.archivo php)

Ejemplo:

add_action('init','do_stuff');
function do_stuff(){
  $current_user = wp_get_current_user();
  // ...
}
 33
Author: Denis de Bernardy,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-09-23 07:29:51

Puedes usar esto,

<?php
if(!function_exists('wp_get_current_user')) {
    include(ABSPATH . "wp-includes/pluggable.php"); 
}
?>

Esto debería solucionar tu problema:)

 15
Author: ,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-05-25 18:05:42

Después de la instalación de wp 3.8 tuve el mismo problema con una página que obtengo con ajax. Lo arreglé con el siguiente código:

if(!function_exists('wp_delete_user')) {
    include(ABSPATH . "wp-admin/includes/user.php.");
}

Aparentemente la función se mueve desde pluggable.php al usuario.php. Todavía no entiendo por qué no funciona después de incluir el wp-blog-header.php.

 4
Author: Benjamin Ziepert,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-12-24 11:59:23

Intenta añadir también

require_once('../../../wp-load.php');

Junto con

require_once(ABSPATH.'wp-includes/pluggable.php');
 3
Author: Mauro,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-04-16 03:10:49

Recibí el mismo mensaje de error después de actualizar WP. La solución que funcionó para mí es rápida y fácil:

Localice capacidades.php en el directorio wp-includes (WP 3.8.x). Agregue lo siguiente en la parte superior, después de la etiqueta php de apertura:

require_once('pluggable.php');
 0
Author: colind,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-02-07 03:05:19

Mi problema resuelto con este código por favor

include_once(ABSPATH . 'wp-includes/pluggable.php');
 0
Author: Kapil Goyal,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-07-30 03:36:26

NO wp-includes pero:

include_once(ABSPATH . "wp-admin/includes/plugin.php");
 0
Author: T.Todua,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-11-15 09:28:44

Quick fix include_once(ABSPATH . 'wp-includes/pluggable.php'); agregue esta línea a sus capacidades.php

 -1
Author: Mikhail Villamor,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-09-06 09:31:02