BP_ENABLE_MULTIBLOG

BP_ENABLE_MULTIBLOG

Codex Home → Getting Started → Customizing → BP_ENABLE_MULTIBLOG
BP_ENABLE_MULTIBLOG

This page is incomplete or needs checking and verifying or updating.

BP_ENABLE_MULTIBLOG is a BuddyPress constant that, when defined as true, allows your BuddyPress content to be displayed on any site in your WordPress Multisite network.
By default, BP_ENABLE_MULTIBLOG is disabled.
Description
On a normal BuddyPress installation (with BP_ENABLE_MULTIBLOG disabled), BuddyPress content – groups, profiles, etc – can only be viewed on the 「root blog」. So, for example, your BuddyPress profile is, by default, located at a URL that looks like this:
http://example.com/members/boonebgorges/
and it is displayed using the BuddyPress theme powering your root blog at http://example.com/. This is true even if you allow users to create subdomain or subdirectory blogs, such as http://boone.example.com/ or http://example.com/boone/ – links to BuddyPress content, such as those that appear in your BuddyBar or WP toolbar, will always point back toward the root blog.
With BP_ENABLE_MULTIBLOG enabled, BuddyPress content will be displayable on any site in your network, and BP links will always point to the current site. Thus,
on http://boone.example.com/, profile links will point to http://boone.example.com/members/boonebgorges/
on http://example.com/boone/, profile links will point to http://example.com/boone/members/boonebgorges/
on http://example.com/, profile links will point to http://example.com/members/boonebgorges
and so forth.
Usage
To turn on BP_ENABLE_MULTIBLOG mode, put the following line in your wp-config.php file, somewhere above 「That』s all, stop editing!」:
define( 'BP_ENABLE_MULTIBLOG', true );
Some warnings about BP_ENABLE_MULTIBLOG
BP_ENABLE_MULTIBLOG is not appropriate for most situations, and you should be sure to understand its limitations carefully before enabling it.

Note that BP_ENABLE_MULTIBLOG is not the same thing as WordPress Multisite, and BP_ENABLE_MULTIBLOG is not necessary for your users to have their own sites/blogs.
BP_ENABLE_MULTIBLOG does not enable separate BuddyPress networks on your installation. While it will be possible to view boonebgorges』s profile at more than one URL, the profile data itself (and group data, etc) will be the same on each site in your network. For multi-network BuddyPress, see https://wordpress.org/extend/plugins/bp-multi-network/.

Example use case
Enabling BuddyPress content to be displayable on any site in your network can be useful when supporting multilingual versions of your site.
If your setup has a separate site for each language, then setting BP_ENABLE_MULTIBLOG to true allows you to access the BuddyPress pages in each language, e.g.:
http://mysite.com/members
http://french.mysite.com/members
http://spanish.mysite.com/members
http://german.mysite.com/members
Using a separate site for each language is one of the common approaches to multilingual web sites.  In the WordPress specific world, it』s the approach that』s adopted by the Multilingual Press plugin https://wordpress.org/plugins/multilingual-press/.
[Note: a future challenge is how to handle multisite networks, where we want to allow some sites to support BuddyPress pages, but disable support on other sites in the network.  As well as underlying implementation, 『Super Admin』 controls to manage this would be useful.]

groups_get_groupmeta()

groups_get_groupmeta()

Codex Home → Developer Resources → Function Examples → groups_get_groupmeta()
groups_get_groupmeta()

Function to get custom group meta.
If you don』t pass a meta_key it returns ALL meta data associated with that group_id.
Returns String or Array of Meta Values.
Odd Behavior: If you pass no meta key to get all values and it has none, it returns a blank array. If you passed a key it returns a blank string.
groups_get_groupmeta( $group_id, $meta_key = '');
See also groups_update_groupmeta()
Source File
groups_get_groupmeta() is located in bp-groups/bp-groups-functions.php

如何编辑群组元数据教程

如何编辑群组元数据教程

Codex Home → BuddyPress Plugin Development → How to Edit Group Meta Tutorial
How to Edit Group Meta Tutorial

This tutorial will show you how to add a custom field to the registration process as well as the admin->」edit details」 section. I will also show you how to print that out into the header and how to echo that data elsewhere.
We are going to do this as a standalone plugin but you could easily add this to your existing plugins or even your functions.php (without the plugin header data)
Firstly create a folder in your wp-contents/plugins folder. Call it whatever you want this plugin to be called. Lets call ours 「Favorite Color」 Then create a file inside. Mines called favorite_color.php Open that file up and start with:


<input id="favorite-color" type="text" name="favorite-color" value="" />

