WordPress 4.9.5を利用しています。
却下ボタンを追加して却下ボタンを押下したら
強制的に投稿のステータスを下書きにするボタンを作成したいと思い、
以下のコードをかきました。
しかし、ステータス変更のコードで書いてもステータスが変更されません。
何が悪いのかわかる方いましたらご教示いただけますでしょうか?
// 却下ボタン追加 function custom_button(){ global $post; $html = '<div id="major-publishing-actions" style="overflow:hidden">'; $html .= '<div id="publishing-action">'; $html .= '<input type="submit" accesskey="p" tabindex="5" value="却下" class="button-primary" id="reject" name="reject" >'; $html .= '</div>'; $html .= '</div>'; echo $html; } add_action( 'post_submitbox_misc_actions', 'custom_button' ); // 却下ボタン押下時処理 function send_reject_button() { global $post; echo <<< DOC <script type="text/javascript"><!-- var reject = document.getElementById("reject"); if (reject !== null) reject.onclick = function(){ // 却下ボタンが押された jQuery.ajax({ url: ajaxurl, type: 'POST', data: { action: 'save_status', postId:$post->ID } }); } --></script>; DOC; } add_action('admin_footer','send_reject_button'); // ステータス変更関数 function save_status() { $postId = $_POST['postId']; $postdata = get_post($postId); $postdata->post_status = 'draft'; wp_update_post($postdata); } add_action('wp_ajax_save_status', 'save_status');
あなたの回答
tips
プレビュー