自定義電子郵件

自定義電子郵件

Codex Home → Emails → Custom Emails
Custom Emails

BuddyPress only includes emails for BuddyPress core functionality. Blog posting is not part of BuddyPress, but it could be an integral part of your community. Let』s look at an example to send an email to a blog post author when a user comments on their post.
Note: This requires the BP Email API which is only available in BP 2.5.0+.
Email Post Type
BuddyPress emails are a Custom Post Type so adding emails is similar to creating posts and pages. The function below will programmatically add a post and add the correct taxonomy. Taxonomies are used to connect the email with the correct Situation or action that will trigger the sending of the email. Hook your email creation to bp_core_install_emails – this insures that it will be created if you need to reset emails using the 「Re-install emails」 tool in the admin tools. You can call the function directly as part of activating your plugin via register_activation_hook.
function codex15766_custom_email_message() {

// Do not create if it already exists and is not in the trash
$post_exists = post_exists( '[{{{site.name}}}] New post comment.' );

if ( $post_exists != 0 && get_post_status( $post_exists ) == 'publish' )
return;

// Create post object
$my_post = array(
'post_title' => __( '[{{{site.name}}}] New post comment.', 'buddypress' ),
'post_content' => __( '{{commenter.name}} commented on your blog post.', 'buddypress' ), // HTML email content.
'post_excerpt' => __( '{{commenter.name}} commented on your blog post.', 'buddypress' ), // Plain text email content.
'post_status' => 'publish',
'post_type' => bp_get_email_post_type() // this is the post type for emails
);

// Insert the email post into the database
$post_id = wp_insert_post( $my_post );

if ( $post_id ) {
// add our email to the taxonomy term 'post_received_comment'
// Email is a custom post type, therefore use wp_set_object_terms

$tt_ids = wp_set_object_terms( $post_id, 'post_received_comment', bp_get_email_tax_type() );
foreach ( $tt_ids as $tt_id ) {
$term = get_term_by( 'term_taxonomy_id', (int) $tt_id, bp_get_email_tax_type() );
wp_update_term( (int) $term->term_id, bp_get_email_tax_type(), array(
'description' => 'A member comments on a posts',
) );
}
}

}
add_action( 'bp_core_install_emails', 'codex15766_custom_email_message' );

Send Email
For the next step, hook an action to wp_insert_comment to get the comment data and then send the post author an email. In this function, you create the tokens to parse out in the email before sending. The tokens array can be anything but you usually want to keep it personal to the recipient.
bp_send_email() takes three arguments:

the taxonomy term you set up in the the CPT above
the recipients user ID
the array of tokens to parse in the title, body and excerpt of the email

function codex15766_comment_inserted( $comment_id, $comment_object ) {

if ( $comment_object ) {
// get the post data
$post = get_post( $comment_object->comment_post_ID );
// add tokens to parse in email
$args = array(
'tokens' => array(
'site.name' => get_bloginfo( 'name' ),
'commenter.name' => $comment_object->comment_author,
),
);
// send args and user ID to receive email
bp_send_email( 'post_received_comment', (int) $post->post_author, $args );
}
}
add_action( 'wp_insert_comment','codex15766_comment_inserted', 99, 2 );

將自定義選項卡新增到群組目錄

將自定義選項卡新增到群組目錄

Codex Home → Add Custom Tab to Groups Directory
Add Custom Tab to Groups Directory

