登録ユーザーがWordpressブログに投稿できるテーマに取り組んでおり、フォーム(タイトル、カテゴリ、エントリ)を作成しました。
問題は、「新しい回答が投稿されたら通知する」という新しいチェックボックスを追加するにはどうすればよいですか? プラグインではなく関数が必要です。
質問の投稿を処理する関数は次のとおりです。
function 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 関数の使い方は素晴らしいでしょう。