Skip Navigation

[Resolved] Split: Display edit post link that goes to login page for guest users

This support ticket is created 5 years, 11 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 8 replies, has 3 voices.

Last updated by RudiK3597 5 years, 9 months ago.

Assisted by: Nigel.

Author
Posts
#1196551

Thanks! that works very well.

I am using the Access module to control usage of this form above - we only what the edit form to be used by a logged on user.
The link only shows if I am logged in.
How could I always show the link, but rather than going to the Edit form that it first shows a login form then goes to the edit form?

Also once they edit the form - we change the owner to them?

#1196772

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

This is a bit tricky, but let me guide you through what is required.

You will need a custom login form which you add to a standard WordPress page using the wpv-login-form shortcode (https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-login-form).

On the template which displays the post you want users to be able to edit, you insert the link to edit the post using your edit form as normal, meaning it will insert a toolset_edit_post_link shortcode.

Now, you need to use the toolset_access shortcode to control what Guest users can and can not see (as described here: https://toolset.com/documentation/user-guides/access-control-texts-inside-page-content/).

You will want non-Guest users (i.e. those who are logged in) to see the link to the edit form.

You will want Guest users to see a link to the page with the custom login form instead.

So your template where the edit link is inserted would look something like this:

[toolset_access role="Guest" operator="deny"]
    [toolset-edit-post-link content_template_slug='edit-project-form-container' target='self']Edit %%POST_TITLE%%[/toolset-edit-post-link]
[/toolset_access]

[toolset_access role="Guest" operator="allow"]
    <a href="[wpv-post-url item='138']">Login to edit</a>
[/toolset_access]

In that example, 138 is the ID of the page where the custom login form is inserted.

Now, this will achieve part of your task.

If you visit a post that uses that template, if you are logged in you will see the edit post link, if you are logged out you will see a link to login.

If you click the link to login you are taken to the custom login page—where you can log in—but then you are left on the same page.

The wpv-login-form has a redirect_url attribute to specify the page to redirect to after logging in. But on that page we don't know where to redirect to.

The solution is to pass the details of where to redirect to from the template that inserts the link to the page with the log-in form. When viewing a post on the front end which has the link to edit the post we do know what the URL we need to redirect to is: it is the same as the URL generated by the toolset_edit_post_link shortcode, which is the URL of the post to be edited, appended with a URL parameter content-template-id which specifies the ID of the content template which holds your edit form.

So, you need to update the link to the page with the custom login form to pass the post URL and the content template ID, like this:

<a href="[wpv-post-url item='138']?source=[wpv-post-url]&template=244">Login to edit</a>

The 'source' parameter will hold the URL of the post to be edited, and the 'template' parameter will hold the ID of the template which holds the edit form. (It is manually entered—as 244 in my example—and I got the ID by looking at the URL which the edit link generates.)

Now go back to the page where you insert the log-in form and make use of those two parameters to generate the redirect_url parameter of the wpv-login-form shortcode, like so:

[wpv-login-form label_username="Custom label for username/email" redirect_url="[wpv-search-term param='source']?content-template-id=[wpv-search-term param='template']"]

That is quite a lot to digest, but hopefully if you follow step-by-step you will be able to implement.

#1201379
Screen Shot 2019-02-17 at 9.01.31 pm.png

Thanks so much for the detailed instructions!

you won't believe it but I'm stuck on the first part.. I cant get the shortcode to work on any page or view I setup.
I am using:

[wpv-login-form allow_remember="true" remember_default="true"]

in a shortcode container on a standard WordPress page... any ideas? [attached image of the code to insert the shortcode. just displays blank]

#1201396

Hi Nigel... actually I think my process isn't right anyway.... let me explain what I am trying to do.

- I have classified listings that have been loaded by me the admin
- I want users to be able to claim them..
- first step is for them to request ownership of the post.
- so if not logged in - ask them to create an account and login
- when logged, request ownership of the post (including uploading a file for proof)
- admin needs to approve somehow from backend

thats it - then they can go to their account and ill have an edit for to change the post.

I found this: https://toolset.com/forums/topic/have-a-user-claim-a-post-add-another-user-to-post-besides-the-admin/
but its old and doesn't cover the approval process..

#1202276

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Rudi

First, you probably didn't see the login form in your previous response because you were viewing the page logged-in already. The login form only appears to guest users.

If you are adding an approval process into the mix then you can use a similar set-up as I described above with a few modifications.

If you display a link to claim a post the person clicking it could be registered and logged in (case 1), registered but logged out (case 2) or not yet registered (case 3).

Presumably you would like the administrator to be notified when someone claims a post, so that they can review it, and the user to be advised when their post has been approved, so that they can edit it.

You can't readily distinguish between case 2 and case 3, so you should make one page "Login or register" which includes both a login form and a registration form.

I would create a dedicated "claim" custom post type that will record the post being claimed and the user making the claim, and include custom fields for the evidence they need to provide.

Make a one-to-many relationship between your classified posts (parent) and the claims (child).

So you will make a form to "publish" a claim that will include a relationship field to link the claim to the classified, where the post author will be the user making the claim. The form can include a notification email to alert the site admin.

When you display a "claim" link against the classifieds you will actually be linking to a page where you include the above form, using "Create child post link" with the Toolset Forms button (which inserts a cred_child_link_form shortcode).

You will use Access to only display the link to logged-in users, and use a process similar to the one I described above for edit forms to pass the ID of the parent that the child post will belong to when linking to the register/login page.

If you need to notify the users that their claim has been approved then you would need the site admin to use a front-end form to do so, rather than making edits in the back end, which wouldn't generate a notification. I don't know what workflow suits you, but it might make sense for you to edit the claim post (rather than the classified post) and have a radio field for whether the post is approved/rejected for example, with separate notifications for each. If approved you might then use the API, e.g. the cred_save_data hook, to run a little code to automatically update the post author of the classified to match the post author of the claim post.

#1214476

Hi there !

I think I have worked everything out except a couple of points.

1 of them is I want to change the child post from draft to published and when I press publish I want it to change the author on the parent post to the same as child post and also update a checkbox field on the parent post from 0 to 1.

I assume ill need some code in the functions.php - in another one of the tickets you gave me some code which changes the author, but that is using the forms logic.

could you help me ?

#1215230

I found some resources that are aligned:

https://toolset.com/forums/topic/claim-ownership-of-a-specific-post-with-admin-approval/
https://toolset.com/forums/topic/have-a-user-claim-a-post-add-another-user-to-post-besides-the-admin/
https://toolset.com/forums/topic/trying-to-grab-parent-title-to-use-as-childs-title/

If I try and focus on just changing a "flag" on the parent post from the child when published I created:

function publish_claim( $post_ID ) {

if ( get_post_type( $post_ID ) == 'claimed-listing' ) {
$businesslisting_id = get_post_meta($post_ID, '_wpcf_belongs_business-listing_id', true);
update_post_meta( $businesslisting_id, 'wpcf-claimed-listing', '1' );
}
}
add_action( 'save_post', 'publish_claim', 99);

but I couldn't get it to work. What is difficult to know is what are the actual fields are... there doesn't seem to be an easy way to work this out?

#1215275

Hi Rudi,

Thanks for the update and glad Nigel's suggestions helped.

He is away on vacation and will be back tomorrow, but I'll be happy to follow up.

Important: Please note that as per our support policy ( https://toolset.com/toolset-support-policy/ ), only one question or issue can be addressed through a single ticket. Long threads covering different topics are not efficient for anyone.

You're welcome to open a new ticket for each new question or concern.

I'll be shortly replying you about the outstanding question in a new ticket that I've created for you.
( https://toolset.com/forums/topic/split-update-the-parent-post-when-the-child-post-is-published-from-the-admin-area/ )

Since this thread's original concern has been addressed, you can mark it as resolved.

regards,
Waqar

#1215279

My issue is resolved now. Thank you!