This is an example of how to add a custom tab to the Groups Directory.
And call a custom template when that tab is clicked.
The same approach can be used to add a custom tab to the Members Directory.
The tab will be called Custom and it will load a template called groups-custom.php.
?12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879// add Custom tab on Groups Pagefunction asdf_groups_custom_tab() {     if ( bp_is_current_action( 'custom' ) )         return;     $button_args = array(        'id'         => 'groups-custom',        'component'  => 'groups',        'link_text'  => __( 'Custom', 'buddypress' ),        'link_title' => __( 'Custom', 'buddypress' ),        'link_class' => 'group-custom no-ajax',        'link_href'  => trailingslashit( bp_get_groups_directory_permalink() . 'custom' ),        'wrapper'    => false,        'block_self' => false,    );           ?>    

  •      0,            'post_title'     => 'Groups Custom',            'post_author'    => 0,            'post_date'      => 0,            'post_content'   => '',            'post_type'      => 'page',            'post_status'    => 'publish',            'is_page'        => true,            'comment_status' => 'closed'        ) );    }     public function create_content() {        return bp_buffer_template_part( 'groups/groups-custom', null, false );    } }
    This example assumes that the groups-custom.php template is in your theme at this location:
    .../wp-content/themes/your-theme/buddypress/groups/groups-custom.php
    If you want to load the template from a plugin, you need to register the location of the template:
    ?12345678910111213// add path to plugin templatesfunction asdf_register_template_location() {    return dirname( __FILE__ ) . '/templates/';}  function asdf_template_start() {     if( function_exists( 'bp_register_template_stack' ) )        bp_register_template_stack( 'asdf_register_template_location' ); }add_action( 'bp_init', 'asdf_template_start' );
    More info about using BP Theme Compat in plugins.

    群組型別

    群組型別

    Codex Home → Developer Resources → Group Types
    Group Types

    BuddyPress 2.6 introduced the concept of group types. This functionality is outlined below.
    Registering group types
    BuddyPress itself does not register any group types. Plugins and themes can register group types using the bp_groups_register_group_type() function:
    function my_bp_custom_group_types() {
    bp_groups_register_group_type( 'team', array(
    'labels' => array(
    'name' => 'Teams',
    'singular_name' => 'Team'
    ),

    // New parameters as of BP 2.7.
    'has_directory' => 'teams',
    'show_in_create_screen' => true,
    'show_in_list' => true,
    'description' => 'Teams are good',
    'create_screen_checked' => true
    ) );
    }
    add_action( 'bp_groups_register_group_types', 'my_bp_custom_group_types' );

    The first parameter of bp_groups_register_group_type() is a string identifier for the group type, used internally by BP as the canonical name of the type. This name should be unique. The second parameter is a list of generic config arguments (see Configuration Arguments section for full details).
    Registering a group type will also enable a meta box so administrators can set a groups』s type when editing a group in the WP admin dashboard.
    Configuration Arguments

    'labels' (available as of BP 2.6)
    An array consisting of the 'name' and 'singular_name' keys. 'name' is for the plural form of the group type.

    'has_directory' (available as of BP 2.7)
    If this argument is passed (eg. 『ninja』), a list of members matching the group type will be available as a filter from the Groups Directory page. (eg. http://example.com/groups/type/ninja/. You can pass any string to customize the URL for the group type』s directory.) Default: false.

    'show_in_create_screen' (available as of BP 2.7)
    If set to true, the group type will be selectable during group creation and when a group administrator is on the group』s 「Manage > Settings」 page. Default: false.

    'show_in_list' (available as of BP 2.7)
    If set to true, the group type will be shown when the bp_group_type_list() function is used by default. Currently, the group type list is shown when on a group page. This defaults to true if 'show_in_create_screen' is set to true. Default: null.

    'description' (available as of BP 2.7)
    Used to describe the group type. If this is passed, this is currently shown on the group creation screen to describe the group type.

    'create_screen_checked' (available as of BP 2.7)
    If the 'show_in_create_screen' argument is set to true, this argument will toggle the checkbox for our group type so it is checked by default during the group creation process. This is handy if you wanted to imply that the group type should be enforced, but the decision ultimately lies with the group creator. Default: false.

    Querying by group type
    A common task is to retrieve a list of groups of a given type (or set of types). bp_has_groups() and BP_Groups_Group::get() accept a 'group_type' parameter, which can be a single group type or an array/comma-separated list of group types. This will filter query results to those groups matching the type. Example:
    // Fetch all teams and companies.
    $group_args = array(
    'group_type' => array( 'team', 'company' ),
    );
    if ( bp_has_groups( $group_args ) ) { // ...

    Fetching and setting group types
    When BuddyPress detects that group types have been registered, it will display a Group Type metabox when editing a group』s page in Dashboard > Groups. Administrators can use this interface to view or change a groups』s type.
    BuddyPress also provides simple functions for fetching and setting group types programatically. To get the group type of a group, use bp_groups_get_group_type():
    // Get the group type of group 5412.
    $group_type = bp_groups_get_group_type( 5412 );

    Set a group』s type using bp_groups_set_group_type():
    // Set the group type of group 5412 to 'team'.
    $group_type = bp_groups_set_group_type( 5412, 'team' );

    活動嵌入

    活動嵌入

    Codex Home → Activity Embeds
    Activity Embeds

    Intro
    WordPress added oEmbed provider support in v4.4.0, allowing users to easily embed posts by copying a WordPress post URL and pasting it into the WordPress editor.
    WordPress 4.5.0 made further enhancements to the embed template for easier customization for theme developers.
    In BuddyPress 2.6.0, we are piggybacking off this functionality and enabling oEmbed provider support for single activity item.
    This means you will be able to embed single activity items by copying the activity permalink and pasting it into the WordPress editors.
    For example:
    Your WordPress version is 4.5 or higher, you can enjoy the Activity Embeds feature we』re introducing in BuddyPress 2.6!https://videopress.com/v/VwVrGm7a?hd=1– Paul Gibbs (@djpaul) June 15, 2016

    This feature will require WordPress 4.5+.
    Disabling Activity Embeds
    If you do not want your BuddyPress site to have activity embeds enabled, you can disable the feature with this small code snippet:
    add_filter( 'bp_is_activity_embeds_active', '__return_false' );
    Media in Activity Embeds
    If an activity item includes a URL from a registered WordPress oEmbed provider on its own line:
    https://codex.wordpress.org/Embeds#Okay.2C_So_What_Sites_Can_I_Embed_From.3F
    We will attempt to display an image and caption of that oEmbed item in the activity embed template.
    If a URL from a registered WordPress oEmbed provider isn』t found, we will attempt to embed an inline audio or video URL using your browser』s native HTML5 player.
    Information for Theme Developers
    As a theme developer, if you do not like the default look of activity embeds, you can override any of the template parts located at /wp-content/plugins/buddypress/bp-templates/bp-legacy/buddypress/assets/embeds/ by copying them to your theme』s directory.
    Let』s say I want to make some tweaks to the activity header embed template part, copy /wp-content/plugins/buddypress/bp-templates/bp-legacy/buddypress/assets/embeds/header-activity.php to /wp-content/themes/YOUR-THEME/buddypress/assets/embeds/header-activity.php and make your changes.
    If you want to override the CSS, copy /wp-content/plugins/buddypress/bp-templates/bp-legacy/css/embeds-activity.min.css to /wp-content/themes/YOUR-THEME/buddypress/css/embeds-activity.min.css or /wp-content/themes/YOUR-THEME/css/embeds-activity.min.css and make your changes.
    If you have WP_DEBUG turned on, then omit the '.min' suffix.
    Note: CSS is rendered inline in the tag. This is similar to what WordPress is doing in their embed template.
    Information for Template Pack developers
    If you do not know what a template pack is, you do not need to read this section!
    As of BuddyPress 2.6, if you are developing a custom template pack that is not bp-legacy, for activity embeds to display properly, you will need to copy the following to your template pack』s directory:

    /wp-content/plugins/buddypress/bp-templates/bp-legacy/buddypress/assets/embeds/
    /wp-content/plugins/buddypress/bp-templates/bp-legacy/css/embeds-activity.css
    /wp-content/plugins/buddypress/bp-templates/bp-legacy/css/embeds-activity-rtl.css
    /wp-content/plugins/buddypress/bp-templates/bp-legacy/css/embeds-activity.min.css
    /wp-content/plugins/buddypress/bp-templates/bp-legacy/css/embeds-activity-rtl.min.css

    There is a proposal to eliminate this copying process in future versions. Keep an eye on the following ticket for more info:
    https://buddypress.trac.wordpress.org/ticket/7116
    Information for Plugin Developers
    In order for oEmbed to work with BuddyPress activity items, we register a custom endpoint with the WordPress oEmbed REST API:
    example.com/wp-json/oembed/1.0/embed/activity?url=URL_TO_ACTIVITY_ITEM
    As well as supporting the regular oEmbed parameters like url, format and maxwidth:
    http://oembed.com/#section2.2
    The BP Activity oEmbed endpoint also supports the hide_media parameter.
    If this is set during the oEmbed request, no media items will be displayed in the embed.

    導航介面 API

    導航介面 API

    Codex Home → Developer Resources → Navigation API
    Navigation API

    BuddyPress』s Navigation API (BP 2.6+) provides an interface for developers to modify BP』s nav menus in group and user contexts.
    Examples
    Changing the position of the user』s Notifications nav item
    function bpcodex_change_notifications_nav_position() {
    buddypress()->members->nav->edit_nav( array(
    'position' => 999,
    ), 'notifications' );
    }
    add_action( 'bp_setup_nav', 'bpcodex_change_notifications_nav_position', 100 );

    Changing the name of the Unread subnav item of the user』s Notifications nav menu
    function bpcodex_change_unread_nav_name() {
    buddypress()->members->nav->edit_nav( array(
    'name' => 'My Unread Notifications',
    ), 'unread', 'notifications' );
    }
    add_action( 'bp_setup_nav', 'bpcodex_change_unread_nav_name', 100 );

    Listing all navigation items belonging to the current group
    function bpcodex_get_current_group_nav_items() {
    // Group nav items are technically subnavs of the top-level item with the current group's slug.
    return buddypress()->groups->nav->get_secondary( array(
    'parent_slug' => bp_get_current_group_slug(),
    ) );
    }

    Change item names of user』s and group』s nav menus
    Profile menu
    function bpcodex_rename_profile_tabs() {

    buddypress()->members->nav->edit_nav( array( 'name' => __( 'My Buddy Forums', 'textdomain' ) ), 'forums' );
    buddypress()->members->nav->edit_nav( array( 'name' => __( 'My Buddy Groups', 'textdomain' ) ), 'groups' );

    }
    add_action( 'bp_actions', 'bpcodex_rename_profile_tabs' );

    Group menu
    function bpcodex_rename_group_tabs() {

    if ( ! bp_is_group() ) {
    return;
    }

    buddypress()->groups->nav->edit_nav( array( 'name' => __( 'Group Discussion', 'buddypress' ) ), 'forum', bp_current_item() );
    }
    add_action( 'bp_actions', 'bpcodex_rename_group_tabs' );

    Changing the position of group』s nav items
    function bpcodex_group_tab_reorder() {

    if( bp_is_group() ) {
    buddypress()->groups->nav->edit_nav( array( 'position' => 1 ), 'forum', bp_current_item() );
    buddypress()->groups->nav->edit_nav( array( 'position' => 2 ), 'send-invites', bp_current_item() );
    buddypress()->groups->nav->edit_nav( array( 'position' => 4 ), 'home', bp_current_item() );
    }
    }
    add_action( 'bp_actions', 'bpcodex_group_tab_reorder' );

    Remove subnav tabs from Group Settings
    function bpcodex_remove_group_manager_subnav_tabs() {
    // site admin will see all tabs
    if ( ! bp_is_group() || ! ( bp_is_current_action( 'admin' ) && bp_action_variable( 0 ) ) || is_super_admin() ) {
    return;
    }
    // all subnav items are listed here.
    // comment those you want to show
    $hide_tabs = array(
    // 'group-settings' => 1,
    'delete-group' => 1,
    'group-avatar' => 1,
    // 'group-invites' => 1,
    'manage-members' => 1,
    // 'forum' => 1,
    // 'group-cover-image' => 1
    );

    $parent_nav_slug = bp_get_current_group_slug() . '_manage';

    //Remove the nav items
    foreach ( array_keys( $hide_tabs ) as $tab ) {
    bp_core_remove_subnav_item( $parent_nav_slug, $tab, 'groups' );
    }
    }
    add_action( 'bp_actions', 'bpcodex_remove_group_manager_subnav_tabs' );

    將 「活動」 元件的名稱和 slug 更改為其他內容。

    將 「活動」 元件的名稱和 slug 更改為其他內容。

    Codex Home → Developer Resources → User Submitted Guides → Change 「Activity」 component』s name and slug to something else.
    Change 「Activity」 component』s name and slug to something else.

    Want to change the default BuddyPress 「Activity」 (activity stream) to 「Dashboard」, or 「The Activity Center」, or anything other than 「Activity」?
    Here is how:

    Create wp-content/plugins/bp-custom.php, and put the following:
    ?12345678910// change BP /activity/ slug to /dashboard/define( 'BP_ACTIVITY_SLUG', 'dashboard' ); // Change the name for the "Activity" tab to "Dashboard", // and reference the newly defined slug /dashboard/function bpcodex_rename_profile_tabs() {    // Change "Activity" to "Dashboard"    buddypress()->members->nav->edit_nav( array( 'name' => __( 'Dashboard', 'textdomain' ) ), 'dashboard' );}add_action( 'bp_actions', 'bpcodex_rename_profile_tabs' );

    You may also want to change all labels associated by following these instructions: 「Customizing Labels, Messages, and URLs「.

    模板更新 2.2

    模板更新 2.2

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

    Theme template changes & updates for BP 2.2.0
    Group create & blog create buttons
    Historically the two buttons to add a new group or blog that displayed on the respective directory pages were rendered within the heading tag for those pages, with the arrival of theme compatibility in 1.7 this practice was continued to preserve backwards compatibility however now we needed to add the link or button into the WP the_title() function
    This was never an ideal situation so in the 2.0.0 release we changed things around slightly ( On ticket #5144 ) so that the buttons were filtered in, this meant that we now had to take deliberate action elsewhere to have this happen with the default behavior being not to push the button through to the title function, in buddypress-functions.php we added two new add_filters and supporting functions to ensure that the established behavior continued and end users would have not seen any change but now we could easily remove the filters and simply add the bp_』group/blog』_create_button() via an add action where we required it.
    Moving forward to BP 2.2.0 and the decision was taken to finally remove this behavior and stop injecting the create buttons in the title tag, prompted by this ticket #6008.
    The tricky part was once removed where were the buttons to be moved to? There were few options available and although a fair bit of debate the consensus was to put them in the item-list-tabs ul list where the filters are. If themes are found to be still filtering the button to 『bp_groups_directory_header』 this will be trapped and redirected to render in the item-list-tabs
    Naturally not everyone might want the links in the header so to that end it is possible to prevent the create buttons rendering in the list tabs by using:
    add_filter( 'bp_get_group_create_nav_item', '__return_false' );
    add_filter( 'bp_get_blog_create_nav_item', '__return_false' );

    Having removed this new positioning you can add your buttons back by using one of the available 『do_action』 function calls in the templates, for example:
    add_action( 'bp_before_directory_groups', 'bp_group_create_button' );
    add_action( 'bp_before_directory_blogs_content', 'bp_blog_create_button' );

    Akismet 反垃圾外掛

    Akismet 反垃圾外掛

    Codex Home → Releases → Version 1.7 → Akismet
    Akismet

    Starting with BuddyPress 1.7, extended support for Akismet『s anti-spam checking was integrated into the Activity Streams component. If you』re using Akismet, BuddyPress will seamlessly and silently send activity stream updates through for scanning, and prevent spammy ones from being made visible to your community based on the very same discussion settings you use for comments.
    Typically, plugins and themes would want to opt into supporting BuddyPress; not the other way around. Akismet is a unique integration situation because it comes bundled with WordPress and is currently the best and most readily available solution for mitigating spam, so BuddyPress has chosen to support it.
    If you wish to turn off Akismet integration, there is a checkbox in BuddyPress』s settings to do so.

    在 BuddyPress 論壇上提供支援

    在 BuddyPress 論壇上提供支援

    Codex Home → Participate and Contribute → Providing Support at the BuddyPress Forums
    Providing Support at the BuddyPress Forums

    Welcome Forum Volunteers
    Thank you for taking the time to provide support at the BuddyPress Forums. Please note that the rules and guidelines set up in the WordPress support forums apply here as well. The following documents will help you navigate through our Forums.
    1. Forum Welcome – this document is in part directed towards those who seek support at the forums but contains information about helping out, when topics can be deleted or closed, and reporting threads, among others. Disregard the mailing list information unless the issue is specific to WordPress.
    2. WordPress Support Handbook – This contains a good number of articles which will help you provide support the 「WordPress Way」. Some articles which you might like to read first:

    How to Give Help
    When Good Users Go Bad
    Approach to providing good support
    Examples of Good vs. Bad Support
    Modlook and Tagging
    What makes a Good Bug Report

    Forum Moderators
    Thank you for accepting the invitation to become moderators at our support forums
    Please take a moment to read the recommended articles above and the ones below to re-acquaint yourself with our forum rules. Should you have any questions or suggestions, feel free to reach out to the BP core team.

    Welcome to Forum Moderators (WP Forum Handbook)
    Closing Posts (Forum Welcome) – Do not feel obliged to close very old topics as there will be a script to auto-close topics after a certain period of time
    Stock Answers for Forum Moderators (WP Forum Handbook)
    Deleting/Editing Posts (Forum Welcome)

    Additional Reference: The accepted conventions on asking questions
    It can be worthwhile reading through this document below as a primer on what is suggested as the correct approach to asking questions on forums and lists. While it』s aimed at the poster as guidance on how to behave and form a question that will gain positive responses, it』s useful for all to understand and is considered as a RFC:
    How To Ask Questions The Smart Way

    WordPress 選單中的 BuddyPress 連結

    WordPress 選單中的 BuddyPress 連結

    Codex Home → Getting Started → BuddyPress Links in WordPress Menus
    BuddyPress Links in WordPress Menus

    You can add links to: (a) the directory pages of your activated BuddyPress components and/or (b) your respective Member screens, in any of the navigation menus available in your theme. This can only be done after you finish configuring your BuddyPress installation (regular site | multisite).
    Add Menu Links to the Directory Pages of Activated BuddyPress Components
    Links include: Sitewide Activity, Members Directory, Groups Directory, and/or Blogs Directory (multisite only).

    Navigate to Appearance > Menus.
    Create a new menu.
    Under the 「Pages」 section, select the links to the BuddyPress pages.
    Click on the 「Add to Menu」 button.
    Arrange the menu links as you like it.
    Click on 「Save the Menu」 button.
    Go to the 「Manage Locations」 tab and assign this menu to a theme menu location.
    Click save and refresh your site to see your new custom menu in place.

    Add Menu Links Specific to the Logged-in Member

    Click on 「Screen Options」 to open up the panel at the top of the screen and check the 「BuddyPress」 option under the 「Show On Screen」 section. You can either create a new menu to contain these membership links or add them to the menu you already created above.

    Navigate to the new 「BuddyPress」 navigation links in the panel shown below.

    Select the items you would like to add to your menu
    Click on the 「Add to Menu」 button. The links will be added to the Menu Structure panel.
    Click on 「Save the Menu」 button.

    Example of this menu in the front page of your site.