first commit

This commit is contained in:
2024-11-10 21:08:49 +01:00
commit 0d932ce5ee
14455 changed files with 2567501 additions and 0 deletions

View File

@@ -0,0 +1,498 @@
<?php
/**
* bbPress Abstractions
*
* This file contains functions for abstracting WordPress core functionality
* into convenient wrappers so they can be used more reliably.
*
* Many of the functions in this file are considered superfluous by
* WordPress coding standards, but they're handy for plugins of plugins to use.
*
* @package bbPress
* @subpackage Core
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/**
* Setup Admin
*
* This exists outside of "/includes/admin/" because the converter may need to
* be setup to convert the passwords of users that were migrated from another
* forum platform.
*
* @since 2.6.0 bbPress (r2596)
*/
function bbp_setup_admin() {
$bbp = bbpress();
// Skip if already setup
if ( empty( $bbp->admin ) ) {
// Require the admin class
require_once $bbp->includes_dir . 'admin/classes/class-bbp-admin.php';
// Setup
$bbp->admin = class_exists( 'BBP_Admin' )
? new BBP_Admin()
: new stdClass();
}
// Return the admin object
return $bbp->admin;
}
/**
* Setup Converter
*
* This exists outside of "/includes/admin/" because the converter may need to
* be setup to convert the passwords of users that were migrated from another
* forum platform.
*
* @since 2.6.0 bbPress (r2596)
*/
function bbp_setup_converter() {
$bbp_admin = bbp_setup_admin();
// Skip if already setup
if ( empty( $bbp_admin->converter ) ) {
// Require the converter files
require_once $bbp_admin->admin_dir . 'tools/converter.php';
require_once $bbp_admin->admin_dir . 'classes/class-bbp-converter.php';
require_once $bbp_admin->admin_dir . 'classes/class-bbp-converter-db.php';
require_once $bbp_admin->admin_dir . 'classes/class-bbp-converter-base.php';
// Setup
$bbp_admin->converter = class_exists( 'BBP_Converter' )
? new BBP_Converter()
: new stdClass();
}
// Return the converter
return $bbp_admin->converter;
}
/** Globals *******************************************************************/
/**
* Lookup and return a global variable
*
* @since 2.5.8 bbPress (r5814)
*
* @param string $name Name of global variable
* @param string $type Type of variable to check with `is_a()`
* @param mixed $default Default value to return if no global found
*
* @return mixed Verified object if valid, Default or null if invalid
*/
function bbp_get_global_object( $name = '', $type = '', $default = null ) {
// If no name passed
if ( empty( $name ) ) {
$retval = $default;
// If no global exists
} elseif ( ! isset( $GLOBALS[ $name ] ) ) {
$retval = $default;
// If not the correct type of global
} elseif ( ! empty( $type ) && ! is_a( $GLOBALS[ $name ], $type ) ) {
$retval = $default;
// Global variable exists
} else {
$retval = $GLOBALS[ $name ];
}
// Filter & return
return apply_filters( 'bbp_get_global_object', $retval, $name, $type, $default );
}
/**
* Get the `$wp_query` global without needing to declare it everywhere
*
* @since 2.6.0 bbPress (r6582)
*
* @return WP_Roles
*/
function bbp_get_wp_query() {
return bbp_get_global_object( 'wp_query', 'WP_Query' );
}
/**
* Get the `$wp_roles` global without needing to declare it everywhere
*
* @since 2.2.0 bbPress (r4293)
*
* @return WP_Roles
*/
function bbp_get_wp_roles() {
return bbp_get_global_object( 'wp_roles', 'WP_Roles' );
}
/**
* Return the database class being used to interface with the environment.
*
* This function is abstracted to avoid global touches to the primary database
* class. bbPress supports WordPress's `$wpdb` global by default, and can be
* filtered to support other configurations if needed.
*
* @since 2.5.8 bbPress (r5814)
*
* @return object
*/
function bbp_db() {
return bbp_get_global_object( 'wpdb', 'WPDB' );
}
/** Pagination ****************************************************************/
/**
* Return the rewrite rules class being used to interact with URLs.
*
* This function is abstracted to avoid global touches to the primary rewrite
* rules class. bbPress supports WordPress's `$wp_rewrite` by default, but can
* be filtered to support other configurations if needed.
*
* @since 2.5.8 bbPress (r5814)
*
* @return object
*/
function bbp_rewrite() {
return bbp_get_global_object( 'wp_rewrite', 'WP_Rewrite', (object) array(
'root' => '',
'pagination_base' => 'page',
) );
}
/**
* Get the root URL
*
* @since 2.5.8 bbPress (r5814)
*
* @return string
*/
function bbp_get_root_url() {
// Default
$retval = '';
$rewrite = bbp_rewrite();
// Use $wp_rewrite->root if available
if ( property_exists( $rewrite, 'root' ) ) {
$retval = $rewrite->root;
}
// Filter & return
return apply_filters( 'bbp_get_root_url', $retval );
}
/**
* Get the slug used for paginated requests
*
* @since 2.4.0 bbPress (r4926)
*
* @return string
*/
function bbp_get_paged_slug() {
// Default
$retval = 'page';
$rewrite = bbp_rewrite();
// Use $wp_rewrite->pagination_base if available
if ( property_exists( $rewrite, 'pagination_base' ) ) {
$retval = $rewrite->pagination_base;
}
// Filter & return
return apply_filters( 'bbp_get_paged_slug', $retval );
}
/**
* Is the environment using pretty URLs?
*
* @since 2.5.8 bbPress (r5814)
*
* @global object $wp_rewrite The WP_Rewrite object
*
* @return bool
*/
function bbp_use_pretty_urls() {
// Default
$retval = false;
$rewrite = bbp_rewrite();
// Use $wp_rewrite->using_permalinks() if available
if ( method_exists( $rewrite, 'using_permalinks' ) ) {
$retval = $rewrite->using_permalinks();
}
// Filter & return
return apply_filters( 'bbp_pretty_urls', $retval );
}
/**
* Remove the first-page from a pagination links result set, ensuring that it
* points to the canonical first page URL.
*
* This is a bit of an SEO hack, to guarantee that the first page in a loop will
* never have pagination appended to the end of it, regardless of what the other
* functions have decided for us.
*
* @since 2.6.0 bbPress (r6678)
*
* @param string $pagination_links The HTML links used for pagination
*
* @return string
*/
function bbp_make_first_page_canonical( $pagination_links = '' ) {
// Default value
$retval = $pagination_links;
// Remove first page from pagination
if ( ! empty( $pagination_links ) ) {
$retval = bbp_use_pretty_urls()
? str_replace( bbp_get_paged_slug() . '/1/', '', $pagination_links )
: preg_replace( '/&#038;paged=1(?=[^0-9])/m', '', $pagination_links );
}
// Filter & return
return apply_filters( 'bbp_make_first_page_canonical', $retval, $pagination_links );
}
/**
* A convenient wrapper for common calls to paginate_links(), complete with
* support for parameters that aren't used internally by bbPress.
*
* @since 2.6.0 bbPress (r6679)
*
* @param array $args
*
* @return string
*/
function bbp_paginate_links( $args = array() ) {
// Maybe add view-all args
$add_args = empty( $args['add_args'] ) && bbp_get_view_all()
? array( 'view' => 'all' )
: false;
// Pagination settings with filter
$r = bbp_parse_args( $args, array(
// Used by callers
'base' => '',
'total' => 1,
'current' => bbp_get_paged(),
'prev_next' => true,
'prev_text' => is_rtl() ? '&rarr;' : '&larr;',
'next_text' => is_rtl() ? '&larr;' : '&rarr;',
'mid_size' => 1,
'end_size' => 3,
'add_args' => $add_args,
// Unused by callers
'show_all' => false,
'type' => 'plain',
'format' => '',
'add_fragment' => '',
'before_page_number' => '',
'after_page_number' => ''
), 'paginate_links' );
// Return paginated links
return bbp_make_first_page_canonical( paginate_links( $r ) );
}
/**
* Parse the WordPress core version number
*
* @since 2.6.0 bbPress (r6051)
*
* @global string $wp_version
*
* @return string $wp_version
*/
function bbp_get_major_wp_version() {
global $wp_version;
return (float) $wp_version;
}
/** Multisite *****************************************************************/
/**
* Is this a large bbPress installation?
*
* @since 2.6.0 bbPress (r6242)
*
* @return bool True if more than 10000 users, false not
*/
function bbp_is_large_install() {
// Multisite has a function specifically for this
$retval = function_exists( 'wp_is_large_network' )
? wp_is_large_network( 'users' )
: ( bbp_get_total_users() > 10000 );
// Filter & return
return (bool) apply_filters( 'bbp_is_large_install', $retval );
}
/**
* Get the total number of users on the forums
*
* @since 2.0.0 bbPress (r2769)
*
* @return int Total number of users
*/
function bbp_get_total_users() {
$bbp_db = bbp_db();
$count = $bbp_db->get_var( "SELECT COUNT(ID) as c FROM {$bbp_db->users} WHERE user_status = '0'" );
// Filter & return
return (int) apply_filters( 'bbp_get_total_users', (int) $count );
}
/**
* Switch to a site in a multisite installation.
*
* If not a multisite installation, no switching will occur.
*
* @since 2.6.0 bbPress (r6733)
*
* @param int $site_id
*/
function bbp_switch_to_site( $site_id = 0 ) {
// Switch to a specific site
if ( is_multisite() ) {
switch_to_blog( $site_id );
}
}
/**
* Switch back to the original site in a multisite installation.
*
* If not a multisite installation, no switching will occur.
*
* @since 2.6.0 bbPress (r6733)
*/
function bbp_restore_current_site() {
// Switch back to the original site
if ( is_multisite() ) {
restore_current_blog();
}
}
/** Interception **************************************************************/
/**
* Generate a default intercept value.
*
* @since 2.6.0
*
* @staticvar mixed $rand Null by default, random string on first call
*
* @return string
*/
function bbp_default_intercept() {
static $rand = null;
// Generate a new random and unique string
if ( null === $rand ) {
// If ext/hash is not present, compat.php's hash_hmac() does not support sha256.
$algo = function_exists( 'hash' )
? 'sha256'
: 'sha1';
// Old WP installs may not have AUTH_SALT defined.
$salt = defined( 'AUTH_SALT' ) && AUTH_SALT
? AUTH_SALT
: (string) wp_rand();
// Create unique ID
$rand = hash_hmac( $algo, uniqid( $salt, true ), $salt );
}
// Return random string (from locally static variable)
return $rand;
}
/**
* Whether a value has been intercepted
*
* @since 2.6.0
*
* @param bool $value
*/
function bbp_is_intercepted( $value = '' ) {
return ( bbp_default_intercept() !== $value );
}
/**
* Allow interception of a method or function call.
*
* @since 2.6.0
*
* @param string $action Typically the name of the caller function
* @param array $args Typically the results of caller function func_get_args()
*
* @return mixed Intercept results. Default bbp_default_intercept().
*/
function bbp_maybe_intercept( $action = '', $args = array() ) {
// Backwards compatibility juggle
$hook = ( false === strpos( $action, 'pre_' ) )
? "pre_{$action}"
: $action;
// Default value
$default = bbp_default_intercept();
// Parse args
$r = bbp_parse_args( (array) $args, array(), 'maybe_intercept' );
// Bail if no args
if ( empty( $r ) ) {
return $default;
}
// Filter
$args = array_merge( array( $hook ), $r );
$filtered = call_user_func_array( 'apply_filters', $args );
// Return filtered value, or default if not intercepted
return ( $filtered === reset( $r ) )
? $default
: $filtered;
}
/** Date/Time *****************************************************************/
/**
* Get an empty datetime value.
*
* @since 2.6.6 bbPress (r7094)
*
* @return string
*/
function bbp_get_empty_datetime() {
// Get the database version
$db_version = bbp_db()->db_version();
// Default return value
$retval = '0000-00-00 00:00:00';
// Filter & return
return (string) apply_filters( 'bbp_get_default_zero_date', $retval, $db_version );
}

View File

