定制 (Customizing)

定制 (Customizing)

Codex Home → Getting Started → Customizing
Customizing

There are various ways to customize your BuddyPress site:

BuddyPress plugins in the WordPress.org repository
create your own plugin or
develop a custom theme

The BuddyPress forums offer up many code snippets and solutions from the community to help you add that extra functionality.
External Resources
http://wordpress.stackexchange.com/questions/tagged/buddypress

头像上传失败

头像上传失败

Codex Home → Getting Started → Troubleshooting → Avatar upload fails
Avatar upload fails

There could be a number of reasons uploads would fail, your server error logs may provide a clue as to what has happened.
The predominant reason uploads fail is due to the server being unable to write to the uploads directory, the 『server』 in this instance is the server process that is running your web server and on *nix boxes is generally 『httpd』 or 『Apache』 this process and it』s 『group』 or 『owner』 must have access to the sites folder structure.
When uploads such as Avatars do fail establish whether this is a general uploads failure by attempting to upload an image via the WordPress Media library interface, more often than not this, too, will fail and you will know it』s an owner/permissions failure that needs correcting – you may need to contact your host to have this corrected explaining that the server process can』t write to your site directories, specifically 『uploads』.
Another important factor is that the PHP image manipulation extension must be installed, make sure you have the 『GD image library』 installed by checking your phpinfo stats – usually available if you have control panel installed if not you would need to upload a file to your site root with the single command in and navigate your browser to that file to see all your PHP configuration detail. Remember to remove that file from your site root after you』ve copied the details for reference.
Next, check permissions, so make sure the web server has correct permissions.
/wp-content/uploads should be set to 755 on a Unix server.
On this matter you may see advice along the lines of setting permissions to 『777』 or 『world writeable』. This is bad advice. Changing permissions to 『777』 may overcome the problem but there is never a case where any folders need completely open permissions; it』s very insecure.

模板包演练 – Twenty Ten

模板包演练 – Twenty Ten

Codex Home → Legacy Docs → Archived Section: Theme Development → Themes & the BuddyPress Template Pack → Template Pack Walkthrough – Twenty Ten
Template Pack Walkthrough – Twenty Ten

Archived file. Good only up to BP 1.6.5 version

BP TEMPLATE PACK 1.2 == BUDDYPRESS 1.5 == WORDPRESS 3.2.1

There are two ways to implement Step Three of the compatibility process:
– First Method: Superimposing the HTML structure of your WordPress theme onto 16 BP template files which were transferred into your WP theme folder during the compatibility process or
– Second Method: Creating the following files in your WordPress theme – header-buddypress.php, sidebar-buddypress.php and/or footer-buddypress.php
We』ll use the second method to make Twenty Ten compatible with BuddyPress. By the end of this article, you should have the basic child theme files required to make Twenty Ten compatible with BP 1.5 using the BP Template Pack plugin:

/bp-twentyten/

header-buddypress.php
sidebar-buddypress.php
style.css

Prelude: Create a Twenty Ten Child Theme
( If you already have your own Twenty Ten Child theme, skip this section and proceed to the Compatibility Process )
1. Create a new theme folder for your Twenty Ten child theme. For this example, the child theme is called BP Twenty Ten so we』ll name our theme folder bp-twentyten.
2. Create a style.css file and add it in the bp-twentyten folder with content below:
/*
Theme Name: BP Twenty Ten
Theme URI: https://codex.buddypress.org/
Description: Twenty Ten child theme for BuddyPress 1.5 Compatibility Process
Version: 1.0
Author: mercime
Author URI: https://codex.buddypress.org/
Template: twentyten
Tags: buddypress, two-column
*/
@import url( ../twentyten/style.css );
3. Upload the bp-twentyten folder with the style.css file within to your server to /wp-content/themes/
N.B. We』ll be creating and uploading more files later during the compatibility process. For now, these are the basic files required for the child theme to be activated so that we can proceed with the BP compatibility process.
Compatibility Process
1. After activating BuddyPress, go to dashboard Appearance > Themes and activate our child theme 「BP Twenty Ten」. At the top of the Themes panel, you』ll see a message with 3 different options to make your theme compatible with BuddyPress. Select update your existing WordPress theme

2. Clicking on the above link will bring you to the 「Install Plugins」 panel. Click on 「Install」 link under BuddyPress Template Pack plugin.