<?php
}

This outputs a label and input field that gets added to the already existing form during registration and editing. That』s why there is no input or other form data.
We created the id and name based upon  whatever we want to name the field. We then call our custom_field() function with that meta data to see if a value already exists. It wont return anything during the signup process but it will afterwards.
// This saves the custom group meta – props to Boone for the function
// Where $plain_fields = array.. you may add additional fields, eg
//  $plain_fields = array(
//      'field-one',
//      'field-two'
//  );
function group_header_fields_save( $group_id ) {
global $bp, $wpdb;
$plain_fields = array(
'favorite-color'
);
foreach( $plain_fields as $field ) {
$key = $field;
if ( isset( $_POST[$key] ) ) {
$value = $_POST[$key];
groups_update_groupmeta( $group_id, $field, $value );
}
}
}

This is a pretty hefty function. It takes the passed data and saves it into the group meta. The reason they use the array and the foreach statement is in the event you want to add multiple fields. It would be a pain to rewrite the code over and over. this way you simply add a comma and a new field name. It then checks to see if there is a post object with the same name. (which if coming from the registration or edit forms we hooked into earlier it will) It then updates the meta accordingly.
Now we hook our functions into BuddyPress:
add_filter( 'groups_custom_group_fields_editable', 'group_header_fields_markup' );
add_action( 'groups_group_details_edited', 'group_header_fields_save' );
add_action( 'groups_created_group',  'group_header_fields_save' );

The first fires any time there is editable fields in BuddyPress and adds our nice input form. The next two are added when any of that data is normally posted and saved.
At this point you should be able to test your plugin. Activate it from the plugin menu and then attempt to create a group. Your field should show up at the bottom. Enter all the data you have and then continue through the process. Once the group is created click admin and look at the edit screen. Your field should be here as well, populated with the data from the registration process.
This next function adds that info to the group header info:
// Show the custom field in the group header
function show_field_in_header( ) {
echo "

My favorite color is:" . custom_field('favorite-color') . "

";
}
add_action('bp_group_header_meta' , 'show_field_in_header') ;

this hooks into the header action and adds our code to the bottom.
Now you can get the group meta using simply groups_get_groupmeta and echo it out wherever you』d like. Just be sure to pass the group_ID or it wont return anything. You can do what I did and use bp_get_group_id() as long as you know you will be in a group loop. I may come back and add more on how to access that data but if you』ve made it this far you have all the tools you』ll need!
Full Code:


<input id="favorite-color" type="text" name="favorite-color" value="" />

<?php }
// This saves the custom group meta – props to Boone for the function
// Where $plain_fields = array.. you may add additional fields, eg
//  $plain_fields = array(
//      'field-one',
//      'field-two'
//  );
function group_header_fields_save( $group_id ) {
global $bp, $wpdb;
$plain_fields = array(
'favorite-color'
);
foreach( $plain_fields as $field ) {
$key = $field;
if ( isset( $_POST[$key] ) ) {
$value = $_POST[$key];
groups_update_groupmeta( $group_id, $field, $value );
}
}
}
add_filter( 'groups_custom_group_fields_editable', 'group_header_fields_markup' );
add_action( 'groups_group_details_edited', 'group_header_fields_save' );
add_action( 'groups_created_group',  'group_header_fields_save' );

// Show the custom field in the group header
function show_field_in_header( ) {
echo "

My favorite color is:" . custom_field('favorite-color') . "

";
}
add_action('bp_group_header_meta' , 'show_field_in_header') ;
}
add_action( 'bp_include', 'bp_group_meta_init' );
/* If you have code that does not need BuddyPress to run, then add it here. */
?>

Props to Charl Kruger for his post: http://charlkruger.com/2011/12/07/getting-started-with-buddypress-group-meta

groups_group_create_complete()

groups_group_create_complete()

Codex Home → Developer Resources → Function Examples → groups_group_create_complete()
groups_group_create_complete()

Quick Note on group creation,
When a group first gets created it fires multiple actions some times multiple times.
For example, groups_create_group and groups_created_group fire first on the initial details page, and AGAIN when the group is actually created.
To bind to when the group is ACTUALLY created use groups_group_create_complete.
so:
?1add_action( 'groups_group_create_complete',  'my_function' );

bp_core_new_nav_default()

bp_core_new_nav_default()

Codex Home → Developer Resources → Function Examples → Core Component → bp_core_new_nav_default()
bp_core_new_nav_default()

This function changes the default subnav item of a parent item.
Example:
function change_settings_subnav() {
$args = array(
'parent_slug' => 'settings',
'screen_function' => 'bp_core_screen_notification_settings',
'subnav_slug' => 'notifications'
);

bp_core_new_nav_default($args);
}
add_action('bp_setup_nav', 'change_settings_subnav', 5);