@@ -0,0 +1,465 @@
<?php
/**
* bbPress Actions
*
* This file contains the actions that are used through-out bbPress. They are
* consolidated here to make searching for them easier, and to help developers
* understand at a glance the order in which things occur.
*
* There are a few common places that additional actions can currently be found
*
* - bbPress: In {@link bbPress::setup_actions()} in bbpress.php
* - Admin: More in {@link BBP_Admin::setup_actions()} in admin.php
*
* @package bbPress
* @subpackage Core
*
* @see /core/filters.php
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/**
* Attach bbPress to WordPress
*
* bbPress uses its own internal actions to help aid in third-party plugin
* development, and to limit the amount of potential future code changes when
* updates to WordPress core occur.
*
* These actions exist to create the concept of 'plugin dependencies'. They
* provide a safe way for plugins to execute code *only* when bbPress is
* installed and activated, without needing to do complicated guesswork.
*
* For more information on how this works, see the 'Plugin Dependency' section
* near the bottom of this file.
*
* v--WordPress Actions v--bbPress Sub-actions
*/
add_action( 'plugins_loaded', 'bbp_loaded', 10 );
add_action( 'init', 'bbp_init', 0 ); // Early for bbp_register
add_action( 'parse_query', 'bbp_parse_query', 2 ); // Early for overrides
add_action( 'generate_rewrite_rules', 'bbp_generate_rewrite_rules', 10 );
add_action( 'after_setup_theme', 'bbp_after_setup_theme', 10 );
add_action( 'setup_theme', 'bbp_setup_theme', 10 );
add_action( 'set_current_user', 'bbp_setup_current_user', 10 );
add_action( 'profile_update', 'bbp_profile_update', 10, 2 ); // user_id and old_user_data
add_action( 'user_register', 'bbp_user_register', 10 );
add_action( 'login_form_login', 'bbp_login_form_login', 10 );
add_action( 'template_redirect', 'bbp_template_redirect', 8 ); // Before BuddyPress's 10 [BB2225]
add_action( 'widgets_init', 'bbp_widgets_init', 10 );
add_action( 'wp_roles_init', 'bbp_roles_init', 10 );
add_action( 'wp_enqueue_scripts', 'bbp_enqueue_scripts', 10 );
add_action( 'wp_head', 'bbp_head', 10 );
add_action( 'wp_footer', 'bbp_footer', 10 );
add_action( 'transition_post_status', 'bbp_transition_post_status', 10, 3 );
/**
* bbp_loaded - Attached to 'plugins_loaded' above
*
* Attach various loader actions to the bbp_loaded action.
* The load order helps to execute code at the correct time.
* v---Load order
*/
add_action( 'bbp_loaded', 'bbp_constants', 2 );
add_action( 'bbp_loaded', 'bbp_boot_strap_globals', 4 );
add_action( 'bbp_loaded', 'bbp_includes', 6 );
add_action( 'bbp_loaded', 'bbp_setup_globals', 8 );
add_action( 'bbp_loaded', 'bbp_setup_option_filters', 10 );
add_action( 'bbp_loaded', 'bbp_setup_user_option_filters', 12 );
add_action( 'bbp_loaded', 'bbp_pre_load_options', 14 );
/**
* bbp_init - Attached to 'init' above
*
* Attach various initialization actions to the init action.
* The load order helps to execute code at the correct time.
* v---Load order
*/
add_action( 'bbp_init', 'bbp_load_textdomain', 0 );
add_action( 'bbp_init', 'bbp_register', 10 );
add_action( 'bbp_init', 'bbp_add_rewrite_tags', 20 );
add_action( 'bbp_init', 'bbp_add_rewrite_rules', 30 );
add_action( 'bbp_init', 'bbp_add_permastructs', 40 );
add_action( 'bbp_init', 'bbp_setup_engagements', 50 );
add_action( 'bbp_init', 'bbp_ready', 999 );
/**
* bbp_setup_theme - Attached to 'setup_theme' above
*
* Attach various theme related actions to the setup_theme action.
* The load order helps to execute code at the correct time.
* v---Load order
*/
add_action( 'bbp_setup_theme', 'bbp_register_theme_packages', 2 ); // Lower than 5
/**
* bbp_roles_init - Attached to 'wp_roles_init' above
*
* Attach various role related actions to the wp_roles_init action.
* The load order helps to execute code at the correct time.
* v---Load order
*/
add_action( 'bbp_roles_init', 'bbp_add_forums_roles', 8 );
/**
* When setting up the current user, make sure they have a role for the forums.
*
* This is multisite aware, thanks to bbp_filter_user_roles_option(), hooked to
* the 'bbp_loaded' action above.
*/
add_action( 'bbp_setup_current_user', 'bbp_set_current_user_default_role' );
/**
* bbp_register - Attached to 'init' above on 0 priority
*
* Attach various initialization actions early to the init action.
* The load order helps to execute code at the correct time.
* v---Load order
*/
add_action( 'bbp_register', 'bbp_register_post_types', 2 );
add_action( 'bbp_register', 'bbp_register_post_statuses', 4 );
add_action( 'bbp_register', 'bbp_register_taxonomies', 6 );
add_action( 'bbp_register', 'bbp_register_views', 8 );
add_action( 'bbp_register', 'bbp_register_shortcodes', 10 );
add_action( 'bbp_register', 'bbp_register_meta', 12 );
// Autoembeds
add_action( 'bbp_init', 'bbp_reply_content_autoembed', 8 );
add_action( 'bbp_init', 'bbp_topic_content_autoembed', 8 );
/**
* bbp_ready - attached to end 'bbp_init' above
*
* Attach actions to the ready action after bbPress has fully initialized.
* The load order helps to execute code at the correct time.
* v---Load order
*/
add_action( 'bbp_ready', 'bbp_setup_akismet', 2 ); // Spam prevention for topics and replies
add_action( 'bp_include', 'bbp_setup_buddypress', 10 ); // Social network integration
// Try to load the bbpress-functions.php file from the active themes
add_action( 'bbp_after_setup_theme', 'bbp_load_theme_functions', 10 );
// Widgets
add_action( 'bbp_widgets_init', array( 'BBP_Login_Widget', 'register_widget' ), 10 );
add_action( 'bbp_widgets_init', array( 'BBP_Views_Widget', 'register_widget' ), 10 );
add_action( 'bbp_widgets_init', array( 'BBP_Search_Widget', 'register_widget' ), 10 );
add_action( 'bbp_widgets_init', array( 'BBP_Forums_Widget', 'register_widget' ), 10 );
add_action( 'bbp_widgets_init', array( 'BBP_Topics_Widget', 'register_widget' ), 10 );
add_action( 'bbp_widgets_init', array( 'BBP_Replies_Widget', 'register_widget' ), 10 );
add_action( 'bbp_widgets_init', array( 'BBP_Stats_Widget', 'register_widget' ), 10 );
// Notices
add_action( 'bbp_template_notices', 'bbp_template_notices', 20 );
add_action( 'bbp_template_notices', 'bbp_login_notices' );
add_action( 'bbp_template_notices', 'bbp_topic_notices' );
add_action( 'bbp_template_notices', 'bbp_notice_edit_user_success' );
add_action( 'bbp_template_notices', 'bbp_notice_edit_user_pending_email' );
add_action( 'bbp_template_notices', 'bbp_notice_edit_user_is_super_admin', 2 );
// Always exclude private/hidden forums if needed
add_action( 'pre_get_posts', 'bbp_pre_get_posts_normalize_forum_visibility', 4 );
// Before Delete/Trash/Untrash Forum
add_action( 'wp_trash_post', 'bbp_trash_forum' );
add_action( 'trash_post', 'bbp_trash_forum' );
add_action( 'untrash_post', 'bbp_untrash_forum' );
add_action( 'before_delete_post', 'bbp_delete_forum' );
// After Deleted/Trashed/Untrashed Forum
add_action( 'trashed_post', 'bbp_trashed_forum' );
add_action( 'untrashed_post', 'bbp_untrashed_forum' );
add_action( 'deleted_post', 'bbp_deleted_forum' );
// Auto trash/untrash/delete a forums topics
add_action( 'bbp_delete_forum', 'bbp_delete_forum_topics', 10 );
add_action( 'bbp_trash_forum', 'bbp_trash_forum_topics', 10 );
add_action( 'bbp_untrash_forum', 'bbp_untrash_forum_topics', 10 );
// New/Edit Forum
add_action( 'bbp_new_forum', 'bbp_update_forum', 10 );
add_action( 'bbp_edit_forum', 'bbp_update_forum', 10 );
// Save forum extra metadata
add_action( 'bbp_new_forum_post_extras', 'bbp_save_forum_extras', 2 );
add_action( 'bbp_edit_forum_post_extras', 'bbp_save_forum_extras', 2 );
add_action( 'bbp_forum_attributes_metabox_save', 'bbp_save_forum_extras', 2 );
// New/Edit Reply
add_action( 'bbp_new_reply', 'bbp_update_reply', 10, 7 );
add_action( 'bbp_edit_reply', 'bbp_update_reply', 10, 7 );
// Before Delete/Trash/Untrash Reply
add_action( 'wp_trash_post', 'bbp_trash_reply' );
add_action( 'trash_post', 'bbp_trash_reply' );
add_action( 'untrash_post', 'bbp_untrash_reply' );
add_action( 'before_delete_post', 'bbp_delete_reply' );
// After Deleted/Trashed/Untrashed Reply
add_action( 'trashed_post', 'bbp_trashed_reply' );
add_action( 'untrashed_post', 'bbp_untrashed_reply' );
add_action( 'deleted_post', 'bbp_deleted_reply' );
// New/Edit Topic
add_action( 'bbp_new_topic', 'bbp_update_topic', 10, 5 );
add_action( 'bbp_edit_topic', 'bbp_update_topic', 10, 5 );
// Split/Merge Topic
add_action( 'bbp_merged_topic', 'bbp_merge_topic_count', 1, 3 );
add_action( 'bbp_post_split_topic', 'bbp_split_topic_count', 1, 3 );
// Move Reply
add_action( 'bbp_post_move_reply', 'bbp_move_reply_count', 1, 3 );
// Before Delete/Trash/Untrash Topic
add_action( 'wp_trash_post', 'bbp_trash_topic' );
add_action( 'trash_post', 'bbp_trash_topic' );
add_action( 'untrash_post', 'bbp_untrash_topic' );
add_action( 'before_delete_post', 'bbp_delete_topic' );
// After Deleted/Trashed/Untrashed Topic
add_action( 'trashed_post', 'bbp_trashed_topic' );
add_action( 'untrashed_post', 'bbp_untrashed_topic' );
add_action( 'deleted_post', 'bbp_deleted_topic' );
// Favorites
add_action( 'bbp_spam_topic', 'bbp_remove_topic_from_all_favorites' );
add_action( 'bbp_trash_topic', 'bbp_remove_topic_from_all_favorites' );
add_action( 'bbp_delete_topic', 'bbp_remove_topic_from_all_favorites' );
// Subscriptions
add_action( 'bbp_spam_topic', 'bbp_remove_topic_from_all_subscriptions' );
add_action( 'bbp_trash_topic', 'bbp_remove_topic_from_all_subscriptions' );
add_action( 'bbp_delete_topic', 'bbp_remove_topic_from_all_subscriptions' );
add_action( 'bbp_trash_forum', 'bbp_remove_forum_from_all_subscriptions' );
add_action( 'bbp_delete_forum', 'bbp_remove_forum_from_all_subscriptions' );
// Subscription notifications
add_action( 'bbp_new_reply', 'bbp_notify_topic_subscribers', 11, 5 );
add_action( 'bbp_new_topic', 'bbp_notify_forum_subscribers', 11, 4 );
// Sticky
add_action( 'bbp_stick_topic', 'bbp_unstick_topic' );
add_action( 'bbp_unapprove_topic', 'bbp_unstick_topic' );
add_action( 'bbp_spam_topic', 'bbp_unstick_topic' );
add_action( 'bbp_trash_topic', 'bbp_unstick_topic' );
add_action( 'bbp_delete_topic', 'bbp_unstick_topic' );
// Update topic branch
add_action( 'bbp_trashed_topic', 'bbp_update_topic_walker' );
add_action( 'bbp_untrashed_topic', 'bbp_update_topic_walker' );
add_action( 'bbp_deleted_topic', 'bbp_update_topic_walker' );
add_action( 'bbp_spammed_topic', 'bbp_update_topic_walker' );
add_action( 'bbp_unspammed_topic', 'bbp_update_topic_walker' );
add_action( 'bbp_approved_topic', 'bbp_update_topic_walker' );
add_action( 'bbp_unapproved_topic', 'bbp_update_topic_walker' );
// Update reply branch
add_action( 'bbp_trashed_reply', 'bbp_update_reply_walker' );
add_action( 'bbp_untrashed_reply', 'bbp_update_reply_walker' );
add_action( 'bbp_deleted_reply', 'bbp_update_reply_walker' );
add_action( 'bbp_spammed_reply', 'bbp_update_reply_walker' );
add_action( 'bbp_unspammed_reply', 'bbp_update_reply_walker' );
add_action( 'bbp_approved_reply', 'bbp_update_reply_walker' );
add_action( 'bbp_unapproved_reply', 'bbp_update_reply_walker' );
// Update forum reply counts
add_action( 'bbp_new_reply', 'bbp_increase_forum_reply_count' );
add_action( 'bbp_untrashed_reply', 'bbp_increase_forum_reply_count' );
add_action( 'bbp_unspammed_reply', 'bbp_increase_forum_reply_count' );
add_action( 'bbp_approved_reply', 'bbp_increase_forum_reply_count' );
add_action( 'bbp_trash_reply', 'bbp_decrease_forum_reply_count' );
add_action( 'bbp_spam_reply', 'bbp_decrease_forum_reply_count' );
add_action( 'bbp_unapprove_reply', 'bbp_decrease_forum_reply_count' );
// Update forum hidden reply counts
add_action( 'bbp_trashed_reply', 'bbp_increase_forum_reply_count_hidden' );
add_action( 'bbp_spammed_reply', 'bbp_increase_forum_reply_count_hidden' );
add_action( 'bbp_unapproved_reply', 'bbp_increase_forum_reply_count_hidden' );
add_action( 'bbp_untrash_reply', 'bbp_decrease_forum_reply_count_hidden' );
add_action( 'bbp_unspam_reply', 'bbp_decrease_forum_reply_count_hidden' );
add_action( 'bbp_approve_reply', 'bbp_decrease_forum_reply_count_hidden' );
add_action( 'bbp_delete_reply', 'bbp_decrease_forum_reply_count_hidden' );
// Update forum topic counts
add_action( 'bbp_new_topic', 'bbp_increase_forum_topic_count' );
add_action( 'bbp_untrashed_topic', 'bbp_increase_forum_topic_count' );
add_action( 'bbp_unspammed_topic', 'bbp_increase_forum_topic_count' );
add_action( 'bbp_approved_topic', 'bbp_increase_forum_topic_count' );
add_action( 'bbp_trash_topic', 'bbp_decrease_forum_topic_count' );
add_action( 'bbp_spam_topic', 'bbp_decrease_forum_topic_count' );
add_action( 'bbp_unapprove_topic', 'bbp_decrease_forum_topic_count' );
// Update forum hidden topic counts
add_action( 'bbp_trashed_topic', 'bbp_increase_forum_topic_count_hidden' );
add_action( 'bbp_spammed_topic', 'bbp_increase_forum_topic_count_hidden' );
add_action( 'bbp_unapproved_topic', 'bbp_increase_forum_topic_count_hidden' );
add_action( 'bbp_untrash_topic', 'bbp_decrease_forum_topic_count_hidden' );
add_action( 'bbp_unspam_topic', 'bbp_decrease_forum_topic_count_hidden' );
add_action( 'bbp_approve_topic', 'bbp_decrease_forum_topic_count_hidden' );
add_action( 'bbp_delete_topic', 'bbp_decrease_forum_topic_count_hidden' );
// Update topic reply counts
add_action( 'bbp_new_reply', 'bbp_increase_topic_reply_count' );
add_action( 'bbp_untrashed_reply', 'bbp_increase_topic_reply_count' );
add_action( 'bbp_unspammed_reply', 'bbp_increase_topic_reply_count' );
add_action( 'bbp_approved_reply', 'bbp_increase_topic_reply_count' );
add_action( 'bbp_trash_reply', 'bbp_decrease_topic_reply_count' );
add_action( 'bbp_spam_reply', 'bbp_decrease_topic_reply_count' );
add_action( 'bbp_unapprove_reply', 'bbp_decrease_topic_reply_count' );
// Update topic hidden reply counts
add_action( 'bbp_trashed_reply', 'bbp_increase_topic_reply_count_hidden' );
add_action( 'bbp_unapproved_reply', 'bbp_increase_topic_reply_count_hidden' );
add_action( 'bbp_spammed_reply', 'bbp_increase_topic_reply_count_hidden' );
add_action( 'bbp_untrash_reply', 'bbp_decrease_topic_reply_count_hidden' );
add_action( 'bbp_unspam_reply', 'bbp_decrease_topic_reply_count_hidden' );
add_action( 'bbp_approve_reply', 'bbp_decrease_topic_reply_count_hidden' );
add_action( 'bbp_delete_reply', 'bbp_decrease_topic_reply_count_hidden' );
// Update forum reply counts for approved/unapproved topics
add_action( 'bbp_approved_topic', 'bbp_approved_unapproved_topic_update_forum_reply_count' );
add_action( 'bbp_unapproved_topic', 'bbp_approved_unapproved_topic_update_forum_reply_count' );
// Users topic & reply counts
add_action( 'bbp_new_topic', 'bbp_increase_user_topic_count' );
add_action( 'bbp_new_reply', 'bbp_increase_user_reply_count' );
add_action( 'bbp_untrash_topic', 'bbp_increase_user_topic_count' );
add_action( 'bbp_untrash_reply', 'bbp_increase_user_reply_count' );
add_action( 'bbp_unspam_topic', 'bbp_increase_user_topic_count' );
add_action( 'bbp_unspam_reply', 'bbp_increase_user_reply_count' );
add_action( 'bbp_trash_topic', 'bbp_decrease_user_topic_count' );
add_action( 'bbp_trash_reply', 'bbp_decrease_user_reply_count' );
add_action( 'bbp_spam_topic', 'bbp_decrease_user_topic_count' );
add_action( 'bbp_spam_reply', 'bbp_decrease_user_reply_count' );
// Topic status transition helpers for replies
add_action( 'bbp_trash_topic', 'bbp_trash_topic_replies' );
add_action( 'bbp_untrash_topic', 'bbp_untrash_topic_replies' );
add_action( 'bbp_delete_topic', 'bbp_delete_topic_replies' );
add_action( 'bbp_spam_topic', 'bbp_spam_topic_replies' );
add_action( 'bbp_unspam_topic', 'bbp_unspam_topic_replies' );
// Topic engagements on user creation
add_action( 'bbp_new_topic', 'bbp_update_topic_engagements', 20 );
add_action( 'bbp_new_reply', 'bbp_update_topic_engagements', 20 );
add_action( 'bbp_new_reply', 'bbp_update_topic_voice_count', 30 );
add_action( 'bbp_new_topic', 'bbp_update_topic_voice_count', 30 );
// Topic/reply counts on code insert (unit tests)
add_action( 'bbp_insert_topic', 'bbp_insert_topic_update_counts', 10, 2 );
add_action( 'bbp_insert_reply', 'bbp_insert_reply_update_counts', 10, 3 );
// Topic engagements on code insert (unit tests)
add_action( 'bbp_insert_topic', 'bbp_update_topic_engagements', 20 );
add_action( 'bbp_insert_reply', 'bbp_update_topic_engagements', 20 );
// Topic engagement counts on code insert (unit tests)
add_action( 'bbp_insert_topic', 'bbp_update_topic_voice_count', 30 );
add_action( 'bbp_insert_reply', 'bbp_update_topic_voice_count', 30 );
// Recalculate engagements
add_action( 'bbp_trashed_reply', 'bbp_recalculate_topic_engagements' );
add_action( 'bbp_untrashed_reply', 'bbp_recalculate_topic_engagements' );
add_action( 'bbp_spammed_reply', 'bbp_recalculate_topic_engagements' );
add_action( 'bbp_unspammed_reply', 'bbp_recalculate_topic_engagements' );
add_action( 'bbp_approved_reply', 'bbp_recalculate_topic_engagements' );
add_action( 'bbp_unapproved_reply', 'bbp_recalculate_topic_engagements' );
add_action( 'bbp_deleted_reply', 'bbp_recalculate_topic_engagements' );
add_action( 'bbp_trashed_topic', 'bbp_recalculate_topic_engagements' );
add_action( 'bbp_untrashed_topic', 'bbp_recalculate_topic_engagements' );
add_action( 'bbp_spammed_topic', 'bbp_recalculate_topic_engagements' );
add_action( 'bbp_unspammed_topic', 'bbp_recalculate_topic_engagements' );
add_action( 'bbp_approved_topic', 'bbp_recalculate_topic_engagements' );
add_action( 'bbp_unapproved_topic', 'bbp_recalculate_topic_engagements' );
add_action( 'bbp_deleted_topic', 'bbp_recalculate_topic_engagements' );
// Update engagement counts
add_action( 'bbp_trashed_reply', 'bbp_update_topic_voice_count', 30 );
add_action( 'bbp_untrashed_reply', 'bbp_update_topic_voice_count', 30 );
add_action( 'bbp_spammed_reply', 'bbp_update_topic_voice_count', 30 );
add_action( 'bbp_unspammed_reply', 'bbp_update_topic_voice_count', 30 );
add_action( 'bbp_approved_reply', 'bbp_update_topic_voice_count', 30 );
add_action( 'bbp_unapproved_reply', 'bbp_update_topic_voice_count', 30 );
add_action( 'bbp_deleted_reply', 'bbp_update_topic_voice_count', 30 );
add_action( 'bbp_trashed_topic', 'bbp_update_topic_voice_count', 30 );
add_action( 'bbp_untrashed_topic', 'bbp_update_topic_voice_count', 30 );
add_action( 'bbp_spammed_topic', 'bbp_update_topic_voice_count', 30 );
add_action( 'bbp_unspammed_topic', 'bbp_update_topic_voice_count', 30 );
add_action( 'bbp_approved_topic', 'bbp_update_topic_voice_count', 30 );
add_action( 'bbp_unapproved_topic', 'bbp_update_topic_voice_count', 30 );
add_action( 'bbp_deleted_topic', 'bbp_update_topic_voice_count', 30 );
// User status
// @todo make these sub-actions
add_action( 'make_ham_user', 'bbp_make_ham_user' );
add_action( 'make_spam_user', 'bbp_make_spam_user' );
// User role
add_action( 'bbp_profile_update', 'bbp_profile_update_role' );
// Hook WordPress admin actions to bbPress profiles on save
add_action( 'bbp_user_edit_after', 'bbp_user_edit_after' );
// Clean bbPress post caches when WordPress's is cleaned
add_action( 'clean_post_cache', 'bbp_clean_post_cache', 10, 2 );
// User Registration
add_action( 'added_existing_user', 'bbp_user_add_role_on_register', 10, 1 );
add_action( 'bbp_user_register', 'bbp_user_add_role_on_register', 10, 1 );
// Invite a New User
add_action( 'invite_user', 'bbp_user_add_role_on_invite', 10, 3 );
// Multisite Activation (does not work in wp-activate.php)
add_action( 'wpmu_activate_user', 'bbp_user_add_role_on_activate', 10, 3 );
/**
* bbPress needs to redirect the user around in a few different circumstances:
*
* 1. POST and GET requests
* 2. Accessing private or hidden content (forums/topics/replies)
* 3. Editing forums, topics, replies, users, and tags
* 4. bbPress specific AJAX requests
*/
add_action( 'bbp_template_redirect', 'bbp_forum_enforce_blocked', 1 );
add_action( 'bbp_template_redirect', 'bbp_forum_enforce_hidden', 1 );
add_action( 'bbp_template_redirect', 'bbp_forum_enforce_private', 1 );
add_action( 'bbp_template_redirect', 'bbp_post_request', 10 );
add_action( 'bbp_template_redirect', 'bbp_get_request', 10 );
add_action( 'bbp_template_redirect', 'bbp_check_user_edit', 10 );
add_action( 'bbp_template_redirect', 'bbp_check_forum_edit', 10 );
add_action( 'bbp_template_redirect', 'bbp_check_topic_edit', 10 );
add_action( 'bbp_template_redirect', 'bbp_check_reply_edit', 10 );
add_action( 'bbp_template_redirect', 'bbp_check_topic_tag_edit', 10 );
// Must be after bbp_template_include_theme_compat
add_action( 'bbp_template_redirect', 'bbp_remove_adjacent_posts', 10 );
// Theme-side POST requests
add_action( 'bbp_post_request', 'bbp_do_ajax', 1 );
add_action( 'bbp_post_request', 'bbp_edit_topic_tag_handler', 1 );
add_action( 'bbp_post_request', 'bbp_edit_user_handler', 1 );
add_action( 'bbp_post_request', 'bbp_edit_forum_handler', 1 );
add_action( 'bbp_post_request', 'bbp_edit_reply_handler', 1 );
add_action( 'bbp_post_request', 'bbp_edit_topic_handler', 1 );
add_action( 'bbp_post_request', 'bbp_merge_topic_handler', 1 );
add_action( 'bbp_post_request', 'bbp_split_topic_handler', 1 );
add_action( 'bbp_post_request', 'bbp_move_reply_handler', 1 );
add_action( 'bbp_post_request', 'bbp_new_forum_handler', 10 );
add_action( 'bbp_post_request', 'bbp_new_reply_handler', 10 );
add_action( 'bbp_post_request', 'bbp_new_topic_handler', 10 );
// Theme-side GET requests
add_action( 'bbp_get_request', 'bbp_toggle_topic_handler', 1 );
add_action( 'bbp_get_request', 'bbp_toggle_reply_handler', 1 );
add_action( 'bbp_get_request', 'bbp_favorites_handler', 1 );
add_action( 'bbp_get_request', 'bbp_subscriptions_handler', 1 );
add_action( 'bbp_get_request', 'bbp_user_email_change_handler', 1 );
add_action( 'bbp_get_request', 'bbp_search_results_redirect', 10 );
// Maybe convert the users password
add_action( 'bbp_login_form_login', 'bbp_user_maybe_convert_pass' );

View File

