Skip Navigation

[Resolved] cred_delete_post_link not working anymore

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: Africa/Casablanca (GMT+01:00)

Tagged: 

This topic contains 9 replies, has 2 voices.

Last updated by geoffreyC 4 years, 5 months ago.

Assisted by: Jamal.

Author
Posts
#1976903

Hi there,

I am trying to have a delete post link in a view loop

Link to a page where the issue can be seen: needs credentials as on the "my account" page

I expected to see the post deleted after link is clicked

Instead, I got the link text go from "delete" to "delete..." and then nothing (with the cred_delete_post_link shortcode).
I also saw on a ticket that the shortcode had been updated. I then tried with the new cred-delete-post shotcode and I got "Something went wrong, please reload the page and try again."

I deactivated all plugins and it didn't work neither.
I then switch to the twenty twenty one theme and both shortcodes work.
The issue seems to come from a conflict between toolset and divi theme.

Could you please help with this?
Many thanks

#1977323

Hello and thank you for contacting the Toolset support.

/wp-admin/ is protected, probably, by a plugin and does not work for me. So, I tried several pages from the "Plan du site" until I was able to login. But, then, I could not find the my-account page that has a view with the delete links. Can you point to me to the page and the view where I can see this issue?

#1978743

Hello Jamal,

My mistake, the login url is not /wp-admin
To see the issue, you need to connect as a freelance at /mon-compte/
If you can mark the next reply as private, I can give you an email and password to connect as a freelance, this account will have 4 or 5 custom posts where you can see the issue.
Alternatively, you can create a test freelance account and then a test "annonce" to get to the same point.

I did some further tests and with admin accounts I can delete the posts while with others I can't.
I've added the right to "delete own" custom post to the corresponding users in access but the issue persists.

Many thanks

#1979441

I created a new user with role "Intervenant enregistré" then I wanted to create a new "annonce" post but I could not find such a CPT. I created a new freelance annonce but I can't assign it to my new user (toolset-jamal).

I am setting your next reply as private to let you prepare the posts. Please share the URL where I can see the link in the frontend.

#1979889
#1979967

Thank you for the credentials, I can see the issue now. However, I would not expect the request to return a 302 status code, as you can see in this screenshot hidden link

I suspect a compatibility conflict with another component(theme, plugins) on the site. Please check if this issue appears when:
- Only Toolset plugins are activated. It will tell us if there is an interaction issue with another plugin.
- The theme is set to a WordPress default like Twenty Twenty. It will tell us if there is an interaction issue with your theme.
If the problem disappears, start activating one at a time to track where the incompatibility is produced.

If this does not help find the cause of the issue, I'll need to take a copy of your website and debug it locally. Let me know if that's fine with you.

#1980065

Hello Jamal,

As mentioned in my first email, the issue disappear when I switch to Twenty Twenty One theme.
It seems to have a compatibility issue with Divi.

If needed, you can make a local copy to debug no problem.
Thanks for your help.

#1983527

My apologies for the late reply, but I do not work on Wednesdays and Thursdays.

I logged in to take a copy of the website and before that, I checked the issue again, and it seems to disappear, even with the Divi theme. Check this screencast, I am able to delete the post using the Toolset Forms delete link.
hidden link

Am I missing something? Please let me know if the issue still persists.

#1984147

Thanks for the reply.
After a few tests I realized I did not specify I was using a child theme with a few custom functions.
So I confirm it works with Divi theme but it does not work with the child theme.
Therefore I still have the issue.

As additional information, if it can be of any help, on the child theme I have added some php code to add the "save as a draft" option. For this, I followed this thread : https://toolset.com/forums/topic/add-a-save-draft-button-on-a-cred-post-form-with-ajax-submission/

Thanks again for your help

#1984743

The issue is not with that custom code, because it is scoped to requests coming from that specific form. The issue is coming from the redirections that you set to restrict access to parts of the site for the users with these permissions:
- client_inscrit_pas_abonne
- client_abonne
- intervenant_enregistre
I commented the following lines an everything works as expected:

// add_action('init', 'ts_lockout_dashboard1');

// add_action('init', 'ts_lockout_dashboard2');

// add_action('init', 'ts_lockout_dashboard3');

This is the codes that are causing these issues with the cred_delete_post_link:

/**
** GC - Access to WP Backoffice restricted, redirect to account page correspoonding to the user role
**/
function ts_lockout_dashboard1() {
    if ( is_admin() && current_user_can('client_inscrit_pas_abonne') ) {
        wp_redirect( home_url( '/mon-compte-client/' ) );
        die();
    }
}
add_action('init', 'ts_lockout_dashboard1');

function ts_lockout_dashboard2() {
    if ( is_admin() && current_user_can('client_abonne') ) {
        wp_redirect( home_url( '/mon-compte-client/' ) );
        die();
    }
}
add_action('init', 'ts_lockout_dashboard2');

function ts_lockout_dashboard3() {
    if ( is_admin() && current_user_can('intervenant_enregistre') ) {
        wp_redirect( home_url( '/mon-compte/' ) );
        die();
    }
}
add_action('init', 'ts_lockout_dashboard3');

These hooks are too generic for any requests made to the backend. cred_delete_post_link is an AJAX request, and all AJAX requests are made to the backend. We need to exclude AJAX requests from these redirections. We can check for AJAX requests with the following code:

if (defined('DOING_AJAX') && DOING_AJAX) { /* it's an Ajax call */ }

I introduced the check for AJAX requests in the code and it fixed the issue:

/**
** GC - Disable Admin Bar for All Users Except for Administrators
**/

add_action('after_setup_theme', 'remove_admin_bar');
 
function remove_admin_bar() {
if (!current_user_can('administrator') && !is_admin()) {
  show_admin_bar(false);
}
}

/**
** GC - Access to WP Backoffice restricted, redirect to account page correspoonding to the user role
**/
function ts_lockout_dashboard1() {
    if ( is_admin() && ( !(defined('DOING_AJAX') && DOING_AJAX) ) && current_user_can('client_inscrit_pas_abonne') ) {
        wp_redirect( home_url( '/mon-compte-client/' ) );
        die();
    }
}
add_action('init', 'ts_lockout_dashboard1');

function ts_lockout_dashboard2() {
    if ( is_admin() && ( !(defined('DOING_AJAX') && DOING_AJAX) )  && current_user_can('client_abonne') ) {
        wp_redirect( home_url( '/mon-compte-client/' ) );
        die();
    }
}
add_action('init', 'ts_lockout_dashboard2');

function ts_lockout_dashboard3() {
    if ( is_admin() && ( !(defined('DOING_AJAX') && DOING_AJAX) )  && current_user_can('intervenant_enregistre') ) {
        wp_redirect( home_url( '/mon-compte/' ) );
        die();
    }
}
add_action('init', 'ts_lockout_dashboard3');

Check this screencast, the child theme is the active theme, and delete posts using the cred link works. hidden link

#1997655

Many thanks Jamal and sorry for the late reply.
The solution works, I will mark this thread as resolved.

Best,
Geoffrey