【发布时间】:2018-11-19 16:25:53
【问题描述】:
我正在尝试将登录用户 ID (wordpress) 添加到 GD 图像。
当我使用常量时,它会正确显示 png,当调用变量时,它会显示损坏的图像链接。
调用是通过短代码调用完成的:
/* ================== GET PIC USER ================== */
function get_pic_user($atts) {
$myphp_folder = get_stylesheet_directory_uri() . '/make-pic.php';
$html = '<img src="'.$myphp_folder.'" alt="Image created by a PHP script" width="1000" height="768" align="middle">';
return $html;
}
add_shortcode( 'display_get_pic_user', 'get_pic_user' );
make-pic.php后面的php是:
<?php
$user = wp_get_current_user();
$string_user = $user->id;
$im = imagecreatefrompng("../my_user_pic.png");
header("Content-type: image/png");
$color = imagecolorallocate($im, 51, 51, 51);
imagestring($im, 21, 500, 350, $string_user, $color);
imagepng($im);
imagedestroy($im);
exit;
所以这行得通:
<?php
$string_user = 15;
$im = imagecreatefrompng("../my_user_pic.png");
这不是:
<?php
$user = wp_get_current_user();
$string_user = $user->id;
$im = imagecreatefrompng("../my_user_pic.png");
任何建议将不胜感激。
谢谢
【问题讨论】:
-
在进一步调试问题时,我注意到以下几点:它给出了一个致命错误:未捕获的错误:调用未定义的函数 wp_get_curent_user() in .....