活動流和 date_query

活動流和 date_query

Codex Home → Developer Resources → Activity Stream and date_query
Activity Stream and date_query

If you have a lot of activity entries on your site, load times can suffer dramatically when viewing activity streams.

You can use the date_query argument to speed things up by limiting the entries to only those from the past day or week or month, etc.

But you cannot add it as a string in the usual fashion. For example, adding a per_page argument:

Instead, you need to use an array, which is easy enough until you try to include the value of bp_ajax_querystring( 『activity』 ) as an argument and the 『Load More』 button stops working properly.

Here』s the solution. You can paste it in your overload of the activity-loop template or you could use the bp_before_has_activities_parse_args filter.

$date_limit,
),
);

$activity_args['per_page'] = 5;

?>

// etc.

Note the use of wp_parse_str to add the query string needed for the 『Load More』 button.

And you can use conditionals to change the date_query argument depending on which activity stream you』re viewing:

?12345678910111213if ( bp_is_activity_directory() ) {     $date_limit = date("Y-m-d H:i:s", strtotime("-1 week"));      } elseif( bp_is_group() ) {     $date_limit = date("Y-m-d H:i:s", strtotime("-1 month"));      } else { // profile stream     $date_limit = date("Y-m-d H:i:s", strtotime("-1 year"));      }

群組管理員 – 新增自定義列

群組管理員 – 新增自定義列

Codex Home → BuddyPress Plugin Development → Groups Admin – Add Custom Column
Groups Admin – Add Custom Column

It can be very handy to see additional information about each group when viewing the Groups screen in wp-admin.

The necessary hooks are found in this file: buddypress/bp-groups/classes/class-bp-groups-list-table.php

This example will add a column to show the number of pending member requests to join each private group. If a group is public there can be no pending requests, so we』ll show a simple dash in that row.

// add the column
function groups_admin_add_custom_column( $columns ) {

$columns["pending_group_members"] = "Join Requests";

return $columns;

}
add_filter( "bp_groups_list_table_get_columns", "groups_admin_add_custom_column" );

// add the column data for each row
function groups_admin_custom_column_content( $retval = "", $column_name, $item ) {

if ( "pending_group_members" !== $column_name ) {
return $retval;
}

if ( "private" == $item["status"] ) {

$user_ids = BP_Groups_Member::get_all_membership_request_user_ids( $item["id"] );

return count( $user_ids );
}

return "-";

}
add_filter( "bp_groups_admin_get_group_custom_column", "groups_admin_custom_column_content", 10, 3 );

This code can be placed in bp-custom.php .

新增電子郵件令牌

新增電子郵件令牌

Codex Home → Emails → Add Email Token
Add Email Token

Adding a token to an existing email can be done by using the bp_email_set_tokens filter.

For example, an email is sent when a member requests membership in a private group. Let』s add the requesting member』s email address to the body of that email.

function maybe_add_tokens_bp_email( $formatted_tokens, $tokens, $obj ) {

if ( isset( $formatted_tokens['requesting-user.name'] ) && isset( $formatted_tokens['requesting-user.id'] ) ) {

$user_info = get_userdata( $formatted_tokens['requesting-user.id'] );

$formatted_tokens['memberemail'] = $user_info->user_email;

}

return $formatted_tokens;

}
add_filter( 'bp_email_set_tokens', 'maybe_add_tokens_bp_email', 11, 3 );

This page lists the default tokens.

We can use that information to set the conditional so that the token is only added when a group membership request email is generated:

if ( isset( $formatted_tokens['requesting-user.name'] ) && isset( $formatted_tokens['requesting-user.id'] ) ) {
// etc

Now that we have added the memberemail token, we need to use the token in the body of the email.

Go to wp-admin > Emails and find the Membership request for group email. Roll over the name and click Edit. 

Then add the new token to the body of the email.

For example: Member Email: {{memberemail}}

Click Update and the token will be used every time that type of email is generated.

過濾電子郵件

過濾電子郵件

Codex Home → Emails → Filter Emails
Filter Emails

You can filter the email fields by using the bp_email_set_tokens filter hook found in /bp-core/classes/class-bp-email.php.

For example, this will limit the BuddyPress message content to 50 words.Change 50 to whatever integer you want.

function bp_email_content_length( $formatted_tokens, $tokens, $obj ) {

$formatted_tokens['usermessage'] = wp_trim_words( $formatted_tokens['usermessage'], 50, '...' );

return $formatted_tokens;

}
add_filter( 'bp_email_set_tokens', 'bp_email_content_length', 10, 3 );

貢獻程式碼

貢獻程式碼

Codex Home → Participate and Contribute → Contribute with Code
Contribute with Code

Thank you for your interest in contributing to BuddyPress! BuddyPress is an open-source project and, as such, is maintained by volunteers just like you. It is vital for the current, and future success of BuddyPress needs to have a healthy group of contributors. You are very welcome to join us to work on making the plugin as great as possible: every enhancement and each improvement depends on the community. This Quick Start Guide to contributing code to BuddyPress Core is where you can find the resources needed to take you through the process of submitting your first patch.

Choose the code editor you feel most comfortable with!

BuddyPress mainly uses four coding languages: PHP, JavaScript, CSS, and HTML. To write into these languages, you need a code/text editor. Here are below some suggestions for nice ones:

Visual Studio Code (download links),Sublime Text (download links),Atom (download links),Notepad++ (MS Windows only).If your a ninja, you can try Vim

Choose the version control system of your preference

BuddyPress uses a Subversion repository to manage the plugin』s code source. This repository is also mirrored on a Git repository. So the version control system you will use is up to you!

If you want to install Subversion, the WordPress 「Core Contributor Handbook」 has a great tutorial about it.

If you prefer Git and you』ve chosen a different text editor than Visual Studio Code (it is included into it), here are some ways to get it:

Git (download links),Git for Windows (download link)Command Line Tools for your Mac (They should be automatically downloaded if you type git or svn into a Terminal window).If you chose the Atom editor, you could install the Git/GitHub package,If you feel more comfortable with GUI software, you can use GitKraken or Sourcetree.

Install some additional tools to fully enjoy BuddyPress contribution

You probably won』t need all the tools listed below when you start contributing to BuddyPress. You can choose only to install NodeJS and install the other tools once you need them.

NodeJS latest LTS version (download links). Required.GruntJS (Installation procedure for the CLI) [1].Composer (Installation procedure) [2]. Once installed we advise you to make it globally available under the command name composer.WP CLI (Installation procedure) [3]. Once installed we advise you to make it globally available under the command name wp.PHPunit (WordPress installation tutorial, Alternative installation tutorial) [4] Once installed we advise you to make it globally available under the command name phpunit.

[1] GruntJS is used by BuddyPress to run some building tasks like preparing files to be committed, generating RTL versions of CSS stylesheets or minimizing JavaScript files.

[2] Composer is used to install some packages in order to be able to check PHP Code Compatibility and to run PHPUnit tests in our default local development environment.

[3] WP CLI is used to generate a POT file out of the plugin』s PHP and JavaScript files. This POT file is used by translators to translate BuddyPress into various languages (French, German, Spanish, etc..). For your information, WP CLI is a very powerful tool to run WordPress scripts from command lines.

[4] PHPUnit is used to run PHPUnit tests in any local development environment.

Get the BuddyPress development version

First you』ll need a Terminal software, macOs and Linux have been including such a software natively for years. If you』re using Microsoft Windows and chose to work with Git for Windows it includes a BASH emulation to run the same commands we』ll use into this tutorial, otherwise the latest Microsoft Terminal is looking great.

Once you opened a new Terminal window, create a new directory named 「buddypress」 into the local path of your choice.

mkdir ~/Plugins/buddypress

if you are using Subversion, run this command:

# SVN
svn co https://buddypress.svn.wordpress.org/trunk/ ~/Plugins/buddypress

If you are using Git, use this command instead.

# Git
git clone git://buddypress.git.wordpress.org/ ~/Plugins/buddypress

If you move to the ~/Plugins/buddypress directory once the download has finished, you should find the highlighted folders and files of the following screen capture.

Install our default local development environment

The BuddyPress development version you just downloaded contains the @wordpress/env package to generate a local environment using NodeJS (latest LTS version) and Docker. To install Docker, please follow the instructions listed below according to your operating system:

Windows 10 Pro,all other versions of Windows,macOS, Linux.

Once Docker is installed and is running in the background, open a Terminal window to setup your local development environment.

cd ~/Plugins/buddypress

From the ~/Plugins/buddypress the folder where you downloaded the code, you』ll first need to install the node modules we are using in BuddyPress. To do so simply run the following command and take a well-deserved break to let NodeJS download the modules we use as development dependencies (it might take some time!) :

npm install

For starters, if you face any error during npm install at the Microsoft windows env, you will also have to install windows-build-tools.

Once node modules are installed, if you plan to run/write PHP unit tests, you』ll also need to install some composer packages:

composer install

You should see that your ~/Plugins/buddypress directory now contains 1 or 2 more sub directories: /node_modules and /vendor if you installed the composer packages.

Now we can setup the local development environment using this command:

npm run wp-env start

The first time you』ll execute this command it will take some time to run and you』ll see that 2 downloads will start:

Core: it』s the WordPress development version.BP REST: it』s the plugin we use to develop the BP REST API.

Wait until the Terminal displays the following message:

✔︎ WordPress started. (in 00s 00ms)

Then, you can open your Internet Browser and go to this URL: http://localhost:8888/wp-admin/.

You』ll have a last step to achieve: setting the permalink structure to something else than the plain option. Here are the default credentials for the Administrator account:

Username: adminPassword: password

Other useful commands

Stopping the development environment

npm run wp-env stop

Once you run this command, you will quickly get the following confirmation message.

✔︎ Stopped WordPress. (in 00s 00ms)

Running PHP unit tests

If you chose to install Composer and the packages we use as development dependencies, you will be able to run our PHP unit tests suite (and of course contribute to it adding new tests).

On a regular WordPress configuration

npm run test-php

On a Multisite WordPress configuration

npm run test-php-multisite

Customizing your BuddyPress local development environment

To develop BuddyPress we use the development version of WordPress, the development version of the BP REST API and we set two debugging constants:

define( 'WP_DEBUG', true );
define( 'SCRIPT_DEBUG', true );

These options are defined into the .wp-env.json file of the BuddyPress repository. You can override these options using a file named .wp-env.override.json into your ~/Plugins/buddypress local directory.

For instance, you could choose to include another plugin like the one we use to develop BP Blocks using this content for the overriding file:

{
"core": "WordPress/WordPress#master",
"plugins": [ ".", "buddypress/BP-REST#master", "buddypress/bp-blocks#master" ],
"config": {
"WP_DEBUG": true,
"SCRIPT_DEBUG": true
}
}

Setting up a different development environment

Our goal with our local development environment is to try to make it easier & faster for new contributors to be ready to help the BuddyPress project. If you prefer to build your very own local environment: it』s totally fine! In this case, to contribute to BuddyPress, you』ll simply need to checkout our SVN repository or clone our Git mirror into the /wp-content/plugins directory of the WordPress you use into your local environment.

For your information, the WordPress core contributor handbook includes great tutorials to build such an environment.

Patching BuddyPress

Let』s work with a real bug example (It might has been fixed when you』ll read this page!) to understand how to suggest a fix to the BuddyPress development team. First, open the ~/Plugins/buddypress directory into your favorite code editor.

As you can see, I』m using the Visual Studio Code editor I like to have a tree of all directories and files on the left and a Terminal window under the opened file』s content.

The first big differences you will find with the way the BuddyPress plugin is organized into the WordPress Plugins directory are:

The plugin』s code is inside a src directory: that』s your main target as a new BuddyPress contributor.There』s a js directory at the same level than the plugin』s component directoriesThe plugin』s PHP unit tests suite is inside the tests directoryThere』s a bunch of configuration files like package.json or composer.json

Before doing any changes, I advise you to always synchronize your local copy of the BuddyPress development version with our central repository. Using your Terminal, simply run the command corresponding to the version control system you chose.

# SVN
svn up

# Git
git pull origin master

Once synchronized, let』s launch the BuddyPress local development environment.

npm run wp-env start

Once you get the confirmation it』s up and running, you can go to http://localhost:8888 to play with the WordPress site.

Finding an issue

If you log in and go to the Dashboard then open the BuddyPress』 tools submenu, here』s what you get.

Nothing special so far, but let』s activate one of the checkboxes, hit the 「Repair items」 button and have eyes on the notice that will then be displayed.

Then, you should see some lack of consistency with the WordPress administration general appearance:

The notice message does not used the width you could find in other administration screens.This notice message also has a bigger height, giving the impression the dismissible button (x) is not vertically aligned.

Moreover, it』s minor but, the color of the information above the 「Repair tools」 form (which seems to be an important advice) is lighter than the rest of the text.

If you look deeper using your Web browser software』s inspector and comparing the BuddyPress tools administration screen (image on the right) with another WordPress tools administration screen (image on the left), you』ll see HTML output [1] needs to be edited as well as the src/bp-core/admin/css/common.css file [2].

[1] You can see that compared to other administration screens, an hr tag is missing under the main title located into the h1 tag. Now if you compare the form structure with the one available into the WordPress Export tool, you can see it』s improvable. Let』s add an h2 tag to visually inform the users about what they need to do to select one or more tools and use the legend tag to inform screen readers about what to expect from the checkboxes. You can also wrap the checkboxes into a paragraph tag.

[2] If the notice message has a bigger height and a smaller width, it』s due to the BuddyPress Admin CSS file that is restricting the content』s width of the wrapper to 950 pixels max and is using a bigger line-height for paragraphs.

Editing the code to fix the issue into your BuddyPress local repository

The content of the BuddyPress tools administration screen is generated by the bp_core_admin_tools() function from the src/bp-core/admin/bp-core-admin-tools.php file.

To successfully warn the administrator about the potential database overhead that may happen if you run more than one tool at a time, you could use the attention CSS class instead of the description one that is used. You should also add the hr tag to delimit the end of the page』s header and use a form structure more inline with the WordPress Export tool 『s screen.

Once edits are saved, let』s check the results into the web browser. You need to reproduce the steps that made you discover the issue.

You still need to deal with the notice presentation: let』s edit the BuddyPress Admin CSS file!

As you』ve edited the HTML output, some CSS rules are not needed anymore and as you』ve seen earlier, you don』t need to restrict the width of the screen』s content wrapper. I believe you don』t need any of the CSS rules of the 5.0 Tools - BuddyPress section actually. So let』s remove it and update the sections numbering.

Generating the patch

To share your suggestion to fix an issue with the BuddyPress development team, you』ll need to use our Trac (our tool to manage the BuddyPress code source and track BuddyPress bugs).

If you don』t have a WordPress.org account yet, create one as you』ll need to log in the BP Trac to be able to submit tickets.

The patch is a file containing the code you changed compared with the existing code and you』ll use this file as an attachment to the Trac ticket explaining the issue.

Here』s the command to run to create this file:

# SVN
svn diff > ~/Desktop/replaceWithTicketNumber.diff

# Git
git diff --no-prefix > ~/Desktop/replaceWithTicketNumber.patch

NB: the --no-prefix option of the Git command is important so that people using SVN can apply your patch. If you want to avoid adding this option each time you create a patch, you can customize your Git configuration this way:

git config --global --bool diff.noprefix true

Here』s how the diff file should look like if you open it into your code editor:

Now you』ve created the patch, you need to clean things up so that next time you synchronize your local copy of the BuddyPress repository you don』t get errors. To do so, run the following command:

# SVN
svn revert -R *

# Git
git checkout .

Sharing your ticket on BuddyPress Trac

Now you have your patch ready and you cleaned your local copy of the BuddyPress repository, you can write a ticket about it to inform the BuddyPress development team about your great contribution. Head over to the BP Trac』s page to submit your ticket to do so.

Into the summary field, insert a short description of your issue. Use the Description multiline text field to detail your issue making sure to inform about the steps to reproduce it and eventually the specific configuration to use to reproduce it (eg: Multisite with BuddyPress active on a sub site). Don』t forget to add the has-patch keyword to your ticket and to activate the checkbox to attach a file once your ticket will be posted. You can include screenshots or any complementary information that can help understanding what your patch will fix once applied.

Submit your ticket and don』t forget to edit the name of your file to match the ticket number you』ll find once the next screen will load.

For this patch, the replaceWithTicketNumber.patch file should be renamed to 8357.patch.

Good job so far! You can have a look at the submitted ticket: #8357.

Every time your ticket will be updated (comments, commits, …), you』ll receive an email notification. Discussions about your ticket are likely to happen: eg. BuddyPress developers may ask you to update/edit your patch. You』ll see these discussions can be really interesting and can greatly help you improve your skills.

Applying a patch to your local copy of the BuddyPress repository

There are 2 situations when you』ll need to apply a patch to your local copy of the BuddyPress repository:

You need to update a patch you previously shared on BP Trac.You want to contribute to a patch shared by another contributor and provide him with your feedbacks about it.

In both cases, the commands to run are the same. First from your Terminal software move to your BuddyPress repository』s local copy.

cd ~/Plugins/buddypress

Once there, don』t forget to synchronize your local copy with the central BuddyPress repository.

# SVN
svn up

# Git
git pull origin master

If you installed the GruntJS tool, you simply need to run this command:

grunt patch:8357

8357 is the ticket number (the one that was created in previous chapter).

Otherwise, you』ll need to download the patch from the ticket』s page before applying it.

Once downloaded, whether you use SVN or Git the command to apply the patch is the same.

patch -p0 < /path-to-the-downloaded-patch/8357.patch

Once you finished updating your patch (& possibly generating a new version of it) or testing another contributor』s patch, don』t forget to clean your BuddyPress repository』s local copy.

# SVN
svn revert -R *

# Git
git checkout .

Follow WordPress Coding & Documentation standards

When editing the BuddyPress code source, it』s important your code follows the WordPress Coding Standards. I advise you to check them often as they can be updated. Here are the coding standard links:

AccessibilityCSSHTMLJavaScriptPHP

For the inline documentation (for Classes, hooks and functions DocBlocks) you might use into your code, it』s also important to use these WordPress standards:

JavaScriptPHP

Congratulations! You are now ready to contribute to the BuddyPress code source. If you』re looking for issues to fix, check our roadmap and click on the 「active」 link of the latest milestone to discover what we need to do

替代註冊工作流程

替代註冊工作流程

Codex Home → Administrator Guide → Alternative Registration Workflows
Alternative Registration Workflows

By default, registration in BuddyPress follows this workflow:

A site administrator can enable registration by checking 「Anyone can register」 on the WP Admin > Settings > General options screen.

If registration is enabled, then site visitors can sign up for an account using the registration form.

Once the registration form has been submitted, the user will be sent an activation email that verifies that the user』s email address is legitimate.

Once the user activates her account, she will be able to login using the username and password she specified on the registration form.

Changing the Registration Process

You can change the default BP registration flow by allowing member invitations and/or requiring membership requests. These features can be used separately or together to change who is allowed to join your site.

Invitations

Invitations can be used when public registration is open to help grow your site』s membership or when public registration is closed to only allow membership by referral from an existing member.

Enable membership invitations by visiting the WP Admin > Settings > BuddyPress > Options screen.

Your site members can send invitations from their user profiles.

The invited member will receive an email containing a link to the registration form.

Even if you have disabled public registration, valid invitation holders will be able to access the form using the link in the email.

Once the user registers, the account will be activated immediately (responding to the invitation has already verified the user』s email address) and will be able to log in to the site.

Membership Requests (available in BuddyPress 10)

Enabling membership requests interrupts the registration process by preventing the activation email from being sent automatically, and instead requires that a site administrator manually review and approve each account request.

Enable membership requests by visiting the WP Admin > Settings > BuddyPress > Options screen. Note that public registration must be disabled for requests to be activated.

Then, visitors will be able to visit the registration form to submit a membership request.

When a new request is submitted, the site admins will receive a site notifications and an email. The email can be disabled via the user』s email preferences screen.

The email message that a BuddyPress site admin receives when a new request is submitted.

The link in the email or site notification will take the administrator to an approval screen where she can review the submitted membership request and choose to confirm it.

The administrator can also visit the Manage Pending Memberships screen at WP Admin > Users > Manage Pending Memberships.

Hovering over a row will reveal the following actions available to the admin:

「Activate」 will activate the user immediately without requiring that they validate their email.「Approve Request」 or 「Resend Approval」 takes you to the confirmation screen before being able to send the activation link to the desired pending request. You can only send the activation email once per day.「Profile Info」 will display extended profile information for the request.「Delete」 allows you to delete a pending account from your site. You will be asked to confirm this deletion.

If the administrator approves the request, the submitter will receive an activation email and can complete their registration.

If the administrator deletes the request, the submitter will receive an email telling them that their request has been declined.

Membership Requests – Automatically approving some membership requests.

There are cases where every user that satisfies some criteria should be granted access immediately and not require manual approval. For example, if you are building a site for students and staff at a specific school, you might want to approve every request that comes in from any user with a my-school.edu email address. You can do this by adding a filter like the following to your bp-custom.php file or your theme』s functions.php file:

?123456789101112131415161718192021222324252627<?php /** * If a user submits a site membership request, but has a * 'my-school.edu' email address, bypass the manual approval of the request. * * @param bool  $send    Whether or not this membership request should be approved *                       immediately and the activation email sent. *                       Default is `false` meaning that the request should be *                       manually approved by a site admin. * @param array $details The details of the request. */function bpcodex_auto_approve_some_requests( $send, $details ) {    // We'll need the prospective user's email address.    if ( empty( $details['user_email'] ) ) {        return $send;    }     $email_parts = explode( '@', $details['user_email'] );     // If the email address is one of ours, approve the request.    if ( ! empty( $email_parts[1] ) && 'my-school.edu' === $email_parts[1] ) {        $send = true;    }     return $send;}add_filter( 'bp_members_membership_requests_bypass_manual_approval', 'bpcodex_auto_approve_some_requests', 10, 2 );

?1

活動 → 提及

活動 → 提及

Codex Home → Member Guide → Activity → Mentions
Activity → Mentions

This page shows all the @ mentions you received throughout the site.
Filter to Show @mentions in:

Everything (default)
Updates
New Sites (if on Multisite installation)
Posts
Comments
Friendships (if Friendships are enabled)
New Groups (if Groups are enabled)
Group Memberships (if Groups are enabled)
Group Updates (if Groups are enabled)

⇒ Next: Activity → Favorites
⇐ Previous: Activity → Personal
⇐ Back to Member Guide

活動 → 收藏夾

活動 → 收藏夾

Codex Home → Member Guide → Activity → Favorites
Activity → Favorites

This is a list of all the items (posts, comments, friendships, etc.) you have 「favorited」 in your Groups』 Activity Streams, the Sitewide Activity Stream, or even your own Personal Activity Stream.
Filter to Show 「favorited items」 in:

Everything (default)
Updates
Posts
Comments
New Groups (if Groups are enabled)
Group Memberships (if Groups are enabled)
Group Updates (if Groups are enabled)
Topics (if bbPress is activated)
Replies (if bbPress is activated)

⇒ Next: Activity → Friends
⇐ Previous: Activity → Mentions
⇐ Back to Member Guide

活動 → 好友

活動 → 好友

Codex Home → Member Guide → Activity → Friends
Activity → Friends

This panel shows all of your friends』 activities throughout the site.
Filter to Show:

Everything (default)
Updates
New Sites (if on Multisite installation)
Posts
Comments
Friendships (if Friendships are enabled)
New Groups (if Groups are enabled)
Group Memberships (if Groups are enabled)
Group Updates (if Groups are enabled)
Topics (if bbPress is activated)
Replies (if bbPress is activated)

⇒ Next: Activity → Groups
⇐ Previous: Activity → Favorites
⇐ Back to Member Guide

活動 → 小組

活動 → 小組

Codex Home → Member Guide → Activity → Groups
Activity → Groups

This page shows all the activities recorded in the groups you have joined.
Filter to Show:

Everything (default)
Updates
Group Updates
Group Memberships
New Groups
Topics (if bbPress is activated)
Replies (if bbPress is activated)

⇒ Next: Profile → View
⇐ Previous: Activity → Friends
⇐ Back to Member Guide