BuddyDev

Search

[Resolved] Hide the Tab "New Post" in BuddyBlog Plugin

  • Participant
    Level: Master
    Posts: 496
    Daniel on #13995

    Hi,

    I am using the BuddyBlog Plugin and I would like to hide the tab “New Post” in order that the members cannot write new post this way, as I am using another plugin to write posts.

    Has someone a solution to hide this “New Post” Tab ?

    Thank you.

    Kind regards,
    Daniel

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2908
    Ravi on #13999

    Hello Daniel,

    Please try the following code in your “bp-custom.php” and let me know if it works or not.

    
    
    function buddydev_remove_new_post_tab() {
        bp_core_remove_subnav_item( buddypress()->buddyblog->slug, 'edit' );
    }
    add_action( 'bp_buddyblog_setup_nav', 'buddydev_remove_new_post_tab' );
    
    function buddydev_remove_admin_new_post_tab( $wp_admin_nav_items ) {
        $new_admin_items = array();
    
        foreach ( $wp_admin_nav_items as $wp_admin_nav_item ) {
    
            if ( $wp_admin_nav_item['id'] == 'my-account-' . buddypress()->buddyblog->id . '-new-post' ) {
                continue;
            }
    
            $new_admin_items[] = $wp_admin_nav_item;
        }
    
        return $new_admin_items;
    }
    add_filter( 'bp_buddyblog_admin_nav', 'buddydev_remove_admin_new_post_tab' );
    

    For “bp-custom.php” you can refer followin url:
    https://codex.buddypress.org/themes/bp-custom-php/

    Thank You
    Ravi

  • Participant
    Level: Master
    Posts: 496
    Daniel on #14060

    Hi Ravi,

    Thanks for your reply.

    I have created the bp-custom.php file as per the link you have provided and I have copy your code inside the file and added the file under wp-content/plugins.

    Unfortunately, the code you have provided did not work. I still can see the “New Post” Tab.

    Kind regards,
    Daniel

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2908
    Ravi on #14063

    Hello Daniel,

    Just paste me the whole file code of the file “bp-custom.php” so that I can check. You can post the code into pastebin.

    https://pastebin.com/

    Thank you
    Ravi

  • Participant
    Level: Master
    Posts: 496
    Daniel on #14064

    Hi Ravi,

    Basically, I had no bp-custom.php file, so what I did was I have created an empty bp-custom.php file and I have copied your code you have provided into the empty bp-custom.php file.

    Therefore, the whole file code of my bp-custom.php file is the same as the code you have provided above. Means, there is no other code included other than your code.

    I hope this helps.

    If you want you can send me an email and I will attach the bp-custom.php file and send you back an email.

    Thank you and please let me know if I can provide any further information.

    Kind regards,
    Daniel

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2908
    Ravi on #14065

    Hello Daniel,

    Thank you for the clarification seems you have not included “<?php” tag. Just remove the old code and paste the following code into that file

    
    
    <?php
    
    function buddydev_remove_new_post_tab() {
    	bp_core_remove_subnav_item( buddypress()->buddyblog->slug, 'edit' );
    }
    add_action( 'bp_buddyblog_setup_nav', 'buddydev_remove_new_post_tab' );
    
    function buddydev_remove_admin_new_post_tab( $wp_admin_nav_items ) {
    	$new_admin_items = array();
    
    	foreach ( $wp_admin_nav_items as $wp_admin_nav_item ) {
    
    		if ( $wp_admin_nav_item['id'] == 'my-account-' . buddypress()->buddyblog->id . '-new-post' ) {
    			continue;
    		}
    
    		$new_admin_items[] = $wp_admin_nav_item;
    	}
    
    	return $new_admin_items;
    }
    add_filter( 'bp_buddyblog_admin_nav', 'buddydev_remove_admin_new_post_tab' );
    
    

    and let me know if it works or not

    Thank You
    Ravi

  • Participant
    Level: Master
    Posts: 496
    Daniel on #14093

    Hi Ravi,

    I have tested the code and the tab “New Post” has disappeared with success.

    But the problem now is, that the user cannot EDIT his post anymore after I have inserted your code.

    When the user wants to EDIT his post, then the user gets redirected to the search page and it says:

    “It looks like nothing was found at this location. (And then it shows the Search bar underneath.)

    I only want that the “New Post” Tab disappears and not more. But I still would like that the user can EDIT his post.

    Is there a way to only hide the “New Post” Tab but that the user still can EDIT his post ?

    Thank you for your support.

    Kind regards,
    Daniel

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2908
    Ravi on #14100

    Hello Daniel,

    Replace the previous code with the following code. It will only show tab on edit post screen.

    
    function buddydev_remove_new_post_tab() {
    	if( ! buddyblog_is_edit_post() ) {
    		bp_core_remove_subnav_item( buddypress()->buddyblog->slug, 'edit' );
    	}
    }
    add_action( 'bp_buddyblog_setup_nav', 'buddydev_remove_new_post_tab' );
    
    function buddydev_remove_admin_new_post_tab( $wp_admin_nav_items ) {
    
        if ( ! buddyblog_is_edit_post() ) {
    	    $new_admin_items = array();
    
    	    foreach ( $wp_admin_nav_items as $wp_admin_nav_item ) {
    
    		    if ( $wp_admin_nav_item['id'] == 'my-account-' . buddypress()->buddyblog->id . '-new-post' ) {
    			    continue;
    		    }
    
    		    $new_admin_items[] = $wp_admin_nav_item;
    	    }
    
    	    return $new_admin_items;
        }
    
        return $wp_admin_nav_items;
    }
    
    add_filter( 'bp_buddyblog_admin_nav', 'buddydev_remove_admin_new_post_tab' );
    
    

    And let me know if it works or not.

    Regards
    Ravi

  • Participant
    Level: Master
    Posts: 496
    Daniel on #14102

    Hi Ravi,

    It works, that’s great! Thank you very much!

    Kind regards,
    Daniel

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2908
    Ravi on #14109

    Hello Daniel,

    Thank you for the acknowledgement. I am glad I could help.

    Thank You
    Ravi

The topic ‘ [Resolved] Hide the Tab "New Post" in BuddyBlog Plugin’ is closed to new replies.

This topic is: resolved