为新功能更新自定义主题

为新功能更新自定义主题

Codex Home → BuddyPress Theme Development → Updating Custom Themes For New Functionality
Updating Custom Themes For New Functionality

This section is your guide to BuddyPress theme updates, by version release.
From time to time Buddypress creates new functionality that requires templates and markup adjustments, adds new JavaScript scripting and perhaps requires CSS properties supporting these additions.
If your BuddyPress installation is a particularly custom one, that is, you have overloaded template files to your theme or child theme, maybe copied JS and CSS files as well and even running your own BuddyPress functions setup you will not necessarily inherit these new features, this section will list these changes grouped under version release numbering detailing just what template files, js, css you need to update in your theme.

Theme Updates for BP 2.7
Template updating and changes

Theme Updates for BP 2.2
Template updating and changes

Theme Updates for BP 2.1
Template updating and changes

Twenty Ten Theme 二〇一〇主题

Twenty Ten Theme 二〇一〇主题

Codex Home → BuddyPress Theme Development → BP Theme Compatibility and the WordPress Default Themes → Twenty Ten Theme
Twenty Ten Theme

A. One column Layout
One column Layout. Click on image to enlarge.If you prefer to have a one column layout for all your BuddyPress pages, follow the steps below.
1. Create a child theme of the Twenty Ten theme.
2. Create a new file in your new child theme folder and name it buddypress.php.
3. The Twenty Ten theme has a one column page template, fortunately. All you need to do is copy over the entire source code of Twenty Ten』s onecolumn-page.php file into the new buddypress.php file and save file.
?1234567891011121314151617         

            

                             

        

 
4. Upload your Twenty Ten child theme folder to your server.
B. Full-width page Layout
Full-width Layout. Click on image to enlarge.If you prefer to have a full-width layout for all your BuddyPress pages, follow the steps below.
1. Create a child theme of the Twenty Ten theme.
2. Create a new file in your new child theme folder and name it buddypress.php.
3. Copy over the content of Twenty Ten theme』s onecolumn-page.php file into the new buddypress.php file.
?1234567891011121314151617         

            

                               

        

 
5. We will simply copy the theme』s one column style and then prepend the buddypress body class to override the theme』s one column styling. Open up your child theme』s style.css file and add the following at the bottom of the file then save the file.
?1234.buddypress #container.one-column {        margin: 0;        width: 100%;}
6. Upload your Twenty Ten child theme folder to your server.
C. Two Column, Right Sidebar Layout
Two-column Layout. Click on image to enlarge.This is the default page layout of the Twenty Ten theme. There is no need to do anything more if this is the layout you prefer for all your BuddyPress pages.
However, if you want to customize the sidebar content of all your BP pages, you can do so by: a) using a plugin like Widget Logic to assign widgets to specific pages by using conditional tags or b) by creating new buddypress.php and sidebar-buddypress.php files and registering a new widget area in your child theme』s functions.php file. The following steps are for the second option.
1. Create a child theme of the Twenty Ten theme.
2. Create a new file in your new child theme folder and name it buddypress.php.
3. Open up the page.php file of the Twenty Ten theme and copy all content within and paste that content into your new buddypress.php file. Then change to and save file.
?123456789101112131415161718         

            

                               

        

 
4. If you don』t have a functions.php file in your child theme, create one. You』ll need to register the new widget area for your BP sidebar in that functions.php file like so:
?1234567891011121314 __( 'BuddyPress Sidebar Widget Area', 'mmechildtheme' ),        'id'            => 'bp-sidebar',        'description'   => __( 'Appears in the sidebar section of all BuddyPress pages.', 'mmechildtheme' ),        'before_widget' => '

  • ',        'after_widget'  => '
  • ',        'before_title'  => '

    ',        'after_title'   => '

    ',    ) );}add_action( 'widgets_init', 'mme_register_bp_widgets_area' );
    5. Create a new file in your child theme folder and name it sidebar-buddypress.php.
    6. Add the following in your new sidebar-buddypress.php and save file:
    ?12345678910111213141516171819     

     
    7. Upload your child theme folder to your server. You』ll need to add at least one widget to the BP Sidebar widget area.

    启动前检查清单

    启动前检查清单

    Codex Home → Prelaunch Checklist
    Prelaunch Checklist

    Releasing BuddyPress to the world is a big deal, and takes quite a few manual steps to ensure safe & comfortable updates & upgrades are had by all. Below are the steps release leads go through with each & every release.

    Note: These steps vary slightly depending on major/minor/urgency of the deployment to WordPress.org. For questions, or if something is not clear, please ping @johnjamesjacoby, @boone, or @djpaul, who are mad enough to comprehend how & why all this works the way it does. (We keep planning to automate this, but until then, please enjoy this extremely long and intimidating list of responsibilities.)

    Prologue

    There are two code repositories, and you』ll be tasked with compiling the BuddyPress codebase from the development repo to the deployment repo. They are separate because BuddyPress is deployed to almost all end-users from the public WordPress.org plugin repository in a way that requires some development assets to be pre-compiled (it』s not a literal 1-to-1 copy) and because BuddyPress is lucky enough to have its own Trac instance on WordPress.org.

    Key

    We』ll refer to these two repositories like this for the duration of these steps:

    [dev] = buddypress.svn.wordpress.org[wporg] = plugins.svn.wordpress.org/buddypress/

    Now that you』re familiar, sit back, relax, put on your headgear, and get ready for a trip to the atmosphere…

    Pre-Release Codex, Trac, & Publicity

    For minor/major full releases only.

    Create release version page on codex (https://codex.buddypress.org/releases/version-1-5-5/)Create version page to codex Releases page (https://codex.buddypress.org/releases/).Review recent rockstars and release credits (props). Change as needed.Updates to bp-about page.Draft blog post.If this is a major release, check to see whether there are tickets closed against a minor release that will not happen due to the major release. (For example, 3.3.0 was subsumed into 4.0.0.) If so, reassign those tickets to the major release milestone, and delete the unused milestone.

    Version Bumps (in dev)

    For major releases (2.7.0), switch to: /trunk/.
    svn switch https://buddypress.svn.wordpress.org/trunk/
    For minor releases (2.7.1), switch to relative branch: branches/2.7/
    svn switch https://buddypress.svn.wordpress.org/branches/2.7/
    For Beta and Release Candidate releases (2.7.1-beta1), switch to: /trunk/.
    svn switch https://buddypress.svn.wordpress.org/trunk/

    Change version in bp-loader.php (plugin header)Change version in src/bp-loader.php (plugin header)Change $this->version (setup_globals()) in class-buddypress.phpChange stable-tag readme.txt (major and minor releases)Change tested-up-to readme.txt (major and minor releases)Change version in package.jsonUse the latest version of npm and: npm install and then npm shrinkwrapAdd 「Upgrade Notice」 & 「Changelog」 entries for this version in readme.txt (major and minor releases)Commit changes

    Tagging/Branching (in dev)

    N.B. Once created, a tag cannot be removed or edited nor trunk merged to it so please ensure all necessary updates to trunk are committed before creating the tag copy from it.

    For major releases (2.7.0), branch from trunk, then tag from new branch.
    svn cp https://buddypress.svn.wordpress.org/trunk/ https://buddypress.svn.wordpress.org/branches/2.7
    svn cp https://buddypress.svn.wordpress.org/branches/2.7 https://buddypress.svn.wordpress.org/tags/2.7.0
    For minor releases (2.7.1), tag from relevant branch.
    svn cp https://buddypress.svn.wordpress.org/branches/2.7 https://buddypress.svn.wordpress.org/tags/2.7.0
    For Beta and Release Candidate releases (2.7.0-beta1), create tag from trunk.
    svn cp https://buddypress.svn.wordpress.org/trunk https://buddypress.svn.wordpress.org/tags/2.7.0-beta1

    Deploying to [wporg]

    You』ll probably want to checkout the entire BuddyPress repository from WordPress.org. This way you can navigate the entire trunk/branches/tags structure, and more easily make changes as necessary.

    svn co https://plugins.svn.wordpress.org/buddypress/

    Omit externals – that will save you lots of time. Checkout into a temporary directory…

    Export the development version of BuddyPress you intend to deploy to users: svn co https://buddypress.svn.wordpress.org/tags/2.7.1/ . --force --ignore-externals.Use the latest version of npm and run: npm install and then composer install && grunt build. (You may need to globally update npm, or other such fun stuff. Your mileage may vary.)Overwrite the contents of the trunk directory with the contents of build in the [wporg] checkout.If it』s a beta or a release candidate, make sure the Stable tag in both trunk and the newly created tag are the same and are the one of current stable version of BuddyPress. Run svn stat to check if you need to svn add or svn delete filesCreate an svn tag from trunk using svn cp trunk tags/2.7.1 . If it』s not a beta or a release candidate, make sure the Stable tag in both trunk and the newly created tag are the same and are the one of the new version of BuddyPress. This is needed to make sure GlotPress will successfully update Translation strings.Commit & cross fingers!Verify the zip file for the tag, which will be at a URL of the format https://downloads.wordpress.org/plugins/buddypress.4.0.0.zipAsk Paul Gibbs to update https://github.com/buddypress/BuddyPress-build (via git-svn he has locally).Ask Boone Gorges to go to https://packagist.org/packages/buddypress/buddypress and click 「Update」.

    Trac cleanup

    If any tickets remain in milestone, close them or reassign them to a future milestone.Close milestone.Ensure that milestone exists for next major and minor releases.Create a Version for the completed release.

    Announcements

    Publish blog post on buddypress.orgUpdate version number in the Downloads page on the buddypress.org.Write a blog post on bpdevel.wordpress.comForum announcement in buddypress.org/supportSend tweets from the BP twitter accounts.

    Version Bumps (in dev)

    If a major x.y release, bump trunk version numbers to alpha in bp-loader.php (2.1-alpha).Bump relevant branch version numbers to alpha in bp-loader.php (2.1-alpha).If a major x.y release, sync [dev] trunk and [wporg] trunk.

    GlotPress Translation Strings

    Development strings are here: https://translate.wordpress.org/projects/wp-plugins/buddypress/devThe source of the buddypress.pot is: https://plugins.svn.wordpress.org/buddypress/trunk/buddypress.potRegular updates by running: grunt release and pushing to https://plugins.svn.wordpress.org/browser/buddypress/trunk/ will make #Polyglots translators happyThis also allows for relatively easy 「string freezes」 as new releases near

    BuddyPress 用您的语言

    BuddyPress 用您的语言

    Codex Home → Getting Started → Customizing → BuddyPress in Your Language
    BuddyPress in Your Language

    Like WordPress, BuddyPress has the built in capability to be used in any language. The instructions below assume you have already configured WordPress in Your Language and Installing WordPress in Your Language.
    Like WordPress, you don』t have to lift a finger to apply BuddyPress translations or translation updates. Most sites are now able to automatically apply these updates in the background. If your site is capable of one-click updates without entering FTP credentials, then your site should be able to automatically update translations.
    Is your language missing?
    BuddyPress translation packages are only updated if the translation is at 100% translated, if you do not see your language after updating your translations, please consider contributing to the the BuddyPress translation project, to get started see Translating WordPress and post any questions you have on the WordPress Polyglots blog.
    Getting the language files
    Go to https://translate.wordpress.org/projects/wp-plugins/buddypress and select your preferred language e.g. Hungarian
    Select 『all current』 as 『.po』 and click 『export』 and save this file to a folder on your computer, do the same again this time selecting 『.mo』
    Using the language files
    Rename each file of the files to buddypress-language_COUNTRY.extension
    eg.
    wp-plugins-buddypress-stable-hu.po to buddypress-hu_HU.po and
    wp-plugins-buddypress-stable-hu.mo to buddypress-hu_HU.mo
    Using FTP upload both the .po and .mo files to /wp-content/languages/ of your WordPress instalation. If the /wp-content/languages/ folder does not exist, create it.

    模板中的活动下拉过滤器

    模板中的活动下拉过滤器

    Codex Home → BuddyPress Theme Development → Activity dropdown filters in templates
    Activity dropdown filters in templates

    Activity dropdown filters are used in order to let a user filter the activity stream in three main contexts: the activity directory, the single member activity page and the single group activity page.
    The Activity directory dropdown filters.

    Version 2.1 of BuddyPress introduced the template tag bp_activity_show_filters() to dynamically generate the options of the activity dropdown filters. While the BP Theme compatibility templates are using this function, the BP-Default templates are not since Core Team has decided that no further development on the theme template files will be made. The goal of this article is to show you how you can enjoy this new template tag within your BP-Default child theme.
    Use bp_activity_show_filters() within your BP-Default child theme
    The three templates that are containing an activity dropdown filters are:

    Activity directory: activity/index.php
    Single Member activity page: members/single/activity.php
    Single Group activity page: groups/single/activity.php

    Let』s look at the activity directory template, focusing on the select tag having the css id 「activity-filter-by」:

    As you can see, this part is checking if the component is active before displaying its actions which are then hardcoded in the template. If you are using, at least, BuddyPress 2.1 you can edit the templates to use the template tag bp_activity_show_filters() instead of the hardcoded options (except for the first one). Once done, the activity/index.php and members/single/activity.php will have a select tag looking like this:

    For the groups/single/activity.php template, the only difference is that the bp_activity_show_filters() template tag is including a context parameter set to 『group』 like this:

    Why using bp_activity_show_filters() within your theme』s templates
    As soon as you are using at least version 2.1 of BuddyPress, you should consider using this new template tag as it will be used by BuddyPress to create new activity actions for its current (and future) components. BuddyPress plugins might also progressively rely on this template tag as setting activity actions have been greatly improved thanks to the function bp_activity_set_action().

    Related Resources

    bp_activity_set_action() codex page
    Posting activities from plugins, section 「Fully enjoy bp_activity_set_action()」

    模板更新 2.1

    模板更新 2.1

    Codex Home → BuddyPress Theme Development → Updating Custom Themes For New Functionality → Template Updates 2.1
    Template Updates 2.1

    BuddyPress 2.1 introduced three new features that specifically require template updates in order that they function.

    @mentions Interface
    Password Strength Meter
    Activity Show Filters

    @mentions Auto Suggest
    @mentions introduces a drop down panel that will auto suggest user names to select from the characters you start typing. For this feature to work you will need to update your templates in two specific places or files

    buddypress/activity/entry.php
    buddypress/activity/post-form.php

    In both of these files you need to locate the textarea elements and add the class 『bp-suggestions』 respectively:
    ?1<textarea id="ac-input-" class="ac-input bp-suggestions" name="ac_input_">

    ?1

    @mentions also requires two new JS files and CSS styles to support the display of the dropdown, these files are loaded from the core directories so themes shouldn』t have to worry about including these.
    Password Strength
    Password Strength Meter This feature requires adjustments and new files as follows:

    buddypress-functions.php
    buddypress/members/register.php
    buddypress/members/single/settings/general.php (user account password update screen)
    css/buddypress.css
    js/password-verify.js

    The buddypress-functions.php adjustment most likely won』t be required but if it is you need to make these changes.
    Just below the wp_enqueue_script(『comment-reply』) at around line 257 add:
    ?1234567891011121314// Maybe enqueue password verify JS (register page or user settings page)        if ( bp_is_register_page() || ( function_exists( 'bp_is_user_settings_general' ) && bp_is_user_settings_general() ) ) {            $min      = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';            $filename = "password-verify{$min}.js";             // Locate the Register Page JS file            $asset = $this->locate_asset_in_stack( $filename, 'js' );             // Enqueue script            $dependencies = array_merge( bp_core_get_js_dependencies(), array(                'password-strength-meter',            ) );            wp_enqueue_script( $asset['handle'] . '-password-verify', $asset['location'], $dependencies, $this->version);        }
    register.php requires the addition of a new element to hold the password strength display, and also note the additional classes on the existing input controls, as follows:
    ?12

    ?1
    general.php requires similar changes as register.php as follows:
    ?123  

     
    Styles are required primarily to provide a background color separation between the various strength strings returned and those added to Buddypress are as follows – although you may want to modify these to suit your theme styling
    ?1234567891011121314151617181920212223242526272829303132333435#buddypress #pass-strength-result {    background-color: #eee;    border-color: #ddd;    border-style: solid;    border-width: 1px;    display: none;    margin: 5px 5px 5px 0;    padding: 5px;    text-align: center;    width: 150px;}#buddypress .standard-form #basic-details-section #pass-strength-result {    width: 35%;}#buddypress #pass-strength-result.error,#buddypress #pass-strength-result.bad {    background-color: #ffb78c;    border-color: #ff853c !important;    display: block;}#buddypress #pass-strength-result.good {    background-color: #ffec8b;    border-color: #fc0 !important;    display: block;}#buddypress #pass-strength-result.short {    background-color: #ffa0a0;    border-color: #f04040 !important;    display: block;}#buddypress #pass-strength-result.strong {    background-color: #c3ff88;    border-color: #8dff1c !important;    display: block;}
    Lastly is the addition of a JS file 『password-verify.js』 this can be copied over from the bp legacy js directory or simply left in place as themes should inherit it』s functionality.
    Activity 『Show』 filters
    In 2.1 the activity filters were updated to dynamically generate the filter options, this allows for additional options to be passed in by plugins and CPT』s
    Previously these filters were hardcoded select options in activity/index.php, groups/single/activity.php, and members/single/activity.php now those hardcoded options are replaced with a single function call:
    ?1bp_activity_show_filters()

    It』s important to retain the first option though which resets the display to 『Everything』. On the groups activity page we need to pass an additional parameter to tell the function it』s the groups component so we add:
    ?1bp_activity_show_filters('group')

    A full and detailed explanation of these changes is available in this codex page:
    Activity Dropdown Filters in Templates

    Twenty Thirteen Theme 二〇一三主题

    Twenty Thirteen Theme 二〇一三主题

    Codex Home → BuddyPress Theme Development → BP Theme Compatibility and the WordPress Default Themes → Twenty Thirteen Theme
    Twenty Thirteen Theme

    A. One column Layout
    One Column Layout. Click on image to enlarge.
    This is the default layout of the Twenty Thirteen theme if and only if you do not add any widget in the Secondary Widget area in Appearance > Widgets. Otherwise, the Twenty Thirteen theme will automatically have a two-column layout if you add widget to the Secondary Widget area.
    If you want to add widgets in the Secondary Widget area for your site』s pages/posts but would prefer a one-column layout for all BP pages, following are the steps to do so.
    1. Create a child theme of the Twenty Thirteen theme.
    2. Create a new file in your new child theme folder and name it buddypress.php.
    3. Copy over the content of Twenty Thirteen』s page.php file into the new buddypress.php file. Remove the get_sidebar tag just before the get_footer call in the template.
    ?12345678910111213141516171819     

            

                                                    

        

     
    4. Create a blank functions.php file in the folder of your child theme if you don』t have one yet. You will need to remove the .sidebar body class generated if any widget is added to the Secondary Widget Area which would move the alignment of the content area away from the center,
    5. Add the following to the new functions.php file then save file.
    ?1234567891011 $value) {             if ($value == 'sidebar') unset($wp_classes[$key]);        }    endif;    return $wp_classes;}add_filter('body_class', 'mme_remove_sidebar_body_class', 20, 2);
    6. Upload your Twenty Thirteen child theme folder to server.
    B. Full Width Layout
    Full-width Layout. Click on image to enlarge.
    You can create a full-width layout for all BP pages even when the Secondary Widget Area (right sidebar) is active for rest of the site by following these steps.
    1. Create a child theme of the Twenty Thirteen theme.
    2. Create a new file in your new child theme folder and name it buddypress.php.
    3. Copy over the content of Twenty Thirteen』s page.php file into the new buddypress.php file. Remove the get_sidebar tag just before the get_footer call in the template as well as the section with the call to post_thumbnail and save file.
    ?12345678910111213141516171819     

            

                                                    

        

     
    4. Create a blank functions.php file in the folder of your child theme if you don』t have one yet. You will need to remove the sidebar body class generated if any widget is added to the Secondary Widget Area which would show up in regular blog posts/pages,
    5. Add the following to your new functions.php file then save file.
    ?1234567891011 $value) {             if ($value == 'sidebar') unset($wp_classes[$key]);        }    endif;    return $wp_classes;}add_filter('body_class', 'mme_remove_sidebar_body_class', 20, 2);
    6. Open up your child theme』s style.css file, add the following and save file.
    ?1234567891011121314151617.buddypress .entry-header,.buddypress .entry-content,.buddypress .entry-summary,.buddypress .entry-meta {    max-width: 1040px;    width: 100%;} @ media (max-width: 1069px) {    .buddypress .entry-header,    .buddypress .entry-content,    .buddypress .entry-summary,    .buddypress .entry-meta {        padding-left: 20px;        padding-right: 20px;    }}
    – delete the space between @ and media in media query above.
    7. Upload your Twenty Thirteen child theme folder to server.
    C. Two Column, Right Sidebar Layout
    Two-column Layout. Click on image to enlarge.
    When you add any widget to the Secondary Widget Area in Appearance > Widgets using the Twenty Thirteen theme, the right sidebar will automatically show up in all posts and pages including the BuddyPress pages. So if you plan to have the same widgets in the right sidebar throughout the site, then you can stop reading at this point as you will not have to do anything further.
    However, if you want to customize the sidebar content of all your BP pages, you can do so by: a) using a plugin like Widget Logic to assign widgets to specific pages by using conditional tags or b) by creating new buddypress.php and sidebar-buddypress.php files and then registering a new widget area in your child theme』s functions.php file. The following steps are for the second option.
    1. Create a child theme of the Twenty Thirteen theme.
    2. Create a new file in your new child theme folder and name it buddypress.php.
    3. Copy over the content of Twenty Thirteen』s page.php file into a new buddypress.php file and remove the section about retrieving the post_thumbnail. Then you will have to change get_sidebar() to get_sidebar(『buddypress』).
    ?12345678910111213141516171819202122232425262728293031323334353637     

            

                                  <article id="post-" >                    

                            

                        

                         

                                                     '

    ', 'link_before' => '', 'link_after' => '' ) ); ?>                    

                         

                            <?php edit_post_link( __( 'Edit', 'twentythirteen' ), '', '' ); ?>                    

                    

                          

        

     
    4. Create a blank functions.php file in the folder of your child theme if you don』t have one yet. You will be creating a new widget area for BuddyPress pages as well as adding a body class to help you style your two column layout.
    5. Add the following to the new functions.php file then save file.
    ?1234567891011121314151617181920212223 __( 'BuddyPress Sidebar Widget Area', 'mmechildtheme' ),        'id'         => 'bp-sidebar',        'description'    => __( 'Appears in the sidebar section of all BuddyPress pages.', 'mmechildtheme' ),        'before_widget' => '

    ',        'before_title'  => '

    ',        'after_title'   => '

    ',    ) );}add_action( 'widgets_init', 'mme_register_bp_widgets_area' ); // Add the sidebar body class for BP pages if the Secondary Widget area is not activefunction mme_add_sidebar_body_class( $classes ) {    if ( function_exists ( 'bp_loaded' ) &&  !bp_is_blog_page() && !is_active_sidebar( 'sidebar-2' )  )  {        $classes[] = 'sidebar';    }    return $classes;}add_filter( 'body_class', 'mme_add_sidebar_body_class' );
    6. Create a new file named sidebar-buddypress.php in your child theme folder and add the following:
    ?123456789101112131415161718192021     

     
    8 . Upload your Twenty Thirteen child theme folder to server. You』ll need to add at least one widget to the BP Sidebar widget area.

    通知 (Notifications)

    通知 (Notifications)

    Codex Home → Administrator Guide → Notifications
    Notifications

    The notifications component was added to BuddyPress 1.9 and works identically to the previous core notifications functionality, but now separates everything into it』s own component. This page will give you a quick overview of it』s functionality.
    An example of the new Notifications component
    Functionality Overview
    Notifications are a central aspect of the user experience on a BuddyPress site. By default new notifications are displayed in the admin bar profile menu, right next to the navigation menus, some themes even integrate the notification counter in other places (like in the header or sidebar of a page).
    Notifications are sent out to your community members as soon as one of the following things happen:
    Activity

    A member mentions you in an update @username」
    A member replies to an update or comment you』ve posted

    The Notifications menu on BuddyPress.org
    Messages

    A member sends you a new message

    Friends

    A member sends you a friendship request
    A member accepts your friendship request

    Groups

    A member invites you to join a group
    Group information is updated
    You are promoted to a group administrator or moderator
    A member requests to join a private group for which you are an admin

    Group Forums

    Receive notifications of your own posts?

    Every user can view their read and unread notifications on their 「Notifications」 page on their profile and easily:

    Mark notifications as 「read」
    Mark notification as 「unread」
    Delete notification (in batches if needed)

    Email Notifications
    User can enable and disable receiving emails when new notifications are received. This can be done through their Settings > Email page.

    Plugin Integrations
    Some plugins can add their own notifications events that can be triggered by activity of your member. A good example is BBPress which sends notifications on new topics and topic replies.
    Related Resources

    BuddyPress Notifications Extension example from BBPresss 2
    bp_notifications_add_notification()

    来自插件的模板重载

    来自插件的模板重载

    Codex Home → BuddyPress Plugin Development → Template Overload from a Plugin
    Template Overload from a Plugin

    Note: overloading and / or adding templates from plugins can be quite complex. For more detailed discussion and examples, please see:

    Upgrading older plugins that bundle custom templates for BP 1.7
    Using BP Theme Compat in Plugins
    Theme Compatibility & Template Files

    The purpose of this page is to provide a simple example of overloading an existing template part. The example shown will allow you to overload the member-header.php file which creates the BuddyPress profile page header section (avatar, messaging buttons, profile navigation menu etc.) for profile pages where cover images are not used. If you are using cover images on the users profile then the file to overload is cover-image-header.php. Both of these files are located in plugins/buddypress/bp-templates/bp-legacy/members/single.
    If you』re using BP 1.7 or greater and not using the bp-default theme, you can use this approach…
    It consists of 2 files and a template folder structure:

    loader.php
    bp-tol.php
    templates/members/single/member-header-tol.php

    loader.php
    /*
    Plugin Name: BP Template Overload
    Plugin URI: http://philopress.com
    Description: Load templates from a plugin
    Version: 1.0
    Author: shanebp
    License: GPLv2 or later
    License URI: http://www.gnu.org/licenses/gpl-2.0.html
    */

    if ( !defined( 'ABSPATH' ) ) exit;

    function bp_tol_init() {

    define( 'BP_TOL_DIR', dirname( __FILE__ ) );

    require( BP_TOL_DIR . '/bp-tol.php' );

    }
    add_action( 'bp_include', 'bp_tol_init' );

    bp-tol.php
    // register the location of the plugin templates
    function bp_tol_register_template_location() {
    return BP_TOL_DIR . '/templates/';
    }

    // replace member-header.php with the template overload from the plugin
    function bp_tol_maybe_replace_template( $templates, $slug, $name ) {

    if( 'members/single/member-header' != $slug )
    return $templates;

    return array( 'members/single/member-header-tol.php' );
    }

    function bp_tol_start() {

    if( function_exists( 'bp_register_template_stack' ) )
    bp_register_template_stack( 'bp_tol_register_template_location' );

    // if viewing a member page, overload the template
    if ( bp_is_user() )
    add_filter( 'bp_get_template_part', 'bp_tol_maybe_replace_template', 10, 3 );

    }
    add_action( 'bp_init', 'bp_tol_start' );

    member-header-tol.php
    Make a copy of
    buddypress/bp-templates/bp-legacy/buddypress/members/single/member-header.php
    rename it and make some small change so that it』s obvious that it』s being loaded.
    Then save it in the folder structure shown above.

    That』s it !
    And you can overload member-header-tol.php by placing a copy in your child-theme directory: [theme]/buddypress/members/single/member-header-tol.php

    文章类型活动

    文章类型活动

    Codex Home → BuddyPress Plugin Development → Post Types Activities
    Post Types Activities

    Note: This guide is for use with BuddyPress 2.2+.
    Any public registered post type can be tracked into the activity streams once it has been published. Here are the different options to add the 「buddypress-activity」 support to a public post type.

    Activate the Blogs component ( aka Site Tracking )
    If you activate the Site Tracking component from the BuddyPress component』s Administration screen, the post post type will automatically have the 「buddypress-activity」 feature enable. Comments about this post type will also generate activities or, if you chose to 「allow the activity stream commenting on blog posts」 from the BuddyPress settings Administration screen, comments will be synchronized with the activity stream.
    Use add_post_type_support( 『post_type』, 『buddypress-activity』 )
    From your bp-custom.php file, you can also manually set a post type to be tracked into the activity stream. For instance, for the page post type you could use this code:
    add_post_type_support( 'page', 'buddypress-activity' );

    In this case, BuddyPress will set an activity action using generic activity attributes : the component, the generated activities will be attached to, will be the Activity component; the action type will be the post type』s name prefixed by the mention 『new_』 (in our example 『new_page』); the label of the front-end activity dropdown filters will be the name parameter of the 『labels』 argument of the post type (in our example 『Pages』); the label of the Activity Administration screens dropdown filters will be __( 'New item published', 'buddypress' ); the action string will be __( '%1$s wrote a new item', 'buddypress' ) where %1$s will be replaced by the member』s link of the post type』s author and %2$s by the url to the post type; the context will be limited to the Activity directory; commenting on generated activities about the post type will be possible if the post type is not supporting comments.
    Simply by using add_post_type_support()
    Customizing generic activity attributes
    You can edit the generic activity attributes of a post type from your bp-custom.php file using the function bp_activity_set_post_type_tracking_args( $post_type = '', $args = array() ). Use the first parameter to inform about the post type you wish to edit the activity attributes of. The second parameter is an associative array containing the activity attributes to edit. For instance you could use this code:
    // Don't forget to add the 'buddypress-activity' support!
    add_post_type_support( 'page', 'buddypress-activity' );

    function customize_page_tracking_args() {
    // Check if the Activity component is active before using it.
    if ( ! bp_is_active( 'activity' ) ) {
    return;
    }

    bp_activity_set_post_type_tracking_args( 'page', array(
    'component_id' => buddypress()->blogs->id,
    'action_id' => 'new_blog_page',
    'bp_activity_admin_filter' => __( 'Published a new page', 'custom-domain' ),
    'bp_activity_front_filter' => __( 'Pages', 'custom-domain' ),
    'contexts' => array( 'activity', 'member' ),
    'activity_comment' => true,
    'bp_activity_new_post' => __( '%1$s posted a new page', 'custom-textdomain' ),
    'bp_activity_new_post_ms' => __( '%1$s posted a new page, on the site %3$s', 'custom-textdomain' ),
    'position' => 100,
    ) );
    }
    add_action( 'bp_init', 'customize_page_tracking_args' );

    Using add_post_type_support() and customizing activity attributes.
    Below a description of the parameters used above:

    $component_id
    The unique string ID of the component the activity action is attached to, defaults to 『activity』
    $action_id
    A string that describes the action type and that is used in the front-end and in the Activity Administration screens as the value of the activity dropdown filters, defaults to 『new_{post_type_name}』
    $bp_activity_admin_filter
    A string that describes the action description and that is used in the Activity Administration screens as the label of the activity dropdown filters.
    $bp_activity_front_filter
    A string that describes the action label of the activity front-end dropdown filters.
    $contexts
    An array that describes the Activity stream contexts where the filter should appear. Possible values are 『activity』, 『member』, 『member_groups』, 『group』.
    $activity_comment
    A boolean to allow/disallow comments on the activity items. Defaults to true if the post type does not natively support comments, otherwise false.
    $bp_activity_new_post
    A string containing the custom action string to use for regular configs. Defaults to __( '%1$s wrote a new item', 'buddypress' )
    $bp_activity_new_post_ms
    A string containing the custom action string to use for multisite configs. Defaults to __( '%1$s wrote a new item, on the site %3$s', 'buddypress' )
    $position
    An integer to set the order of the action within the component』s actions

    Adding the 「buddypress-support」 and specific labels at post type registration
    When registering a post type in WordPress it』s also possible to set the 『buddypress-activity』 feature using the support parameter of the second argument of the register_post_type() function. Custom activity action strings can be defined within the labels parameter and activity attributes can be set using the parameter 『bp_activity』. See below for an example of use.
    function plugin_registers_post_type() {
    $args = array(
    'public' => true,
    'labels' => array(
    'name' => __( 'Books', 'your-plugin-textdomain' ),
    'singular_name' => __( 'Book', 'your-plugin-textdomain' ),
    'bp_activity_admin_filter' => __( 'New book published', 'your-plugin-textdomain' ),
    'bp_activity_front_filter' => __( 'Books', 'your-plugin-textdomain' ),
    'bp_activity_new_post' => __( '%1$s posted a new book', 'your-plugin-textdomain' ),
    'bp_activity_new_post_ms' => __( '%1$s posted a new book, on the site %3$s', 'your-plugin-textdomain' ),
    ),
    'supports' => array( 'title', 'editor', 'buddypress-activity' ),
    'bp_activity' => array(
    'component_id' => buddypress()->activity->id,
    'action_id' => 'new_book',
    'contexts' => array( 'activity', 'member' ),
    'position' => 40,
    ),
    );
    register_post_type( 'book', $args );
    }
    add_action( 'init', 'plugin_registers_post_type' );

    Important note: public parameter should be defined and set to true, otherwise the connection between post type and Activity component won』t be established.
    Customizing Post Type Activity Content
    You can customize the activity action of a Post Type via the register_post_type() example above. If you want to customize the Post Type activity content you can filter bp_before_activity_add_parse_args or bp_after_activity_add_parse_args.
    function record_cpt_activity_content( $cpt ) {

    if ( 'new_book' === $cpt['type'] ) {

    $cpt['content'] = 'what you need';
    }

    return $cpt;
    }
    add_filter('bp_before_activity_add_parse_args', 'record_cpt_activity_content');

    Tracking comments about a Post Type
    Version 2.5 is bringing Post Type comments tracking into the Activity stream for the Post Types supporting the 'comments' and the 'buddypress-activity' features. You can set the comments tracking feature to an existing Post Type or during the Post Type registration by adding the 'comment_action_id' specific parameter. If you wish to customize dropdown filter labels and action strings, you simply need to define some extra parameters. Here is the list of the available parameters :

    $comment_action_id
    A string that describes the action type and that is used in the front-end and in the Activity Administration screens as the value of the activity dropdown filters
    $bp_activity_comments_admin_filter
    A string that describes the action description and that is used in the Activity Administration screens as the label of the activity dropdown filters.
    $bp_activity_comments_front_filter
    A string that describes the action label of the activity front-end dropdown filters.
    $bp_activity_new_comment
    A string containing the custom action string to use for regular configs. Defaults to __( '%1$s commented on the item', 'buddypress' )
    $bp_activity_new_comment_ms
    A string containing the custom action string to use for multisite configs. Defaults to __( '%1$s commented on the item, on the site %3$s', 'buddypress' )

    1. Add comments tracking to an Existing Post Type
    Below is an example of code to put into your bp-custom.php file to add the comments tracking feature to the 「page」 Post Type.
    function customize_page_tracking_args() {
    // Check if the Activity component is active before using it.
    if ( ! bp_is_active( 'activity' ) ) {
    return;
    }

    // Don't forget to add the 'buddypress-activity' support!
    add_post_type_support( 'page', 'buddypress-activity' );

    /**
    * Also don't forget to allow comments from the WordPress Edit Page screen
    * see this screencap https://cldup.com/nsl4TxBV_j.png
    */

    bp_activity_set_post_type_tracking_args( 'page', array(
    'action_id' => 'new_blog_page',
    'bp_activity_admin_filter' => __( 'Published a new page', 'custom-textdomain' ),
    'bp_activity_front_filter' => __( 'Page', 'custom-textdomain' ),
    'bp_activity_new_post' => __( '%1$s posted a new page', 'custom-textdomain' ),
    'bp_activity_new_post_ms' => __( '%1$s posted a new page, on the site %3$s', 'custom-textdomain' ),
    'contexts' => array( 'activity', 'member' ),
    'comment_action_id' => 'new_blog_page_comment',
    'bp_activity_comments_admin_filter' => __( 'Commented a page', 'custom-textdomain' ),
    'bp_activity_comments_front_filter' => __( 'Pages Comments', 'custom-textdomain' ),
    'bp_activity_new_comment' => __( '%1$s commented on the page', 'custom-textdomain' ),
    'bp_activity_new_comment_ms' => __( '%1$s commented on the page, on the site %3$s', 'custom-textdomain' ),
    'position' => 100,
    ) );
    }
    add_action( 'bp_init', 'customize_page_tracking_args' );

    2. Add comments tracking feature during the Post Type registration
    Below is an example of code to put into your bp-custom.php file to registyer a 「foo」 Post Type and directly set the 'buddypress-activity' and 'comments' supports during this registration.
    $labels = array(
    'name' => 'foos',
    'singular_name' => 'foo',
    'bp_activity_comments_admin_filter' => __( 'Comments about foos', 'custom-textdomain' ), // label for the Admin dropdown filter
    'bp_activity_comments_front_filter' => __( 'Foo Comments', 'custom-textdomain' ), // label for the Front dropdown filter
    'bp_activity_new_comment' => __( '%1$s commented on the foo', 'custom-textdomain' ),
    'bp_activity_new_comment_ms' => __( '%1$s commented on the foo, on the site %3$s', 'custom-textdomain' )
    );

    register_post_type( 'foo', array(
    'labels' => $labels,
    'public' => true,
    'supports' => array( 'buddypress-activity', 'comments' ), // Adding the comments support
    'bp_activity' => array(
    'action_id' => 'new_foo', // The activity type for posts
    'comment_action_id' => 'new_foo_comment', // The activity type for comments
    ),
    ) );

    Notes
    On multisite configurations, the post types that are registered on any sub-site will need to be registered on the root site in order to be listed in the Activity dropdown filters. That』s the case for the post and page post types
    Some of you may have used the 'bp_blogs_record_post_post_types' filter to include custom post types to the site tracking having the Blogs component activated. These post types will keep on being included as long as the Blogs component is active.
    About Post Type comments tracking: if the Blogs component (Site Tracking) is active and if the 「Allow activity stream commenting on blog and forum posts」 setting is checked, comments about the Post Type will be synchronized with the activity comments about the corresponding Post Type activity.

    Related Resources

    register_post_type() WordPress Codex page
    Posting activities from plugins
    Activity dropdown filters in templates
    More details and explanation in this topic
    More details and possible field values on bp_activity_set_action() page