我已经创建了一个名为testsave.php的文件,它将数据写入WordPress数据库,代码如下:
$content1 = '<img class="alignnone wp-image-11" src="http://web.qp2qp.com/qp2qp2/'.$file.'.png" alt="" />';
$sql = "INSERT INTO wp_njvt_posts (post_date,post_date_gmt,post_author, post_content, post_title, post_excerpt, post_password, post_name, to_ping, pinged, post_content_filtered, guid, post_mime_type)
VALUES (NOW(),NOW(),'1','', '', '', '','$file','','','','http://www.sktcho.com/?p=$file','')";
testsave.php现已放置在/wp-includes中,现在我需要将用户ID插入到数据库中的数据中。
我尝试将此代码放入文件中,并使用$current_user->ID而不是'1'来获取用户ID,但这并没有起作用。
$current_user = wp_get_current_user();
/**
* @example Safe usage: $current_user = wp_get_current_user();
* if ( !($current_user instanceof WP_User) )
* return;
*/
echo 'Username: ' . $current_user->user_login . '<br />';
echo 'User email: ' . $current_user->user_email . '<br />';
echo 'User first name: ' . $current_user->user_firstname . '<br />';
echo 'User last name: ' . $current_user->user_lastname . '<br />';
echo 'User display name: ' . $current_user->display_name . '<br />';
echo 'User ID: ' . $current_user->ID . '<br />';
有什么办法可以将用户 ID 放置在插入到数据库中的数据中吗?