Setujui pos langsung dari mode pratinjau?


10

Bagaimana cara menyetujui posting secara langsung dari mode pratinjau, alih-alih harus kembali ke mode edit dan / atau mode "daftar posting"?

Saya secara skrip mengunggah beberapa (ratusan) posting, tetapi ingin melihat dulu secara singkat sebelum persetujuan.

Jawaban:


8

Ini adalah sesuatu yang saya miliki:

<?php
/*
Plugin Name: Approve From preview
Plugin URI: http://en.bainternet.info
Description: Approve from privew  is Plugin that lets yo approve posts (draft and pending) from the preview itself.
Version: 0.1
Author: Bainternet
License:

  Copyright 2012 Bainternet (admin@bainternet.info)

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License, version 2, as 
  published by the Free Software Foundation.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

*/
if (!class_exists('ApproveFromPreview')){

        class ApproveFromPreview {
                /**
                 * Constructor
                 */
                function __construct() {
                    //create approve link
                    add_filter('the_content',array($this,'add_approve_button'));
                    add_filter('the_content',array($this,'show_approved'));

                    //create message
                    add_action('wp',array($this,'approve_post'));
                }

                /**
                 * add_approve_button  shows a link when in preview
                 * @param  string $content 
                 * @return string 
                 */
                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;
                }

                /**
                 * show_approved shows a message if approved or not
                 * @param  string $content 
                 * @return string 
                 */
                public function show_approved($content){
                    //show fail success message
                    $msg = '';
                    if ( isset( $_GET['msg'] ) ){
                        if( $_GET['msg'] == 'approved' ) 
                            $con =  '<div class="success" style="background: #1599CC;padding: 3px;border-radius: 10px;">' . __( 'Post Approved' ) . '</div>';
                        else
                            $con =  '<div class="error" style="background: #CC1515;padding: 3px;border-radius: 10px;">' . __( 'Post not Approved' ) . '</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">'.__('Approve').'</a><br/>';
                }

                /**
                 * approve_post if needed this plugin will call the approval action and 
                 * redirect to the newly approved post with a message.
                 * @return Void
                 */
                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;
                }

                /**
                * the function that will actually change the post status
                * $post_id - The ID of the post you'd like to change.
                * $status -  The post status publish|pending|draft|private|static|object|attachment|inherit|future|trash.
                */
                /**
                 * change_post_status description
                 * @param  int $post_id  post id
                 * @param  string $status  new status
                 * @return int 1 if successfully  0  if not :)
                 */
                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);
                }



        } // end class
}//end if
new ApproveFromPreview();

Saya belum diuji di dalamnya tetapi harus bekerja dengan baik.


0

Apa yang terjadi dengan hanya CTRL-klik tombol "Pratinjau" sehingga Anda mendapatkan pratinjau di jendela / tab lain di browser Anda? Kemudian cukup CTRL-W untuk menutup tab pratinjau dan kemudian tekan tombol Terbitkan Anda.

Oke, solusi berteknologi rendah, dan solusi Bainternet jelas mengguncang. Hanya berpikir saya akan meletakkannya di sana ...


Terlalu banyak klik :) Sebenarnya, itulah yang saya maksud dengan mode "daftar posting". Saya sedang meninjau ribuan posting, dan setiap klik sangat berarti.
barrycarter
Dengan menggunakan situs kami, Anda mengakui telah membaca dan memahami Kebijakan Cookie dan Kebijakan Privasi kami.
Licensed under cc by-sa 3.0 with attribution required.