【问题标题】:Loading github project into wordpress plugin将 github 项目加载到 wordpress 插件中
【发布时间】:2016-11-30 16:13:54
【问题描述】:

我正在尝试在我的 wordpress 插件中使用以下 github 项目:

PHP Object wrapper for the Google Chart API

我尝试了以下方法:

 require_once(WPPLUGIN_PATH. "gchart/gChartInit.php");

 $piChart = new gPieChart(); // <---- here I get the error

 $piChart->addDataSet(array(112,315,66,40));
 $piChart->setLabels(array("first", "second", "third","fourth"));
 $piChart->setLegend(array("first", "second", "third","fourth"));
 $piChart->setColors(array("ff3344", "11ff11", "22aacc", "3333aa"));
 echo $piChart->getImgCode();

我的问题似乎是,当我使用上面的代码时,它会在$piChart = new gPieChart(); 行跳转到另一个 wordpress-plugins 自动加载器并且没有正确加载gPieChart.php

错误信息是:

[26-Jul-2016 20:39:59 UTC] PHP Fatal error:  Class 'gPieChart' not found in /home/ubuntu/workspace/wp-content/plugins/wp-analytics-mail/sendTestMail.php on line 267
[26-Jul-2016 20:39:59 UTC] PHP Stack trace:
[26-Jul-2016 20:39:59 UTC] PHP   1. {main}() /home/ubuntu/workspace/index.php:0
[26-Jul-2016 20:39:59 UTC] PHP   2. require() /home/ubuntu/workspace/index.php:17
[26-Jul-2016 20:39:59 UTC] PHP   3. require_once() /home/ubuntu/workspace/wp-blog-header.php:19
[26-Jul-2016 20:39:59 UTC] PHP   4. include() /home/ubuntu/workspace/wp-includes/template-loader.php:75
[26-Jul-2016 20:39:59 UTC] PHP   5. include() /home/ubuntu/workspace/wp-content/themes/twentysixteen/page-analytics-analytics-mail.php:138

对如何使上述代码正常工作有什么建议吗?

感谢您的回复!

【问题讨论】:

标签: php wordpress github


【解决方案1】:

这就是你要做的。

  1. 按照the doc 安装 Composer,或者,如果您使用的是 Windows/Unix,请了解如何在您的环境中安装 the thing
  2. 在插件的根文件夹中创建名为 composer.json 的新文件(在本例中为 wp-analytics-mail
  3. 再次,按照文档,将其粘贴到composer.json

{ "require": { "gchartphp/gchartphp": "dev-master" } }

  1. 在命令行中,进入插件文件夹并运行composer update

  2. require 'vendor/autoload.php'; 放在靠近主插件文件顶部的位置 (sendTestMail.php)

  3. 在同一个文件下,初始化并使用库:

$piChart = new gchart\gPieChart();

【讨论】:

    猜你喜欢
    • 2016-11-30
    • 1970-01-01
    • 2019-10-04
    • 2014-08-23
    • 2016-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多