@@ -0,0 +1,168 @@
<?php
/**
* bbPress Cache Helpers
*
* Helper functions used to communicate with WordPress's various caches. Many
* of these functions are used to work around specific WordPress nuances. They
* are subject to changes, tweaking, and will need iteration as performance
* improvements are made to WordPress core.
*
* @package bbPress
* @subpackage Cache
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/** Helpers *******************************************************************/
/**
* Skip invalidation of child post content when editing a parent.
*
* This prevents invalidating caches for topics and replies when editing a forum
* or a topic. Without this in place, WordPress will attempt to invalidate all
* child posts whenever a parent post is modified. This can cause thousands of
* cache invalidations to occur on a single edit, which is no good for anyone.
*
* @since 2.1.0 bbPress (r4011)
*
* @package bbPress
* @subpackage Cache
*/
class BBP_Skip_Children {
/**
* @var int Post ID being updated
*/
private $updating_post = 0;
/**
* @var bool The original value of $_wp_suspend_cache_invalidation global
*/
private $original_cache_invalidation = false;
/** Methods ***************************************************************/
/**
* Hook into the 'pre_post_update' action.
*
* @since 2.1.0 bbPress (r4011)
*/
public function __construct() {
add_action( 'pre_post_update', array( $this, 'pre_post_update' ) );
}
/**
* Only clean post caches for main bbPress posts.
*
* Check that the post being updated is a bbPress post type, saves the
* post ID to be used later, and adds an action to 'clean_post_cache' that
* prevents child post caches from being cleared.
*
* @since 2.1.0 bbPress (r4011)
*
* @param int $post_id The post ID being updated
* @return If invalid post data
*/
public function pre_post_update( $post_id = 0 ) {
// Bail if post ID is not a bbPress post type
if ( empty( $post_id ) || ! bbp_is_custom_post_type( $post_id ) ) {
return;
}
// Store the $post_id
$this->updating_post = $post_id;
// Skip related post cache invalidation. This prevents invalidating the
// caches of the child posts when there is no reason to do so.
add_action( 'clean_post_cache', array( $this, 'skip_related_posts' ) );
}
/**
* Skip cache invalidation of related posts if the post ID being invalidated
* is not the one that was just updated.
*
* @since 2.1.0 bbPress (r4011)
*
* @param int $post_id The post ID of the cache being invalidated
* @return If invalid post data
*/
public function skip_related_posts( $post_id = 0 ) {
// Bail if this post is not the current bbPress post
if ( empty( $post_id ) || ( $this->updating_post !== $post_id ) ) {
return;
}
// Stash the current cache invalidation value in a variable, so we can
// restore back to it nicely in the future.
global $_wp_suspend_cache_invalidation;
$this->original_cache_invalidation = $_wp_suspend_cache_invalidation;
// Turn off cache invalidation
wp_suspend_cache_invalidation( true );
// Restore cache invalidation
add_action( 'wp_insert_post', array( $this, 'restore_cache_invalidation' ) );
}
/**
* Restore the cache invalidation to its previous value.
*
* @since 2.1.0 bbPress (r4011)
*/
public function restore_cache_invalidation() {
wp_suspend_cache_invalidation( $this->original_cache_invalidation );
}
}
new BBP_Skip_Children();
/** General *******************************************************************/
/**
* Will clean a post in the cache.
*
* Will call to clean the term object cache associated with the post ID.
*
* @since 2.1.0 bbPress (r4040)
* @since 2.6.0 bbPress (r6053) Introduced the `$post_id` parameter.
*
* @param int $post_id The post id.
* @param WP_Post $post The WP_Post object.
*/
function bbp_clean_post_cache( $post_id = null, $post = null ) {
// Child query types to clean
$post_types = array(
bbp_get_forum_post_type(),
bbp_get_topic_post_type(),
bbp_get_reply_post_type()
);
// Bail if not a bbPress post type
if ( ! in_array( $post->post_type, $post_types, true ) ) {
return;
}
/**
* Fires immediately after the given post cache is cleaned.
*
* @since 2.1.0
*
* @param int $post_id Post ID.
* @param WP_Post $post Post object.
*/
do_action( 'bbp_clean_post_cache', $post->ID, $post );
// Invalidate parent caches
if ( ! empty( $post->post_parent ) ) {
clean_post_cache( $post->post_parent );
// Only bump `last_changed` when forum-root is reached
} else {
wp_cache_set( 'last_changed', microtime(), 'bbpress_posts' );
}
}

View File

@@ -0,0 +1,525 @@
<?php
/**
* bbPress Capabilites
*
* The functions in this file are used primarily as convenient wrappers for
* capability output in user profiles. This includes mapping capabilities and
* groups to human readable strings,
*
* @package bbPress
* @subpackage Capabilities
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/** Mapping *******************************************************************/
/**
* Returns an array of capabilities based on the role that is being requested.
*
* @since 2.0.0 bbPress (r2994)
*
* @todo Map all of these and deprecate
*
* @param string $role Optional. Defaults to The role to load caps for
*
* @return array Capabilities for $role
*/
function bbp_get_caps_for_role( $role = '' ) {
// Which role are we looking for?
switch ( $role ) {
// Keymaster
case bbp_get_keymaster_role() :
$caps = array(
// Keymasters only
'keep_gate' => true,
// Primary caps
'spectate' => true,
'participate' => true,
'moderate' => true,
'throttle' => true,
'view_trash' => true,
'assign_moderators' => true,
// Forum caps
'publish_forums' => true,
'edit_forums' => true,
'edit_others_forums' => true,
'delete_forums' => true,
'delete_others_forums' => true,
'read_private_forums' => true,
'read_hidden_forums' => true,
// Topic caps
'publish_topics' => true,
'edit_topics' => true,
'edit_others_topics' => true,
'delete_topics' => true,
'delete_others_topics' => true,
'read_private_topics' => true,
// Reply caps
'publish_replies' => true,
'edit_replies' => true,
'edit_others_replies' => true,
'delete_replies' => true,
'delete_others_replies' => true,
'read_private_replies' => true,
// Topic tag caps
'manage_topic_tags' => true,
'edit_topic_tags' => true,
'delete_topic_tags' => true,
'assign_topic_tags' => true
);
break;
// Moderator
case bbp_get_moderator_role() :
$caps = array(
// Primary caps
'spectate' => true,
'participate' => true,
'moderate' => true,
'throttle' => true,
'view_trash' => true,
'assign_moderators' => true,
// Forum caps
'publish_forums' => true,
'edit_forums' => true,
'read_private_forums' => true,
'read_hidden_forums' => true,
// Topic caps
'publish_topics' => true,
'edit_topics' => true,
'edit_others_topics' => true,
'delete_topics' => true,
'delete_others_topics' => true,
'read_private_topics' => true,
// Reply caps
'publish_replies' => true,
'edit_replies' => true,
'edit_others_replies' => true,
'delete_replies' => true,
'delete_others_replies' => true,
'read_private_replies' => true,
// Topic tag caps
'manage_topic_tags' => true,
'edit_topic_tags' => true,
'delete_topic_tags' => true,
'assign_topic_tags' => true,
);
break;
// Spectators can only read
case bbp_get_spectator_role() :
$caps = array(
// Primary caps
'spectate' => true,
);
break;
// Explicitly blocked
case bbp_get_blocked_role() :
$caps = array(
// Primary caps
'spectate' => false,
'participate' => false,
'moderate' => false,
'throttle' => false,
'view_trash' => false,
// Forum caps
'publish_forums' => false,
'edit_forums' => false,
'edit_others_forums' => false,
'delete_forums' => false,
'delete_others_forums' => false,
'read_private_forums' => false,
'read_hidden_forums' => false,
// Topic caps
'publish_topics' => false,
'edit_topics' => false,
'edit_others_topics' => false,
'delete_topics' => false,
'delete_others_topics' => false,
'read_private_topics' => false,
// Reply caps
'publish_replies' => false,
'edit_replies' => false,
'edit_others_replies' => false,
'delete_replies' => false,
'delete_others_replies' => false,
'read_private_replies' => false,
// Topic tag caps
'manage_topic_tags' => false,
'edit_topic_tags' => false,
'delete_topic_tags' => false,
'assign_topic_tags' => false,
);
break;
// Participant/Default
case bbp_get_participant_role() :
default :
$caps = array(
// Primary caps
'spectate' => true,
'participate' => true,
// Forum caps
'read_private_forums' => true,
// Topic caps
'publish_topics' => true,
'edit_topics' => true,
// Reply caps
'publish_replies' => true,
'edit_replies' => true,
// Topic tag caps
'assign_topic_tags' => true,
);
break;
}
// Filter & return
return apply_filters( 'bbp_get_caps_for_role', $caps, $role );
}
/**
* Adds capabilities to WordPress user roles.
*
* @since 2.0.0 bbPress (r2608)
*/
function bbp_add_caps() {
// Loop through available roles and add caps
foreach ( bbp_get_wp_roles()->role_objects as $role ) {
foreach ( bbp_get_caps_for_role( $role->name ) as $cap => $value ) {
$role->add_cap( $cap, $value );
}
}
do_action( 'bbp_add_caps' );
}
/**
* Removes capabilities from WordPress user roles.
*
* @since 2.0.0 bbPress (r2608)
*/
function bbp_remove_caps() {
// Loop through available roles and remove caps
foreach ( bbp_get_wp_roles()->role_objects as $role ) {
foreach ( array_keys( bbp_get_caps_for_role( $role->name ) ) as $cap ) {
$role->remove_cap( $cap );
}
}
do_action( 'bbp_remove_caps' );
}
/**
* Get the available roles, minus the dynamic roles that come with bbPress
*
* @since 2.4.0 bbPress (r5064)
*
* @return array
*/
function bbp_get_blog_roles() {
// Get WordPress's roles (returns $wp_roles global)
$wp_roles = bbp_get_wp_roles();
// Apply the WordPress 'editable_roles' filter to let plugins ride along.
//
// We use this internally via bbp_filter_blog_editable_roles() to remove
// any custom bbPress roles that are added to the global.
$the_roles = isset( $wp_roles->roles ) ? $wp_roles->roles : false;
$all_roles = apply_filters( 'editable_roles', $the_roles );
// Filter & return
return apply_filters( 'bbp_get_blog_roles', $all_roles, $wp_roles );
}
/** Forum Roles ***************************************************************/
/**
* Add the bbPress roles to the $wp_roles global.
*
* We do this to avoid adding these values to the database.
*
* Note: bbPress is purposely assertive here, overwriting any keys & values
* that may already exist in the $wp_roles array.
*
* @since 2.2.0 bbPress (r4290)
*
* @param WP_Roles $wp_roles The array of WP_Role objects that was initialized
*
* @return WP_Roles The main $wp_roles global
*/
function bbp_add_forums_roles( $wp_roles = null ) {
// Get the dynamic roles
$bbp_roles = bbp_get_dynamic_roles();
// Loop through dynamic roles and add them to the $wp_roles array
foreach ( $bbp_roles as $role_id => $details ) {
$wp_roles->roles[ $role_id ] = $details;
$wp_roles->role_objects[ $role_id ] = new WP_Role( $role_id, $details['capabilities'] );
$wp_roles->role_names[ $role_id ] = $details['name'];
}
// Return the modified $wp_roles array
return $wp_roles;
}
/**
* Helper function to add filter to option_wp_user_roles
*
* @since 2.2.0 bbPress (r4363)
* @deprecated 2.6.0 bbPress (r6105)
*
* @see _bbp_reinit_dynamic_roles()
*/
function bbp_filter_user_roles_option() {
$role_key = bbp_db()->prefix . 'user_roles';
add_filter( 'option_' . $role_key, '_bbp_reinit_dynamic_roles' );
}
/**
* This is necessary because in a few places (noted below) WordPress initializes
* a blog's roles directly from the database option. When this happens, the
* $wp_roles global gets flushed, causing a user to magically lose any
* dynamically assigned roles or capabilities when $current_user in refreshed.
*
* Because dynamic multiple roles is a new concept in WordPress, we work around
* it here for now, knowing that improvements will come to WordPress core later.
*
* Also note that if using the $wp_user_roles global non-database approach,
* bbPress does not have an intercept point to add its dynamic roles.
*
* @see bbp_switch_to_site()
* @see bbp_restore_current_site()
* @see WP_Roles::_init()
*
* @since 2.2.0 bbPress (r4363)
* @deprecated 2.6.0 bbPress (r6105)
*
* @internal Used by bbPress to reinitialize dynamic roles on blog switch
*
* @param array $roles
* @return array Combined array of database roles and dynamic bbPress roles
*/
function _bbp_reinit_dynamic_roles( $roles = array() ) {
foreach ( bbp_get_dynamic_roles() as $role_id => $details ) {
$roles[ $role_id ] = $details;
}
return $roles;
}
/**
* Fetch a filtered list of forum roles that the current user is
* allowed to have.
*
* Simple function who's main purpose is to allow filtering of the
* list of forum roles so that plugins can remove inappropriate ones depending
* on the situation or user making edits.
*
* Specifically because without filtering, anyone with the edit_users
* capability can edit others to be administrators, even if they are
* only editors or authors. This filter allows admins to delegate
* user management.
*
* @since 2.2.0 bbPress (r4284)
* @since 2.6.0 bbPress (r6117) Use bbpress()->roles
*
* @return array
*/
function bbp_get_dynamic_roles() {
// Defaults
$to_array = array();
$roles = bbpress()->roles;
// Convert WP_Roles objects to arrays
foreach ( $roles as $role_id => $wp_role ) {
$to_array[ $role_id ] = (array) $wp_role;
}
// Filter & return
return (array) apply_filters( 'bbp_get_dynamic_roles', $to_array, $roles );
}
/**
* Gets a translated role name from a role ID
*
* @since 2.3.0 bbPress (r4792)
* @since 2.6.0 bbPress (r6117) Use bbp_translate_user_role()
*
* @param string $role_id
* @return string Translated role name
*/
function bbp_get_dynamic_role_name( $role_id = '' ) {
$roles = bbp_get_dynamic_roles();
$role = isset( $roles[ $role_id ] )
? bbp_translate_user_role( $roles[ $role_id ]['name'] )
: '';
// Filter & return
return apply_filters( 'bbp_get_dynamic_role_name', $role, $role_id, $roles );
}
/**
* Removes the bbPress roles from the editable roles array
*
* This used to use array_diff_assoc() but it randomly broke before 2.2 release.
* Need to research what happened, and if there's a way to speed this up.
*
* @since 2.2.0 bbPress (r4303)
*
* @param array $all_roles All registered roles
* @return array
*/
function bbp_filter_blog_editable_roles( $all_roles = array() ) {
// Loop through bbPress roles
foreach ( array_keys( bbp_get_dynamic_roles() ) as $bbp_role ) {
// Loop through WordPress roles
foreach ( array_keys( $all_roles ) as $wp_role ) {
// If keys match, unset
if ( $wp_role === $bbp_role ) {
unset( $all_roles[ $wp_role ] );
}
}
}
return $all_roles;
}
/**
* The keymaster role for bbPress users
*
* @since 2.2.0 bbPress (r4284)
*
* @return string
*/
function bbp_get_keymaster_role() {
// Filter & return
return apply_filters( 'bbp_get_keymaster_role', 'bbp_keymaster' );
}
/**
* The moderator role for bbPress users
*
* @since 2.0.0 bbPress (r3410)
*
* @return string
*/
function bbp_get_moderator_role() {
// Filter & return
return apply_filters( 'bbp_get_moderator_role', 'bbp_moderator' );
}
/**
* The participant role for registered user that can participate in forums
*
* @since 2.0.0 bbPress (r3410)
*
* @return string
*/
function bbp_get_participant_role() {
// Filter & return
return apply_filters( 'bbp_get_participant_role', 'bbp_participant' );
}
/**
* The spectator role is for registered users without any capabilities
*
* @since 2.1.0 bbPress (r3860)
*
* @return string
*/
function bbp_get_spectator_role() {
// Filter & return
return apply_filters( 'bbp_get_spectator_role', 'bbp_spectator' );
}
/**
* The blocked role is for registered users that cannot spectate or participate
*
* @since 2.2.0 bbPress (r4284)
*
* @return string
*/
function bbp_get_blocked_role() {
// Filter & return
return apply_filters( 'bbp_get_blocked_role', 'bbp_blocked' );
}
/**
* Adds bbPress-specific user roles.
*
* @since 2.0.0 bbPress (r2741)
*
* @deprecated 2.2.0 bbPress (r4164)
*/
function bbp_add_roles() {
_doing_it_wrong( 'bbp_add_roles', esc_html__( 'Editable forum roles no longer exist.', 'bbpress' ), '2.2' );
}
/**
* Removes bbPress-specific user roles from the `wp_user_roles` array.
*
* This is currently only used when updating, uninstalling, or resetting bbPress.
*
* @see bbp_admin_reset_handler()
* @see bbp_do_uninstall()
* @see bbp_version_updater()
*
* @since 2.0.0 bbPress (r2741)
*/
function bbp_remove_roles() {
// Remove the bbPress roles
foreach ( array_keys( bbp_get_dynamic_roles() ) as $bbp_role ) {
remove_role( $bbp_role );
}
// Some early adopters may have a deprecated visitor role. It was later
// replaced by the Spectator role.
remove_role( 'bbp_visitor' );
}

View File

@@ -0,0 +1,76 @@
<?php
/**
* bbPress Extentions
*
* There's a world of really cool plugins out there, and bbPress comes with
* support for some of the most popular ones.
*
* @package bbPress
* @subpackage Extend
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/**
* Loads Akismet inside the bbPress global class
*
* @since 2.0.0 bbPress (r3277)
*
* @return If bbPress is not active
*/
function bbp_setup_akismet() {
// Bail if no akismet
if ( ! defined( 'AKISMET_VERSION' ) ) {
return;
}
// Bail if Akismet is turned off
if ( ! bbp_is_akismet_active() ) {
return;
}
// Include the Akismet Component
require_once bbpress()->includes_dir . 'extend/akismet.php';
// Instantiate Akismet for bbPress
bbpress()->extend->akismet = new BBP_Akismet();
}
/**
* Requires and creates the BuddyPress extension, and adds component creation
* action to bp_init hook. @see bbp_setup_buddypress_component()
*
* @since 2.0.0 bbPress (r3395)
*
* @return If BuddyPress is not active
*/
function bbp_setup_buddypress() {
if ( ! function_exists( 'buddypress' ) ) {
/**
* Helper for BuddyPress 1.6 and earlier
*
* @since 2.2.0 bbPress (r4395)
*
* @return BuddyPress
*/
function buddypress() {
return isset( $GLOBALS['bp'] ) ? $GLOBALS['bp'] : false;
}
}
// Bail if in maintenance mode
if ( ! buddypress() || buddypress()->maintenance_mode ) {
return;
}
// Include the BuddyPress Component
require_once bbpress()->includes_dir . 'extend/buddypress/loader.php';
// Instantiate BuddyPress for bbPress
bbpress()->extend->buddypress = new BBP_Forums_Component();
}

View File

