Publish Post After Click On A Link

I have a frontend posting form (CF7), where user inputs (among other data of course) his email. Now I set the status to pending.

What I want is, that the user would get trough autoresponder a mail, in which would be the link for changing the status to PUBLISH when clicked on. Is there any solution for this? Autoresponder is not the problem, I do not know, how to set up this link.

Related posts

1 comment

  1. 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' );
    }
    

Comments are closed.