Codex Home → BuddyPress Plugin Development → Using BP Theme Compat in Plugins
Using BP Theme Compat in Plugins
A BuddyPress plugin can need to display content in several areas of a BuddyPress powered community :
In its own directory
In the member』s profile pages
In groups
The goal of this tutorial is to show you a way to take benefit of the magic that will be introduced in the next major release of BuddyPress (version 1.7) to maximize theme compatibility for BuddyPress content and for the content generated by your plugin.
In Plugin』s main directory.
When using the BP_Component class, we can specify that our plugin will have its own directory area. Here』s a quick reminder :
class BP_Plugin_Component extends BP_Component {
function __construct() {}
function includes() {
// Files to include
$includes = array(
/* some files */
'includes/bp-plugin-screen.php',
/*some other files */
);
parent::includes( $includes );
}
function setup_globals() {
$globals = array(
'slug' => 'some-slug',
'root_slug' => 'some-root-slug',
/* has_directory is set to true in order to setup plugin's main directory */
'has_directory' => true,
'notification_callback' => 'function_to_format_notification',
/* etc... */
);
parent::setup_globals( $globals );
}
function setup_nav() {}
function setup_admin_bar() {}
}
function bp_plugin_load_core_component() {
global $bp;
$bp->bp_plugin = new BP_Plugin_Component;
}
add_action( 'bp_loaded', 'bp_plugin_load_core_component' );
In this example, i』m using the file bp-plugin-screen.php in order to hold all the functions that will allow us to set the needed template for our plugin』s main directory.
So far, in order to indicate to BuddyPress the path to my plugin』s template, i used to filter the bp_located_template hook :
function bp_plugin_load_template_filter( $found_template, $templates ) {
//Only filter the template location when we're on the bp-plugin component pages.
if ( !bp_is_current_component( 'bp-plugin' ) )
return $found_template;
foreach ( (array) $templates as $template ) {
if ( file_exists( STYLESHEETPATH . '/' . $template ) )
$filtered_templates[] = STYLESHEETPATH . '/' . $template;
elseif( file_exists( TEMPLATEPATH . '/' . $template ) )
$filtered_templates[] = TEMPLATEPATH . '/' . $template;
else
$filtered_templates[] = BP_PLUGIN_DIR . '/templates/' . $template;
}
$found_template = $filtered_templates[0];
return apply_filters( 'bp_plugin_load_template_filter', $found_template );
}
add_filter( 'bp_located_template', 'bp_plugin_load_template_filter', 10, 2 );
We first check for our template file in the active theme or in the parent theme, and if nothing was found, we add to the templates array the path to our plugin template folder. Doing so, we allow themes to 「override」 and adapt the template to their design.
This done, in order to tell to BuddyPress to load the required template for my root plugin directory i filter the hook 『bp_screens『 :
function bp_plugin_screen_index() {
// i first check i'm on my plugin directory area...
if ( !bp_displayed_user_id() && bp_is_current_component( 'bp-plugin' ) && !bp_current_action() ) {
bp_update_is_directory( true, 'bp-plugin' );
//... before using bp_core_load_template to ask BuddyPress
// to load the template bp-plugin (which is located in
// BP_PLUGIN_DIR . '/templates/bp-plugin.php)
bp_core_load_template( apply_filters( 'bp_plugin_screen_index', 'bp-plugin' ) );
}
}
add_action( 'bp_screens', 'bp_plugin_screen_index' );
As you can see, when BuddyPress will run the function bp_core_load_template, which is located at line 346 of the /bp-core/bp-core-catchuri.php file (in BuddyPress 1.7-beta1), as soon as it meets the 『bp_located_template『 filter, my function 『bp_plugin_load_template_filter』 will step in to add my plugin template path. This is made possible thanks to line 379 of this file :
// Filter the template locations so that plugins can alter where they are located
$located_template = apply_filters( 'bp_located_template', locate_template( (array) $filtered_templates, false ), $filtered_templates );
In BuddyPress 1.7, this method is still working fine as soon as the community administrator is using the bundled BP Default theme or a child of it. But, if he decides to enjoy the 「BP Theme Compat」 great new feature in order to use any WordPress theme, then the content generated by our plugin will not display the best way.
To maximize this, we need to use the new hook introduced in the 1.7 version : do_action(『bp_setup_theme_compat』) which is located at line 410 of the bp_core_load_template function.
Actually, if BuddyPress haven』t found the required template then this hook is finally fired. Unlike what we』ve done just above, the funny part of this tutorial is that we first won』t tell BuddyPress what template to load if the active theme is not BP Default or a child of it.
In order to check if BP Default, or a child of it, or an eventual BuddyPress theme that is not relying on BP Default is active on the blog, i use this function :
function bp_plugin_is_bp_default() {
// if active theme is BP Default or a child theme, then we return true
// If the Buddypress version is < 1.7, then return true too
if(current_theme_supports('buddypress') || in_array( 'bp-default', array( get_stylesheet(), get_template() ) ) || ( defined( 'BP_VERSION' ) && version_compare( BP_VERSION, '1.7', ' 0,
'post_title' => 'BP Plugin Directory',
'post_author' => 0,
'post_date' => 0,
'post_content' => '',
'post_type' => 'bp_plugin',
'post_status' => 'publish',
'is_archive' => true,
'comment_status' => 'closed'
) );
}
/**
* Filter the_content with bp-plugin index template part
*/
public function directory_content() {
bp_buffer_template_part( 'bp-plugin' );
}
}
new BP_Plugin_Theme_Compat ();
Thanks to this step, we just made sure that BuddyPress will look for the bp-plugin template in the WordPress Theme or in the BP Legacy templates before trying to load it.
However, unless the active theme thought about adding this template, it won』t find it as it won』t check our plugin』s templates folder. We need to reference our plugin template folder first.
To do so, we can add a filter on the 「bp_get_template_stack」 hook in order to store our plugin path into the BuddyPress template paths :
function bp_plugin_add_template_stack( $templates ) {
// if we're on a page of our plugin and the theme is not BP Default, then we
// add our path to the template path array
if ( bp_is_current_component( 'bp-plugin' ) && !bp_plugin_is_bp_default() ) {
$templates[] = BP_PLUGIN_DIR . '/templates/';
}
return $templates;
}
add_filter( 'bp_get_template_stack', 'bp_plugin_add_template_stack', 10, 1 );
Doing so we make sure that if our template is not found in the WordPress active theme or in bp-legacy, it will be found in our plugin』s template folder. Finally we just need to adapt our plugin template in BP_PLUGIN_DIR . 『/templates/』 in order to strip the get_header, get_sidebar, and get_footer calls and to simply put our output into the new container tag 『
function bp_plugin_locate_template( $template = false ) {
if( empty( $template ) )
return false;
if( bp_plugin_is_bp_default() ) {
locate_template( array( $template . '.php' ), true );
} else {
bp_get_template_part( $template );
}
}
In the member』s profile pages
We have two choices to load our plugin template in this area. First, we can take benefit of the different hooks bundled in the members/single/plugins.php BuddyPress template to inject our plugin』s content in its member area. Three hooks can be used :
do_action( 'bp_template_content_header' );
do_action( 'bp_template_title' );
do_action( 'bp_template_content' );
Back on our component class, when setting our plugin user navigation, we specify the screen function to play :
class BP_Plugin_Component extends BP_Component {
function __construct() {}
function includes() {}
function setup_globals() {}
function setup_nav() {
$main_nav = array(
'name' => __( 'BP Plugin' ),
'slug' => BP_PLUGIN_SLUG,
'position' => 80,
/* main nav screen function callback */
'screen_function' => 'bp_plugin_main_screen_function',
'default_subnav_slug' => 'bp-plugin-subnav'
);
// Add a few subnav items under the main tab
$sub_nav[] = array(
'name' => __( 'BP Plugin' ),
'slug' => 'bp-plugin-subnav',
'parent_url' => 'link to the parent url',
'parent_slug' => 'parent slug',
/* sub nav screen function callback */
'screen_function' => 'bp_plugin_main_screen_function',
'position' => 10,
);
parent::setup_nav( $main_nav, $sub_nav );
}
function setup_admin_bar() {}
}
Now in our bp-plugin-screen.php file, we need to write some code for our screen function in order to add actions when the three different hooks will be fired to display our content, for example :
function bp_plugin_main_screen_function {
add_action( 'bp_template_content_header', 'bp_plugin_menu_header' );
add_action( 'bp_template_title', 'bp_plugin_title' );
add_action( 'bp_template_content', 'bp_plugin_content' );
bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
}
function bp_plugin_menu_header() {
_e( 'Menu Header' );
}
function bp_plugin_title() {
_e( 'Plugin title' );
}
function bp_plugin_content() {
_e( 'Plugin content');
}
We can use another approach by using a new template from our plugin』s template directory. However, unlike what we』ve accomplished earlier when we hooked 『bp_setup_theme_compat『 to display our root plugin directory content, we』ll use another method to modify the template to load as whatever happens, BP_Members_Theme_Compat will buffer the members/single/plugins template. So in our screen function, we first use the bp_core_load_template as it will be used in the BP Default case and as it will finally fire the bp_setup_theme_compat hook for any WordPress theme. Then we use our BP Default check in order to add a filter (if it returns false) to the bp_get_template_part function.
function bp_plugin_main_screen_function(){
bp_core_load_template( apply_filters( 'bp_plugin_main_screen_function', 'bp-plugin-main-user-template' ) );
//if BP Default is not used, we filter bp_get_template_part
if( !bp_plugin_is_bp_default() )
add_filter('bp_get_template_part','bp_plugin_user_template_part', 10, 3 );
}
function bp_plugin_user_template_part( $templates, $slug, $name ) {
if( $slug != 'members/single/plugins' )
return $templates;
return array( 'bp-plugin-main-user-template.php' );
}
Our bp_plugin_user_template_part will override the members/single/plugins.php BuddyPress template by our bp-plugin-main-user-template.php plugin template.
Finally, don』t forget to create the template BP_PLUGIN_DIR . 『/templates/bp-plugin-main-user-template.php』
In Group pages
here we just need to rely on the display function of the BuddyPress Group Api. In order to make sure our content will load the best way in BP Default or a child of it and any WordPress theme we can use our custom bp_plugin_locate_template function.
class BP_Plugin_Group extends BP_Group_Extension {
/** other function of group API **/
function display() {
bp_plugin_locate_template( 'bp-plugin-group-template' );
}
/** other function of group API **/
}
Finally, don』t forget to create the template BP_PLUGIN_DIR . 『/templates/bp-plugin-group-template.php』
bp_profile_field_data()
Codex Home → Developer Resources → Function Examples → bp_profile_field_data()
bp_profile_field_data()
Description
Takes a field name and outputs its corresponding field value. Can be specified by user ID.
Usage
$args = array(
'field' => 'Field Name',
'user_id' => 1
);
bp_profile_field_data( $args );
Parameters
field
(string) Name of profile field to retrieve. The default is false
user_id
(integer) Display field corresponding to a specific user. If no parameter is used, it defaults to bp_displayed_user_id()
Example
To get the current user』s 『Birthday』:
bp_profile_field_data( 'field=Birthday' );
To get User 4』s 『Hire Date』:
bp_profile_field_data( 'field=Hire Date&user_id=4' );
Source File
bp_profile_field_data() is located in bp-xprofile/bp-xprofile-template.php
为依赖 BuddyPress 的插件编写自动化测试
Codex Home → Developer Resources → Automated Testing → Writing automated tests for BuddyPress-dependent plugins
Writing automated tests for BuddyPress-dependent plugins
The automated testing suite introduced into BuddyPress after 1.7 make it easy to write unit tests for your BP-dependent plugins. Our implementation assumes that you』ll be writing your plugin tests according to wordpress-plugin-tests method. If you』re new to writing WordPress plugin tests, it』s highly recommended that you use the wordpress-plugin-tests technique (or, even easier, the wp-cli unit-tests scaffold tool.
BuddyPress provides two useful kinds of utilities that your plugin』s tests can take advantage of. We』ll discuss the two utilities briefly, and follow it with a working example.
Note: In this tutorial, we』ll be extending BP』s test suite for use in a plugin. But a similar technique could be used for BP themes, as well as for setting up integration tests for an entire, highly-customized BuddyPress installation.
BuddyPress installation and bootstrapping – If your plugin depends on BuddyPress, then you』ll need to make sure that BuddyPress is installed and running when running your tests. Establishing the proper dependencies manually can be very tricky, because BP』s setup routine requires the installation of custom tables and other important one-time configuration, and it all has to happen in a very specific order in order to have a functioning version of BuddyPress. Luckily, you don』t have to do it manually. Just require buddypress/tests/phpunit/includes/loader.php in a callback function hooked to muplugins_loaded using tests_add_filter() – right before you manually load your own plugin – and BP will make sure that (1) BP gets installed correctly, and (2) BP is fully loaded.
BP_UnitTestCase and data factories – When you use the BP_UnitTestCase class for your test cases, you automatically get access to some helpful utility methods (such as go_to(), which is sensitive to the requirements of BP URLs), as well as the BuddyPress data factories for generating groups, activity, and other BP test data. Does your plugin have additional data factories? Consider building your own _UnitTestCase that extends BP_UnitTestCase.
What follows is an annotated bootstrap.php that demonstrates the best way to take inherit BP』s unit testing tools in your own plugin』s test suite. The plugin in the example can be found at BP-CLI, and the code below is from the file bp-cli/tests/bootstrap.php. You should be able to copy and paste this code into your own tests/phpunit/bootstrap.php file – just change the paths for your plugin loader file, and your optional _UnitTestCase class file.
<?php
// The BP_TESTS_DIR constant is a helpful shorthand for accessing assets later
// on. By defining in a constant, we allow for setups where the BuddyPress
// tests may be located in a non-standard location.
if ( ! defined( 'BP_TESTS_DIR' ) ) {
define( 'BP_TESTS_DIR', dirname( __FILE__ ) . '/../../buddypress/tests/phpunit' );
}
// Checking for the existence of tests/phpunit/bootstrap.php ensures that your version
// of BuddyPress supports this kind of automated testing
if ( file_exists( BP_TESTS_DIR . '/bootstrap.php' ) ) {
// The functions.php file from the WP test suite needs to be defined early,
// because it gives us access to the tests_add_filter() function
require_once getenv( 'WP_TESTS_DIR' ) . '/includes/functions.php';
// Hooked to muplugins_loaded, this function is responsible for bootstrapping
// BuddyPress, as well as your own plugin
function _bootstrap_plugins() {
// loader.php will ensure that BP gets installed at the right time, and
// that BP is initialized before your own plugin
require BP_TESTS_DIR . '/includes/loader.php';
// Change this path to point to your plugin's loader file
require dirname( __FILE__ ) . '/../bp-cli.php';
}
tests_add_filter( 'muplugins_loaded', '_bootstrap_plugins' );
// Start up the WP testing environment
require getenv( 'WP_TESTS_DIR' ) . '/includes/bootstrap.php';
// Requiring this file gives you access to BP_UnitTestCase
require BP_TESTS_DIR . '/includes/testcase.php';
// Optional: If your plugin needs its own _UnitTestCase class, include it
// here so that it's available when your testcases are loaded
require dirname( __FILE__ ) . '/bp-cli-testcase.php';
}
模板层次结构
Codex Home → BuddyPress Theme Development → Theme Compatibility → Template Hierarchy
Template Hierarchy
A detailed look at theme compatibilities template hierarchy
BuddyPress 1.7 introduced universal theme compatibility making it easier for WordPress theme designers to work with BuddyPress.
What this means is if you are on a BuddyPress page, BuddyPress will look for a specific template file in your theme and use that template to inject its contents into.
If you』re unfamiliar with BP』s Theme Compatibility please read this guide first which explains the templates and how and where to overload them theme compatibility
The base templates that BP looks for in order of priority are:
plugin-buddypress.php
buddypress.php
community.php
generic.php
page.php
single.php
singular.php
index.php
Most of the time BP will use page.php since that template file exists in the majority of WordPress themes. However, if you wanted to style BuddyPress pages differently than a regular WordPress page, you could add a template file named buddypress.php to your theme』s directory and BP would use that template instead since that file is ahead of page.php in the hierarchy above.
See also: a-quick-look-at-1-7-theme-compatibility for an introduction to theme compatibility and how to overload the templates to your child theme
This is all fine and dandy if you wanted all your BuddyPress pages to look the same, but let』s say I wanted to style the member pages differently than group pages? You』ll notice that this isn』t quite possible.
What if BuddyPress had a more advanced template hierarchy that looked for additional template files depending on the BuddyPress page you』re on?
BuddyPress 1.8 solves this problem.
Overview of Template Hierarchy in BuddyPress
Single Member Pages
If you are on a single member page, BuddyPress will use the following template hierarchy:
(We will use the following URL as an example – example.com/members/admin/activity/mentions/)
/buddypress/members/single/index-id-{id}.php – If the member profile』s user ID is 1, BuddyPress will look to use /buddypress/members/single/index-id-1.php first.
/buddypress/members/single/index-nicename-{nicename}.php – If we look at the sample URL, the user』s nicename is admin, BuddyPress will look to use /buddypress/members/single/index-nicename-admin.php second.
/buddypress/members/single/index-action-{action}.php – If we look at the sample URL, the action is mentions, BuddyPress will look to use /buddypress/members/single/index-action-mentions.php third.
/buddypress/members/single/index-component-{component}.php – If we look at the sample URL, the component is activity, BuddyPress will look to use /buddypress/members/single/index-component-activity.php fourth.
/buddypress/members/single/index.php – If this template file is used in your theme, all member pages will use this template. BP will look to use this if the other four templates mentioned above are not found.
The rest of the base templates as listed here.
Single Member Front page
Since version 2.6.0, if a front.php template is located into the /buddypress/members/single/ directory it will be used as the home page for members profile pages. This template is not included into the BP Legacy template pack. Themes can use it to customize the Member』s home page. If you need different front pages for your users, you can use this template hierarchy:
/buddypress/members/single/front-id-{id}.php – If the member』s ID is 42, BuddyPress will look to use /buddypress/members/single/front-id-42.php first.
/buddypress/members/single/front-nicename-{nicename}.php – If the member』s nicename is 「john」, BuddyPress will look to use /buddypress/members/single/front-nicename-john.php second.
/buddypress/members/single/front-member-type-{member-type}.php – If you registered member types (see this codex page), you can use the member type name to build different front pages for each member type. For instance BP will look to use /buddypress/members/single/front-member-type-student.php if the other two templates mentioned above are not found and the displayed user has the 「student」 member type.
/buddypress/members/single/front.php – If none of the above are found.
If you have trouble determining the action or component, you could try using this small debug plugin to help output information about the current BuddyPress page.
Single Group Pages
If you are on a single group page, BuddyPress will use the following template hierarchy:
(We will use the following URL as an example – example.com/groups/my-test-group/members/)
/buddypress/groups/single/index-id-{id}.php -If the group』s ID is 1, BuddyPress will look to use /buddypress/groups/single/index-id-1.php first.
/buddypress/groups/single/index-slug-{slug}.php – If we look at the sample URL, the slug is my-test-group, BuddyPress will look to use /buddypress/groups/single/index-slug-my-test-group.php second.
/buddypress/groups/single/index-action-{action}.php – If we look at the sample URL, the action is members, BuddyPress will look to use /buddypress/groups/single/index-action-members.php third.
/buddypress/groups/single/index-status-{status}.php – Either public, private or hidden. So let』s say you wanted all private groups to have a similar look, you would want to add the following template – /buddypress/groups/single/index-status-private.php. BP will look to use this if the other three templates mentioned above are not found.
/buddypress/groups/single/index.php – If this template file is used in your theme, all group pages will use this template. BP will look to use this if the other three templates mentioned above are not found.
The rest of the base templates as listed here.
Single Groups Front page
Since version 2.4.0, we added a template hierarchy to the front.php template. This template is not included into the BP Legacy template pack. Themes can use it to customize the Group』s home page.
/buddypress/groups/single/front-id-{id}.php – If the group』s ID is 1, BuddyPress will look to use /buddypress/groups/single/front-id-1.php first.
/buddypress/groups/single/front-slug-{slug}.php – If we look at the sample URL, the slug is my-test-group, BuddyPress will look to use /buddypress/groups/single/front-slug-my-test-group.php second.
/buddypress/groups/single/front-group-type-{type}.php – (Since 2.6.0) If the group has the type of 「team」, BuddyPress will look to use /buddypress/groups/single/front-group-type-team.php next.
/buddypress/groups/single/front-status-{status}.php – Either public, private or hidden. So let』s say you wanted all public groups to have a similar front page, you would want to add the following template – /buddypress/groups/single/front-status-public.php. BP will look to use this if the templates mentioned above are not found.
/buddypress/groups/single/front.php – If none of the above are found.
If you have trouble determining the slug, action or status, you could try using this small debug plugin to help output information about the current BuddyPress page.
Activity Permalink pages
If you are on an activity permalink page, BuddyPress will use the following template hierarchy:
/buddypress/activity/single/index.php
The rest of the base templates as listed here.
Activity Directory page
If you are on the activity directory page, BuddyPress will use the following template hierarchy:
/buddypress/activity/index-directory.php
The rest of the base templates as listed here.
Member Directory page
If you are on the members directory page, BuddyPress will use the following template hierarchy:
/buddypress/members/index-directory-type-{member_type}.php when viewing member type specific directory page, {member_type} is the current member type.
/buddypress/members/index-directory.php
The rest of the base templates as listed here.
Group Directory page
If you are on the groups directory page, BuddyPress will use the following template hierarchy:
/buddypress/groups/index-directory.php
The rest of the base templates as listed here.
Group Creation page
If you are on the group creation page, BuddyPress will use the following template hierarchy:
/buddypress/groups/index-create.php
The rest of the base templates as listed here.
Site Directory page
Only applicable if you are running WordPress multisite.
If you are on the site directory page, BuddyPress will use the following template hierarchy:
/buddypress/blogs/index-directory.php
The rest of the base templates as listed here.
Site Creation page
Only applicable if you are running WordPress multisite.
If you are on the site creation page, BuddyPress will use the following template hierarchy:
/buddypress/blogs/index-create.php
The rest of the base templates as listed here.
Registration page
If you are on the registration page, BuddyPress will use the following template hierarchy:
/buddypress/members/index-register.php
The rest of the base templates as listed here.
Activation page
If you are on the activation page, BuddyPress will use the following template hierarchy:
/buddypress/members/index-activate.php
The rest of the base templates as listed here.
Codex 标准和指南
Codex Home → Participate and Contribute → Codex Standards & Guidelines
Codex Standards & Guidelines
If you are considering contributing to the codex this simple guide is here to help you with the formatting of pages and standards & conventions to follow to keep a set appearance to pages.
The Codex is curated by a team of volunteers they will check and verify articles for accuracy and adherence to Codex Standards, this is in order to maintain a consistent quality of article and standard throughout the codex. If you notice any articles of concern or think something is outdated or needs checking please contact one of the team members, if you are sure an article contains content that needs attention you may edit it and add a warning to the top of the article – please see the bottom of this page for markup to be copied and used in such circumstances.
Please note: All entries to the Codex are covered by the GNU General Public Licence. All entries may be edited or altered by other contributors.
Sections
How to Create a New Codex Article
How to Edit/Update an Article in the Codex
Codex General Guidelines
Codex Conventions
Formatting Guide
Adding article header messages
How to Create a New Codex Article
Log in using your WordPress username and password.
Click on the 「Create New Page」 link under the header or click on the 「+New > Page」 link on the WP Toolbar
Add the Title of your article
Add the article metas: Versions, Components, Types and Context. Meta boxes are located on the screen』s right sidebar
Add your article in the appropriate codex section in the Page Attributes meta box under the Context box.
For reference, please go to the BuddyPress Codex Table of Contents which is updated regularly to guide you where to place your article
Add content of your article. Check that it follows the Codex General Guidelines, Codex Conventions, and Formatting guides posted below for your reference
After you』re done, click on the 「Publish」 button
How to Edit/Update an Article in the Codex
Log in using your WordPress username and password
Navigate to the page you want to edit/update
Click on the 「Edit Page」 link under the header of the page or click on the 「Edit Page」 link on the WP Toolbar
After you have made the edit/update, please double-check that the Versions, Components, Types and Context are correct and updated as well
Click on the 「Update」 button in the Publish meta box
General Guidelines
Broad guidelines on writing for the BuddyPress Codex
When writing articles please use the second-person point of view to address the reader. e.g. 「Now navigate to your」 Rather than 「Now navigate to our「
When writing technical articles (functions, actions, etc.) please use the draft template you will find in the dashboard, copy and paste it』s body outline markup to your new post
Please keep styling to a minimum, avoid inline styling of elements unless to provide something like a color highlight if thought necessary to lend further emphasis to a piece of text e.g styling a warning in red Ensure you have backed up your DB. Please use elements sparingly , are typographic conventions and used to embolden text and italicize text for foreign & scientific words/phrases; , are to lend weight or importance to a word or phrase i.e 』em』 is not used simply to visually style text in italics
Links: External resource links: Provided to the bottom of the article framework is a section for links to external resources, please use this section for any links to resources that help further however please ensure that these links are additional resources and that your article does not depend on them for all or any part of your article explanation, the reasoning here is external links are not guaranteed to always be available and if the article relies on them and they are down then the article is effectively useless for users. Links that are not related directly to the article content are to be avoided and if found will be removed
Images: Do add images to articles where they help to illustrate your points or explanations, nothing helps illustrate things better than a timely graphic, screen shots of BuddyPress or WordPress screens help to show the reader layouts. As with links please avoid calling remote images, always upload to the media library, and embed. If uploading images please ensure you have the right to do so and are not infringing on any copyrights that may exist. Any images thought to be or that are under copyright will be removed from pages
Creating pages: When creating pages , please ensure you select a suitable 『Version』 tag, and optionally select from available 『Components』 tags & 『Types』. Please only select a parent category from the available parent sections, We request that authors DO NOT create new pages that act as parent pages for their article/s, this is to ensure the integrity of the codex structure, however it may be possible to expand the structure if thought beneficial, but please make a request for this to one of the Codex curation team members for consideration
Codex Conventions
Website Example Names: Always use example.com, example.org or example.net wherever you need to state a domain as an example. This is per RFC 2606.
Admin: The username admin describes the default administrator account of a WordPress installation in examples (admin should never be used on a live site due to negative security implications).
Using people』s names in examples: When a name is needed for an ordinary, non-admin user, or a person, use Harriet as the first name, and Smith as the last name
Administration Panels: The WordPress interface is called Administration Panels not admin panels or dashboard. Dashboard is a specific panel within Administration Panels. Individual panels are also called Administration Screens
WordPress is spelled WordPress: WordPress is spelled with two capital letters: WordPress
BuddyPress is spelled BuddyPress: BuddyPress is spelled with two capital letters: BuddyPress
With thanks to WP codex guidelines for borrowed bullet points: WP Codex:Guidelines
Formatting Guide
If writing a technical guide please use the template format provided in this draft document ( copy paste to new page ) Codex template – technical examples layout
1. Heading Tags:
Use h3 – h6. For example, on this page h3 is used for 「Sections」 above and for the title of this Section, 「Style and Formatting「.
2. Code examples: Surround your code with the appropriate shortcodes
[php] your PHP code [/php]
[html] your HTML code [/html]
Also available are bash, shell, css, diff, patch, js, javascript, plain, text, sql and xml and are used in the same format as the previous examples.
N.B: When adding code examples please escape angle brackets with Numeric/Decimal entities rather than 『Named ones, so use &# 060; and &# 062;
3. Lists: Use unordered and ordered lists where appropriate.
4. File names: Surround file names with the code tags
index.php
5. The structure of a technical guide
[Intro]
a brief intro to the guide
[/Intro][Functions]
List the functions, location, params etc.
[/Functions][Your Content]
The content body – explanation/guide.
[/Your content][Example Usage]
Provide a simple example of code use – using pre/code tags.
[/Example Usage][Additional Resources]
Add any links to off site or internal pages that might help further.
[/Additional Resources]
Flagging articles – adding article header messages
Page may be tagged in the body with two 『Notes』
1/ This page is a legacy document (at top of page)
if a page is deemed to be outdated or superseded by BP versions, or changes then it may be marked with this code block
This is Legacy Document
The details in this page have either been updated or are deprecated completely. Legacy Docs are retained for historic reference.
and the page would be re-assigned under the parent section 『legacy』
2/ This page is in need of updating
A page is considered incomplete or needs to be verified for detail.
This page is incomplete or needs checking and verifying.
将 BuddyPress 样式添加到主题
Codex Home → BuddyPress Theme Development → Theme Compatibility → Add BuddyPress Styles to a Theme
Add BuddyPress Styles to a Theme
BuddyPress 1.7 adds the ability to use any WordPress theme. The theme compatibility has a base style sheet that helps format the BuddyPress content. The styles may not be perfectly suited to your theme.
It』s very easy to add your own styles. If your theme folder has a sub folder called css you only need to add a stylesheet buddypress.css to this folder and BuddyPress will use this file overriding the BuddyPress styles. If the css folder is missing just create one and include the file inside. You can copy the buddypress.css file from the BuddyPress plugin folder and edit or create your own.
Theme Developer:
If you want to ship your theme with extra styles to support BuddyPress add the BuddyPress styles to the buddypress.css file and include it in your theme. Do not add the BuddyPress styles to your style.css file. This will ensure the styles are only loaded when BuddyPress is activated and will override the default styles supplied by the plugin.
Prefix your styles with #buddypress to target the areas of BuddyPress content.
#buddypress .activity-content {
}
*NOTE As of 1.8 you can place the file in /my-theme/community/css/ or /my-theme/buddypress/css/
GSoC 2013
Codex Home → GSoC 2013
GSoC 2013
Table of contents
Introduction
Timeline
Ideas
Introduction
Google Summer of Code is a program in which Google sponsors exceptional college students to develop open source code under the guidance of mentoring open source projects. This year, BuddyPress is hoping to be a mentoring organisation.
Know you want to propose a GSoC project around BuddyPress, but aren』t sure what you want to do? Check out our Ideas list below. If you have your own idea for a project, include it in your application and describe it thoroughly. You are not limited to ideas from this list.
Unfortunately, BuddyPress wasn』t chosen to be a mentoring organisation for 2013. However, WordPress did make it in and we can mentor BuddyPress projects under their umbrella, so if you were interested, you should check out https://codex.wordpress.org/GSoC2013 and apply through WordPress.
Timeline
March 18, 19:00 UTC: Mentoring organizations can begin submitting applications to Google.
March 29, 19:00 UTC: Mentoring organization application deadline.
April 1 – 5: Google program administrators review organization applications.
April 8 19:00 UTC: List of accepted mentoring organizations published on the Google Summer of Code 2013 site.
April 9 – 21: Would-be student participants discuss application ideas with mentoring organizations.
April 22, 19:00 UTC: Student application period opens.
May 3, 19:00 UTC: Student application deadline.
Ideas
Project: Extract Notifications into BP-Notifications Component
Brief explanation: Every part of BuddyPress has some kind of interaction with notifications. Since notifications were first introduced, they』ve always treated like second-class citizens. It』s time to elevate this functionality to the major component level it should be in.
Expected results: Make the notifications functionality into a new Notifications Component which can be activated and deactivated at will, then refactor each existing BuddyPress component to work with this new approach.
Knowledge Prerequisite: PHP, WordPress
Questions? Find this person on IRC: jjj
Project: Privacy Component
Brief explanation: Comprehensive privacy controls has been one of the most popular feature requests since the first release of BuddyPress, and while we made some small improvements in BuddyPress 1.6, there』s lots more to do. Provide users with fine, granular control over who has access to which pieces of their BuddyPress-generated personal data.
Expected results: Privacy controls for the users. API for developers to use with other plugins.
Knowledge Prerequisite: PHP, WordPress
Questions? Find any of these people on IRC: boonebgorges, jjj, paulgibbs, r-a-y
Project: Media Albums
Brief explanation: BuddyPress doesn』t have a canonical solution for handling or displaying user-generated content from their other social networks; for example, videos from YouTube and Vimeo, pictures from Flickr, music from soundcloud, and much more. Build a media album that allows users to upload images, but also pull in and display their external content.
Expected results: A media album page added to the user profiles which shows that user』s uploaded images and linked external content.
Knowledge Prerequisite: PHP, Backbone.js, WordPress
Questions? Find this person on IRC: paulgibbs
Project: Unified Activity Stream
Brief explanation: BuddyPress has distinct channels for communication: direct messages, user updates, forums, and blog post comments. This creates a fragmented experience where you』re forced to interact in a variety of different places depending on the type of content. Create a centralised place for all discussion that also routes updates back to the source. e.g. replying to a forum topic creates a reply; replying to a blog post creates a comment.
Expected results: Updated activity templates that unify discussion and act as a central point for interaction on the site.
Knowledge Prerequisite: PHP, Javascript, WordPress
Questions? Find this person on IRC: karmatosed, paulgibbs
Project: Import/Export BuddyPress Data
Brief explanation: To create a backup or migrate a BuddyPress site from one host to another, you currently require technical knowledge as this has to be done at the database/filesystem level. This is not user friendly and contributes to a perception that BuddyPress data somehow has a proprietary lock-in (anything but!). Create an importer/exporter for WordPress that migrates BuddyPress data.
Expected results: WordPress importer/exporter for BuddyPress data.
Knowledge Prerequisite: PHP, XML, WordPress
Questions? Find any of these people on IRC: boonebgorges, jjj, paulgibbs, r-a-y
会员导航菜单
Codex Home → BuddyPress Theme Development → Members Navigation Menus
Members Navigation Menus
With the stable release of BP 1.7 came the introduction of a new means of rendering the members navigational elements.
Long discussed and requested had been the desire to have the menu navigation rendered as a true UL construct with sub menu items as correctly nested ul/li elements as this would allow for not only a far better semantic description of this aspect of nav links but allow for a far greater range of options and flexibility in being able to style them e.g as drop down or fly out sub menu items.
Historically BP rendered the navigational elements as two separate functions bp_get_displayed_user_nav() & bp_get_options_nav() for the child elements making things quite hard to style effectively.
Thanks to the work Paul Gibbs ( @DJPaul ) put in over the 1.7 release cycle we now have a solution and a new template function we can use to replace bp_get_displayed_user_nav() et al. without further ado we welcome to the mix in a fanfare of glory:
bp_nav_menu()
This one function now replaces the previous two to render a true navigational nested UL construct.
Using the function
Using this function really is pretty straightforward however there are a number of aspects that need to be considered and dealt with by the developer.
To use the function we would need to modify the markup in /members/single/home.php by finding this section:
and replacing it with:
In the individual template pages e.g /members/single/activity.php this function needs to be removed from the div#subnav:
Additional Considerations
The above examples are a guide and may need further refining, for instance now the top level parent div 『#object-nav』 could be considered redundant and removed ( it』s left there in the example for the moment as it shouldn』t harm) The same can be said for the parent div 『#subnav』.
In the #subnav we have filters on tabs such as 『Activity』 these are essentially hardcoded select elements that reside in the now redundant ul wrapper in #subnav, in theory it ought to be safe to move this series of elements around as long as one pays attention to class/id tokens so as to not upset any Ajax/JS functionality ( in 1.7 we attempted to unchain JS functions from element selectors i.e 『div』 to instead just hooking on the class or id token alone to allow for greater flexibility in marking up these sorts of elements.)
Styling: At present it is up to the developer implementing this new nav function to understand that they will need to build a series of rulesets to handle the hide /show of child nav items – the elements have all been given appropriate class tokens to aid this. In time and given time perhaps some generic snippets might be provided somewhere for people to download to give them a head start ( the experimental project managed by @DJPaul and @karmatosed 『Turtleshell』 will probably incorporate this new function and basic styling)
Filters, Walkers, Args
The function has been fully scoped with filters, function args, and a walker function.
View the Changeset to see all that can be modified but briefly:
The function can take a series of arguments to modify aspects of the display such as parent elements or classes, this mirrors the functionality of the WP wp_nav_menu() so usage will be familiar to anyone :
$defaults = array(
'after' => '',
'before' => '',
'container' => 'div',
'container_class' => '',
'container_id' => '',
'depth' => 0,
'echo' => true,
'fallback_cb' => false,
'items_wrap' => '
- %3$s
',
'link_after' => '',
'link_before' => '',
'menu_class' => 'menu',
'menu_id' => '',
'walker' => '',
);
There are a full range of filters provided so that you can do things like filter new li items as shown below:
$items = apply_filters( 'bp_nav_menu_items', $items, $args );
This is a brief glimpse of this new function but one that will see increasing usage and deserves a big thanks to DJPaul and the rest of the core lead development team for pulling this out of the hat.
bp_activity_action_spam_activity()
Codex Home → Developer Resources → Function Examples → bp_activity_action_spam_activity()
bp_activity_action_spam_activity()
bp_activity_action_spam_activity($activity_id=0) is a function that simply allows you to flag Budddypress Activity, like comments or activity updates as spam.
Source File
bp_activity_action_spam_activity() is located in bp-activity/bp-activity-actions.php
过滤器和常量参考
Codex Home → Developer Resources → Filters & Constants Reference
Filters & Constants Reference
BuddyPress Core Filters and Constants
BudyPress provides a series of filters and constants you can add to your bp-custom.php or functions.php files to modify the behaviour of your BP install. These range from defining the avatar sizes BP will look for as defined defaults to filters that can be set to deactivate components fully such as @mentions
Constants
Define default values for BP avatars – shown are the BP default values; 『ORIGINAL_MAX_FILESIZE』 is a value generally taken from WP site settings.
?123456define( 'BP_AVATAR_THUMB_WIDTH', 50 );define( 'BP_AVATAR_THUMB_HEIGHT', 50 );define( 'BP_AVATAR_FULL_WIDTH', 150 );define( 'BP_AVATAR_FULL_HEIGHT', 150 );define( 'BP_AVATAR_ORIGINAL_MAX_WIDTH', 450 );define( 'BP_AVATAR_ORIGINAL_MAX_FILESIZE', 5120000 );
Force BP to display usernames with spaces
?1define('BP_ENABLE_USERNAME_COMPATIBILITY_MODE', true);
Define the user account tab that is designated as the default to open with
?1define( 'BP_DEFAULT_COMPONENT', 'profile' )
Do the same as user account screens default page for Groups.
?1define( 'BP_GROUPS_DEFAULT_EXTENSION', 'members' );
Enabling this constant allows you remove the portion of the url path /members/ and have your member name at the 『Root『 of the domain url. N.B. If you use BP_ENABLE_ROOT_PROFILES there might be a situation where some user profiles get the same url as some posts or pages rendering either of them inaccessible. This might also be true of sub-sites if you』re running multisite with subdirectories. See ticket #1426 for more information.
?1define('BP_ENABLE_ROOT_PROFILES', true )
Allow User screens to be viewed under the domain path of MS sub domains / sub directories N.B. As of 1.7 it is recommended not to define this constant as BP will activate on individual sites.
?1define( 'BP_ENABLE_MULTIBLOG', true );
Enable private messaging to all users
By default you can only send private messages to people in your friends list, to change this behaviour you can add this constant to your wp-config.php or bp-custom.php file
?1define( 'BP_MESSAGES_AUTOCOMPLETE_ALL', true );
If you do allow this please consider that it allows possible spamming of you members , this is why if only friends can PM it』s by consent.
Filters
BP functions are well specified with filters available for most of them, these are a few that are provided to act as simple switches.
BP @-mention functionality is enabled by default If you don』t wish to use @-mentions, disable them completely.
?1add_filter( 'bp_activity_do_mentions', '__return_false' );
BP by default converts certain strings in user profiles to links, to disable this behaviour add:
?1remove_filter( 'bp_get_the_profile_field_value', 'xprofile_filter_link_profile_data', 9, 2 );
Admin Bar: Since BP 1.6 the default behaviour has been to use the WP adminbar for BP related links deprecating the older BP buddybar
You may alter this behaviour and return to using the older style buddybar by adding this filter
?1add_filter('bp_use_wp_admin_bar', __return_false);