我处理一个允许注册用户在 Wordpress 博客上发帖的主题,我创建了一个表单(标题、类别、条目)。
问题是,如何添加一个新的复选框“发布新答案时通知我”?我需要一个函数,而不是插件。
这是处理问题发布的函数:
功能 post_new_question($question_title, $question_content, $question_category) {
$question_title_stripped = strip_tags($question_title);
$question_content_stripped = strip_tags($question_content);
$user = wp_get_current_user();
global $wpdb;
$gather_questions = "SELECT * FROM wp_posts WHERE post_author = '" . $user->ID . "'";
$user_questions = $wpdb->get_results($gather_questions);
if (isEmptyString($question_title_stripped)) return new WP_Error('no_title_entered', 'Enter a title for your quesion');
if (isEmptyString($question_content_stripped)) return new WP_Error('no_content', 'Enter a breif description for your quesion');
foreach ($user_questions as $user_question) {
if ($user_question->post_author == $user->ID ) {
if ($user_question->post_title == $question_title_stripped) {
return new WP_Error('duplicate_user_question', 'You have already asked this exact question.');
} else {}
} else {}
}
$question_author = $user->ID;
$post = array(
'ID' => '',
'post_author' => $question_author,
'post_category' => array($question_category),
'post_content' => $question_content_stripped,
'post_title' => $question_title_stripped,
'post_status' => 'publish'
);
$question_id = wp_insert_post($post); }
PS:使用 wp_email 功能会很棒。