BuddyDev

Search

BuddyBlog Pro – override Submit Post for Review

  • Participant
    Level: Master
    Posts: 279
    NikB on #47903

    Hi Brajesh

    Would there possibly be a way of overriding the “Submit Post for Review” for certain roles and/or group owners (so that their posts don’t require approval and are published immediately)?

    eg.

    1. Personal posts – currently I have users with “editor” status who use the (BuddyBlog) front end to add their posts, but then have to go to the dashboard to approve their OWN posts which is causing some confusion.

    2. Group posts – similar to the above, although in this case it can at least all be done in the front end, in this case, group owners have to approve their own posts before they are published (which seems like an unnecessary step).

    Any thoughts? The personal posts issue is the most significant for me currently…

    With many thanks in advance.
    Nik

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #47908

    Hello Nik,

    Please try the following code and let me know if it helps or not

    
    add_filter( 'bblpro_form_post_status', function ( $post_status, $form_id ) {
    
    	if ( is_super_admin() || ! is_user_logged_in() ) {
    		return $post_status;
    	}
    
    	$form_type = bblpro_get_form_type( $form_id, 'members' );
    
    	if ( 'members' == $form_type ) {
    		// Replace with your roles.
    		$skipped_roles = array( 'editor' );
    		if ( 'pending' == $post_status && bblpro_user_has_role_in( get_current_user_id(), $skipped_roles ) ) {
    			$post_status = 'publish';
    		}
    	}
    
    	return $post_status;
    }, 10, 2 );
    
    

    Regards
    Ravi

    • This reply was modified 1 year, 11 months ago by Ravi.
  • Participant
    Level: Master
    Posts: 279
    NikB on #47915

    Hi Ravi

    Thank you so much for your quick and helpful reply.

    At least from tests so far, that seems to work perfectly.

    Regards
    Nik

  • Participant
    Level: Master
    Posts: 279
    NikB on #48292

    Hi again Ravi (or Brajesh)

    I’ve now had a chance to test things a bit more and have realised that the whilst the above code works insofar as “editors” posts are now published without requiring approval, it also seems to have the unintended consequence of hiding the “Post Approval” meta box in the WP Dashboard for the designated roles (ie. editors) which means that editors are unable to approve the posts of other members.

    I’m guessing it needs some additional criteria to eliminate this scenario but can’t quite figure out the logic.

    Any suggestions would be much appreciated.

    With many thanks in advance.
    Nik

    PS. I’ve also just realised that despite publishing them immediately, the above code doesn’t actually set editors posts status to “approved” which ideally should happen too 😉

  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #48296

    Hi Nik,
    Thank you for the feedback.


    @ravisharma
    will be assisting you with it.

    I will be replying to your other topic about instant publish.

    Regards
    Brajesh

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #48306

    Hello Nik,

    Please replace the old code with the following one:

    
    
    /**
     * Retrieves skipped roles
     *
     * @return string[]
     */
    function bblpro_custom_get_skipped_roles() {
    	return array( 'administrator', 'editor' );
    }
    
    add_filter( 'bblpro_form_post_status', function ( $post_status, $form_id ) {
    
    	if ( ! is_user_logged_in() ) {
    		return $post_status;
    	}
    
    	$form_type = bblpro_get_form_type( $form_id, 'members' );
    
    	if ( 'members' == $form_type && doing_action( 'wp_ajax_bblpro_submit_post' ) ) {
    		// Will always be published if having skipped roles.
    		if ( bblpro_user_has_role_in( get_current_user_id(), bblpro_custom_get_skipped_roles() ) ) {
    			$post_status = 'publish';
    		}
    	}
    
    	return $post_status;
    }, 10, 2 );
    
    add_filter( 'bblpro_submit_button_label', function ( $label, $form ) {
    
    	if ( ! bblpro_user_has_role_in( get_current_user_id(), bblpro_custom_get_skipped_roles() ) ) {
    		return $label;
    	}
    
    	if ( bblpro_is_edit_page() ) {
    		$post_id = bblpro_get_current_editable_post_id();
    
    		if ( 'publish' !== get_post_status( $post_id ) ) {
    			$label = _x( 'Publish', 'Post submission button label', 'buddyblog-pro' );
    		}
    	} elseif ( 'pending' == bblpro_form_get_post_status( $form->ID ) ) {
    		// On create post form.
    		$label = _x( 'Publish', 'Post submission button label', 'buddyblog-pro' );
    	}
    
    	return $label;
    }, 10, 2 );
    
    

    Please give it a try now.

    Regards
    Ravi

  • Participant
    Level: Master
    Posts: 279
    NikB on #48329

    Hi Ravi

    Thank you again. The revised code does now seem to work insofar as editors can now view the Post Approval meta box in the WordPress dashboard (as well as their own posts being published without approval) so that definitely solves the biggest issues.

    Unfortunately, it stil doesn’t actually change the editors’ posts status to “Approved”, and editors still receive an email saying that their post needs to be approved (even though it doesn’t) but from Brajesh’s comment above, I’m not sure if this is possibly something he may be thinking of addressing in the next release anyway?

    Regards
    Nik

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #48344

    Hello Nik,

    Thank you for the acknowledgment. I will check this and will let you know.

    Regards
    Ravi

  • Participant
    Level: Master
    Posts: 279
    NikB on #48550

    Hi Ravi (and Brajesh)

    Using the above code as a starting point, I have managed to add an additional filter to GROUP posts so that posts from both those holding the role of “editor” AND group admins are published instantly (ie. without the need for approval).

    This seems to be working fairly well, however, for some reason I am really struggling to change the submit button label for group admins, so although their posts will be published instantly, the text on the button still shows as “Submit for Review”).

    It works fine for those holding the role of editor (ie. button text is changed to “Publish”) but I just can’t seem to figure out how to tweak the bblpro_submit_button_label filter so that if it is being displayed on a GROUP post and the person viewing is a group admin, the text will show as “Publish” rather than “Submit for Review”.

    Any suggestions would be very much appreciated and with many thanks in advance.
    Nik

  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #48562

    Hi Nik,
    I am sorry, we could not push the update and assist you better wit this.

    I am working on a solution that will not need approval for group admins and we will take care of label in that case.

    I am expecting a release mid next week.

    Regards
    Brajesh

You must be logged in to reply to this topic.

This topic is: not resolved