3. Click OK to install BuddyPress Template Pack plugin.

4. Activate BuddyPress Template Pack plugin.

5. Go to Appearance > BP Compatibility

6. Step One: Moving template files automatically. Click on Move Template Files

7. Templates moved successfully! Click on Continue to Step Three You only need to go through Step Two if there was a problem transferring the files.

Pages: 1 2 3

groups_group_create_complete()

groups_group_create_complete()

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

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

安装

安装

Codex Home → Getting Started → Installation
Installation

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

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

Manual Installation

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

⇒ Next: Configure BuddyPress
⇐ Previous: Getting Started

检查 BuddyPress

检查 BuddyPress

Codex Home → BuddyPress Plugin Development → Checking For BuddyPress
Checking For BuddyPress

Because of the way that WordPress loads plugins, it』s possible that your plugin could load before or after BuddyPress. This makes it difficult to know if BuddyPress is loaded, or if your plugin has the proper functions available that it might need. If you don』t check, and assume BuddyPress is loaded, it could take an entire site down when BuddyPress is upgraded.
It』s really easy to do this. In your plugin, create a loader.php file that will check to see if BuddyPress is active, and only then load code that relies on BP:
?12345678910111213141516171819/*Plugin Name: My PluginPlugin URI: http://example.org/my-plugin/Description: My BuddyPress pluginVersion: 1.0Requires at least: WordPress 2.9.1 / BuddyPress 1.2Tested up to: WordPress 2.9.1 / BuddyPress 1.2License: GNU/GPL 2Author: Some PersonAuthor URI: http://example.org/me/*/ /* Only load code that needs BuddyPress to run once BP is loaded and initialized. */function my_plugin_init() {    require( dirname( __FILE__ ) . '/my-plugin.php' );}add_action( 'bp_include', 'my_plugin_init' ); /* If you have code that does not need BuddyPress to run, then add it here. */

将 1.0 主题升级到 1.1

将 1.0 主题升级到 1.1

Codex Home → Legacy Docs → Archived Section: Theme Development → Upgrading a 1.0 Theme to 1.1
Upgrading a 1.0 Theme to 1.1

Archived file. Good up to BP 1.1

