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

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #42839
    pluginovenpluginoven
    Participant

    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?

    #42840
    pluginovenpluginoven
    Participant

    the 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;
    }
    #42848
    PeterPeter
    Moderator

    Hello,

    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.

    #43424
    Salony MohantySalony Mohanty
    Participant

    has this issue been fixed in the latest release available to download?

    #43428
    PeterPeter
    Moderator

    Hello,

    Yes, it is fixed in the new version of MB Frontend Submission or Meta Box AIO.

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.