When the post is created and set to pending
, build a unique identifier for auto-publishing, for example:
$unique = md5( $post->post_content );
add_post_meta( $post->ID, '_auto_publish', $unique );
Now create a link for the email:
$link = get_permalink( $post->ID );
$link = add_query_arg(
array(
'autopublish' => $unique,
'pid' => $post->ID
),
$link
);
Send this link in your email to the submitter’s address:
print "<$link>";
Then watch for the matching $_GET
parameters when the recipient clicks the link:
if ( isset ( $_GET[ 'autopublish' ] )
and isset ( $_GET[ 'pid' ] )
and is_numeric( $_GET[ 'pid' ] )
and $post = get_post( $_GET[ 'pid' ] )
and $_GET[ 'autopublish' ] === get_post_meta( $post->ID, '_auto_publish', TRUE )
)
{
$post->post_status="publish";
wp_update_post( $post );
delete_post_meta( $post->ID, '_auto_publish' );
}