@@ -0,0 +1,421 @@
<?php
/**
* bbPress Filters
*
* This file contains the filters that are used through-out bbPress. They are
* consolidated here to make searching for them easier, and to help developers
* understand at a glance the order in which things occur.
*
* There are a few common places that additional filters can currently be found
*
* - bbPress: In {@link bbPress::setup_actions()} in bbpress.php
* - Admin: More in {@link BBP_Admin::setup_actions()} in admin.php
*
* @package bbPress
* @subpackage Core
*
* @see /core/actions.php
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/**
* Attach bbPress to WordPress
*
* bbPress uses its own internal actions to help aid in third-party plugin
* development, and to limit the amount of potential future code changes when
* updates to WordPress core occur.
*
* These actions exist to create the concept of 'plugin dependencies'. They
* provide a safe way for plugins to execute code *only* when bbPress is
* installed and activated, without needing to do complicated guesswork.
*
* For more information on how this works, see the 'Plugin Dependency' section
* near the bottom of this file.
*
* v--WordPress Actions v--bbPress Sub-actions
*/
add_filter( 'request', 'bbp_request', 10 );
add_filter( 'template_include', 'bbp_template_include', 10 );
add_filter( 'wp_mail', 'bbp_mail', 10, 3 );
add_filter( 'wp_title', 'bbp_title', 10, 3 );
add_filter( 'body_class', 'bbp_body_class', 10, 2 );
add_filter( 'map_meta_cap', 'bbp_map_meta_caps', 10, 4 );
add_filter( 'allowed_themes', 'bbp_allowed_themes', 10 );
add_filter( 'redirect_canonical', 'bbp_redirect_canonical', 10 );
add_filter( 'login_redirect', 'bbp_redirect_login', 2, 3 );
add_filter( 'logout_url', 'bbp_logout_url', 2, 2 );
add_filter( 'plugin_locale', 'bbp_plugin_locale', 10, 2 );
// Fix post author id for anonymous posts (set it back to 0) when the post status is changed
add_filter( 'wp_insert_post_data', 'bbp_fix_post_author', 30, 2 );
// Force comments_status on bbPress post types
add_filter( 'comments_open', 'bbp_force_comment_status' );
// Remove forums roles from list of all roles
add_filter( 'editable_roles', 'bbp_filter_blog_editable_roles' );
// Reply title fallback
add_filter( 'the_title', 'bbp_get_reply_title_fallback', 2, 2 );
// Avoid queries & 404s
add_filter( 'pre_handle_404', 'bbp_pre_handle_404', 10, 2 );
add_action( 'posts_pre_query', 'bbp_posts_pre_query', 10, 2 );
// User Creation
add_filter( 'signup_user_meta', 'bbp_user_add_role_to_signup_meta', 10 );
/**
* Emails
*
* bbPress sends emails for a few different reasons, largely related to user
* notifications or account changes. Because the `wp_mail` filter can be a
* crowded space, the `bbp_mail` subfilter should be used in conjunction with
* bbp_get_email_header() to narrow the results to only bbPress emails.
*/
add_filter( 'bbp_mail', 'bbp_chunk_emails' );
/**
* Feeds
*
* bbPress comes with a number of custom RSS2 feeds that get handled outside
* the normal scope of feeds that WordPress would normally serve. To do this,
* we filter every page request, listen for a feed request, and trap it.
*/
add_filter( 'bbp_request', 'bbp_request_feed_trap' );
/**
* Template Compatibility
*
* If you want to completely bypass this and manage your own custom bbPress
* template hierarchy, start here by removing this filter, then look at how
* bbp_template_include() works and do something similar. :)
*/
add_filter( 'bbp_template_include', 'bbp_template_include_theme_supports', 2, 1 );
add_filter( 'bbp_template_include', 'bbp_template_include_theme_compat', 4, 2 );
// Filter bbPress template locations
add_filter( 'bbp_get_template_stack', 'bbp_add_template_stack_locations' );
// Links
add_filter( 'paginate_links', 'bbp_add_view_all' );
add_filter( 'bbp_get_topic_permalink', 'bbp_add_view_all' );
add_filter( 'bbp_get_reply_permalink', 'bbp_add_view_all' );
add_filter( 'bbp_get_forum_permalink', 'bbp_add_view_all' );
// wp_filter_kses on new/edit forum/topic/reply title
add_filter( 'bbp_new_forum_pre_title', 'wp_filter_kses' );
add_filter( 'bbp_new_reply_pre_title', 'wp_filter_kses' );
add_filter( 'bbp_new_topic_pre_title', 'wp_filter_kses' );
add_filter( 'bbp_edit_forum_pre_title', 'wp_filter_kses' );
add_filter( 'bbp_edit_reply_pre_title', 'wp_filter_kses' );
add_filter( 'bbp_edit_topic_pre_title', 'wp_filter_kses' );
// Prevent posting malicious or malformed content on new/edit topic/reply
add_filter( 'bbp_new_reply_pre_content', 'bbp_encode_bad', 10 );
add_filter( 'bbp_new_reply_pre_content', 'bbp_code_trick', 20 );
add_filter( 'bbp_new_reply_pre_content', 'bbp_filter_kses', 30 );
add_filter( 'bbp_new_reply_pre_content', 'balanceTags', 40 );
add_filter( 'bbp_new_topic_pre_content', 'bbp_encode_bad', 10 );
add_filter( 'bbp_new_topic_pre_content', 'bbp_code_trick', 20 );
add_filter( 'bbp_new_topic_pre_content', 'bbp_filter_kses', 30 );
add_filter( 'bbp_new_topic_pre_content', 'balanceTags', 40 );
add_filter( 'bbp_new_forum_pre_content', 'bbp_encode_bad', 10 );
add_filter( 'bbp_new_forum_pre_content', 'bbp_code_trick', 20 );
add_filter( 'bbp_new_forum_pre_content', 'bbp_filter_kses', 30 );
add_filter( 'bbp_new_forum_pre_content', 'balanceTags', 40 );
add_filter( 'bbp_edit_reply_pre_content', 'bbp_encode_bad', 10 );
add_filter( 'bbp_edit_reply_pre_content', 'bbp_code_trick', 20 );
add_filter( 'bbp_edit_reply_pre_content', 'bbp_filter_kses', 30 );
add_filter( 'bbp_edit_reply_pre_content', 'balanceTags', 40 );
add_filter( 'bbp_edit_topic_pre_content', 'bbp_encode_bad', 10 );
add_filter( 'bbp_edit_topic_pre_content', 'bbp_code_trick', 20 );
add_filter( 'bbp_edit_topic_pre_content', 'bbp_filter_kses', 30 );
add_filter( 'bbp_edit_topic_pre_content', 'balanceTags', 40 );
add_filter( 'bbp_edit_forum_pre_content', 'bbp_encode_bad', 10 );
add_filter( 'bbp_edit_forum_pre_content', 'bbp_code_trick', 20 );
add_filter( 'bbp_edit_forum_pre_content', 'bbp_filter_kses', 30 );
add_filter( 'bbp_edit_forum_pre_content', 'balanceTags', 40 );
// No follow and wp_unslash on links
add_filter( 'bbp_get_reply_author_link', 'bbp_rel_nofollow' );
add_filter( 'bbp_get_reply_author_link', 'wp_unslash' );
add_filter( 'bbp_get_reply_to_link', 'bbp_rel_nofollow' );
add_filter( 'bbp_get_reply_to_link', 'wp_unslash' );
add_filter( 'bbp_get_topic_author_link', 'bbp_rel_nofollow' );
add_filter( 'bbp_get_topic_author_link', 'wp_unslash' );
add_filter( 'bbp_get_topic_reply_link', 'bbp_rel_nofollow' );
add_filter( 'bbp_get_topic_reply_link', 'wp_unslash' );
add_filter( 'bbp_get_user_favorites_link', 'bbp_rel_nofollow' );
add_filter( 'bbp_get_user_favorites_link', 'wp_unslash' );
add_filter( 'bbp_get_user_subscribe_link', 'bbp_rel_nofollow' );
add_filter( 'bbp_get_user_subscribe_link', 'wp_unslash' );
add_filter( 'bbp_get_user_profile_link', 'bbp_rel_nofollow' );
add_filter( 'bbp_get_user_profile_link', 'wp_unslash' );
add_filter( 'bbp_get_user_profile_edit_link', 'bbp_rel_nofollow' );
add_filter( 'bbp_get_user_profile_edit_link', 'wp_unslash' );
add_filter( 'bbp_get_cancel_reply_to_link', 'bbp_rel_nofollow' );
add_filter( 'bbp_get_cancel_reply_to_link', 'wp_unslash' );
// Run filters on reply content
add_filter( 'bbp_get_reply_content', 'wptexturize', 6 );
add_filter( 'bbp_get_reply_content', 'convert_chars', 8 );
add_filter( 'bbp_get_reply_content', 'capital_P_dangit', 10 );
add_filter( 'bbp_get_reply_content', 'convert_smilies', 20 );
add_filter( 'bbp_get_reply_content', 'force_balance_tags', 30 );
add_filter( 'bbp_get_reply_content', 'bbp_make_clickable', 40 );
add_filter( 'bbp_get_reply_content', 'wpautop', 50 );
add_filter( 'bbp_get_reply_content', 'bbp_rel_nofollow', 60 );
// Run filters on topic content
add_filter( 'bbp_get_topic_content', 'wptexturize', 6 );
add_filter( 'bbp_get_topic_content', 'convert_chars', 8 );
add_filter( 'bbp_get_topic_content', 'capital_P_dangit', 10 );
add_filter( 'bbp_get_topic_content', 'convert_smilies', 20 );
add_filter( 'bbp_get_topic_content', 'force_balance_tags', 30 );
add_filter( 'bbp_get_topic_content', 'bbp_make_clickable', 40 );
add_filter( 'bbp_get_topic_content', 'wpautop', 50 );
add_filter( 'bbp_get_topic_content', 'bbp_rel_nofollow', 60 );
// Admin-only
if ( is_admin() ) {
// Run wp_kses_data on topic/reply content in admin section
add_filter( 'bbp_get_reply_content', 'bbp_kses_data' );
add_filter( 'bbp_get_topic_content', 'bbp_kses_data' );
// Filters outside of wp-admin
} else {
// WordPress 5.5.x and above
if ( function_exists( 'wp_filter_content_tags' ) ) {
// Responsive images
add_filter( 'bbp_get_reply_content', 'wp_filter_content_tags', 60 );
add_filter( 'bbp_get_topic_content', 'wp_filter_content_tags', 60 );
// WordPress 5.4.x and below
} else {
// Responsive images
add_filter( 'bbp_get_reply_content', 'wp_make_content_images_responsive', 60 );
add_filter( 'bbp_get_topic_content', 'wp_make_content_images_responsive', 60 );
}
// Revisions
add_filter( 'bbp_get_reply_content', 'bbp_reply_content_append_revisions', 99, 2 );
add_filter( 'bbp_get_topic_content', 'bbp_topic_content_append_revisions', 99, 2 );
}
// Form textarea output - undo the code-trick done pre-save, and sanitize
add_filter( 'bbp_get_form_forum_content', 'bbp_code_trick_reverse' );
add_filter( 'bbp_get_form_forum_content', 'esc_textarea' );
add_filter( 'bbp_get_form_forum_content', 'trim' );
add_filter( 'bbp_get_form_topic_content', 'bbp_code_trick_reverse' );
add_filter( 'bbp_get_form_topic_content', 'esc_textarea' );
add_filter( 'bbp_get_form_topic_content', 'trim' );
add_filter( 'bbp_get_form_reply_content', 'bbp_code_trick_reverse' );
add_filter( 'bbp_get_form_reply_content', 'esc_textarea' );
add_filter( 'bbp_get_form_reply_content', 'trim' );
// Form input/output - sanitize
add_filter( 'bbp_get_form_reply_edit_reason', 'esc_attr' );
add_filter( 'bbp_get_form_reply_edit_reason', 'trim' );
add_filter( 'bbp_get_form_topic_edit_reason', 'esc_attr' );
add_filter( 'bbp_get_form_topic_edit_reason', 'trim' );
add_filter( 'bbp_get_form_topic_title', 'esc_attr' );
add_filter( 'bbp_get_form_topic_title', 'trim' );
add_filter( 'bbp_get_form_topic_tags', 'esc_attr' );
add_filter( 'bbp_get_form_topic_tags', 'trim' );
add_filter( 'bbp_get_form_forum_type', 'esc_attr' );
add_filter( 'bbp_get_form_forum_type', 'trim' );
add_filter( 'bbp_get_form_forum_visibility', 'esc_attr' );
add_filter( 'bbp_get_form_forum_visibility', 'trim' );
add_filter( 'bbp_get_form_forum_moderators', 'esc_attr' );
add_filter( 'bbp_get_form_forum_moderators', 'trim' );
add_filter( 'bbp_get_form_topic_forum', 'intval' );
add_filter( 'bbp_get_form_forum_parent', 'intval' );
add_filter( 'bbp_get_form_reply_to', 'intval' );
// Add number format filter to functions requesting formatted values
add_filter( 'bbp_get_user_topic_count', 'bbp_number_format', 10 );
add_filter( 'bbp_get_user_reply_count', 'bbp_number_format', 10 );
add_filter( 'bbp_get_user_post_count', 'bbp_number_format', 10 );
add_filter( 'bbp_get_forum_subforum_count', 'bbp_number_format', 10 );
add_filter( 'bbp_get_forum_topic_count', 'bbp_number_format', 10 );
add_filter( 'bbp_get_forum_reply_count', 'bbp_number_format', 10 );
add_filter( 'bbp_get_forum_post_count', 'bbp_number_format', 10 );
add_filter( 'bbp_get_topic_voice_count', 'bbp_number_format', 10 );
add_filter( 'bbp_get_topic_reply_count', 'bbp_number_format', 10 );
add_filter( 'bbp_get_topic_post_count', 'bbp_number_format', 10 );
add_filter( 'bbp_get_topic_revision_count', 'bbp_number_format', 10 );
add_filter( 'bbp_get_reply_revision_count', 'bbp_number_format', 10 );
add_filter( 'bbp_get_forum_topic_count_hidden', 'bbp_number_format', 10 );
add_filter( 'bbp_get_topic_reply_count_hidden', 'bbp_number_format', 10 );
// Add number-not-negative filter to values that can never be negative numbers
add_filter( 'bbp_get_user_topic_count', 'bbp_number_not_negative', 8 );
add_filter( 'bbp_get_user_reply_count', 'bbp_number_not_negative', 8 );
add_filter( 'bbp_get_user_post_count', 'bbp_number_not_negative', 8 );
add_filter( 'bbp_get_forum_subforum_count', 'bbp_number_not_negative', 8 );
add_filter( 'bbp_get_forum_topic_count', 'bbp_number_not_negative', 8 );
add_filter( 'bbp_get_forum_reply_count', 'bbp_number_not_negative', 8 );
add_filter( 'bbp_get_forum_post_count', 'bbp_number_not_negative', 8 );
add_filter( 'bbp_get_topic_voice_count', 'bbp_number_not_negative', 8 );
add_filter( 'bbp_get_topic_reply_count', 'bbp_number_not_negative', 8 );
add_filter( 'bbp_get_topic_post_count', 'bbp_number_not_negative', 8 );
add_filter( 'bbp_get_forum_topic_count_hidden', 'bbp_number_not_negative', 8 );
add_filter( 'bbp_get_topic_reply_count_hidden', 'bbp_number_not_negative', 8 );
add_filter( 'bbp_get_topic_revision_count', 'bbp_number_not_negative', 8 );
add_filter( 'bbp_get_reply_revision_count', 'bbp_number_not_negative', 8 );
add_filter( 'bbp_get_user_topic_count_int', 'bbp_number_not_negative', 8 );
add_filter( 'bbp_get_user_reply_count_int', 'bbp_number_not_negative', 8 );
add_filter( 'bbp_get_user_post_count_int', 'bbp_number_not_negative', 8 );
add_filter( 'bbp_get_forum_subforum_count_int', 'bbp_number_not_negative', 8 );
add_filter( 'bbp_get_forum_topic_count_int', 'bbp_number_not_negative', 8 );
add_filter( 'bbp_get_forum_reply_count_int', 'bbp_number_not_negative', 8 );
add_filter( 'bbp_get_forum_post_count_int', 'bbp_number_not_negative', 8 );
add_filter( 'bbp_get_topic_voice_count_int', 'bbp_number_not_negative', 8 );
add_filter( 'bbp_get_topic_reply_count_int', 'bbp_number_not_negative', 8 );
add_filter( 'bbp_get_topic_post_count_int', 'bbp_number_not_negative', 8 );
add_filter( 'bbp_get_forum_topic_count_hidden_int', 'bbp_number_not_negative', 8 );
add_filter( 'bbp_get_topic_reply_count_hidden_int', 'bbp_number_not_negative', 8 );
add_filter( 'bbp_get_topic_revision_count_int', 'bbp_number_not_negative', 8 );
add_filter( 'bbp_get_reply_revision_count_int', 'bbp_number_not_negative', 8 );
// Sanitize displayed user data
add_filter( 'bbp_get_displayed_user_field', 'bbp_sanitize_displayed_user_field', 10, 3 );
// Suppress private forum details
add_filter( 'bbp_get_forum_topic_count', 'bbp_suppress_private_forum_meta', 10, 2 );
add_filter( 'bbp_get_forum_reply_count', 'bbp_suppress_private_forum_meta', 10, 2 );
add_filter( 'bbp_get_forum_post_count', 'bbp_suppress_private_forum_meta', 10, 2 );
add_filter( 'bbp_get_forum_freshness_link', 'bbp_suppress_private_forum_meta', 10, 2 );
add_filter( 'bbp_get_author_link', 'bbp_suppress_private_author_link', 10, 2 );
add_filter( 'bbp_get_topic_author_link', 'bbp_suppress_private_author_link', 10, 2 );
add_filter( 'bbp_get_reply_author_link', 'bbp_suppress_private_author_link', 10, 2 );
// Allow private & hidden forum details for moderators
add_filter( 'bbp_get_excluded_forum_ids', 'bbp_allow_forums_of_user', 10, 2 );
// Topic and reply author display names
add_filter( 'bbp_get_topic_author_display_name', 'wptexturize' );
add_filter( 'bbp_get_topic_author_display_name', 'convert_chars' );
add_filter( 'bbp_get_topic_author_display_name', 'esc_html' );
add_filter( 'bbp_get_reply_author_display_name', 'wptexturize' );
add_filter( 'bbp_get_reply_author_display_name', 'convert_chars' );
add_filter( 'bbp_get_reply_author_display_name', 'esc_html' );
/**
* Add filters to anonymous post author data
*/
// Post author name
add_filter( 'bbp_pre_anonymous_post_author_name', 'trim', 10 );
add_filter( 'bbp_pre_anonymous_post_author_name', 'sanitize_text_field', 10 );
add_filter( 'bbp_pre_anonymous_post_author_name', 'wp_filter_kses', 10 );
add_filter( 'bbp_pre_anonymous_post_author_name', '_wp_specialchars', 30 );
// Save email
add_filter( 'bbp_pre_anonymous_post_author_email', 'trim', 10 );
add_filter( 'bbp_pre_anonymous_post_author_email', 'sanitize_email', 10 );
add_filter( 'bbp_pre_anonymous_post_author_email', 'wp_filter_kses', 10 );
// Save URL
add_filter( 'bbp_pre_anonymous_post_author_website', 'trim', 10 );
add_filter( 'bbp_pre_anonymous_post_author_website', 'wp_strip_all_tags', 10 );
add_filter( 'bbp_pre_anonymous_post_author_website', 'esc_url_raw', 10 );
add_filter( 'bbp_pre_anonymous_post_author_website', 'wp_filter_kses', 10 );
// Queries
add_filter( 'posts_request', '_bbp_has_replies_where', 10, 2 );
// Capabilities
add_filter( 'bbp_map_meta_caps', 'bbp_map_primary_meta_caps', 10, 4 ); // Primary caps
add_filter( 'bbp_map_meta_caps', 'bbp_map_forum_meta_caps', 10, 4 ); // Forums
add_filter( 'bbp_map_meta_caps', 'bbp_map_topic_meta_caps', 10, 4 ); // Topics
add_filter( 'bbp_map_meta_caps', 'bbp_map_topic_tag_meta_caps', 10, 4 ); // Topic tags
add_filter( 'bbp_map_meta_caps', 'bbp_map_reply_meta_caps', 10, 4 ); // Replies
// Clickables
add_filter( 'bbp_make_clickable', 'bbp_make_urls_clickable', 2 ); // https://bbpress.org
add_filter( 'bbp_make_clickable', 'bbp_make_ftps_clickable', 4 ); // ftps://bbpress.org
add_filter( 'bbp_make_clickable', 'bbp_make_emails_clickable', 6 ); // jjj@bbpress.org
add_filter( 'bbp_make_clickable', 'bbp_make_mentions_clickable', 8 ); // @jjj
/** Deprecated ****************************************************************/
/**
* The following filters are deprecated.
*
* These filters were most likely replaced by bbp_parse_args(), which includes
* both passive and aggressive filters anywhere parse_args is used to compare
* default arguments to passed arguments, without sprinkling the project with
* _before_ and _after_ filters everywhere.
*/
/**
* Deprecated locale filter
*
* @since 2.2.0 bbPress (r4213)
*
* @param string $locale
* @return string $domain
*/
function _bbp_filter_locale( $locale = '', $domain = '' ) {
// Only apply to the bbPress text-domain
if ( bbpress()->domain !== $domain ) {
return $locale;
}
return apply_filters( 'bbpress_locale', $locale, $domain );
}
add_filter( 'bbp_plugin_locale', '_bbp_filter_locale', 10, 1 );
/**
* Deprecated forums query filter
*
* @since 2.1.0 bbPress (r3961)
*
* @param array $args
* @return array
*/
function _bbp_has_forums_query( $args = array() ) {
// Filter & return
return (array) apply_filters( 'bbp_has_forums_query', $args );
}
add_filter( 'bbp_after_has_forums_parse_args', '_bbp_has_forums_query' );
/**
* Deprecated topics query filter
*
* @since 2.1.0 bbPress (r3961)
*
* @param array $args
* @return array
*/
function _bbp_has_topics_query( $args = array() ) {
// Filter & return
return (array) apply_filters( 'bbp_has_topics_query', $args );
}
add_filter( 'bbp_after_has_topics_parse_args', '_bbp_has_topics_query' );
/**
* Deprecated replies query filter
*
* @since 2.1.0 bbPress (r3961)
*
* @param array $args
* @return array
*/
function _bbp_has_replies_query( $args = array() ) {
// Filter & return
return (array) apply_filters( 'bbp_has_replies_query', $args );
}
add_filter( 'bbp_after_has_replies_parse_args', '_bbp_has_replies_query' );

