issue using rwmb_frontend_dashboard_delete_action filter to remove delete icon
Support › MB Frontend Submission › issue using rwmb_frontend_dashboard_delete_action filter to remove delete iconResolved
- This topic has 4 replies, 3 voices, and was last updated 2 years ago by
Peter.
-
AuthorPosts
-
August 8, 2023 at 3:40 AM #42839
pluginoven
ParticipantFor 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 fordelete_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
returnsfalse
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?August 8, 2023 at 4:00 AM #42840pluginoven
Participantthe filter function is returning the
$show_delete
var. it was missing in the above example: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; } return $show_delete; }
August 8, 2023 at 10:00 PM #42848Peter
ModeratorHello,
Thanks for your feedback.
I also see that issue on my demo site. I've escalated this issue to the development team to fix it in the next update.
October 5, 2023 at 5:54 AM #43424Salony Mohanty
Participanthas this issue been fixed in the latest release available to download?
October 5, 2023 at 8:48 PM #43428Peter
ModeratorHello,
Yes, it is fixed in the new version of MB Frontend Submission or Meta Box AIO.
-
AuthorPosts
- You must be logged in to reply to this topic.