Skip Navigation

[Resolved] Delete Post Link with no reference to wp-admin

This support ticket is created 4 years, 6 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 4 replies, has 2 voices.

Last updated by andrei-laurentiuP 4 years, 6 months ago.

Assisted by: Waqar.

Author
Posts
#1341979

Tell us what you are trying to do?
I am trying to insert a delete post button in a view listing posts. I am using [cred_delete_post_link action='delete' text='Delete' message='Are you sure you want to delete this post?' message_show='1' class='cred-refresh-after-delete']

However, this shows in the bottom left corner a reference to /wp-admin/admin-ajax.php?action=cred-ajax-delete...

Is there any way to remove that, so no reference to wp-admin or wordpress is made?

Also, is there a way to update the page using ajax instead of refreshing the page all together?

#1342577

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Andrei,

Thank you for waiting.

I've performed some tests and here is a workaround that you can use, to delete the post from the front-end, without reloading the page and exposing the link with path "/wp-admin/admin-ajax.php".

1. Please create a new post form and set it to "Edit existing content" and select the post type that is being shown in the view.
( ref: https://toolset.com/documentation/getting-started-with-toolset/publish-content-from-the-front-end/forms-for-editing/ )

Also, check the option "Submit this form without reloading the page (use AJAX)" in the form's settings, so that the page is not refreshed.

Screenshot: hidden link

2. This form doesn't need to have any front-end visible fields other than the submit button and an HTML content, that will hold the content that you're showing for a single loop item in the view.

Screenshot: hidden link

3. In the view's loop item content template, you can insert the shortcode for this new edit form, because now the repeating content for each post will need to be shown from inside the editing form.


[cred_form form='slug-of-the-form']

This will ensure that when the form will be submitted to delete the post, its content is also removed from the page.

4. The last step would be to add a special function, attached to the hook "cred_submit_complete", which deletes the post, for which the form is submitted.
( ref: https://toolset.com/documentation/programmer-reference/cred-api/#cred_submit_complete )


add_action('cred_submit_complete', 'custom_post_delete_function',10,2);
function custom_post_delete_function($post_id, $form_data)
{
    // if a specific form
    if ($form_data['id']==1234)
    {
        wp_delete_post( $post_id, true );
    }
}

Please replace "1234" with the actual ID of the form created in step 1.

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#1342775

Hey Waqar, I have implemented this solution. However, the post is only removed from the current loop, but not actually deleted altogether - you can see that easily by refreshing the page where the view is inserted. Is this happening on your side as well or should I further check, maybe I missed something...

#1342795

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Andrei,

Thanks for writing back and for sharing the update.

The code snippet shared in step 4 is actually responsible for deleting the target post from the backend and it is working, as expected on my test website.

Can you please make sure that the code snippet has been included in the active theme's "functions.php" file and "1234" in the snippet has been replaced by the new form's ID?

In case, the post is still not deleted, you're welcome to share temporary admin login details and the link to a page where this view can be seen.

Note: Your next reply will be private and though no changes will be made on your website, please make a complete backup copy, before sharing the access details.

regards,
Waqar

#1348245

Sorry for late reply. Managed to sort it out! Thanks!! My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.