Support » Plugin: GiveWP - Donation Plugin and Fundraising Platform » Add an “edit” link to Give Form post?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Matt Cromwell

    (@webdevmattcrom)

    Hey Adam, apologies for the delay. I thought that was a great idea so I put together this quick snippet to do that:

    add_action('give_post_form_output', 'give_add_edit_form_link');
    
    function give_add_edit_form_link() {
    
        if (current_user_can('edit_give_forms')) {
    	   edit_post_link('Edit this donation form', '<p>', '</p>');
        }
    }

    Note that you can change the “edit_give_forms” to be any capability you want. Naturally, you’ll probably want to add some additional logic to only allow them to edit the forms that they are the author of as well.

    Thanks!

    • This reply was modified 4 years, 8 months ago by Matt Cromwell. Reason: removed additional snippet which was a little misleading
    • This reply was modified 4 years, 8 months ago by Matt Cromwell. Reason: Removed unnecessary echo
    Thread Starter adambradford

    (@adambradford)

    Hi Matt,

    Many thanks for replying! That works a treat!

    The only problem is, I need to make it so that only the owner of the form can edit. At the moment, it looks like any user can. Could you give me some guidance on the conditional logic required?

    Thanks,

    Adam.

    • This reply was modified 4 years, 8 months ago by adambradford.
    Thread Starter adambradford

    (@adambradford)

    Actually, on further investigation, I just tried clicking a link as logged-in user but non-owner of a form, and it just redirected me to the home page. So it appears it does work as expected. Is there any way to hide the link completely from any visitor who may be logged in but doesn’t own the form?

    Thanks.

    Adam.

    Plugin Author Matt Cromwell

    (@webdevmattcrom)

    This ought to do it for you:

    add_action('give_post_form_output', 'give_add_edit_form_link');
    
    function give_add_edit_form_link() {
    
        $author_id = get_the_author_meta( 'ID' );
        $current_userid = get_current_user_id();
    
        if ( ( $author_id == $current_userid ) && current_user_can('edit_give_forms') && is_singular('give_forms')) {
    	   edit_post_link('Edit this donation form', '<p>', '</p>');
        }
    }

    If you’re enjoying Give and appreciate our support, we’d love a kind review from you here:
    https://wordpress.org/support/plugin/give/reviews/

    Thanks, and best of luck!

    Thread Starter adambradford

    (@adambradford)

    That’s Brilliant Matt, thank you!

    5 star review left!

    Adam.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Add an “edit” link to Give Form post?’ is closed to new replies.