Skip to:
Content
Pages
Categories
Search
Top
Bottom

Re: Limit Blog Creation to Admins


Burt Adsit
Participant

@burtadsit

We’ve unhooked the current fns and hooked up our replacement fns. So far they do exactly the same thing as the current fns. We need the ability to decide who gets to see the menu item. I choose to create yet another fn to decide yes or no on blog creation.

function my_can_user_create_a_blog(){

if (is_site_admin())

return true;

else

return false;

}

That goes in bp-custom.php also. Ya, all it does is check if the current user is the site admin. I’m not sure what you mean by only letting ‘Admins’ create blogs. There are blog admins and one site admin. Everyone with a blog gets to have the wp role ‘administrator’. Not sure what you want so i’ve wrapped the logic in a fn so you can change it to whatever you like.

Now we need to alter our new replacement fns to skip the display of the menu items if that returns false.

In our my_blogs_setup_nav() there is a line like this:

bp_core_add_subnav_item( $bp->blogs->slug, ‘create-a-blog’ __(‘Create a Blog’,

‘buddypress’), $blogs_link, ‘bp_blogs_screen_create_a_blog’ );

We need to wrap it like this:

if (my_can_user_create_a_blog()){

‘bp_core_add_subnav_item( $bp->blogs->slug, ‘create-a-blog’Create a Blog’,’buddypress’), $blogs_link, ‘bp_blogs_screen_create_a_blog’ );

}

Also the function my_adminbar_blogs_menu() has code that looks like this:

echo '<li' . $alt . '>';
echo '<a href="' . $bp->loggedin_user->domain . $bp->blogs->slug . '/create-a-blog">'
. __('Create a Blog!', 'buddypress') . '</a>';
echo '</li>';

You need to wrap that the same way:

if (my_can_user_create_a_blog()){

..all that stuff..

}

Skip to toolbar