この後に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'が必要なためです。need(int)投稿を追加したユーザーのIDです。デフォルトは現在のユーザーIDです。 –
ポストメタに匿名ユーザー名ストアを保存することができます –