Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Is it possible to take the blue publish button in back end of the wordpress and place it in the frontend near the post in my index.php. I need a way to publish the pending article without going to dashboard and only admin can see the publish button?

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

Thank You all in advance for help :D

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

First create a function that will print the publish button :

//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>';
    }
}

Next create a function to change the post status:

//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);
}

Then make sure to catch the submit of the button:

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

Now all of the above code can go in your theme's functions.php file and all you have to do is add show_publish_button(); in your loop of pending posts after each post.

share|improve this answer
    
Thank You very much :) –  jimilesku May 21 '11 at 18:15
    
Glad i could help. –  Bainternet May 21 '11 at 18:41
    
Is it possible to have a different name on the buttom? Like submit instaead of publish.. –  user7790 Aug 10 '11 at 12:29
    
Of course just change the 'value' of the submit button. –  curtismchale Sep 12 '11 at 21:21
    
Sorry for reviving this old topic @Bainternet but using this code on a test I'm doing is taking me to the wordpress error page "Are you sure you want to do this? Please try again". The post is actually published but it's going to that page for some reason. I'm using Membership plugin and 'manage_options' is active on that user role. Thanks. –  Jaypee Jan 25 at 18:47
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.