继此guide后,我试图创建自己的匿名用户提交的插件。WordPress的 - 允许匿名用户提交帖子?
下面是到目前为止我的代码:
function suq_form_shortcode() {
if (
isset($_POST['suq_form_create_quote_submitted'])
&& wp_verify_nonce($_POST['suq_form_create_quote_submitted'],'suq_form_create_quote')
) {
$suq_quote_title = trim($_POST['suq_quote_title']);
$suq_quote_author = trim($_POST['suq_quote_author']);
$suq_quote_text = trim($_POST['suq_quote_text']);
if ($suq_quote_author != '' && $suq_quote_text != '') {
$quote_data = array(
'post_title' => $suq_quote_title,
'post_content' => $suq_quote_text,
'post_status' => 'pending',
'post_author' => $suq_quote_author,
'post_type' => 'post'
);
if($quote_id = wp_insert_post($quote_data)){
echo '<p>Quote created and awaiting moderation!</p>';
}
} else { // author or text field is empty
echo '<p>Quote NOT saved! Who said it? and Quote must not be empty.</p>';
}
}
echo suq_get_create_quote_form($suq_quote_author, $suq_quote_text, $suq_quote_category);
}
function suq_get_create_quote_form ($suq_quote_author = '', $suq_quote_text = '', $suq_quote_category = 0) {
$out .= '<form id="create_quote_form" method="post" action="">';
$out .= wp_nonce_field('suq_form_create_quote', 'suq_form_create_quote_submitted');
$out .= '<label for="suq_quote_author">Name</label><br/>';
$out .= '<input type="text" id="suq_quote_author" name="suq_quote_author" value="' . $suq_quote_author . '"/><br/>';
$out .= '<label for="suq_quote_title">Title</label><br/>';
$out .= '<input type="text" id="suq_quote_title" name="suq_quote_title" value=""/><br/>';
$out .= '<label for="suq_quote_text">Quote</label><br/>';
$out .= '<textarea id="suq_quote_text" name="suq_quote_text" />' . $suq_quote_text . '</textarea><br/><br/>';
$out .= '<input type="submit" id="suq_submit" name="suq_submit" value="Submit Quote For Publication">';
$out .= '</form>';
return $out;
}
它正常工作,因为我可以看到在我的管理区提交的职位,但它的信息之一是缺少这是用户提交的作者姓名。
任何想法如何,我可以证明,由用户自行提供作者姓名?
我已经通过了作者姓名,以WP:
'post_author' => $suq_quote_author,
但WP似乎并没有把它捡起来......
这是因为'post_author'需要(int)添加帖子的用户的ID。默认值是当前用户标识。 –
您可以在后期meta中存储匿名用户名称商店 –