This changes the default subnav of the 「Settings」 nav item to 「Notifications」
NOTE: The 5 priority flag is required
Source File
bp_core_new_nav_default() is located in bp-core/bp-core-buddybar.php

论坛 (Forums)

论坛 (Forums)

Codex Home → Legacy Docs → Archived Section: Getting Started → Forums
Forums

Archived file. Good only up to BP 1.5 version

bbPress 2.2+ Update
Using bbPress 2.2+ with BuddyPress

BuddyPress 1.5 Update
: Installation of BuddyPress 1.5+ Group Forums and Sitewide Forums

Introduction for Forums in BP 1.2+
BuddyPress 1.1 introduces a new way of thinking about how forums function around a social setup. Instead of having a categorical, separated top-down list of forums, they are now fully integrated and attached to groups that can be created and controlled by any registered user. The included default theme shows all recent topics regardless of their group (public groups only).
With previous versions of BuddyPress, integrating bbPress often required special attention and little voo-doo magic. Even getting basic functions like shared logins and template styles working together on both sides was not an easy task. In BuddyPress 1.1 this all works with one click. Thanks to a robust set of classes and functions, BuddyPress controls your forums transparently, eliminating all previous integration pains. No more cookie headaches, no more 「deep integration」 because bbPress』s functions are available right within BuddyPress.
Another benefit of this approach is an integrated theme. There is no need to create a completely separate bbPress theme for your forums. Your existing BuddyPress enabled WordPress theme will control the design.
Extensions to bbPress and BuddyPress forum support can be added through WordPress plugins. Some existing bbPress plugins that do not require an admin interface can be added via the mu-plugins folder in WordPress MU. They can also be converted to a standard WordPress plugin.
Previous Installations
If you』d prefer to use the previous integration method for your existing forum setup, this is still possible. In this scenario BuddyPress will use its own internal bbPress files for group forum support, while your existing external bbPress installation will continue to work as it did. Both sets of bbPress files will use the same existing database tables. However, you will need to go through the upgrade instructions below before BuddyPress group forums will work again.
Upgrading from 1.0 to 1.1
After upgrading BuddyPress to 1.1, head to the 「WP-Admin ? BuddyPress ? Forum Setup」 menu and a wizard will run you through the re-connection process. BuddyPress will create a bb-config.php file at the root of your WordPressMU installation. This file is automatically generated and will not require additional editing for your group forums to function.
Existing or New installation?
If you have an existing bbPress installation or a previously integrated BuddyPress1.0 setup, do not choose to create a new installation as this will break your existing group forums. Instead choose existing installation, so that your old bbPress database will be retained.
If you do not have an existing bbPress installation, select new installation and BuddyPress will take care of everything for you.
If you have an external bbPress database that does not use the same database as your WordPressMU installation, this is considered an atypical installation and is not currently supported by the BuddyPress1.1 upgrade process.
Process for installing bbPress included with BuddyPress
(1) Install bbPress within the wp-admin panel
In the wp-admin panel > BuddyPress > Forums Setup
(2) Each group now has access to enabling a forum. Go to Group Settings for each group Group > Admin > Edit Settings. There is a checkbox for enabling the forum. Once enabled then the link for a forum for that particular group becomes available

升级 BuddyPress

升级 BuddyPress

Codex Home → Legacy Docs → Archived Section: Getting Started → Upgrading BuddyPress
Upgrading BuddyPress

Upgrading from an earlier version of BuddyPress? No problem, please follow the instructions that match your situation.
BACKUP – this cannot be emphasized enough! Make a copy of your database and all files before upgrading. There have been major changes in the latest version of BuddyPress and you will want a copy of your existing setup to fall back on if needed.
Upgrading from 1.5.x to 1.6
BuddyPress 1.6 requires WordPress 3.4 and has its own upgrade page, with information and advice about the upgrade process. You may also be interested in BP 1.6』s list of features and fixes.
Upgrading from 1.2.x to 1.5
BuddyPress 1.5 has its own upgrade page, with information and advice about the upgrade process. You may also be interested in BP 1.5』s list of features and fixes.
Upgrading from 1.1.x to 1.2.5

Deactivate any BuddyPress plugins and then deactivate BuddyPress.
If you are not going to use the new default theme, please download, install and activate the BuddyPress backwards compatibility plugin.
Upgrade BuddyPress automatically, or download BuddyPress and overwrite your existing copy.
Delete 「bp-default」 and 「bp-sn-parent」 from your themes directory.
If you are using your own custom theme from 1.1, you will need to add define( 'BP_CLASSIC_TEMPLATE_STRUCTURE', true ); to your wp-config.php file above the 「stop editing」 line.
Activate BuddyPress. You do not need to move any themes in this version.

