我正在尝试在我的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
有关如何使上述代码有效的建议吗?
感谢您的回复!
答案 0 :(得分:1)
这是你做的。
composer.json
的新文件(在本例中为wp-analytics-mail
)composer.json
{
"require": {
"gchartphp/gchartphp": "dev-master"
}
}
在命令行中,转到插件文件夹并运行composer update
将require 'vendor/autoload.php';
放在靠近主插件文件顶部的位置(sendTestMail.php
)
在同一个文件中缩小,初始化并使用库:
$piChart = new gchart\gPieChart();