Domanda

E 'possibile prendere il blu pulsante di pubblicare in back-end del wordpress e posizionarlo nel frontend vicino al palo nel mio index.php. Ho bisogno di un modo per pubblicare l'articolo in attesa senza andare a cruscotto e unico amministratore può vedere il pulsante di pubblicare?

<?php   
$args=array(
'post_type'         => 'post',
'post_status'       => 'pending',
'order'                 => 'ASC',
'caller_get_posts'  =>1,
'paged'         =>$paged,
            );

Grazie a tutti in anticipo per l'aiuto: D

È stato utile?

Soluzione

Per prima cosa creare una funzione che stamperà il pulsante di pubblicare:

//function to print publish button
function show_publish_button(){
    Global $post;
    //only print fi admin
    if (current_user_can('manage_options')){
        echo '<form name="front_end_publish" method="POST" action="">
                <input type="hidden" name="pid" id="pid" value="'.$post->ID.'">
                <input type="hidden" name="FE_PUBLISH" id="FE_PUBLISH" value="FE_PUBLISH">
                <input type="submit" name="submit" id="submit" value="Publish">
            </form>';
    }
}

Avanti creare una funzione per cambiare lo stato del messaggio:

//function to update post status
function change_post_status($post_id,$status){
    $current_post = get_post( $post_id, 'ARRAY_A' );
    $current_post['post_status'] = $status;
    wp_update_post($current_post);
}

Quindi assicuratevi di prendere il submit del pulsante:

if (isset($_POST['FE_PUBLISH']) && $_POST['FE_PUBLISH'] == 'FE_PUBLISH'){
    if (isset($_POST['pid']) && !empty($_POST['pid'])){
        change_post_status((int)$_POST['pid'],'publish');
    }
}

Ora, tutto il codice di cui sopra può andare nel file di functions.php del tema e tutto quello che dovete fare è aggiungere show_publish_button(); nel loop di messaggi in attesa dopo ogni post.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a wordpress.stackexchange
scroll top