Link for user to unpublish post (status: draft)
-
I am using this function:
if(isset($_REQUEST['action']) && $_REQUEST['action']=='mypublish') add_action('init','my_publish_draft'); function my_publish_draft(){ //Get the post's ID. $post_id = (isset($_REQUEST['post']) ? (int) $_REQUEST['post'] : 0); //No post? Oh well.. if(empty($post_id)) return; $nonce = $_REQUEST['_wpnonce']; //Check nonce if (! wp_verify_nonce($nonce,'my-publish-post_'.$post_id)) wp_die('Are you sure?'); //Check user permissions if (!current_user_can('publish_posts')) wp_die("You can't do that"); //Any other checks you may wish to perform.. //Publish post $post = get_post($post_id,ARRAY_A); $post['post_status'] ='publish'; wp_update_post($post); //Redirect to published post wp_redirect('/dashboard/'); exit; }
And this code:
<?php $status=get_post_status($upost->ID); if ($status!='publish') $url=add_query_arg(array('action'=>'mypublish', 'post'=>$upost->ID),home_url()); echo "<a href='" . wp_nonce_url($url, 'my-publish-post_' . $upost->ID) . "'>Publish</a>"; ?>
To allow users to publish their posts via the front end of my site (theseattlevine.com/dashboard). I now want to give them an option to un-publish their posts (change them back to drafts).
Can anyone help me figure out how to do this?
Thanks!
- The topic ‘Link for user to unpublish post (status: draft)’ is closed to new replies.