View File

@@ -0,0 +1,702 @@
<?php
/**
* bbPress Core Functions
*
* @package bbPress
* @subpackage Functions
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/** Versions ******************************************************************/
/**
* Output the bbPress version
*
* @since 2.0.0 bbPress (r3468)
*/
function bbp_version() {
echo bbp_get_version();
}
/**
* Return the bbPress version
*
* @since 2.0.0 bbPress (r3468)
*
* @retrun string The bbPress version
*/
function bbp_get_version() {
return bbpress()->version;
}
/**
* Output the bbPress asset version
*
* @since 2.6.7 bbPress (r7188)
*/
function bbp_asset_version() {
echo bbp_get_asset_version();
}
/**
* Return the bbPress asset version
*
* @since 2.6.7 bbPress (r7188)
*
* @retrun string The bbPress asset version
*/
function bbp_get_asset_version() {
return bbp_doing_script_debug()
? (string) time()
: bbp_get_version();
}
/**
* Output the bbPress database version
*
* @since 2.0.0 bbPress (r3468)
*/
function bbp_db_version() {
echo bbp_get_db_version();
}
/**
* Return the bbPress database version
*
* @since 2.0.0 bbPress (r3468)
*
* @retrun string The bbPress version
*/
function bbp_get_db_version() {
return bbpress()->db_version;
}
/**
* Output the bbPress database version directly from the database
*
* @since 2.0.0 bbPress (r3468)
*/
function bbp_db_version_raw() {
echo bbp_get_db_version_raw();
}
/**
* Return the bbPress database version directly from the database
*
* @since 2.0.0 bbPress (r3468)
*
* @retrun string The current bbPress version
*/
function bbp_get_db_version_raw() {
return get_option( '_bbp_db_version', '' );
}
/** Post Meta *****************************************************************/
/**
* Update the forum meta ID of a post
*
* @since 2.0.0 bbPress (r3181)
*
* @param int $post_id The post to update
* @param int $forum_id The forum
*/
function bbp_update_forum_id( $post_id = 0, $forum_id = 0 ) {
// Allow the forum ID to be updated 'just in time' before save
$forum_id = (int) apply_filters( 'bbp_update_forum_id', $forum_id, $post_id );
// Update the post meta forum ID
update_post_meta( $post_id, '_bbp_forum_id', $forum_id );
return $forum_id;
}
/**
* Update the topic meta ID of a post
*
* @since 2.0.0 bbPress (r3181)
*
* @param int $post_id The post to update
* @param int $topic_id The topic
*/
function bbp_update_topic_id( $post_id = 0, $topic_id = 0 ) {
// Allow the topic ID to be updated 'just in time' before save
$topic_id = (int) apply_filters( 'bbp_update_topic_id', $topic_id, $post_id );
// Update the post meta topic ID
update_post_meta( $post_id, '_bbp_topic_id', $topic_id );
return $topic_id;
}
/**
* Update the reply meta ID of a post
*
* @since 2.0.0 bbPress (r3181)
*
* @param int $post_id The post to update
* @param int $reply_id The reply
*/
function bbp_update_reply_id( $post_id = 0, $reply_id = 0 ) {
// Allow the reply ID to be updated 'just in time' before save
$reply_id = (int) apply_filters( 'bbp_update_reply_id', $reply_id, $post_id );
// Update the post meta reply ID
update_post_meta( $post_id, '_bbp_reply_id', $reply_id );
return $reply_id;
}
/**
* Update the reply-to meta ID of a post
*
* @since 2.6.0 bbPress (r5735)
*
* @param int $post_id The post to update
* @param int $reply_id The reply ID
*/
function bbp_update_reply_to_id( $post_id = 0, $reply_id = 0 ) {
// Allow the reply ID to be updated 'just in time' before save
$reply_id = (int) apply_filters( 'bbp_update_reply_to_id', $reply_id, $post_id );
// Update the post meta reply ID
update_post_meta( $post_id, '_bbp_reply_to', $reply_id );
return $reply_id;
}
/** Views *********************************************************************/
/**
* Get the registered views
*
* Does nothing much other than return the {@link $bbp->views} variable
*
* @since 2.0.0 bbPress (r2789)
*
* @return array Views
*/
function bbp_get_views() {
return bbpress()->views;
}
/**
* Register a bbPress view
*
* @since 2.0.0 bbPress (r2789)
*
* @param string $view View name
* @param string $title View title
* @param mixed $query_args {@link bbp_has_topics()} arguments.
* @param bool $feed Have a feed for the view? Defaults to true.
* @param string $capability Capability that the current user must have
*
* @return array The just registered (but processed) view
*/
function bbp_register_view( $view, $title, $query_args = '', $feed = true, $capability = '' ) {
// Bail if user does not have capability
if ( ! empty( $capability ) && ! current_user_can( $capability ) ) {
return false;
}
$bbp = bbpress();
$view = sanitize_title( $view );
$title = esc_html( $title );
if ( empty( $view ) || empty( $title ) ) {
return false;
}
$query_args = bbp_parse_args( $query_args, '', 'register_view' );
// Set show_stickies to false if it wasn't supplied
if ( ! isset( $query_args['show_stickies'] ) ) {
$query_args['show_stickies'] = false;
}
$bbp->views[ $view ] = array(
'title' => $title,
'query' => $query_args,
'feed' => $feed
);
return $bbp->views[ $view ];
}
/**
* Deregister a bbPress view
*
* @since 2.0.0 bbPress (r2789)
*
* @param string $view View name
* @return bool False if the view doesn't exist, true on success
*/
function bbp_deregister_view( $view ) {
$bbp = bbpress();
$view = sanitize_title( $view );
if ( ! isset( $bbp->views[ $view ] ) ) {
return false;
}
unset( $bbp->views[ $view ] );
return true;
}
/**
* Run the query of a topic-view
*
* @since 2.0.0 bbPress (r2789)
*
* @param string $view Optional. View id
* @param mixed $new_args New arguments. See {@link bbp_has_topics()}
* @return bool False if the view doesn't exist, otherwise if topics are there
*/
function bbp_view_query( $view = '', $new_args = '' ) {
// Get view, or bail
$view = bbp_get_view_id( $view );
if ( empty( $view ) ) {
return false;
}
$query_args = bbp_get_view_query_args( $view );
if ( ! empty( $new_args ) ) {
$new_args = bbp_parse_args( $new_args, '', 'view_query' );
$query_args = array_merge( $query_args, $new_args );
}
return bbp_has_topics( $query_args );
}
/**
* Return the query arguments of a topic-view
*
* @since 2.0.0 bbPress (r2789)
*
* @param string $view View name
* @return array Query arguments
*/
function bbp_get_view_query_args( $view = '' ) {
$bbp = bbpress();
$view = bbp_get_view_id( $view );
$retval = ! empty( $view ) && ! empty( $bbp->views[ $view ] )
? $bbp->views[ $view ]['query']
: array();
// Filter & return
return (array) apply_filters( 'bbp_get_view_query_args', $retval, $view );
}
/** Errors ********************************************************************/
/**
* Adds an error message to later be output in the theme
*
* @since 2.0.0 bbPress (r3381)
*
* @see WP_Error()
*
* @param string $code Unique code for the error message
* @param string $message Translated error message
* @param string $data Any additional data passed with the error message
*/
function bbp_add_error( $code = '', $message = '', $data = '' ) {
bbpress()->errors->add( $code, $message, $data );
}
/**
* Check if error messages exist in queue
*
* @since 2.0.0 bbPress (r3381)
*
* @see WP_Error()
*/
function bbp_has_errors() {
$has_errors = bbpress()->errors->get_error_codes()
? true
: false;
return (bool) apply_filters( 'bbp_has_errors', $has_errors, bbpress()->errors );
}
/** Mentions ******************************************************************/
/**
* Set the pattern used for matching usernames for mentions.
*
* Moved into its own function to allow filtering of the regex pattern
* anywhere mentions might be used.
*
* @since 2.4.0 bbPress (r4997)
* @deprecated 2.6.0 bbp_make_clickable()
*
* @return string Pattern to match usernames with
*/
function bbp_find_mentions_pattern() {
// Filter & return
return apply_filters( 'bbp_find_mentions_pattern', '/[@]+([A-Za-z0-9-_\.@]+)\b/' );
}
/**
* Searches through the content to locate usernames, designated by an @ sign.
*
* @since 2.2.0 bbPress (r4323)
* @deprecated 2.6.0 bbp_make_clickable()
*
* @param string $content The content
* @return bool|array $usernames Existing usernames. False if no matches.
*/
function bbp_find_mentions( $content = '' ) {
$pattern = bbp_find_mentions_pattern();
preg_match_all( $pattern, $content, $usernames );
$usernames = array_unique( array_filter( $usernames[1] ) );
// Bail if no usernames
if ( empty( $usernames ) ) {
$usernames = false;
}
// Filter & return
return apply_filters( 'bbp_find_mentions', $usernames, $pattern, $content );
}
/**
* Finds and links @-mentioned users in the content
*
* @since 2.2.0 bbPress (r4323)
* @deprecated 2.6.0 bbp_make_clickable()
*
* @return string $content Content filtered for mentions
*/
function bbp_mention_filter( $content = '' ) {
// Get Usernames and bail if none exist
$usernames = bbp_find_mentions( $content );
if ( empty( $usernames ) ) {
return $content;
}
// Loop through usernames and link to profiles
foreach ( (array) $usernames as $username ) {
// Skip if username does not exist or user is not active
$user = get_user_by( 'slug', $username );
if ( empty( $user->ID ) || bbp_is_user_inactive( $user->ID ) ) {
continue;
}
// Link
$profile_url = bbp_get_user_profile_url( $user->ID );
$profile_link = sprintf( '<a href="%1$s">@%2$s</a>', esc_url( $profile_url ), esc_html( $username ) );
$no_followed = bbp_rel_nofollow( $profile_link );
$pattern = "/(@{$username}\b)/";
// Replace name in content
$content = preg_replace( $pattern, $no_followed, $content );
}
// Return modified content
return $content;
}
/** Post Statuses *************************************************************/
/**
* Return the public post status ID
*
* @since 2.0.0 bbPress (r3504)
*
* @return string
*/
function bbp_get_public_status_id() {
return bbpress()->public_status_id;
}
/**
* Return the pending post status ID
*
* @since 2.1.0 bbPress (r3581)
*
* @return string
*/
function bbp_get_pending_status_id() {
return bbpress()->pending_status_id;
}
/**
* Return the private post status ID
*
* @since 2.0.0 bbPress (r3504)
*
* @return string
*/
function bbp_get_private_status_id() {
return bbpress()->private_status_id;
}
/**
* Return the hidden post status ID
*
* @since 2.0.0 bbPress (r3504)
*
* @return string
*/
function bbp_get_hidden_status_id() {
return bbpress()->hidden_status_id;
}
/**
* Return the closed post status ID
*
* @since 2.0.0 bbPress (r3504)
*
* @return string
*/
function bbp_get_closed_status_id() {
return bbpress()->closed_status_id;
}
/**
* Return the spam post status ID
*
* @since 2.0.0 bbPress (r3504)
*
* @return string
*/
function bbp_get_spam_status_id() {
return bbpress()->spam_status_id;
}
/**
* Return the trash post status ID
*
* @since 2.0.0 bbPress (r3504)
*
* @return string
*/
function bbp_get_trash_status_id() {
return bbpress()->trash_status_id;
}
/**
* Return the orphan post status ID
*
* @since 2.0.0 bbPress (r3504)
*
* @return string
*/
function bbp_get_orphan_status_id() {
return bbpress()->orphan_status_id;
}
/** Rewrite IDs ***************************************************************/
/**
* Return the unique ID for user profile rewrite rules
*
* @since 2.1.0 bbPress (r3762)
*
* @return string
*/
function bbp_get_user_rewrite_id() {
return bbpress()->user_id;
}
/**
* Return the unique ID for all edit rewrite rules (forum|topic|reply|tag|user)
*
* @since 2.1.0 bbPress (r3762)
*
* @return string
*/
function bbp_get_edit_rewrite_id() {
return bbpress()->edit_id;
}
/**
* Return the unique ID for all search rewrite rules
*
* @since 2.3.0 bbPress (r4579)
*
* @return string
*/
function bbp_get_search_rewrite_id() {
return bbpress()->search_id;
}
/**
* Return the unique ID for user topics rewrite rules
*
* @since 2.2.0 bbPress (r4321)
*
* @return string
*/
function bbp_get_user_topics_rewrite_id() {
return bbpress()->tops_id;
}
/**
* Return the unique ID for user replies rewrite rules
*
* @since 2.2.0 bbPress (r4321)
*
* @return string
*/
function bbp_get_user_replies_rewrite_id() {
return bbpress()->reps_id;
}
/**
* Return the unique ID for user favorites rewrite rules
*
* @since 2.2.0 bbPress (r4181)
*
* @return string
*/
function bbp_get_user_favorites_rewrite_id() {
return bbpress()->favs_id;
}
/**
* Return the unique ID for user subscriptions rewrite rules
*
* @since 2.2.0 bbPress (r4181)
*
* @return string
*/
function bbp_get_user_subscriptions_rewrite_id() {
return bbpress()->subs_id;
}
/**
* Return the unique ID for user engagement rewrite rules
*
* @since 2.6.0 bbPress (r6320)
*
* @return string
*/
function bbp_get_user_engagements_rewrite_id() {
return bbpress()->engagements_id;
}
/**
* Return the unique ID for topic view rewrite rules
*
* @since 2.1.0 bbPress (r3762)
*
* @return string
*/
function bbp_get_view_rewrite_id() {
return bbpress()->view_id;
}
/** Rewrite Extras ************************************************************/
/**
* Get the id used for paginated requests
*
* @since 2.4.0 bbPress (r4926)
*
* @return string
*/
function bbp_get_paged_rewrite_id() {
return bbpress()->paged_id;
}
/**
* Delete a blogs rewrite rules, so that they are automatically rebuilt on
* the subsequent page load.
*
* @since 2.2.0 bbPress (r4198)
*/
function bbp_delete_rewrite_rules() {
delete_option( 'rewrite_rules' );
}
/** Requests ******************************************************************/
/**
* Return true|false if this is a POST request
*
* @since 2.3.0 bbPress (r4790)
*
* @return bool
*/
function bbp_is_post_request() {
return (bool) ( 'POST' === strtoupper( $_SERVER['REQUEST_METHOD'] ) );
}
/**
* Return true|false if this is a GET request
*
* @since 2.3.0 bbPress (r4790)
*
* @return bool
*/
function bbp_is_get_request() {
return (bool) ( 'GET' === strtoupper( $_SERVER['REQUEST_METHOD'] ) );
}
/** Redirection ***************************************************************/
/**
* Perform a safe, local redirect somewhere inside the current site
*
* On some setups, passing the value of wp_get_referer() may result in an empty
* value for $location, which results in an error on redirection. If $location
* is empty, we can safely redirect back to the forum root. This might change
* in a future version, possibly to the site root.
*
* @since 2.6.0 bbPress (r5658)
*
* @see bbp_redirect_to_field()
*
* @param string $location The URL to redirect the user to.
* @param int $status Optional. The numeric code to give in the redirect
* headers. Default: 302.
*/
function bbp_redirect( $location = '', $status = 302 ) {
// Prevent errors from empty $location
if ( empty( $location ) ) {
$location = bbp_get_forums_url();
}
// Setup the safe redirect
wp_safe_redirect( $location, $status );
// Exit so the redirect takes place immediately
exit();
}
/** Global Helpers ************************************************************/
/**
* Return if debugging scripts or not
*
* @since 2.6.7 (r7188)
*
* @return bool True if debugging scripts. False if not debugging scripts.
*/
function bbp_doing_script_debug() {
return defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG;
}
/**
* Return if auto-saving or not
*
* @since 2.6.7 (r7188)
*
* @return bool True if mid auto-save. False if not mid auto-save.
*/
function bbp_doing_autosave() {
return defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE;
}

View File

@@ -0,0 +1,5 @@
<?php
/**
* Do not modify the files in this folder.
*/

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,553 @@
<?php
/**
* Plugin Dependency
*
* The purpose of the following hooks is to mimic the behavior of something
* called 'plugin dependency' which enables a plugin to have plugins of their
* own in a safe and reliable way.
*
* We do this in bbPress by mirroring existing WordPress hooks in many places
* allowing dependant plugins to hook into the bbPress specific ones, thus
* guaranteeing proper code execution only when bbPress is active.
*
* The following functions are wrappers for hooks, allowing them to be
* manually called and/or piggy-backed on top of other hooks if needed.
*
* @package bbPress
* @subpackage Core
*
* @todo use anonymous functions when PHP minimum requirement allows (5.3)
*/
/** Activation Actions ********************************************************/
/**
* Runs on bbPress activation
*
* @since 2.0.0 bbPress (r2509)
*/
function bbp_activation() {
do_action( 'bbp_activation' );
}
/**
* Runs on bbPress deactivation
*
* @since 2.0.0 bbPress (r2509)
*/
function bbp_deactivation() {
do_action( 'bbp_deactivation' );
}
/**
* Runs when uninstalling bbPress
*
* @since 2.0.0 bbPress (r2509)
*/
function bbp_uninstall() {
do_action( 'bbp_uninstall' );
}
/** Main Actions **************************************************************/
/**
* Main action responsible for constants, globals, and includes
*
* @since 2.0.0 bbPress (r2599)
*/
function bbp_loaded() {
do_action( 'bbp_loaded' );
}
/**
* Setup constants
*
* @since 2.0.0 bbPress (r2599)
*/
function bbp_constants() {
do_action( 'bbp_constants' );
}
/**
* Setup globals BEFORE includes
*
* @since 2.0.0 bbPress (r2599)
*/
function bbp_boot_strap_globals() {
do_action( 'bbp_boot_strap_globals' );
}
/**
* Include files
*
* @since 2.0.0 bbPress (r2599)
*/
function bbp_includes() {
do_action( 'bbp_includes' );
}
/**
* Setup globals AFTER includes
*
* @since 2.0.0 bbPress (r2599)
*/
function bbp_setup_globals() {
do_action( 'bbp_setup_globals' );
}
/**
* Register any objects before anything is initialized
*
* @since 2.2.0 bbPress (r4180)
*/
function bbp_register() {
do_action( 'bbp_register' );
}
/**
* Initialize any code after everything has been loaded
*
* @since 2.0.0 bbPress (r2599)
*/
function bbp_init() {
do_action( 'bbp_init' );
}
/**
* Initialize roles
*
* @since 2.6.0 bbPress (r6106)
*
* @param WP_Roles $wp_roles The array of WP_Role objects that was initialized
*/
function bbp_roles_init( $wp_roles ) {
do_action( 'bbp_roles_init', $wp_roles );
}
/**
* Initialize widgets
*
* @since 2.0.0 bbPress (r3389)
*/
function bbp_widgets_init() {
do_action( 'bbp_widgets_init' );
}
/**
* Setup the currently logged-in user
*
* @link https://bbpress.trac.wordpress.org/ticket/2309
* @link https://core.trac.wordpress.org/ticket/24169
*
* @since 2.0.0 bbPress (r2695)
*/
function bbp_setup_current_user() {
do_action( 'bbp_setup_current_user' );
}
/**
* Setup the user engagements strategy
*
* @since 2.6.0 bbPress (r6875)
*/
function bbp_setup_engagements() {
do_action( 'bbp_setup_engagements' );
}
/** Supplemental Actions ******************************************************/
/**
* Load translations for current language
*
* @since 2.0.0 bbPress (r2599)
*/
function bbp_load_textdomain() {
do_action( 'bbp_load_textdomain' );
}
/**
* Setup the post types
*
* @since 2.0.0 bbPress (r2464)
*/
function bbp_register_post_types() {
do_action( 'bbp_register_post_types' );
}
/**
* Setup the post statuses
*
* @since 2.0.0 bbPress (r2727)
*/
function bbp_register_post_statuses() {
do_action( 'bbp_register_post_statuses' );
}
/**
* Register the built in bbPress taxonomies
*
* @since 2.0.0 bbPress (r2464)
*/
function bbp_register_taxonomies() {
do_action( 'bbp_register_taxonomies' );
}
/**
* Register the default bbPress views
*
* @since 2.0.0 bbPress (r2789)
*/
function bbp_register_views() {
do_action( 'bbp_register_views' );
}
/**
* Register the default bbPress shortcodes
*
* @since 2.2.0 bbPress (r4211)
*/
function bbp_register_shortcodes() {
do_action( 'bbp_register_shortcodes' );
}
/**
* Register the default bbPress meta-data
*
* @since 2.6.0 bbPress (r46300)
*/
function bbp_register_meta() {
do_action( 'bbp_register_meta' );
}
/**
* Enqueue bbPress specific CSS and JS
*
* @since 2.0.0 bbPress (r3373)
*/
function bbp_enqueue_scripts() {
do_action( 'bbp_enqueue_scripts' );
}
/**
* Add the bbPress-specific rewrite tags
*
* @since 2.0.0 bbPress (r2753)
*/
function bbp_add_rewrite_tags() {
do_action( 'bbp_add_rewrite_tags' );
}
/**
* Add the bbPress-specific rewrite rules
*
* @since 2.4.0 bbPress (r4918)
*/
function bbp_add_rewrite_rules() {
do_action( 'bbp_add_rewrite_rules' );
}
/**
* Add the bbPress-specific permalink structures
*
* @since 2.4.0 bbPress (r4918)
*/
function bbp_add_permastructs() {
do_action( 'bbp_add_permastructs' );
}
/**
* Add the bbPress-specific login forum action
*
* @since 2.0.0 bbPress (r2753)
*/
function bbp_login_form_login() {
do_action( 'bbp_login_form_login' );
}
/**
* Add the bbPress-specific post status transition action
*
* @since 2.6.0 bbPress (r6792)
*
* @param string $new_status New post status
* @param string $old_status Old post status
* @param WP_Post $post Post object
*/
function bbp_transition_post_status( $new_status = '', $old_status = '', $post = false ) {
// Get bbPress post types
$post_type = get_post_type( $post );
$types = bbp_get_post_types();
// Bail if post is not a bbPress post type
if ( ! in_array( $post_type, $types, true ) ) {
return;
}
// Do the action
do_action( 'bbp_transition_post_status', $new_status, $old_status, $post );
}
/** User Actions **************************************************************/
/**
* The main action for hooking into when a user account is updated
*
* @since 2.2.0 bbPress (r4304)
*
* @param int $user_id ID of user being edited
* @param array $old_user_data The old, unmodified user data
*/
function bbp_profile_update( $user_id = 0, $old_user_data = array() ) {
do_action( 'bbp_profile_update', $user_id, $old_user_data );
}
/**
* The main action for hooking into a user being registered
*
* @since 2.2.0 bbPress (r4304)
*
* @param int $user_id ID of user being edited
*/
function bbp_user_register( $user_id = 0 ) {
do_action( 'bbp_user_register', $user_id );
}
/** Final Action **************************************************************/
/**
* bbPress has loaded and initialized everything, and is okay to go
*
* @since 2.0.0 bbPress (r2618)
*/
function bbp_ready() {
do_action( 'bbp_ready' );
}
/** Theme Permissions *********************************************************/
/**
* The main action used for redirecting bbPress theme actions that are not
* permitted by the current_user
*
* @since 2.1.0 bbPress (r3605)
*/
function bbp_template_redirect() {
do_action( 'bbp_template_redirect' );
}
/** Theme Helpers *************************************************************/
/**
* The main action used for executing code before the theme has been setup
*
* @since 2.1.0 bbPress (r3829)
*/
function bbp_register_theme_packages() {
do_action( 'bbp_register_theme_packages' );
}
/**
* The main action used for executing code before the theme has been setup
*
* @since 2.1.0 bbPress (r3732)
*/
function bbp_setup_theme() {
do_action( 'bbp_setup_theme' );
}
/**
* The main action used for executing code after the theme has been setup
*
* @since 2.1.0 bbPress (r3732)
*/
function bbp_after_setup_theme() {
do_action( 'bbp_after_setup_theme' );
}
/**
* The main action used for handling theme-side POST requests
*
* @since 2.3.0 bbPress (r4550)
*/
function bbp_post_request() {
// Bail if not a POST action
if ( ! bbp_is_post_request() ) {
return;
}
// Bail if no action, or if not a string (arrays not supported)
if ( empty( $_POST['action'] ) || ! is_string( $_POST['action'] ) ) {
return;
}
// Sanitize the POST action
$action = sanitize_key( $_POST['action'] );
// Bail if action was totally invalid
if ( empty( $action ) ) {
return;
}
// This dynamic action is probably the one you want to use. It narrows down
// the scope of the 'action' without needing to check it in your function.
do_action( 'bbp_post_request_' . $action );
// Use this static action if you don't mind checking the 'action' yourself.
do_action( 'bbp_post_request', $action );
}
/**
* The main action used for handling theme-side GET requests
*
* @since 2.3.0 bbPress (r4550)
*/
function bbp_get_request() {
// Bail if not a POST action
if ( ! bbp_is_get_request() ) {
return;
}
// Bail if no action, or if not a string (arrays not supported)
if ( empty( $_GET['action'] ) || ! is_string( $_GET['action'] ) ) {
return;
}
// Sanitize the GET action
$action = sanitize_key( $_GET['action'] );
// Bail if action was totally invalid
if ( empty( $action ) ) {
return;
}
// This dynamic action is probably the one you want to use. It narrows down
// the scope of the 'action' without needing to check it in your function.
do_action( 'bbp_get_request_' . $action );
// Use this static action if you don't mind checking the 'action' yourself.
do_action( 'bbp_get_request', $action );
}
/** Filters *******************************************************************/
/**
* Filter the plugin locale and domain.
*
* @since 2.2.0 bbPress (r4213)
*
* @param string $locale
* @param string $domain
*/
function bbp_plugin_locale( $locale = '', $domain = '' ) {
// Filter & return
return apply_filters( 'bbp_plugin_locale', $locale, $domain );
}
/**
* Piggy back filter for WordPress's 'request' filter
*
* @since 2.1.0 bbPress (r3758)
*
* @param array $query_vars
* @return array
*/
function bbp_request( $query_vars = array() ) {
// Filter & return
return apply_filters( 'bbp_request', $query_vars );
}
/**
* The main filter used for theme compatibility and displaying custom bbPress
* theme files.
*
* @since 2.0.0 bbPress (r3311)
*
* @param string $template
* @return string Template file to use
*/
function bbp_template_include( $template = '' ) {
// Filter & return
return apply_filters( 'bbp_template_include', $template );
}
/**
* Generate bbPress-specific rewrite rules
*
* @since 2.0.0 bbPress (r2688)
*
* @deprecated 2.4.0 bbPress (r4918)
*
* @param WP_Rewrite $wp_rewrite
*/
function bbp_generate_rewrite_rules( $wp_rewrite ) {
do_action_ref_array( 'bbp_generate_rewrite_rules', array( &$wp_rewrite ) );
}
/**
* Filter the allowed themes list for bbPress specific themes
*
* @since 2.0.0 bbPress (r2944)
*
* @param array $themes
*
* @return array Array of allowed themes
*/
function bbp_allowed_themes( $themes ) {
// Filter & return
return (array) apply_filters( 'bbp_allowed_themes', $themes );
}
/**
* Maps forum/topic/reply caps to built in WordPress caps
*
* @since 2.0.0 bbPress (r2593)
*
* @param array $caps Capabilities for meta capability
* @param string $cap Capability name
* @param int $user_id User id
* @param array $args Arguments
*
* @return array Array of capabilities
*/
function bbp_map_meta_caps( $caps = array(), $cap = '', $user_id = 0, $args = array() ) {
// Filter & return
return (array) apply_filters( 'bbp_map_meta_caps', $caps, $cap, $user_id, $args );
}
/**
* Filter the arguments used by wp_mail for bbPress specific emails
*
* @since 2.6.0 bbPress (r6918)
*
* @param array $args A compacted array of wp_mail() arguments, including the "to" email,
* subject, message, headers, and attachments values.
*
* @return array Array of capabilities
*/
function bbp_mail( $args = array() ) {
// Bail if headers are missing/malformed
if ( empty( $args['headers'] ) || ! is_array( $args['headers'] ) ) {
return $args;
}
// Header to search all headers for
$bbp_header = bbp_get_email_header();
// Bail if no bbPress header found
if ( false === array_search( $bbp_header, $args['headers'], true ) ) {
return $args;
}
// Filter & return
return (array) apply_filters( 'bbp_mail', $args );
}

View File

@@ -0,0 +1,738 @@
<?php
/**
* bbPress Template Functions
*
* This file contains functions necessary to mirror the WordPress core template
* loading process. Many of those functions are not filterable, and even then
* would not be robust enough to predict where bbPress templates might exist.
*
* @package bbPress
* @subpackage TemplateFunctions
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/**
* Adds bbPress theme support to any active WordPress theme
*
* @since 2.0.0 bbPress (r3032)
*
* @param string $slug
* @param string $name Optional. Default null
*/
function bbp_get_template_part( $slug, $name = null ) {
// Execute code for this part
do_action( 'get_template_part_' . $slug, $slug, $name );
// Setup possible parts
$templates = array();
if ( isset( $name ) ) {
$templates[] = $slug . '-' . $name . '.php';
}
$templates[] = $slug . '.php';
// Allow template parst to be filtered
$templates = apply_filters( 'bbp_get_template_part', $templates, $slug, $name );
// Return the part that is found
return bbp_locate_template( $templates, true, false );
}
/**
* Retrieve the name of the highest priority template file that exists.
*
* Searches in the child theme before parent theme so that themes which
* inherit from a parent theme can just overload one file. If the template is
* not found in either of those, it looks in the theme-compat folder last.
*
* @since 2.1.0 bbPress (r3618)
*
* @param string|array $template_names Template file(s) to search for, in order.
* @param bool $load If true the template file will be loaded if it is found.
* @param bool $require_once Whether to require_once or require. Default true.
* Has no effect if $load is false.
* @return string The template filename if one is located.
*/
function bbp_locate_template( $template_names, $load = false, $require_once = true ) {
// No file found yet
$located = false;
$template_locations = bbp_get_template_stack();
// Try to find a template file
foreach ( (array) $template_names as $template_name ) {
// Continue if template is empty
if ( empty( $template_name ) ) {
continue;
}
// Trim off any slashes from the template name
$template_name = ltrim( $template_name, '/' );
// Loop through template stack
foreach ( (array) $template_locations as $template_location ) {
// Continue if $template_location is empty
if ( empty( $template_location ) ) {
continue;
}
// Check child theme first
if ( file_exists( trailingslashit( $template_location ) . $template_name ) ) {
$located = trailingslashit( $template_location ) . $template_name;
break 2;
}
}
}
/**
* This action exists only to follow the standard bbPress coding convention,
* and should not be used to short-circuit any part of the template locator.
*
* If you want to override a specific template part, please either filter
* 'bbp_get_template_part' or add a new location to the template stack.
*/
do_action( 'bbp_locate_template', $located, $template_name, $template_names, $template_locations, $load, $require_once );
// Maybe load the template if one was located
if ( ( defined( 'WP_USE_THEMES' ) && WP_USE_THEMES ) && ( true === $load ) && ! empty( $located ) ) {
load_template( $located, $require_once );
}
return $located;
}
/**
* Locate an enqueueable file on the server. Used before being enqueued.
*
* If SCRIPT_DEBUG is set and the file includes a .min suffix, this function
* will automatically attempt to locate a non-minified version of that file.
*
* If SCRIPT_DEBUG is not set and the file exclude a .min suffix, this function
* will automatically attempt to locate a minified version of that file.
*
* See: https://bbpress.trac.wordpress.org/ticket/3218
*
* @since 2.6.0
*
* @param string $file
*
* @return boolean
*/
function bbp_locate_enqueueable( $file = '' ) {
// Bail if no file to locate
if ( empty( $file ) ) {
return false;
}
// Add file to files array
$files = array( $file );
// Get the file variant (minified or not, but opposite of $file)
$file_is_min = ( false !== strpos( $file, '.min' ) );
$file_variant = ( false === $file_is_min )
? str_replace( array( '.css', '.js' ), array( '.min.css', '.min.js' ), $file )
: str_replace( '.min', '', $file );
// Are we debugging?
$script_debug = bbp_doing_script_debug();
// Debugging, so prefer unminified files
if ( true === $script_debug ) {
if ( true === $file_is_min ) {
array_unshift( $files, $file_variant );
} else {
array_push( $files, $file_variant );
}
// Not debugging, so prefer minified files
} elseif ( false === $script_debug ) {
if ( true === $file_is_min ) {
array_push( $files, $file_variant );
} else {
array_unshift( $files, $file_variant );
}
}
// Return first found file location in the stack
return bbp_locate_template( $files, false, false );
}
/**
* Convert an enqueueable file path to a URL
*
* @since 2.6.0
* @param string $file
*
* @return string
*/
function bbp_urlize_enqueueable( $file = '' ) {
// Get DIR and URL
$content_dir = constant( 'WP_CONTENT_DIR' );
$content_url = content_url();
// IIS (Windows) here
// Replace back slashes with forward slash
if ( false !== strpos( $file, '\\' ) ) {
$file = str_replace( '\\', '/', $file );
$content_dir = str_replace( '\\', '/', $content_dir );
}
// Return path to file relative to site URL
return str_replace( $content_dir, $content_url, $file );
}
/**
* Enqueue a script from the highest priority location in the template stack.
*
* Registers the style if file provided (does NOT overwrite) and enqueues.
*
* @since 2.5.0 bbPress (r5180)
*
* @param string $handle Name of the stylesheet.
* @param string|bool $file Relative path to stylesheet. Example: '/css/mystyle.css'.
* @param array $deps An array of registered style handles this stylesheet depends on. Default empty array.
* @param string|bool $ver String specifying the stylesheet version number, if it has one. This parameter is used
* to ensure that the correct version is sent to the client regardless of caching, and so
* should be included if a version number is available and makes sense for the stylesheet.
* @param string $media Optional. The media for which this stylesheet has been defined.
* Default 'all'. Accepts 'all', 'aural', 'braille', 'handheld', 'projection', 'print',
* 'screen', 'tty', or 'tv'.
*
* @return mixed The style filename if one is located. False if not.
*/
function bbp_enqueue_style( $handle = '', $file = '', $deps = array(), $ver = false, $media = 'all' ) {
// Attempt to locate an enqueueable
$located = bbp_locate_enqueueable( $file );
// Enqueue if located
if ( ! empty( $located ) ) {
// Make sure there is always a version
if ( empty( $ver ) ) {
$ver = bbp_get_asset_version();
}
// Make path to file relative to site URL
$located = bbp_urlize_enqueueable( $located );
// Register the style
wp_register_style( $handle, $located, $deps, $ver, $media );
// Enqueue the style
wp_enqueue_style( $handle );
}
return $located;
}
/**
* Enqueue a script from the highest priority location in the template stack.
*
* Registers the style if file provided (does NOT overwrite) and enqueues.
*
* @since 2.5.0 bbPress (r5180)
*
* @param string $handle Name of the script.
* @param string|bool $file Relative path to the script. Example: '/js/myscript.js'.
* @param array $deps An array of registered handles this script depends on. Default empty array.
* @param string|bool $ver Optional. String specifying the script version number, if it has one. This parameter
* is used to ensure that the correct version is sent to the client regardless of caching,
* and so should be included if a version number is available and makes sense for the script.
* @param bool $in_footer Optional. Whether to enqueue the script before </head> or before </body>.
* Default 'false'. Accepts 'false' or 'true'.
*
* @return mixed The script filename if one is located. False if not.
*/
function bbp_enqueue_script( $handle = '', $file = '', $deps = array(), $ver = false, $in_footer = false ) {
// Attempt to locate an enqueueable
$located = bbp_locate_enqueueable( $file );
// Enqueue if located
if ( ! empty( $located ) ) {
// Make sure there is always a version
if ( empty( $ver ) ) {
$ver = bbp_get_asset_version();
}
// Make path to file relative to site URL
$located = bbp_urlize_enqueueable( $located );
// Register the style
wp_register_script( $handle, $located, $deps, $ver, $in_footer );
// Enqueue the style
wp_enqueue_script( $handle );
}
return $located;
}
/**
* This is really cool. This function registers a new template stack location,
* using WordPress's built in filters API.
*
* This allows for templates to live in places beyond just the parent/child
* relationship, to allow for custom template locations. Used in conjunction
* with bbp_locate_template(), this allows for easy template overrides.
*
* @since 2.2.0 bbPress (r4323)
*
* @param string $location_callback Callback function that returns the
* @param int $priority
*/
function bbp_register_template_stack( $location_callback = '', $priority = 10 ) {
// Bail if no location, or function/method is not callable
if ( empty( $location_callback ) || ! is_callable( $location_callback ) ) {
return false;
}
// Add location callback to template stack
return add_filter( 'bbp_template_stack', $location_callback, (int) $priority );
}
/**
* Deregisters a previously registered template stack location.
*
* @since 2.3.0 bbPress (r4652)
*
* @param string $location_callback Callback function that returns the
* @param int $priority
* @return bool Whether stack was removed
*/
function bbp_deregister_template_stack( $location_callback = '', $priority = 10 ) {
// Bail if no location, or function/method is not callable
if ( empty( $location_callback ) || ! is_callable( $location_callback ) ) {
return false;
}
// Remove location callback to template stack
return remove_filter( 'bbp_template_stack', $location_callback, (int) $priority );
}
/**
* Call the functions added to the 'bbp_template_stack' filter hook, and return
* an array of the template locations.
*
* @since 2.2.0 bbPress (r4323)
* @since 2.6.0 bbPress (r5944) Added support for `WP_Hook`
*
* @global array $wp_filter Stores all of the filters
* @global array $merged_filters Merges the filter hooks using this function.
* @global array $wp_current_filter stores the list of current filters with the current one last
*
* @return array The filtered value after all hooked functions are applied to it.
*/
function bbp_get_template_stack() {
global $wp_filter, $merged_filters, $wp_current_filter;
// Setup some default variables
$tag = 'bbp_template_stack';
$args = $stack = array();
// Add 'bbp_template_stack' to the current filter array
$wp_current_filter[] = $tag;
// Bail if no stack setup
if ( empty( $wp_filter[ $tag ] ) ) {
return array();
}
// Check if WP_Hook class exists, see #WP17817
if ( class_exists( 'WP_Hook' ) ) {
$filter = $wp_filter[ $tag ]->callbacks;
} else {
$filter = &$wp_filter[ $tag ];
// Sort
if ( ! isset( $merged_filters[ $tag ] ) ) {
ksort( $filter );
$merged_filters[ $tag ] = true;
}
}
// Ensure we're always at the beginning of the filter array
reset( $filter );
// Loop through 'bbp_template_stack' filters, and call callback functions
do {
foreach ( (array) current( $filter ) as $the_ ) {
if ( ! is_null( $the_['function'] ) ) {
$args[1] = $stack;
$stack[] = call_user_func_array( $the_['function'], array_slice( $args, 1, (int) $the_['accepted_args'] ) );
}
}
} while ( next( $filter ) !== false );
// Remove 'bbp_template_stack' from the current filter array
array_pop( $wp_current_filter );
// Remove empties and duplicates
$stack = array_unique( array_filter( $stack ) );
// Filter & return
return (array) apply_filters( 'bbp_get_template_stack', $stack ) ;
}
/**
* Get a template part in an output buffer, and return it
*
* @since 2.4.0 bbPress (r5043)
*
* @param string $slug
* @param string $name
* @return string
*/
function bbp_buffer_template_part( $slug, $name = null, $echo = true ) {
ob_start();
bbp_get_template_part( $slug, $name );
// Get the output buffer contents
$output = ob_get_clean();
// Echo or return the output buffer contents
if ( true === $echo ) {
echo $output;
} else {
return $output;
}
}
/**
* Retrieve path to a template
*
* Used to quickly retrieve the path of a template without including the file
* extension. It will also check the parent theme and theme-compat theme with
* the use of {@link bbp_locate_template()}. Allows for more generic template
* locations without the use of the other get_*_template() functions.
*
* @since 2.1.0 bbPress (r3629)
*
* @param string $type Filename without extension.
* @param array $templates An optional list of template candidates
* @return string Full path to file.
*/
function bbp_get_query_template( $type, $templates = array() ) {
$type = preg_replace( '|[^a-z0-9-]+|', '', $type );
// Fallback template
if ( empty( $templates ) ) {
$templates = array( "{$type}.php" );
}
// Filter possible templates
$templates = apply_filters( "bbp_get_{$type}_template", $templates );
// Stash the possible templates for this query, for later use
bbp_set_theme_compat_templates( $templates );
// Try to locate a template in the stack
$template = bbp_locate_template( $templates );
// Stash the located template for this query, for later use
bbp_set_theme_compat_template( $template );
// Filter & return
return apply_filters( "bbp_{$type}_template", $template, $templates );
}
/**
* Get the possible subdirectories to check for templates in
*
* @since 2.1.0 bbPress (r3738)
*
* @param array $templates Templates we are looking for
* @return array Possible subdirectories to look in
*/
function bbp_get_template_locations( $templates = array() ) {
$locations = array(
'bbpress',
'forums',
''
);
// Filter & return
return apply_filters( 'bbp_get_template_locations', $locations, $templates );
}
/**
* Add template locations to template files being searched for
*
* @since 2.1.0 bbPress (r3738)
*
* @param array $stacks
* @return array()
*/
function bbp_add_template_stack_locations( $stacks = array() ) {
$retval = array();
// Get alternate locations
$locations = bbp_get_template_locations();
// Loop through locations and stacks and combine
foreach ( (array) $stacks as $stack ) {
foreach ( (array) $locations as $custom_location ) {
$retval[] = untrailingslashit( trailingslashit( $stack ) . $custom_location );
}
}
// Filter & return
return (array) apply_filters( 'bbp_add_template_stack_locations', array_unique( $retval ), $stacks );
}
/**
* Add checks for bbPress conditions to parse_query action
*
* If it's a user page, WP_Query::bbp_is_single_user is set to true.
*
* If it's a user edit page, WP_Query::bbp_is_single_user_edit is set to true
* and the the 'wp-admin/includes/user.php' file is included.
*
* In addition, on user/user edit pages, WP_Query::home is set to false & query
* vars 'bbp_user_id' with the displayed user id is added.
*
* In 2.6.0, the 'author_name' variable is no longer set when viewing a single
* user, because of is_author() weirdness. If this removal causes problems, it
* may come back in a future release.
*
* If it's a forum edit, WP_Query::bbp_is_forum_edit is set to true
* If it's a topic edit, WP_Query::bbp_is_topic_edit is set to true
* If it's a reply edit, WP_Query::bbp_is_reply_edit is set to true.
*
* If it's a view page, WP_Query::bbp_is_view is set to true
* If it's a search page, WP_Query::bbp_is_search is set to true
*
* @since 2.0.0 bbPress (r2688)
*
* @param WP_Query $posts_query
*/
function bbp_parse_query( $posts_query ) {
// Bail if $posts_query is not the main loop
if ( ! $posts_query->is_main_query() ) {
return;
}
// Bail if filters are suppressed on this query
if ( true === $posts_query->get( 'suppress_filters' ) ) {
return;
}
// Bail if in admin
if ( is_admin() ) {
return;
}
// Get query variables (default to null if not set)
$bbp_view = $posts_query->get( bbp_get_view_rewrite_id(), null );
$bbp_user = $posts_query->get( bbp_get_user_rewrite_id(), null );
$is_edit = $posts_query->get( bbp_get_edit_rewrite_id(), null );
$is_search = $posts_query->get( bbp_get_search_rewrite_id(), null );
// It is a user page - We'll also check if it is user edit
if ( ! is_null( $bbp_user ) ) {
/** Find User *********************************************************/
// Setup the default user variable
$the_user = false;
// If using pretty permalinks, always use slug
if ( get_option( 'permalink_structure' ) ) {
$the_user = get_user_by( 'slug', $bbp_user );
// If not using pretty permalinks, always use numeric ID
} elseif ( is_numeric( $bbp_user ) ) {
$the_user = get_user_by( 'id', $bbp_user );
}
// 404 and bail if user does not have a profile
if ( empty( $the_user->ID ) || ! bbp_user_has_profile( $the_user->ID ) ) {
$posts_query->bbp_is_404 = true;
return;
}
/** User Exists *******************************************************/
$is_favs = $posts_query->get( bbp_get_user_favorites_rewrite_id() );
$is_subs = $posts_query->get( bbp_get_user_subscriptions_rewrite_id() );
$is_topics = $posts_query->get( bbp_get_user_topics_rewrite_id() );
$is_replies = $posts_query->get( bbp_get_user_replies_rewrite_id() );
$is_engagements = $posts_query->get( bbp_get_user_engagements_rewrite_id() );
// View or edit?
if ( ! is_null( $is_edit ) ) {
// We are editing a profile
$posts_query->bbp_is_single_user_edit = true;
// Load the core WordPress contact methods
if ( ! function_exists( '_wp_get_user_contactmethods' ) ) {
require_once ABSPATH . 'wp-includes/registration.php';
}
// Load the edit_user functions
if ( ! function_exists( 'edit_user' ) ) {
require_once ABSPATH . 'wp-admin/includes/user.php';
}
// Load the grant/revoke super admin functions
if ( is_multisite() && ! function_exists( 'revoke_super_admin' ) ) {
require_once ABSPATH . 'wp-admin/includes/ms.php';
}
// Editing a user
$posts_query->bbp_is_edit = true;
// User favorites
} elseif ( ! empty( $is_favs ) ) {
$posts_query->bbp_is_single_user_favs = true;
// User subscriptions
} elseif ( ! empty( $is_subs ) ) {
$posts_query->bbp_is_single_user_subs = true;
// User topics
} elseif ( ! empty( $is_topics ) ) {
$posts_query->bbp_is_single_user_topics = true;
// User topics
} elseif ( ! empty( $is_replies ) ) {
$posts_query->bbp_is_single_user_replies = true;
// User engagements
} elseif ( ! empty( $is_engagements ) ) {
$posts_query->bbp_is_single_user_engagements = true;
// User profile
} else {
$posts_query->bbp_is_single_user_profile = true;
}
// Make sure 404 is not set
$posts_query->is_404 = false;
// Correct is_home variable
$posts_query->is_home = false;
// Looking at a single user
$posts_query->bbp_is_single_user = true;
// User found so don't 404 yet
$posts_query->bbp_is_404 = false;
// User is looking at their own profile
if ( bbp_get_current_user_id() === $the_user->ID ) {
$posts_query->bbp_is_single_user_home = true;
}
// Set bbp_user_id for future reference
$posts_query->set( 'bbp_user_id', $the_user->ID );
// Set the displayed user global to this user
bbpress()->displayed_user = $the_user;
// View Page
} elseif ( ! is_null( $bbp_view ) ) {
// Check if the view exists by checking if there are query args are set
$view_args = bbp_get_view_query_args( $bbp_view );
// Bail if view args are empty
if ( empty( $view_args ) ) {
$posts_query->bbp_is_404 = true;
return;
}
// Correct is_home variable
$posts_query->is_home = false;
// We are in a custom topic view
$posts_query->bbp_is_view = true;
// No 404 because views are all (currently) public
$posts_query->bbp_is_404 = false;
// Search Page
} elseif ( ! is_null( $is_search ) ) {
// Check if there are search query args set
$search_terms = bbp_get_search_terms();
if ( ! empty( $search_terms ) ) {
$posts_query->bbp_search_terms = $search_terms;
}
// Correct is_home variable
$posts_query->is_home = false;
// We are in a search query
$posts_query->bbp_is_search = true;
// No 404 because search is always public
$posts_query->bbp_is_404 = false;
// Forum/Topic/Reply Edit Page
} elseif ( ! is_null( $is_edit ) ) {
// Get the post type from the main query loop
$post_type = $posts_query->get( 'post_type' );
// Check which post_type we are editing, if any
if ( ! empty( $post_type ) ) {
switch ( $post_type ) {
// We are editing a forum
case bbp_get_forum_post_type() :
$posts_query->bbp_is_forum_edit = true;
$posts_query->bbp_is_edit = true;
$posts_query->bbp_is_404 = false;
break;
// We are editing a topic
case bbp_get_topic_post_type() :
$posts_query->bbp_is_topic_edit = true;
$posts_query->bbp_is_edit = true;
$posts_query->bbp_is_404 = false;
break;
// We are editing a reply
case bbp_get_reply_post_type() :
$posts_query->bbp_is_reply_edit = true;
$posts_query->bbp_is_edit = true;
$posts_query->bbp_is_404 = false;
break;
}
// We are editing a topic tag
} elseif ( bbp_is_topic_tag() ) {
$posts_query->bbp_is_topic_tag_edit = true;
$posts_query->bbp_is_edit = true;
$posts_query->bbp_is_404 = false;
}
// We save post revisions on our own
remove_action( 'pre_post_update', 'wp_save_post_revision' );
// Topic tag page
} elseif ( bbp_is_topic_tag() ) {
$posts_query->set( 'bbp_topic_tag', get_query_var( 'term' ) );
$posts_query->set( 'post_type', bbp_get_topic_post_type() );
$posts_query->set( 'posts_per_page', bbp_get_topics_per_page() );
// Do topics on forums root
} elseif ( is_post_type_archive( bbp_get_post_types( array( 'has_archive' => true ) ) ) && ( 'topics' === bbp_show_on_root() ) ) {
$posts_query->bbp_show_topics_on_root = true;
}
}

View File

@@ -0,0 +1,472 @@
<?php
/**
* bbPress Template Loader
*
* @package bbPress
* @subpackage TemplateLoader
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/**
* Possibly intercept the template being loaded
*
* Listens to the 'template_include' filter and waits for any bbPress specific
* template condition to be met. If one is met and the template file exists,
* it will be used; otherwise
*
* Note that the _edit() checks are ahead of their counterparts, to prevent them
* from being stomped on accident.
*
* @since 2.0.0 bbPress (r3032)
*
* @param string $template
*
* @return string The path to the template file that is being used
*/
function bbp_template_include_theme_supports( $template = '' ) {
// Editing a user
if ( bbp_is_single_user_edit() && ( $new_template = bbp_get_single_user_edit_template() ) ) :
// User favorites
elseif ( bbp_is_favorites() && ( $new_template = bbp_get_favorites_template() ) ) :
// User favorites
elseif ( bbp_is_subscriptions() && ( $new_template = bbp_get_subscriptions_template() ) ) :
// Viewing a user
elseif ( bbp_is_single_user() && ( $new_template = bbp_get_single_user_template() ) ) :
// Single View
elseif ( bbp_is_single_view() && ( $new_template = bbp_get_single_view_template() ) ) :
// Search
elseif ( bbp_is_search() && ( $new_template = bbp_get_search_template() ) ) :
// Forum edit
elseif ( bbp_is_forum_edit() && ( $new_template = bbp_get_forum_edit_template() ) ) :
// Single Forum
elseif ( bbp_is_single_forum() && ( $new_template = bbp_get_single_forum_template() ) ) :
// Forum Archive
elseif ( bbp_is_forum_archive() && ( $new_template = bbp_get_forum_archive_template() ) ) :
// Topic merge
elseif ( bbp_is_topic_merge() && ( $new_template = bbp_get_topic_merge_template() ) ) :
// Topic split
elseif ( bbp_is_topic_split() && ( $new_template = bbp_get_topic_split_template() ) ) :
// Topic edit
elseif ( bbp_is_topic_edit() && ( $new_template = bbp_get_topic_edit_template() ) ) :
// Single Topic
elseif ( bbp_is_single_topic() && ( $new_template = bbp_get_single_topic_template() ) ) :
// Topic Archive
elseif ( bbp_is_topic_archive() && ( $new_template = bbp_get_topic_archive_template() ) ) :
// Reply move
elseif ( bbp_is_reply_move() && ( $new_template = bbp_get_reply_move_template() ) ) :
// Editing a reply
elseif ( bbp_is_reply_edit() && ( $new_template = bbp_get_reply_edit_template() ) ) :
// Single Reply
elseif ( bbp_is_single_reply() && ( $new_template = bbp_get_single_reply_template() ) ) :
// Editing a topic tag
elseif ( bbp_is_topic_tag_edit() && ( $new_template = bbp_get_topic_tag_edit_template() ) ) :
// Viewing a topic tag
elseif ( bbp_is_topic_tag() && ( $new_template = bbp_get_topic_tag_template() ) ) :
endif;
// A bbPress template file was located, so override the WordPress template
// and use it to switch off theme compatibility.
if ( ! empty( $new_template ) ) {
$template = bbp_set_template_included( $new_template );
}
// Filter & return
return apply_filters( 'bbp_template_include_theme_supports', $template );
}
/**
* Set the included template
*
* @since 2.4.0 bbPress (r4975)
*
* @param mixed $template Default false
* @return mixed False if empty. Template name if template included
*/
function bbp_set_template_included( $template = false ) {
bbpress()->theme_compat->bbpress_template = $template;
return bbpress()->theme_compat->bbpress_template;
}
/**
* Is a bbPress template being included?
*
* @since 2.4.0 bbPress (r4975)
*
* @return bool True if yes, false if no
*/
function bbp_is_template_included() {
return ! empty( bbpress()->theme_compat->bbpress_template );
}
/** Custom Functions **********************************************************/
/**
* Attempt to load a custom bbPress functions file, similar to each themes
* functions.php file.
*
* @since 2.1.0 bbPress (r3732)
*
* @global string $pagenow
*/
function bbp_load_theme_functions() {
global $pagenow;
// If bbPress is being deactivated, do not load any more files
if ( bbp_is_deactivation() ) {
return;
}
if ( ! defined( 'WP_INSTALLING' ) || ( ! empty( $pagenow ) && ( 'wp-activate.php' !== $pagenow ) ) ) {
bbp_locate_template( 'bbpress-functions.php', true );
}
}
/** Individual Templates ******************************************************/
/**
* Get the user profile template
*
* @since 2.0.0 bbPress (r3311)
*
* @return string Path to template file
*/
function bbp_get_single_user_template() {
$nicename = bbp_get_displayed_user_field( 'user_nicename' );
$user_id = bbp_get_displayed_user_id();
$templates = array(
'single-user-' . $nicename . '.php', // Single User nicename
'single-user-' . $user_id . '.php', // Single User ID
'single-user.php', // Single User
'user.php', // User
);
return bbp_get_query_template( 'profile', $templates );
}
/**
* Get the user profile edit template
*
* @since 2.0.0 bbPress (r3311)
*
* @return string Path to template file
*/
function bbp_get_single_user_edit_template() {
$nicename = bbp_get_displayed_user_field( 'user_nicename' );
$user_id = bbp_get_displayed_user_id();
$templates = array(
'single-user-edit-' . $nicename . '.php', // Single User Edit nicename
'single-user-edit-' . $user_id . '.php', // Single User Edit ID
'single-user-edit.php', // Single User Edit
'user-edit.php', // User Edit
'user.php', // User
);
return bbp_get_query_template( 'profile_edit', $templates );
}
/**
* Get the user favorites template
*
* @since 2.2.0 bbPress (r4225)
*
* @return string Path to template file
*/
function bbp_get_favorites_template() {
$nicename = bbp_get_displayed_user_field( 'user_nicename' );
$user_id = bbp_get_displayed_user_id();
$templates = array(
'single-user-favorites-' . $nicename . '.php', // Single User Favs nicename
'single-user-favorites-' . $user_id . '.php', // Single User Favs ID
'favorites-' . $nicename . '.php', // Favorites nicename
'favorites-' . $user_id . '.php', // Favorites ID
'favorites.php', // Favorites
'user.php', // User
);
return bbp_get_query_template( 'favorites', $templates );
}
/**
* Get the user subscriptions template
*
* @since 2.2.0 bbPress (r4225)
*
* @return string Path to template file
*/
function bbp_get_subscriptions_template() {
$nicename = bbp_get_displayed_user_field( 'user_nicename' );
$user_id = bbp_get_displayed_user_id();
$templates = array(
'single-user-subscriptions-' . $nicename . '.php', // Single User Subs nicename
'single-user-subscriptions-' . $user_id . '.php', // Single User Subs ID
'subscriptions-' . $nicename . '.php', // Subscriptions nicename
'subscriptions-' . $user_id . '.php', // Subscriptions ID
'subscriptions.php', // Subscriptions
'user.php', // User
);
return bbp_get_query_template( 'subscriptions', $templates );
}
/**
* Get the view template
*
* @since 2.0.0 bbPress (r3311)
*
* @return string Path to template file
*/
function bbp_get_single_view_template() {
$view_id = bbp_get_view_id();
$templates = array(
'single-view-' . $view_id . '.php', // Single View ID
'view-' . $view_id . '.php', // View ID
'single-view.php', // Single View
'view.php', // View
);
return bbp_get_query_template( 'single_view', $templates );
}
/**
* Get the search template
*
* @since 2.3.0 bbPress (r4579)
*
* @return string Path to template file
*/
function bbp_get_search_template() {
$templates = array(
'page-forum-search.php', // Single Search
'forum-search.php', // Search
);
return bbp_get_query_template( 'single_search', $templates );
}
/**
* Get the single forum template
*
* @since 2.1.0 bbPress (r3922)
*
* @return string Path to template file
*/
function bbp_get_single_forum_template() {
$templates = array(
'single-' . bbp_get_forum_post_type() . '.php' // Single Forum
);
return bbp_get_query_template( 'single_forum', $templates );
}
/**
* Get the forum archive template
*
* @since 2.1.0 bbPress (r3922)
*
* @return string Path to template file
*/
function bbp_get_forum_archive_template() {
$templates = array(
'archive-' . bbp_get_forum_post_type() . '.php' // Forum Archive
);
return bbp_get_query_template( 'forum_archive', $templates );
}
/**
* Get the forum edit template
*
* @since 2.1.0 bbPress (r3566)
*
* @return string Path to template file
*/
function bbp_get_forum_edit_template() {
$templates = array(
'single-' . bbp_get_forum_post_type() . '-edit.php' // Single Forum Edit
);
return bbp_get_query_template( 'forum_edit', $templates );
}
/**
* Get the single topic template
*
* @since 2.1.0 bbPress (r3922)
*
* @return string Path to template file
*/
function bbp_get_single_topic_template() {
$templates = array(
'single-' . bbp_get_topic_post_type() . '.php'
);
return bbp_get_query_template( 'single_topic', $templates );
}
/**
* Get the topic archive template
*
* @since 2.1.0 bbPress (r3922)
*
* @return string Path to template file
*/
function bbp_get_topic_archive_template() {
$templates = array(
'archive-' . bbp_get_topic_post_type() . '.php' // Topic Archive
);
return bbp_get_query_template( 'topic_archive', $templates );
}
/**
* Get the topic edit template
*
* @since 2.0.0 bbPress (r3311)
*
* @return string Path to template file
*/
function bbp_get_topic_edit_template() {
$templates = array(
'single-' . bbp_get_topic_post_type() . '-edit.php' // Single Topic Edit
);
return bbp_get_query_template( 'topic_edit', $templates );
}
/**
* Get the topic split template
*
* @since 2.0.0 bbPress (r3311)
*
* @return string Path to template file
*/
function bbp_get_topic_split_template() {
$templates = array(
'single-' . bbp_get_topic_post_type() . '-split.php', // Topic Split
);
return bbp_get_query_template( 'topic_split', $templates );
}
/**
* Get the topic merge template
*
* @since 2.0.0 bbPress (r3311)
*
* @return string Path to template file
*/
function bbp_get_topic_merge_template() {
$templates = array(
'single-' . bbp_get_topic_post_type() . '-merge.php', // Topic Merge
);
return bbp_get_query_template( 'topic_merge', $templates );
}
/**
* Get the single reply template
*
* @since 2.1.0 bbPress (r3922)
*
* @return string Path to template file
*/
function bbp_get_single_reply_template() {
$templates = array(
'single-' . bbp_get_reply_post_type() . '.php'
);
return bbp_get_query_template( 'single_reply', $templates );
}
/**
* Get the reply edit template
*
* @since 2.0.0 bbPress (r3311)
*
* @return string Path to template file
*/
function bbp_get_reply_edit_template() {
$templates = array(
'single-' . bbp_get_reply_post_type() . '-edit.php' // Single Reply Edit
);
return bbp_get_query_template( 'reply_edit', $templates );
}
/**
* Get the reply move template
*
* @since 2.3.0 bbPress (r4521)
*
* @return string Path to template file
*/
function bbp_get_reply_move_template() {
$templates = array(
'single-' . bbp_get_reply_post_type() . '-move.php', // Reply move
);
return bbp_get_query_template( 'reply_move', $templates );
}
/**
* Get the topic template
*
* @since 2.0.0 bbPress (r3311)
*
* @return string Path to template file
*/
function bbp_get_topic_tag_template() {
$tt_slug = bbp_get_topic_tag_slug();
$tt_id = bbp_get_topic_tag_tax_id();
$templates = array(
'taxonomy-' . $tt_slug . '.php', // Single Topic Tag slug
'taxonomy-' . $tt_id . '.php', // Single Topic Tag ID
);
return bbp_get_query_template( 'topic_tag', $templates );
}
/**
* Get the topic edit template
*
* @since 2.0.0 bbPress (r3311)
*
* @return string Path to template file
*/
function bbp_get_topic_tag_edit_template() {
$tt_slug = bbp_get_topic_tag_slug();
$tt_id = bbp_get_topic_tag_tax_id();
$templates = array(
'taxonomy-' . $tt_slug . '-edit.php', // Single Topic Tag Edit slug
'taxonomy-' . $tt_id . '-edit.php' // Single Topic Tag Edit ID
);
return bbp_get_query_template( 'topic_tag_edit', $templates );
}
/**
* Get the templates to use as the endpoint for bbPress template parts
*
* @since 2.0.0 bbPress (r3311)
* @since 2.6.0 bbPress (r5950) Added `singular.php` to template stack
*
* @return string Path to template file
*/
function bbp_get_theme_compat_templates() {
$templates = array(
'plugin-bbpress.php',
'bbpress.php',
'forums.php',
'forum.php',
'generic.php',
'page.php',
'single.php',
'singular.php',
'index.php'
);
return bbp_get_query_template( 'bbpress', $templates );
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,631 @@
<?php
/**
* bbPress Updater
*
* @package bbPress
* @subpackage Core
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/**
* If there is no raw DB version, this is the first installation
*
* @since 2.1.0 bbPress (r3764)
*
* @return bool True if update, False if not
*/
function bbp_is_install() {
return ! bbp_get_db_version_raw();
}
/**
* Compare the bbPress version to the DB version to determine if updating
*
* @since 2.0.0 bbPress (r3421)
*
* @return bool True if update, False if not
*/
function bbp_is_update() {
$raw = (int) bbp_get_db_version_raw();
$cur = (int) bbp_get_db_version();
$retval = (bool) ( $raw < $cur );
return $retval;
}
/**
* Determine if bbPress is being activated
*
* Note that this function currently is not used in bbPress core and is here
* for third party plugins to use to check for bbPress activation.
*
* @since 2.0.0 bbPress (r3421)
*
* @return bool True if activating bbPress, false if not
*/
function bbp_is_activation( $basename = '' ) {
global $pagenow;
$bbp = bbpress();
$action = false;
// Bail if not in admin/plugins
if ( ! ( is_admin() && ( 'plugins.php' === $pagenow ) ) ) {
return false;
}
if ( ! empty( $_REQUEST['action'] ) && ( '-1' !== $_REQUEST['action'] ) ) {
$action = $_REQUEST['action'];
} elseif ( ! empty( $_REQUEST['action2'] ) && ( '-1' !== $_REQUEST['action2'] ) ) {
$action = $_REQUEST['action2'];
}
// Bail if not activating
if ( empty( $action ) || ! in_array( $action, array( 'activate', 'activate-selected', true ) ) ) {
return false;
}
// The plugin(s) being activated
if ( $action === 'activate' ) {
$plugins = isset( $_GET['plugin'] ) ? array( $_GET['plugin'] ) : array();
} else {
$plugins = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
}
// Set basename if empty
if ( empty( $basename ) && ! empty( $bbp->basename ) ) {
$basename = $bbp->basename;
}
// Bail if no basename
if ( empty( $basename ) ) {
return false;
}
// Is bbPress being activated?
return in_array( $basename, $plugins, true );
}
/**
* Determine if bbPress is being deactivated
*
* @since 2.0.0 bbPress (r3421)
*
* @return bool True if deactivating bbPress, false if not
*/
function bbp_is_deactivation( $basename = '' ) {
global $pagenow;
$bbp = bbpress();
$action = false;
// Bail if not in admin/plugins
if ( ! ( is_admin() && ( 'plugins.php' === $pagenow ) ) ) {
return false;
}
if ( ! empty( $_REQUEST['action'] ) && ( '-1' !== $_REQUEST['action'] ) ) {
$action = $_REQUEST['action'];
} elseif ( ! empty( $_REQUEST['action2'] ) && ( '-1' !== $_REQUEST['action2'] ) ) {
$action = $_REQUEST['action2'];
}
// Bail if not deactivating
if ( empty( $action ) || ! in_array( $action, array( 'deactivate', 'deactivate-selected' ), true ) ) {
return false;
}
// The plugin(s) being deactivated
if ( $action === 'deactivate' ) {
$plugins = isset( $_GET['plugin'] ) ? array( $_GET['plugin'] ) : array();
} else {
$plugins = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
}
// Set basename if empty
if ( empty( $basename ) && ! empty( $bbp->basename ) ) {
$basename = $bbp->basename;
}
// Bail if no basename
if ( empty( $basename ) ) {
return false;
}
// Is bbPress being deactivated?
return in_array( $basename, $plugins, true );
}
/**
* Update the DB to the latest version
*
* @since 2.0.0 bbPress (r3421)
*/
function bbp_version_bump() {
update_option( '_bbp_db_version', bbp_get_db_version() );
}
/**
* Setup the bbPress updater
*
* @since 2.0.0 bbPress (r3419)
*/
function bbp_setup_updater() {
// Bail if no update needed
if ( ! bbp_is_update() ) {
return;
}
// Call the automated updater
bbp_version_updater();
}
/**
* Runs when a new site is created in a multisite network, and bbPress is active
* on that site (hooked to `bbp_new_site`)
*
* @since 2.6.0 bbPress (r6779)
*/
function bbp_setup_new_site( $site_id = 0 ) {
// Look for initial content
$created = is_multisite()
? get_blog_option( $site_id, '_bbp_flag_initial_content', false )
: get_option( '_bbp_flag_initial_content', false );
// Maybe create the initial content
if ( ! empty( $created ) ) {
bbp_create_initial_content();
// Flag initial content as created
is_multisite()
? update_blog_option( $site_id, '_bbp_flag_initial_content', true )
: update_option( '_bbp_flag_initial_content', true );
}
}
/**
* Create a default forum, topic, and reply
*
* @since 2.1.0 bbPress (r3767)
*
* @param array $args Array of arguments to override default values
*/
function bbp_create_initial_content( $args = array() ) {
// Cannot use bbp_get_current_user_id() during activation process
$user_id = get_current_user_id();
// Parse arguments against default values
$r = bbp_parse_args( $args, array(
'forum_author' => $user_id,
'forum_parent' => 0,
'forum_status' => 'publish',
'forum_title' => esc_html__( 'General', 'bbpress' ),
'forum_content' => esc_html__( 'General Discussion', 'bbpress' ),
'topic_author' => $user_id,
'topic_title' => esc_html__( 'Hello World!', 'bbpress' ),
'topic_content' => esc_html__( 'This is the very first topic in these forums.', 'bbpress' ),
'reply_author' => $user_id,
'reply_content' => esc_html__( 'And this is the very first reply.', 'bbpress' ),
), 'create_initial_content' );
// Use the same time for each post
$current_time = time();
$forum_time = date( 'Y-m-d H:i:s', $current_time - 60 * 60 * 80 );
$topic_time = date( 'Y-m-d H:i:s', $current_time - 60 * 60 * 60 );
$reply_time = date( 'Y-m-d H:i:s', $current_time - 60 * 60 * 40 );
// Create the initial forum
$forum_id = bbp_insert_forum( array(
'post_author' => $r['forum_author'],
'post_parent' => $r['forum_parent'],
'post_status' => $r['forum_status'],
'post_title' => $r['forum_title'],
'post_content' => $r['forum_content'],
'post_date' => $forum_time
) );
// Create the initial topic
$topic_id = bbp_insert_topic(
array(
'post_author' => $r['topic_author'],
'post_parent' => $forum_id,
'post_title' => $r['topic_title'],
'post_content' => $r['topic_content'],
'post_date' => $topic_time,
),
array(
'forum_id' => $forum_id
)
);
// Create the initial reply
$reply_id = bbp_insert_reply(
array(
'post_author' => $r['reply_author'],
'post_parent' => $topic_id,
'post_content' => $r['reply_content'],
'post_date' => $reply_time
),
array(
'forum_id' => $forum_id,
'topic_id' => $topic_id
)
);
return array(
'forum_id' => $forum_id,
'topic_id' => $topic_id,
'reply_id' => $reply_id
);
}
/**
* The version updater looks at what the current database version is, and
* runs whatever other code is needed.
*
* This is most-often used when the data schema changes, but should also be used
* to correct issues with bbPress meta-data silently on software update.
*
* @since 2.2.0 bbPress (r4104)
*/
function bbp_version_updater() {
// Get the raw database version
$raw_db_version = (int) bbp_get_db_version_raw();
// Only run updater if previous installation exists
if ( ! empty( $raw_db_version ) ) {
/** 2.0 Branch ********************************************************/
// 2.0, 2.0.1, 2.0.2, 2.0.3
if ( $raw_db_version < 200 ) {
// No changes
}
/** 2.1 Branch ********************************************************/
// 2.1, 2.1.1
if ( $raw_db_version < 211 ) {
/**
* Repair private and hidden forum data
*
* @link https://bbpress.trac.wordpress.org/ticket/1891
*/
bbp_admin_repair_forum_visibility();
}
/** 2.2 Branch ********************************************************/
// 2.2.x
if ( $raw_db_version < 220 ) {
// Remove any old bbPress roles
bbp_remove_roles();
// Remove capabilities
bbp_remove_caps();
}
/** 2.3 Branch ********************************************************/
// 2.3.x
if ( $raw_db_version < 230 ) {
// No changes
}
/** 2.4 Branch ********************************************************/
// 2.4.x
if ( $raw_db_version < 240 ) {
// No changes
}
/** 2.5 Branch ********************************************************/
// 2.5.x
if ( $raw_db_version < 250 ) {
// No changes
}
/** 2.6 Branch ********************************************************/
// Smaller installs run the upgrades directly
if ( ! bbp_is_large_install() ) {
/**
* Upgrade user favorites and subscriptions
*/
if ( $raw_db_version < 261 ) {
bbp_admin_upgrade_user_favorites();
bbp_admin_upgrade_user_topic_subscriptions();
bbp_admin_upgrade_user_forum_subscriptions();
}
/**
* Upgrade user engagements
*/
if ( $raw_db_version < 262 ) {
bbp_admin_upgrade_user_engagements();
}
/**
* Repair forum hidden reply count
*/
if ( $raw_db_version < 263 ) {
bbp_admin_repair_forum_hidden_reply_count();
}
// Large installs require manual intervention
} else {
/**
* Upgrade user favorites and subscriptions
*/
if ( $raw_db_version < 261 ) {
bbp_add_pending_upgrade( 'bbp-user-favorites-move' );
bbp_add_pending_upgrade( 'bbp-user-topic-subscriptions-move' );
bbp_add_pending_upgrade( 'bbp-user-forum-subscriptions-move' );
// Set strategy to pre-2.6 on large network
update_option( '_bbp_engagements_strategy', 'user' );
}
/**
* Upgrade user engagements
*/
if ( $raw_db_version < 262 ) {
bbp_add_pending_upgrade( 'bbp-user-topic-engagements-move' );
// Set strategy to pre-2.6 on large network
update_option( '_bbp_engagements_strategy', 'user' );
}
/**
* Upgrade user engagements
*/
if ( $raw_db_version < 263 ) {
bbp_add_pending_upgrade( 'bbp-forum-hidden-replies' );
}
}
}
/** All done! *************************************************************/
// Bump the version
bbp_version_bump();
// Delete rewrite rules to force a flush
bbp_delete_rewrite_rules();
}
/**
* Redirect user to the "What's New" page on activation
*
* @since 2.2.0 bbPress (r4389)
*
* @internal Used internally to redirect bbPress to the about page on activation
*
* @return If network admin or bulk activation
*/
function bbp_add_activation_redirect() {
// Bail if activating from network, or bulk
if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
return;
}
// Add the redirect trigger
update_user_option( get_current_user_id(), '_bbp_activation_redirect', true );
}
/**
* Redirect user to "What's New" page on activation
*
* @since 2.2.0 bbPress (r4389)
*
* @internal Used internally to redirect bbPress to the about page on activation
*
* @return If no transient, or in network admin, or is bulk activation
*/
function bbp_do_activation_redirect() {
// Bail if no redirect trigger
if ( ! get_user_option( '_bbp_activation_redirect' ) ) {
return;
}
// Delete the redirect trigger
delete_user_option( get_current_user_id(), '_bbp_activation_redirect' );
// Bail if activating from network, or bulk
if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
return;
}
// Bail if the current user cannot see the about page
if ( ! current_user_can( 'bbp_about_page' ) ) {
return;
}
// Redirect to bbPress about page
bbp_redirect( add_query_arg( array( 'page' => 'bbp-about' ), admin_url( 'index.php' ) ) );
}
/**
* Hooked to the 'bbp_activate' action, this helper function automatically makes
* the current user a Key Master in the forums if they just activated bbPress,
* regardless of the bbp_allow_global_access() setting.
*
* @since 2.4.0 bbPress (r4910)
*
* @internal Used to internally make the current user a keymaster on activation
*
* @return If user can't activate plugins or is already a keymaster
*/
function bbp_make_current_user_keymaster() {
// Catch all, to prevent premature user initialization
if ( ! did_action( 'set_current_user' ) ) {
return;
}
// Bail if not logged in or already a member of this site
if ( ! is_user_logged_in() ) {
return;
}
// Bail if the current user can't activate plugins since previous pageload
if ( ! current_user_can( 'activate_plugins' ) ) {
return;
}
// Cannot use bbp_get_current_user_id() during activation process
$user_id = get_current_user_id();
// Get the current blog ID, to know if they should be promoted here
$blog_id = get_current_blog_id();
// Bail if user is not actually a member of this site
if ( ! is_user_member_of_blog( $user_id, $blog_id ) ) {
return;
}
// Bail if the current user already has a forum role to prevent
// unexpected role and capability escalation.
if ( bbp_get_user_role( $user_id ) ) {
return;
}
// Make the current user a keymaster
bbp_set_user_role( $user_id, bbp_get_keymaster_role() );
// Reload the current user so caps apply immediately
wp_get_current_user();
}
/** Pending Upgrades **********************************************************/
/**
* Return the number of pending upgrades
*
* @since 2.6.0 bbPress (r6895)
*
* @param string $type Type of pending upgrades (upgrade|repair|empty)
*
* @return int
*/
function bbp_get_pending_upgrade_count( $type = '' ) {
return count( (array) bbp_get_pending_upgrades( $type ) );
}
/**
* Return an array of pending upgrades
*
* @since 2.6.0 bbPress (r6895)
*
* @param string $type Type of pending upgrades (upgrade|repair|empty)
*
* @return array
*/
function bbp_get_pending_upgrades( $type = '' ) {
// Get the pending upgrades
$retval = (array) get_option( '_bbp_db_pending_upgrades', array() );
// Looking for a specific type?
if ( ! empty( $type ) ) {
$tools = bbp_get_admin_repair_tools( $type );
$plucked = array_keys( wp_list_pluck( $tools, 'type' ) );
$retval = array_intersect( $retval, $plucked );
}
return (array) $retval;
}
/**
* Add an upgrade ID to pending upgrades array
*
* @since 2.6.0 bbPress (r6895)
*
* @param string $upgrade_id
*/
function bbp_add_pending_upgrade( $upgrade_id = '' ) {
// Get the pending upgrades option
$pending = bbp_get_pending_upgrades();
// Maybe add upgrade ID to end of pending array
if ( false === array_search( $upgrade_id, $pending, true ) ) {
array_push( $pending, $upgrade_id );
}
// Update and return
return update_option( '_bbp_db_pending_upgrades', $pending );
}
/**
* Add an upgrade ID to pending upgrades array
*
* @since 2.6.0 bbPress (r6895)
*
* @param string $upgrade_id
*/
function bbp_remove_pending_upgrade( $upgrade_id = '' ) {
// Get the pending upgrades option
$pending = bbp_get_pending_upgrades();
// Look for this upgrade ID
$index = array_search( $upgrade_id, $pending, true );
// Maybe remove upgrade ID from pending array
if ( false !== $index ) {
unset( $pending[ $index ] );
}
// Update and return
return update_option( '_bbp_db_pending_upgrades', $pending );
}
/**
* Delete all pending upgrades
*
* @since 2.6.0 bbPress (r6895)
*/
function bbp_clear_pending_upgrades() {
return delete_option( '_bbp_db_pending_upgrades' );
}
/**
* Maybe append an upgrade count to a string
*
* @since 2.6.0 bbPress (r6896)
*
* @param string $string Text to append count to
* @param string $type Type of pending upgrades (upgrade|repair|empty)
*
* @return string
*/
function bbp_maybe_append_pending_upgrade_count( $string = '', $type = '' ) {
// Look for an upgrade count
$count = bbp_get_pending_upgrade_count( $type );
// Append the count to the string
if ( ! empty( $count ) ) {
$suffix = ' <span class="awaiting-mod count-' . absint( $count ) . '"><span class="pending-count">' . bbp_number_format( $count ) . '</span></span>';
$string = "{$string}{$suffix}";
}
// Return the string, maybe with a count
return $string;
}