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