Starting at version 1.1, BuddyPress themes are simply WordPress themes with extra template files. The separation between a WordPress (old bphome) and BuddyPress (old bpmember) theme has been removed. All theme files are contained in the same theme and one theme design applies to the site as a whole.
This guide will help those people who have built custom themes for BuddyPress 1.0 transition to the new theme setup.
How you approach upgrading your theme really depends on your setup in BuddyPress 1.0. Please choose the section that best describes your situation and follow those instructions only.
These help guides make the assumption that you have copied the new 1.1 default themes (/plugins/buddypress/bp-themes/bp-sn-parent/ and /plugins/buddypress/bp-themes/bp-default/ into the /wp-content/themes/ directory.
「I』ve used the old default themes, but modified the layout/colors」

Duplicate /wp-content/themes/bp-default/ and give it a new unique name.
In your new duplicated default theme, inside the _inc/css folder create a file called 「custom.css」
Copy the custom CSS from both your old bphome and bpmember theme into this file and save the file.
Open up style.css in the root of your duplicated default theme.
Edit the 「Theme Name」 at the top of the style.css file and give it a unique name.
The last line of style.css is: /* @import url( _inc/css/custom.css ); */. Remove the starting /* and the ending */ on that line. Save the file.
Make sure you have backed up your 「/wp-content/bp-themes/」 directory, then delete it.
Log in as an admin and head to /wp-admin/ on your root blog.
Under 「Site Admin > Themes」, select 「yes」 next to the theme with the custom name you just entered into style.css
Under 「Appearance > Themes」 activate the theme for the root blog.
You should now be using the new one theme system with your design customizations.

「I』ve used a WordPress theme for my blog with the default BuddyPress member theme」
In BuddyPress 1.0 you could use a WordPress theme that was completely separate from your BuddyPress theme design. More often than not the BuddyPress theme would not get updated to match the WordPress theme design in use. This made the overall experience clunky.
With BuddyPress 1.1 you can integrate BuddyPress templates with your WordPress theme design. One thing to be aware of before taking this route is that WordPress themes only contain layout styles for blog pages – they are not built for the extra features BuddyPress provides. You will have to add custom CSS to your WordPress templates to handle the layout for the BuddyPress pages.

Duplicate your existing WordPress theme so you have a backup.
Open up the folder /wp-content/themes/bp-sn-parent/ and copy every folder and the following files 「optionsbar.php」, 「userbar.php」 and 「plugin-template.php」. Paste these folders and files into your active WordPress theme.

You will now need to make an edit:

Open up header.php and add the following lines (usually at the bottom inside of a content or container div, not inside the header div):
?123456<?php if ( !bp_is_blog_page() && !bp_is_directory() && !bp_is_register_page() && !bp_is_activation_page() ) : ?> <?php locate_template( array( 'userbar.php' ), true ) ?><?php locate_template( array( 'optionsbar.php' ), true ) ?> <?php endif; ?>
Save the header.php file.
Make sure you have backed up your 「/wp-content/bp-themes/」 directory (this is important for the last step), then delete it.
You should now be able to visit your site and BuddyPress URL』s and find that the BuddyPress pages will work with your general site design and header/footer. You will however find that BuddyPress pages are generally not presented correctly.
You can try including the components.css file from the BuddyPress parent theme to add layout styles to BuddyPress pages. Open up your WordPress theme』s style.css file. Add the following line below the comment header:@import url( ../bp-sn-parent/_inc/css/components.css )
You should now see basic layout styles for BuddyPress pages within your WordPress theme. You will likely still need to perform some cleanup to get things working completely seamlessly.

If you find that your WordPress theme is not being co-operative, you can install BuddyPress on a secondary blog giving you the option to theme BuddyPress differently than your root blog.
Full instructions to do this can be found here:
https://codex.buddypress.org/how-to-guides/install-buddypress-on-a-secondary-blog/
「I』ve built a completely custom WordPress theme and BuddyPress theme」
Not a problem, in your case you need to merge the two into one single WordPress theme.
It should be as simple as copying all of the templates from the BuddyPress theme and pasting them into the WordPress theme. Be sure to copy and paste over all of the CSS from the BuddyPress theme also.
Once you are done, backup your /wp-content/bp-themes/ directory and remove it. This will allow the new integrated theme to work.
p

论坛主题循环

论坛主题循环

Codex Home → Developer Resources → Loops Reference → Forum Topics Loop
Forum Topics Loop

The forum topics loop can be used to output a list of forum topics.
Standard Loop

<tr class="">

<a class="topic-title" href="" title=" - ">

<a href="">

<a href="">

<a href="" title="">

Accepted Parameters
The bp_has_forum_topics() function will accept a number of parameters that will manipulate the data being returned.

type optional
List forum topics by type.

Accepted arguments: newest,popular,unreplied,tags (if type equals 「tags」, define the 「search_terms」 argument and list the tag you wish to filter by)
Default value: newest

forum_id optional
Return only forum topics from a specific group forum.

Default value: false

user_id optional
Return only forum topics that this user has started.

Default value: false

per_page optional
Number of forum topics to display in the loop.

Default value: 20

page optional
The page to display.

Default value: 1

max optional
The total number of forum topics to return.

Default value: false (no limit)

no_stickies optional
Return 「false」 if you do not want stickies listed at the top of the forum loop.

Default value: all

search_terms optional
Return only groups that match these search terms. When used in conjuction with 「type=tags」, can use search_terms to define the tag name.

Default value: false

Examples
Modifying the forum loop to list forum topics by most popular:

更改内部配置设置

更改内部配置设置

Codex Home → Getting Started → Customizing → Changing Internal Configuration Settings
Changing Internal Configuration Settings

N.B: This article lists deprecated settings as well as current ones
 
There are many internal configuration settings that can be changed by adding a configuration definition line to your wp-content/plugins/bp-custom.php file or use a filter if available. Here』s a list of the current configurations that can be changed:
 
Avatar Configurations
Avatar specific settings can be changed:
define ( 'BP_AVATAR_THUMB_WIDTH', 50 );
define ( 'BP_AVATAR_THUMB_HEIGHT', 50 );
define ( 'BP_AVATAR_FULL_WIDTH', 150 );
define ( 'BP_AVATAR_FULL_HEIGHT', 150 );
define ( 'BP_AVATAR_ORIGINAL_MAX_WIDTH', 640 );
define ( 'BP_AVATAR_ORIGINAL_MAX_FILESIZE', $max_in_kb );
define ( 'BP_AVATAR_DEFAULT', $img_url );
define ( 'BP_AVATAR_DEFAULT_THUMB', $img_url );

 
Cover Image Configurations
To customize cover images please visit this link: https://codex.buddypress.org/themes/buddypress-cover-images/
 
Advanced Configurations
Put profiles in the root — http://example.org/username/
define ( 'BP_ENABLE_ROOT_PROFILES', true );
add_filter( 'bp_core_enable_root_profiles', '__return_true' );
N.B. If you use BP_ENABLE_ROOT_PROFILES there might be a situation where some user profiles get the same url as some posts or pages rendering either of them inaccessible. This might also be true of sub-sites if you』re running multisite with subdirectories. See ticket #1426 for more information.
Change the default tab opened when looking at a user』s profile (default is activity):
define( 'BP_DEFAULT_COMPONENT', 'profile' );
(Note: if you change the URL slug of xprofile, say, define ( 'BP_XPROFILE_SLUG', 'info' );, you would have to change it here accordingly,  define( 'BP_DEFAULT_COMPONENT', 'info' );  otherwise, link to the profile page would always jump to homepage.)
Change the default tab opened when looking at a group (default is home):
define( 'BP_GROUPS_DEFAULT_EXTENSION', 'members' );
Disable the admin bar / buddybar at the top of every screen:
define ( 'BP_DISABLE_ADMIN_BAR', true );
Swap the Buddybar for the WordPress toolbar: (default in buddypress 1.6)
define ( 'BP_USE_WP_ADMIN_BAR', true );
Disable the custom header functionality on the default BuddyPress theme:
define( 'BP_DTHEME_DISABLE_CUSTOM_HEADER', true );
Disable the 「You』ll need to activate a BuddyPress compatible theme…」 warning message in the WordPress administration screens:
define( 'BP_SILENCE_THEME_NOTICE', true );
Enable support for LDAP usernames that include dots:
define( 'BP_ENABLE_USERNAME_COMPATIBILITY_MODE', true );
Disable auto-joining of a group when non group member performs group activity:
defined( 'BP_DISABLE_AUTO_GROUP_JOIN', true );
Ignore all deprecated code (don』t load it):
define ( 'BP_IGNORE_DEPRECATED', true );
add_filter( 'bp_ignore_deprecated', '__return_true' );
 
Forum Configurations
Change the parent forum to use for all BuddyPress group forums:
define ( 'BP_FORUMS_PARENT_FORUM_ID', $forum_id );
 
Database Configurations
Set a custom user database table for BuddyPress (and WordPress to use):
define ( 'CUSTOM_USER_TABLE', $tablename );
Set a custom usermeta database table for BuddyPress (and WordPress to use):
define ( 'CUSTOM_USER_META_TABLE', $tablename );
 
Multisite Configurations
Allow BuddyPress to function on multiple blogs of a WPMU installation, not just on one root blog (More details about BP_ENABLE_MULTIBLOG):
define ( 'BP_ENABLE_MULTIBLOG', true );
add_filter( 'bp_is_multiblog_mode', '__return_true' );
Set which blog ID BuddyPress will run on:
define ( 'BP_ROOT_BLOG', $blog_id );
add_filter( 'bp_get_root_blog_id', 'filter_root_blog_id' ); // return blog ID integer
 
Deprecated Configurations
Change the URL slugs of BuddyPress components:
The references to slug Constants are deprecated, this section requires updating.
define ( 'BP_ACTIVITY_SLUG', 'streams' );
define ( 'BP_BLOGS_SLUG', 'journals' );
define ( 'BP_MEMBERS_SLUG', 'users' );
define ( 'BP_FRIENDS_SLUG', 'peeps' );
define ( 'BP_GROUPS_SLUG', 'gatherings' );
define ( 'BP_FORUMS_SLUG', 'discussions' );
define ( 'BP_MESSAGES_SLUG', 'notes' );
define ( 'BP_WIRE_SLUG', 'pinboard' );
define ( 'BP_XPROFILE_SLUG', 'info' );
define ( 'BP_REGISTER_SLUG', 'signup' );
define ( 'BP_ACTIVATION_SLUG', 'enable' );
define ( 'BP_SEARCH_SLUG', 'find' );
define ( 'BP_HOME_BLOG_SLUG', 'news' );