【发布时间】:2018-09-11 12:16:24
【问题描述】:
我正在使用 tuto 构建一个小插件,以将数据库中的结果打印为 pdf。 我使用 FPDF 库来做。
现在我只想将用户名打印到我的 pdf 中。但它似乎对我不起作用......这是问题所在: “未捕获的错误:调用未定义的函数 wp_get_current_user()”
这是我的代码:
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
include($_SERVER['DOCUMENT_ROOT'].'/wp-load.php');
if(!function_exists('wp_get_current_user')) { include(ABSPATH . "wp-includes/pluggable.php"); }
include( 'atomicsmash-pdf-helper-functions.php');
if( isset($_POST['generate_posts_pdf'])){
output_pdf();
}
function output_pdf() {
global $wpdb;
$current_user = wp_get_current_user();
$pdf = new PDF_HTML();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10, $current_user->display_name);
$pdf->Cell(0,5,'L NAME:'.$current_user['display_name'], 0, 0, 'L');
$pdf->Cell(40,10, 'Hello World');
$pdf->Output('D','resultat.pdf');
exit;
}
function as_fpdf_create_admin_page() {
?>
<div class="wrap">
<form method="post" id="as-fdpf-form">
<button class="button button-primary" type="submit" name="generate_posts_pdf" value="generate">Generate PDF from Wordpress Posts</button>
</form>
</div>
<?php
}
好像我没有连接到 wpdb...
如果有人可以帮助我,我将非常感激!
再见
【问题讨论】: