duanmu0834 2019-02-27 22:04
浏览 108
已采纳

函数get_plugins()无法执行

I'm trying to code simple php script which will return all plugins of Wordpress.

My code:

<?php 
ini_set('display_errors', 'On');

include('../../../wp-admin/includes/plugin.php');

$all_plugins = get_plugins();

error_log( print_r( $all_plugins, true ) );

And my output is:

 Uncaught Error: Call to undefined function wp_cache_get() in /home/user/domains/mydomain.com/public_html/wp-admin/includes/plugin.php:273 Stack trace: #0 /home/user/domains/mydomain.com/public_html/wp-content/plugins/myplugin/versions.php(6): get_plugins() #1 {main} thrown in /home/user/domains/mydomain.com/public_html/wp-admin/includes/plugin.php on line 273

I used official example from: https://codex.wordpress.org/Function_Reference/get_plugins

I did:

  • change of PHP version from 7.2 to 5.6
  • set right permission of files
  • install WordPres once again

So my wordpress is totally fresh and I still have the same error. Somebody knows how to solve it?

  • 写回答

1条回答 默认 最新

  • dtjpz48440 2019-02-27 23:40
    关注

    To load all the WordPress functions you need to include the file wp-load.php:

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

    and not the plugins one.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题