BuddyDev

Search

Edit Link for Original Author

  • Participant
    Level: Initiated
    Posts: 19
    Ada on #2032

    Hi Brajesh,

    If you may recall a few months ago you gave me advice how to mark a post as anonymous using Simple Front End Post and via a follow-up some guidance on how to enable the original author to edit the post. Unfortunately the original thread is no longer in this forum and so for reference this is what you wrote:

    “The basic strategy should be:-
    1. When a post is created, assign post to the anonymous user but store the current user’s ID in post meta.
    2. When the user is logged in, fetch all the posts where author = anonymous user and meta_key = original author and meta_value = logged in user id ( Please see WP_Query). That will give you all the anonymous posts by current user.

    After that it is just a matter of filtering on post like/capabilities to allow current user edit their post.”

    I have a few questions because I guess I am not clear on some of these if you don’t mind helping out.

    1)
    I managed to have the logic in place with the following code (please feel free to scrutinize):


    if (get_post_meta( $post->ID, ‘original_author’, true)){
    global $current_user;
    get_currentuserinfo();
    $original_user_id = get_post_meta( $post->ID, ‘original_author’, true);
    if (is_user_logged_in() && current_user_can(‘publish_posts’) && $current_user->ID == $original_user_id) {
    //echo ‘Test passed: You are the original author and can edit!’;
    edit_post_link(‘edit’, ”, ”);

    }}

    It does pass the test but I can’t get the edit link to show (it shows for admin though). The original author does have the author role. What else needs to be done to enable the edit link?

    2)
    Not exactly sure if I understand how to construct the WP_Query to show only those posts by the original author that are marked anonymous (obviously we don’t want to publically display all the posts by the author – this would be counter-intuitive). Apprciate any guidance in this regard as well.

    Many thanks for all your help all along!

You must be logged in to reply to this topic.

This topic is: not resolved