How to display deleted post in MB Frontend Submission Dashboard (Trash Section)

Support MB Frontend Submission How to display deleted post in MB Frontend Submission Dashboard (Trash Section)

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #41422
    Way LeongWay Leong
    Participant

    Hi,

    https://prnt.sc/5fYKNvSDA7A-

    I would like to display the posts that have been deleted by the user via MB Frontend Submission Dashboard. What is the workaround? Because MB Frontend Submission Dashboard did not have that feature available.

    #41433
    PeterPeter
    Moderator

    Hello,

    If you want to display the trash posts in the frontend dashboard, you can use the filter hook rwmb_frontend_dashboard_query_args

    The frontend dashboard is a custom query to display posts belonging to a user so you can create your own query to display a custom dashboard on your own.
    https://developer.wordpress.org/reference/classes/wp_query/

    #41455
    Way LeongWay Leong
    Participant

    Hi, I applied the following php code into code snippets

    <?php
    
    add_filter( 'rwmb_frontend_dashboard_query_args', 'my_frontend_dashboard_query_args' );
    function my_frontend_dashboard_query_args( $args ) {
        $args['post_status'] = array( 'publish', 'trash' ); // Include trashed posts in the query
        return $args;
    }
    
    add_filter( 'wp_trash_post_status', 'my_trash_post_status', 10, 2 );
    function my_trash_post_status( $trash_status, $post ) {
        $allowed_post_types = array( 'post','newsroom', 'property', 'leadership', 'company' ); // Set allowed post types
    
        if ( in_array( $post->post_type, $allowed_post_types ) ) {
            $trash_status = 'auto-draft'; // Set trashed posts to auto-draft status
        }
        return $trash_status;
    }

    It does display the trashed post on the Frontend dashboard, but I am unable to edit the post even my user role is Admin. You may view the image here (https://prnt.sc/krDt4y39ovz8)

    I applied this code to let the trashed post status to become auto-draft status

    if ( in_array( $post->post_type, $allowed_post_types ) ) {
            $trash_status = 'auto-draft'; // Set trashed posts to auto-draft status
        }
        return $trash_status;
    }
    #41459
    PeterPeter
    Moderator

    Hello,

    >> It does display the trashed post on the Frontend dashboard, but I am unable to edit the post even my user role is Admin.

    It is expected behavior. You are also not able to edit the trash post in the admin area, just restore it.

    #41490
    Way LeongWay Leong
    Participant

    Hi Peter,

    Sorry for repeating this over again but I promise this would be the last.

    
    add_filter( 'rwmb_frontend_dashboard_query_args', 'my_frontend_dashboard_query_args' );
    function my_frontend_dashboard_query_args( $args ) {
        $args['post_status'] = array( 'publish', 'trash' ); // Include trashed posts in the query
        return $args;
    }
    
    add_filter( 'wp_trash_post_status', 'my_trash_post_status', 10, 2 );
    function my_trash_post_status( $trash_status, $post ) {
        $allowed_post_types = array( 'post','newsroom', 'property', 'leadership', 'company' ); // Set allowed post types
        if ( in_array( $post->post_type, $allowed_post_types ) ) {
            $trash_status = 'auto-draft'; // Set trashed posts to auto-draft status
        }
        
        return $trash_status;
    }
    
    add_action( 'rwmb_frontend_after_delete_post', 'my_frontend_restore_post_status', 10, 2 );
    function my_frontend_restore_post_status( $post_id, $post ) {
        if ( $post->post_status === 'trash' ) {
            $allowed_post_types = array( 'post','newsroom', 'property', 'leadership', 'company' ); // Set allowed post types
            if ( in_array( $post->post_type, $allowed_post_types ) ) {
                wp_update_post( array( 'ID' => $post_id, 'post_status' => 'draft' ) ); // Restore trashed posts to draft status
            }
        }
    

    I tried to enable allowed edit for deleted post but the code doesn't seem working and it will still the same as this photo (https://prnt.sc/krDt4y39ovz8). Could you guide me on which PHP function is the correct one to allow deleted post to be edit?

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