Upgrading from 1.0.x to 1.2.x
To upgrade from BuddyPress 1.0 to 1.2 you will first need to download version 1.1 and upgrade manually by overwriting the existing BuddyPress plugin folder. Once you are running 1.1, please follow the instructions for upgrading from 1.1.
It』s important to note that if you are still using the old two theme setup (member theme & home theme) then this will no longer work in version 1.2. You will need to merge your theme into one. If you are running a standard WordPress theme as the home theme, you may want to read this guide to running BuddyPress on a sub blog. If you are running a bbPress integration you will need to run through the bbPress connection wizard under 「BuddyPress > Forums Setup > Use Existing install..」 in your wp-admin area after upgrading to 1.2.

已弃用

已弃用

Codex Home → Developer Resources → Deprecated
Deprecated

The following functions are considered deprecated as of BuddyPress 1.1. They will still work, but have been replaced by newer, more powerful functions. In the future, codex documentation will link current and deprecated functions together so you can see the differences and understand how to migrate from one to the other.

bp_core_new_nav_item()

bp_core_new_nav_item()

Codex Home → Developer Resources → Function Examples → Core Component → bp_core_new_nav_item()
bp_core_new_nav_item()

Description
Adds a navigation item to the main navigation array used in BuddyPress themes.
Example Usage
The snippet below is taken from bp-messages.php, and is used to add the main 「Messages」 link to the user navigation.
bp_core_new_nav_item(
array(
'name' => __('Messages', 'buddypress'),
'slug' => $bp->messages->slug,
'position' => 50,
'show_for_displayed_user' => false,
'screen_function' => 'messages_screen_inbox',
'default_subnav_slug' => 'inbox',
'item_css_id' => $bp->messages->id
));

As you can see above, this menu item is not displayed when viewing another users profile, it will call the 『messages_screen_inbox』 function when clicked, and will take you to your 『inbox』 sub navigation when clicked. It is also given the ID of the internal core component set from within BuddyPress, so that it can be styled later with an icon.
Parameters
name
String | Required | The display name for the navigation item.
slug
String | Required | The URL slug for the navigation item.
item_css_id
String | Optional/Recommended | Default: FALSE | The ID to give the navigation item in HTML for CSS styling.
show_for_displayed_user
Boolean | Optional | Default: TRUE | Determines if this navigation item appears when viewing another users profile.
site_admin_only
Boolean | Optional | Default: FALSE | Set to TRUE if a menu item is only to be seen by site admins (See is_site_admin())
position
Integer | Optional | Default: 99 | Index of where this navigation item appears in the list. Lower numbers appear sooner than higher numbers.
screen_function
String | Optional | Default: FALSE | Name of function to run when the navigation item is clicked.
default_subnav_slug
String | Required | Sets which sub navigation item is selected when this root navigation item is clicked. If you do not have sub navigation – use the same value used for slug.
Notes
It』s important to note that if either the 『slug』 or the 『name』 are omitted, this function will return false and no menu item will be created.
This function replaces bp_core_add_nav_item(), which was deprecated in BuddyPress 1.1.
Related Functions

bp_core_remove_nav_item()
bp_core_sort_nav_items() – deprecated since 2.6
bp_core_new_subnav_item()
bp_core_sort_subnav_items() – deprecated since 2.6
bp_core_remove_subnav_item()
bp_core_reset_subnav_items()

Source File
bp_core_new_nav_item() is located in bp-core/bp-core-buddybar.php

安装

安装

Codex Home → Getting Started → Installation
Installation

Before installing BuddyPress, please make sure that you』ve checked the minimum server requirements and WordPress version compatibility.
Automated Installation

Download and install WordPress.
Head to your 「Plugins → Add New」 menu in wp-admin. Search and install 『BuddyPress』.
Make sure you have pretty permalinks enabled on your WordPress install.
Activate BuddyPress. You will be redirected to the BuddyPress Welcome screen.

Manual Installation

Download BuddyPress.
Upload the plugin to the wp-content/plugins folder in your WordPress directory online using your favorite FTP program.
Make sure you have pretty permalinks enabled on your WordPress install.
Go to your admin dashboard → Plugins → Installed Plugins
Activate BuddyPress. You will be redirected to the BuddyPress Welcome screen.

⇒ Next: Configure BuddyPress
⇐ Previous: Getting Started