После этого 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) Идентификатор пользователя, который добавил сообщение. По умолчанию используется текущий идентификатор пользователя. –
Вы можете сохранить анонимное имя пользователя в post meta –