I’m trying to add a “Publish” link by the quick actions:
but I’m not exactly sure of how implement it.
Here’s what I’ve got so far:
add_filter('post_row_actions', function ( $actions )
{
global $post;
// If the post hasn't been published yet
if ( get_post_status($post) != 'publish' )
{
$nonce = wp_create_nonce('quick-publish-action');
$link = get_admin_url('path to where') . "?id={$post->id}&_wpnonce=$nonce";
$actions['publish'] = "<a href="$link">Publish</a>";
}
return $actions;
});
As you can see, I don’t know where to link to in get_admin_url
. I think I should be using wp_publish_post()
, but I don’t know where to put that code, and how to link to it.
Without doing Ajax (like in Quick Edit), the
admin_url
should be the veryedit.php
page.Note that:
post_row_actions
takes two arguments, the second one being$post
, so the global is not necessary.id
as query argument, it’s best practice to use custom names, in this caseupdate_id
.get_admin_url
and normally useadmin_url
for this.Then, we need to hook in a very early action,
load-edit.php
, and perform awp_update_post
if the nonce andupdate_id
are ok: