For whatever reason, the delete icon on the frontend dashboard is being displayed, even if a user does not have permission to delete a post type. For example, if the post type is workplace
and the permission for delete_workplaces
is not granted, the delete icon is still displayed.
To get around this we are using the rwmb_frontend_dashboard_delete_action
as follows:
add_filter( 'rwmb_frontend_dashboard_delete_action', 'fix_frontend_delete_button', 20, 2 );
function fix_frontend_delete_button ( $show_delete, $post_id ){
$post_type = get_post_type( $post_id ); //workplace
if ( !current_user_can( 'delete_'.$post_type.'s' ) ) {
$show_delete = false;
}
}
However, if $show_delete
returns false
then a JS error is being thrown in the console:
frontend-submission.js?ver=4.4.0:1 Uncaught ReferenceError: mbFrontendForm is not defined
at frontend-submission.js?ver=4.4.0:1:22
at frontend-submission.js?ver=4.4.0:1:2579
After looking at how the rwmb_frontend_dashboard_delete_action
filter is being used in DashboardRenderer.php:
$delete_action = true;
// Filter the delete action
$delete_action = apply_filters( 'rwmb_frontend_dashboard_delete_action', $delete_action, get_the_ID() );
if ( $delete_action ) {
echo do_shortcode( '[mb_frontend_form id="' . $this->edit_page_atts['id'] . '" post_id="' . get_the_ID() . '" ajax="true" allow_delete="true" force_delete="' . $atts['force_delete'] . '" only_delete="true" delete_button="<img src=\'' . MBFS_URL . 'assets/trash.svg\'>"]' );
}
it seems that the mb_frontend_form
shortcode must be present. We have found a temp work-around by adding:
else {
echo do_shortcode( '[mb_frontend_form id="' . $this->edit_page_atts['id'] . '" post_id="' . get_the_ID() . '" ajax="true" allow_delete="false" only_delete="true" delete_button=" "]' );
}
But it seems there is a deeper issue that needs to be addressed here.
Any ideas on how this can be properly addressed?