記事のプレビュー画面から公開できるボタンを作成する Ads X Bluesky Misskey はてブ 2013.03.08 Code <?php if (!class_exists('ApproveFromPreview')){ class ApproveFromPreview { function __construct() { add_filter('the_content',array($this,'add_approve_button')); add_filter('the_content',array($this,'show_approved')); add_action('wp',array($this,'approve_post')); } public function add_approve_button($content){ global $post; if (is_preview() && current_user_can( 'edit_post', $post->ID ) && current_user_can( 'publish_posts', $post->ID ) && in_array($post->post_status,array('draft', 'pending')) ){ return $this->get_button().$content; } return $content; } public function show_approved($content){ $msg = ''; if ( isset( $_GET['msg'] ) ){ if( $_GET['msg'] == 'approved' ) $con = '<div class="success" style="background: #c9e8f5;padding: 3px;">' . __( '公開されました' ) . '</div>'; else $con = '<div class="error" style="background: #f8c7c7;padding: 3px;">' . __( '記事は下書きのままです' ) . '</div>'; } return $con . $content; } public function get_button(){ global $post; return '<a href="'.wp_nonce_url( "?action=AFP&pid=" . $post->ID, 'AFP_NONCE').'" class="button">'.__('この記事を公開する').'</a><br/>'; } public function approve_post(){ if (!isset($_REQUEST['_wpnonce']) || !isset($_REQUEST['pid']) || !isset( $_REQUEST['action']) || $_REQUEST['action'] != "AFP" ) { return; } $nonce = $_REQUEST['_wpnonce']; if ( !wp_verify_nonce( $nonce, 'AFP_NONCE' ) ) { return; } $pid = intval($_REQUEST['pid']); if (current_user_can( 'edit_post',$pid ) && current_user_can( 'publish_posts', $pid )){ $p = $this->change_post_status($pid,'publish'); if ($p > 0){ $redirect = add_query_arg( array('msg' => 'approved'), get_permalink($p) ); wp_redirect( $redirect ); exit; }else{ $redirect = add_query_arg( array('msg' => 'not_approved'), get_permalink() ); wp_redirect( $redirect ); exit; } return; } return; } public function change_post_status($post_id,$status){ $current_post = get_post( $post_id, 'ARRAY_A' ); $current_post['post_status'] = $status; return wp_update_post($current_post); } } } new ApproveFromPreview(); ?> Screen shot Note Description プレビューを確認してそのまま投稿出来る様にする、というボタンの作成 WordPress Ver. 3.5 Via Approve post directly from preview mode?