first commit
This commit is contained in:
1271
wp-content/plugins/bbpress/includes/extend/akismet.php
Normal file
1271
wp-content/plugins/bbpress/includes/extend/akismet.php
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,619 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* bbPress BuddyPress Activity Class
|
||||
*
|
||||
* @package bbPress
|
||||
* @subpackage BuddyPress
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
if ( ! class_exists( 'BBP_BuddyPress_Activity' ) ) :
|
||||
/**
|
||||
* Loads BuddyPress Activity extension
|
||||
*
|
||||
* @since 2.0.0 bbPress (r3395)
|
||||
*
|
||||
* @package bbPress
|
||||
* @subpackage BuddyPress
|
||||
*/
|
||||
class BBP_BuddyPress_Activity {
|
||||
|
||||
/** Variables *************************************************************/
|
||||
|
||||
/**
|
||||
* The name of the BuddyPress component, used in activity streams
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $component = '';
|
||||
|
||||
/**
|
||||
* Forum Create Activity Action
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $forum_create = '';
|
||||
|
||||
/**
|
||||
* Topic Create Activity Action
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $topic_create = '';
|
||||
|
||||
/**
|
||||
* Topic Close Activity Action
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $topic_close = '';
|
||||
|
||||
/**
|
||||
* Topic Edit Activity Action
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $topic_edit = '';
|
||||
|
||||
/**
|
||||
* Topic Open Activity Action
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $topic_open = '';
|
||||
|
||||
/**
|
||||
* Reply Create Activity Action
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $reply_create = '';
|
||||
|
||||
/**
|
||||
* Reply Edit Activity Action
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $reply_edit = '';
|
||||
|
||||
/** Setup Methods *********************************************************/
|
||||
|
||||
/**
|
||||
* The bbPress BuddyPress Activity loader
|
||||
*
|
||||
* @since 2.0.0 bbPress (r3395)
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->setup_globals();
|
||||
$this->setup_actions();
|
||||
$this->setup_filters();
|
||||
$this->fully_loaded();
|
||||
}
|
||||
|
||||
/**
|
||||
* Extension variables
|
||||
*
|
||||
* @since 2.0.0 bbPress (r3395)
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
private function setup_globals() {
|
||||
|
||||
// The name of the BuddyPress component, used in activity streams
|
||||
$this->component = 'bbpress';
|
||||
|
||||
// Forums
|
||||
$this->forum_create = 'bbp_forum_create';
|
||||
|
||||
// Topics
|
||||
$this->topic_create = 'bbp_topic_create';
|
||||
$this->topic_edit = 'bbp_topic_edit';
|
||||
$this->topic_close = 'bbp_topic_close';
|
||||
$this->topic_open = 'bbp_topic_open';
|
||||
|
||||
// Replies
|
||||
$this->reply_create = 'bbp_reply_create';
|
||||
$this->reply_edit = 'bbp_reply_edit';
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup the actions
|
||||
*
|
||||
* @since 2.0.0 bbPress (r3395)
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
private function setup_actions() {
|
||||
|
||||
// Register the activity stream actions
|
||||
add_action( 'bp_register_activity_actions', array( $this, 'register_activity_actions' ) );
|
||||
|
||||
// Hook into topic and reply creation
|
||||
add_action( 'bbp_new_topic', array( $this, 'topic_create' ), 10, 4 );
|
||||
add_action( 'bbp_new_reply', array( $this, 'reply_create' ), 10, 5 );
|
||||
|
||||
// Hook into topic and reply status changes
|
||||
add_action( 'edit_post', array( $this, 'topic_update' ), 10, 2 );
|
||||
add_action( 'edit_post', array( $this, 'reply_update' ), 10, 2 );
|
||||
|
||||
// Hook into topic and reply deletion
|
||||
add_action( 'bbp_delete_topic', array( $this, 'topic_delete' ), 10, 1 );
|
||||
add_action( 'bbp_delete_reply', array( $this, 'reply_delete' ), 10, 1 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup the filters
|
||||
*
|
||||
* @since 2.0.0 bbPress (r3395)
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
private function setup_filters() {
|
||||
|
||||
// Obey BuddyPress commenting rules
|
||||
add_filter( 'bp_activity_can_comment', array( $this, 'activity_can_comment' ) );
|
||||
|
||||
// Link directly to the topic or reply
|
||||
add_filter( 'bp_activity_get_permalink', array( $this, 'activity_get_permalink' ), 10, 2 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow the variables, actions, and filters to be modified by third party
|
||||
* plugins and themes.
|
||||
*
|
||||
* @since 2.1.0 bbPress (r3902)
|
||||
*/
|
||||
private function fully_loaded() {
|
||||
do_action_ref_array( 'bbp_buddypress_activity_loaded', array( $this ) );
|
||||
}
|
||||
|
||||
/** Methods ***************************************************************/
|
||||
|
||||
/**
|
||||
* Register our activity actions with BuddyPress
|
||||
*
|
||||
* @since 2.0.0 bbPress (r3395)
|
||||
*/
|
||||
public function register_activity_actions() {
|
||||
|
||||
// Sitewide topic
|
||||
bp_activity_set_action(
|
||||
$this->component,
|
||||
$this->topic_create,
|
||||
esc_html__( 'New forum topic', 'bbpress' ),
|
||||
'bbp_format_activity_action_new_topic',
|
||||
esc_html__( 'Topics', 'bbpress' ),
|
||||
array( 'activity', 'member', 'member_groups', 'group' )
|
||||
);
|
||||
|
||||
// Sitewide reply
|
||||
bp_activity_set_action(
|
||||
$this->component,
|
||||
$this->reply_create,
|
||||
esc_html__( 'New forum reply', 'bbpress' ),
|
||||
'bbp_format_activity_action_new_reply',
|
||||
esc_html__( 'Replies', 'bbpress' ),
|
||||
array( 'activity', 'member', 'member_groups', 'group' )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper for recoding bbPress actions to the BuddyPress activity stream
|
||||
*
|
||||
* @since 2.0.0 bbPress (r3395)
|
||||
*
|
||||
* @param array $args Array of arguments for bp_activity_add()
|
||||
*
|
||||
* @return int Activity ID if successful, false if not
|
||||
*/
|
||||
private function record_activity( $args = array() ) {
|
||||
|
||||
// Default activity args
|
||||
$activity = bbp_parse_args( $args, array(
|
||||
'id' => null,
|
||||
'user_id' => bbp_get_current_user_id(),
|
||||
'type' => '',
|
||||
'action' => '',
|
||||
'item_id' => '',
|
||||
'secondary_item_id' => '',
|
||||
'content' => '',
|
||||
'primary_link' => '',
|
||||
'component' => $this->component,
|
||||
'recorded_time' => bp_core_current_time(),
|
||||
'hide_sitewide' => false
|
||||
), 'record_activity' );
|
||||
|
||||
// Add the activity
|
||||
return bp_activity_add( $activity );
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper for deleting bbPress actions from BuddyPress activity stream
|
||||
*
|
||||
* @since 2.0.0 bbPress (r3395)
|
||||
*
|
||||
* @param array $args Array of arguments for bp_activity_add()
|
||||
*
|
||||
* @return int Activity ID if successful, false if not
|
||||
*/
|
||||
public function delete_activity( $args = array() ) {
|
||||
|
||||
// Default activity args
|
||||
$activity = bbp_parse_args( $args, array(
|
||||
'item_id' => false,
|
||||
'component' => $this->component,
|
||||
'type' => false,
|
||||
'user_id' => false,
|
||||
'secondary_item_id' => false
|
||||
), 'delete_activity' );
|
||||
|
||||
// Delete the activity
|
||||
bp_activity_delete_by_item_id( $activity );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for an existing activity stream entry for a given post_id
|
||||
*
|
||||
* @param int $post_id ID of the topic or reply
|
||||
* @return int if an activity id is verified, false if not
|
||||
*/
|
||||
private static function get_activity_id( $post_id = 0 ) {
|
||||
|
||||
// Try to get the activity ID of the post
|
||||
$activity_id = (int) get_post_meta( $post_id, '_bbp_activity_id', true );
|
||||
|
||||
// Bail if no activity ID is in post meta
|
||||
if ( empty( $activity_id ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Get the activity stream item, bail if it doesn't exist
|
||||
$existing = new BP_Activity_Activity( $activity_id );
|
||||
if ( empty( $existing->component ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Return the activity ID since we've verified the connection
|
||||
return $activity_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Maybe disable activity stream comments on select actions
|
||||
*
|
||||
* @since 2.0.0 bbPress (r3399)
|
||||
*
|
||||
* @global BP_Activity_Template $activities_template
|
||||
* @param boolean $can_comment
|
||||
* @return boolean
|
||||
*/
|
||||
public function activity_can_comment( $can_comment = true ) {
|
||||
global $activities_template;
|
||||
|
||||
// Already forced off, so comply
|
||||
if ( false === $can_comment ) {
|
||||
return $can_comment;
|
||||
}
|
||||
|
||||
// Check if blog & forum activity stream commenting is off
|
||||
if ( ! empty( $activities_template->disable_blogforum_replies ) ) {
|
||||
|
||||
// Get the current action name
|
||||
$action_name = bp_get_activity_action_name();
|
||||
|
||||
// Setup the array of possibly disabled actions
|
||||
$disabled_actions = array(
|
||||
$this->topic_create,
|
||||
$this->reply_create
|
||||
);
|
||||
|
||||
// Check if this activity stream action is disabled
|
||||
if ( in_array( $action_name, $disabled_actions, true ) ) {
|
||||
$can_comment = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $can_comment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Maybe link directly to topics and replies in activity stream entries
|
||||
*
|
||||
* @since 2.0.0 bbPress (r3399)
|
||||
*
|
||||
* @param string $link
|
||||
* @param mixed $activity_object
|
||||
* @return string The link to the activity stream item
|
||||
*/
|
||||
public function activity_get_permalink( $link = '', $activity_object = false ) {
|
||||
|
||||
// Setup the array of actions to link directly to
|
||||
$disabled_actions = array(
|
||||
$this->topic_create,
|
||||
$this->reply_create
|
||||
);
|
||||
|
||||
// Check if this activity stream action is directly linked
|
||||
if ( in_array( $activity_object->type, $disabled_actions, true ) ) {
|
||||
$link = $activity_object->primary_link;
|
||||
}
|
||||
|
||||
return $link;
|
||||
}
|
||||
|
||||
/** Topics ****************************************************************/
|
||||
|
||||
/**
|
||||
* Record an activity stream entry when a topic is created or updated
|
||||
*
|
||||
* @since 2.0.0 bbPress (r3395)
|
||||
*
|
||||
* @param int $topic_id
|
||||
* @param int $forum_id
|
||||
* @param array $anonymous_data
|
||||
* @param int $topic_author_id
|
||||
* @return Bail early if topic is by anonymous user
|
||||
*/
|
||||
public function topic_create( $topic_id = 0, $forum_id = 0, $anonymous_data = array(), $topic_author_id = 0 ) {
|
||||
|
||||
// Bail early if topic is by anonymous user
|
||||
if ( ! empty( $anonymous_data ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Bail if site is private
|
||||
if ( ! bbp_is_site_public() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Validate activity data
|
||||
$user_id = bbp_get_user_id( $topic_author_id );
|
||||
$topic_id = bbp_get_topic_id( $topic_id );
|
||||
$forum_id = bbp_get_forum_id( $forum_id );
|
||||
|
||||
// Bail if user is not active
|
||||
if ( bbp_is_user_inactive( $user_id ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Bail if topic is not published
|
||||
if ( ! bbp_is_topic_published( $topic_id ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// User link for topic author
|
||||
$user_link = bbp_get_user_profile_link( $user_id );
|
||||
|
||||
// Topic
|
||||
$topic_permalink = bbp_get_topic_permalink( $topic_id );
|
||||
$topic_title = get_post_field( 'post_title', $topic_id, 'raw' );
|
||||
$topic_content = get_post_field( 'post_content', $topic_id, 'raw' );
|
||||
$topic_link = '<a href="' . $topic_permalink . '">' . $topic_title . '</a>';
|
||||
|
||||
// Forum
|
||||
$forum_permalink = bbp_get_forum_permalink( $forum_id );
|
||||
$forum_title = get_post_field( 'post_title', $forum_id, 'raw' );
|
||||
$forum_link = '<a href="' . $forum_permalink . '">' . $forum_title . '</a>';
|
||||
|
||||
// Activity action & text
|
||||
$activity_text = sprintf( esc_html__( '%1$s started the topic %2$s in the forum %3$s', 'bbpress' ), $user_link, $topic_link, $forum_link );
|
||||
$activity_action = apply_filters( 'bbp_activity_topic_create', $activity_text, $user_id, $topic_id, $forum_id );
|
||||
$activity_content = apply_filters( 'bbp_activity_topic_create_excerpt', $topic_content );
|
||||
|
||||
// Compile and record the activity stream results
|
||||
$activity_id = $this->record_activity( array(
|
||||
'id' => $this->get_activity_id( $topic_id ),
|
||||
'user_id' => $user_id,
|
||||
'action' => $activity_action,
|
||||
'content' => $activity_content,
|
||||
'primary_link' => $topic_permalink,
|
||||
'type' => $this->topic_create,
|
||||
'item_id' => $topic_id,
|
||||
'secondary_item_id' => $forum_id,
|
||||
'recorded_time' => get_post_time( 'Y-m-d H:i:s', true, $topic_id ),
|
||||
'hide_sitewide' => ! bbp_is_forum_public( $forum_id, false )
|
||||
) );
|
||||
|
||||
// Add the activity entry ID as a meta value to the topic
|
||||
if ( ! empty( $activity_id ) ) {
|
||||
update_post_meta( $topic_id, '_bbp_activity_id', $activity_id );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the activity stream entry when a topic is spammed, trashed, or deleted
|
||||
*
|
||||
* @param int $topic_id
|
||||
*/
|
||||
public function topic_delete( $topic_id = 0 ) {
|
||||
|
||||
// Get activity ID, bail if it doesn't exist
|
||||
$activity_id = $this->get_activity_id( $topic_id );
|
||||
if ( ! empty( $activity_id ) ) {
|
||||
return bp_activity_delete( array( 'id' => $activity_id ) );
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the activity stream entry when a topic status changes
|
||||
*
|
||||
* @param int $topic_id
|
||||
* @param obj $post
|
||||
* @return Bail early if not a topic, or topic is by anonymous user
|
||||
*/
|
||||
public function topic_update( $topic_id = 0, $post = null ) {
|
||||
|
||||
// Bail early if not a topic
|
||||
if ( get_post_type( $post ) !== bbp_get_topic_post_type() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Bail early if revisions are off
|
||||
if ( ! bbp_allow_revisions() || ! post_type_supports( bbp_get_topic_post_type(), 'revisions' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$topic_id = bbp_get_topic_id( $topic_id );
|
||||
|
||||
// Bail early if topic is by anonymous user
|
||||
if ( bbp_is_topic_anonymous( $topic_id ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Action based on new status
|
||||
if ( bbp_is_topic_public( $post->ID ) ) {
|
||||
|
||||
// Validate topic data
|
||||
$forum_id = bbp_get_topic_forum_id( $topic_id );
|
||||
$topic_author_id = bbp_get_topic_author_id( $topic_id );
|
||||
|
||||
$this->topic_create( $topic_id, $forum_id, array(), $topic_author_id );
|
||||
} else {
|
||||
$this->topic_delete( $topic_id );
|
||||
}
|
||||
}
|
||||
|
||||
/** Replies ***************************************************************/
|
||||
|
||||
/**
|
||||
* Record an activity stream entry when a reply is created
|
||||
*
|
||||
* @since 2.0.0 bbPress (r3395)
|
||||
*
|
||||
* @param int $topic_id
|
||||
* @param int $forum_id
|
||||
* @param array $anonymous_data
|
||||
* @param int $topic_author_id
|
||||
* @return Bail early if topic is by anonymous user
|
||||
*/
|
||||
public function reply_create( $reply_id = 0, $topic_id = 0, $forum_id = 0, $anonymous_data = array(), $reply_author_id = 0 ) {
|
||||
|
||||
// Do not log activity of anonymous users
|
||||
if ( ! empty( $anonymous_data ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Bail if site is private
|
||||
if ( ! bbp_is_site_public() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Validate activity data
|
||||
$user_id = bbp_get_user_id( $reply_author_id );
|
||||
$reply_id = bbp_get_reply_id( $reply_id );
|
||||
$topic_id = bbp_get_topic_id( $topic_id );
|
||||
$forum_id = bbp_get_forum_id( $forum_id );
|
||||
|
||||
// Bail if user is not active
|
||||
if ( bbp_is_user_inactive( $user_id ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Bail if reply is not published
|
||||
if ( ! bbp_is_reply_published( $reply_id ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Setup links for activity stream
|
||||
$user_link = bbp_get_user_profile_link( $user_id );
|
||||
|
||||
// Reply
|
||||
$reply_url = bbp_get_reply_url( $reply_id );
|
||||
$reply_content = get_post_field( 'post_content', $reply_id, 'raw' );
|
||||
|
||||
// Topic
|
||||
$topic_permalink = bbp_get_topic_permalink( $topic_id );
|
||||
$topic_title = get_post_field( 'post_title', $topic_id, 'raw' );
|
||||
$topic_link = '<a href="' . $topic_permalink . '">' . $topic_title . '</a>';
|
||||
|
||||
// Forum
|
||||
$forum_permalink = bbp_get_forum_permalink( $forum_id );
|
||||
$forum_title = get_post_field( 'post_title', $forum_id, 'raw' );
|
||||
$forum_link = '<a href="' . $forum_permalink . '">' . $forum_title . '</a>';
|
||||
|
||||
// Activity action & text
|
||||
$activity_text = sprintf( esc_html__( '%1$s replied to the topic %2$s in the forum %3$s', 'bbpress' ), $user_link, $topic_link, $forum_link );
|
||||
$activity_action = apply_filters( 'bbp_activity_reply_create', $activity_text, $user_id, $reply_id, $topic_id );
|
||||
$activity_content = apply_filters( 'bbp_activity_reply_create_excerpt', $reply_content );
|
||||
|
||||
// Compile and record the activity stream results
|
||||
$activity_id = $this->record_activity( array(
|
||||
'id' => $this->get_activity_id( $reply_id ),
|
||||
'user_id' => $user_id,
|
||||
'action' => $activity_action,
|
||||
'content' => $activity_content,
|
||||
'primary_link' => $reply_url,
|
||||
'type' => $this->reply_create,
|
||||
'item_id' => $reply_id,
|
||||
'secondary_item_id' => $topic_id,
|
||||
'recorded_time' => get_post_time( 'Y-m-d H:i:s', true, $reply_id ),
|
||||
'hide_sitewide' => ! bbp_is_forum_public( $forum_id, false )
|
||||
) );
|
||||
|
||||
// Add the activity entry ID as a meta value to the reply
|
||||
if ( ! empty( $activity_id ) ) {
|
||||
update_post_meta( $reply_id, '_bbp_activity_id', $activity_id );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the activity stream entry when a reply is spammed, trashed, or deleted
|
||||
*
|
||||
* @param int $reply_id
|
||||
*/
|
||||
public function reply_delete( $reply_id ) {
|
||||
|
||||
// Get activity ID, bail if it doesn't exist
|
||||
$activity_id = $this->get_activity_id( $reply_id );
|
||||
if ( ! empty( $activity_id ) ) {
|
||||
return bp_activity_delete( array( 'id' => $activity_id ) );
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the activity stream entry when a reply status changes
|
||||
*
|
||||
* @param int $reply_id
|
||||
* @param obj $post
|
||||
* @return Bail early if not a reply, or reply is by anonymous user
|
||||
*/
|
||||
public function reply_update( $reply_id, $post ) {
|
||||
|
||||
// Bail early if not a reply
|
||||
if ( get_post_type( $post ) !== bbp_get_reply_post_type() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Bail early if revisions are off
|
||||
if ( ! bbp_allow_revisions() || ! post_type_supports( bbp_get_reply_post_type(), 'revisions' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$reply_id = bbp_get_reply_id( $reply_id );
|
||||
|
||||
// Bail early if reply is by anonymous user
|
||||
if ( bbp_is_reply_anonymous( $reply_id ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Action based on new status
|
||||
if ( bbp_get_public_status_id() === $post->post_status ) {
|
||||
|
||||
// Validate reply data
|
||||
$topic_id = bbp_get_reply_topic_id( $reply_id );
|
||||
$forum_id = bbp_get_reply_forum_id( $reply_id );
|
||||
$reply_author_id = bbp_get_reply_author_id( $reply_id );
|
||||
|
||||
$this->reply_create( $reply_id, $topic_id, $forum_id, array(), $reply_author_id );
|
||||
} else {
|
||||
$this->reply_delete( $reply_id );
|
||||
}
|
||||
}
|
||||
}
|
||||
endif;
|
||||
@@ -0,0 +1,908 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Main bbPress BuddyPress Class
|
||||
*
|
||||
* @package bbPress
|
||||
* @subpackage BuddyPress
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
// Hooks
|
||||
add_filter( 'bp_modify_page_title', 'bbp_filter_modify_page_title', 10, 3 );
|
||||
add_filter( 'bbp_get_user_id', 'bbp_filter_user_id', 10, 3 );
|
||||
add_filter( 'bbp_is_single_user', 'bbp_filter_is_single_user', 10, 1 );
|
||||
add_filter( 'bbp_is_user_home', 'bbp_filter_is_user_home', 10, 1 );
|
||||
|
||||
// Group Forum Root
|
||||
add_action( 'load-settings_page_bbpress', 'bbp_maybe_create_group_forum_root' );
|
||||
add_action( 'bbp_delete_forum', 'bbp_maybe_delete_group_forum_root' );
|
||||
|
||||
/** BuddyPress Helpers ********************************************************/
|
||||
|
||||
/**
|
||||
* Return component name/ID ('forums' by default)
|
||||
*
|
||||
* This is used primarily for Notifications integration.
|
||||
*
|
||||
* @since 2.6.0 bbPress (r5232)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function bbp_get_component_name() {
|
||||
|
||||
// Use existing ID or default
|
||||
$retval = ! empty( bbpress()->extend->buddypress->id )
|
||||
? bbpress()->extend->buddypress->id
|
||||
: 'forums';
|
||||
|
||||
// Filter & return
|
||||
return apply_filters( 'bbp_get_component_name', $retval );
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the current bbPress user ID with the current BuddyPress user ID
|
||||
*
|
||||
* @since 2.1.0 bbPress (r3552)
|
||||
*
|
||||
* @param int $user_id
|
||||
* @param bool $displayed_user_fallback
|
||||
* @param bool $current_user_fallback
|
||||
*
|
||||
* @return int User ID
|
||||
*/
|
||||
function bbp_filter_user_id( $user_id = 0, $displayed_user_fallback = true, $current_user_fallback = false ) {
|
||||
|
||||
// Define local variable
|
||||
$bbp_user_id = 0;
|
||||
|
||||
// Get possible user ID's
|
||||
$did = bp_displayed_user_id();
|
||||
$lid = bp_loggedin_user_id();
|
||||
|
||||
// Easy empty checking
|
||||
if ( ! empty( $user_id ) && is_numeric( $user_id ) ) {
|
||||
$bbp_user_id = $user_id;
|
||||
|
||||
// Currently viewing or editing a user
|
||||
} elseif ( ( true === $displayed_user_fallback ) && ! empty( $did ) ) {
|
||||
$bbp_user_id = $did;
|
||||
|
||||
// Maybe fallback on the current_user ID
|
||||
} elseif ( ( true === $current_user_fallback ) && ! empty( $lid ) ) {
|
||||
$bbp_user_id = $lid;
|
||||
}
|
||||
|
||||
return $bbp_user_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the bbPress is_single_user function with BuddyPress equivalent
|
||||
*
|
||||
* @since 2.1.0 bbPress (r3552)
|
||||
*
|
||||
* @param bool $is Optional. Default false
|
||||
* @return bool True if viewing single user, false if not
|
||||
*/
|
||||
function bbp_filter_is_single_user( $is = false ) {
|
||||
if ( ! empty( $is ) ) {
|
||||
return $is;
|
||||
}
|
||||
|
||||
return bp_is_user();
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the bbPress is_user_home function with BuddyPress equivalent
|
||||
*
|
||||
* @since 2.1.0 bbPress (r3552)
|
||||
*
|
||||
* @param bool $is Optional. Default false
|
||||
* @return bool True if viewing single user, false if not
|
||||
*/
|
||||
function bbp_filter_is_user_home( $is = false ) {
|
||||
if ( ! empty( $is ) ) {
|
||||
return $is;
|
||||
}
|
||||
|
||||
return bp_is_my_profile();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the topic title to the <title> if viewing a single group forum topic
|
||||
*
|
||||
* @since 2.5.0 bbPress (r5161)
|
||||
*
|
||||
* @param string $new_title The title to filter
|
||||
* @param string $old_title (Not used)
|
||||
* @param string $sep The separator to use
|
||||
* @return string The possibly modified title
|
||||
*/
|
||||
function bbp_filter_modify_page_title( $new_title = '', $old_title = '', $sep = '' ) {
|
||||
|
||||
// Only filter if group forums are active
|
||||
if ( bbp_is_group_forums_active() ) {
|
||||
|
||||
// Only filter for single group forum topics
|
||||
if ( bp_is_group_forum_topic() || bp_is_group_forum_topic_edit() ) {
|
||||
|
||||
// Get the topic
|
||||
$topic = get_posts( array(
|
||||
'name' => bp_action_variable( 1 ),
|
||||
'post_status' => array_keys( bbp_get_topic_statuses() ),
|
||||
'post_type' => bbp_get_topic_post_type(),
|
||||
'numberposts' => 1
|
||||
) );
|
||||
|
||||
// Add the topic title to the <title>
|
||||
$new_title .= bbp_get_topic_title( $topic[0]->ID ) . ' ' . $sep . ' ';
|
||||
}
|
||||
}
|
||||
|
||||
// Return the title
|
||||
return $new_title;
|
||||
}
|
||||
|
||||
/** BuddyPress Screens ********************************************************/
|
||||
|
||||
/**
|
||||
* Hook bbPress topics template into plugins template
|
||||
*
|
||||
* @since 2.1.0 bbPress (r3552)
|
||||
*/
|
||||
function bbp_member_forums_screen_topics() {
|
||||
add_action( 'bp_template_content', 'bbp_member_forums_topics_content' );
|
||||
bp_core_load_template( apply_filters( 'bbp_member_forums_screen_topics', 'members/single/plugins' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook bbPress replies template into plugins template
|
||||
*
|
||||
* @since 2.1.0 bbPress (r3552)
|
||||
*/
|
||||
function bbp_member_forums_screen_replies() {
|
||||
add_action( 'bp_template_content', 'bbp_member_forums_replies_content' );
|
||||
bp_core_load_template( apply_filters( 'bbp_member_forums_screen_replies', 'members/single/plugins' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook bbPress engagements template into plugins template
|
||||
*
|
||||
* @since 2.6.0 bbPress (r6320)
|
||||
*/
|
||||
function bbp_member_forums_screen_engagements() {
|
||||
add_action( 'bp_template_content', 'bbp_member_forums_engagements_content' );
|
||||
bp_core_load_template( apply_filters( 'bbp_member_forums_screen_engagements', 'members/single/plugins' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook bbPress favorites template into plugins template
|
||||
*
|
||||
* @since 2.1.0 bbPress (r3552)
|
||||
*/
|
||||
function bbp_member_forums_screen_favorites() {
|
||||
add_action( 'bp_template_content', 'bbp_member_forums_favorites_content' );
|
||||
bp_core_load_template( apply_filters( 'bbp_member_forums_screen_favorites', 'members/single/plugins' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook bbPress subscriptions template into plugins template
|
||||
*
|
||||
* @since 2.1.0 bbPress (r3552)
|
||||
*/
|
||||
function bbp_member_forums_screen_subscriptions() {
|
||||
add_action( 'bp_template_content', 'bbp_member_forums_subscriptions_content' );
|
||||
bp_core_load_template( apply_filters( 'bbp_member_forums_screen_subscriptions', 'members/single/plugins' ) );
|
||||
}
|
||||
|
||||
/** BuddyPress Templates ******************************************************/
|
||||
|
||||
/**
|
||||
* Get the topics created template part
|
||||
*
|
||||
* @since 2.1.0 bbPress (r3552)
|
||||
*/
|
||||
function bbp_member_forums_topics_content() {
|
||||
?>
|
||||
|
||||
<div id="bbpress-forums" class="bbpress-wrapper">
|
||||
|
||||
<?php bbp_get_template_part( 'user', 'topics-created' ); ?>
|
||||
|
||||
</div>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the topics replied to template part
|
||||
*
|
||||
* @since 2.1.0 bbPress (r3552)
|
||||
*/
|
||||
function bbp_member_forums_replies_content() {
|
||||
?>
|
||||
|
||||
<div id="bbpress-forums" class="bbpress-wrapper">
|
||||
|
||||
<?php bbp_get_template_part( 'user', 'replies-created' ); ?>
|
||||
|
||||
</div>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the topic engagements template part
|
||||
*
|
||||
* @since 2.6.0 bbPress (r6320)
|
||||
*/
|
||||
function bbp_member_forums_engagements_content() {
|
||||
?>
|
||||
|
||||
<div id="bbpress-forums" class="bbpress-wrapper">
|
||||
|
||||
<?php bbp_get_template_part( 'user', 'engagements' ); ?>
|
||||
|
||||
</div>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the topics favorited template part
|
||||
*
|
||||
* @since 2.1.0 bbPress (r3552)
|
||||
*/
|
||||
function bbp_member_forums_favorites_content() {
|
||||
?>
|
||||
|
||||
<div id="bbpress-forums" class="bbpress-wrapper">
|
||||
|
||||
<?php bbp_get_template_part( 'user', 'favorites' ); ?>
|
||||
|
||||
</div>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the topics subscribed template part
|
||||
*
|
||||
* @since 2.1.0 bbPress (r3552)
|
||||
*/
|
||||
function bbp_member_forums_subscriptions_content() {
|
||||
?>
|
||||
|
||||
<div id="bbpress-forums" class="bbpress-wrapper">
|
||||
|
||||
<?php bbp_get_template_part( 'user', 'subscriptions' ); ?>
|
||||
|
||||
</div>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
/** Forum Group Root **********************************************************/
|
||||
|
||||
/**
|
||||
* Clean up the group root setting if the forum is being deleted
|
||||
*
|
||||
* @since 2.6.0 bbPress (r6479)
|
||||
*
|
||||
* @param int $forum_id The forum ID being deleted
|
||||
*/
|
||||
function bbp_maybe_delete_group_forum_root( $forum_id = 0 ) {
|
||||
|
||||
// Bail if no forum ID
|
||||
$forum_id = bbp_get_forum_id();
|
||||
if ( empty( $forum_id ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the group root
|
||||
$group_root = (int) get_option( '_bbp_group_forums_root_id', 0 );
|
||||
|
||||
// Delete the group root if the forum just got deleted
|
||||
if ( $group_root === $forum_id ) {
|
||||
delete_option( '_bbp_group_forums_root_id' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the new group forum root creation
|
||||
*
|
||||
* @since 2.6.0 bbPress (r6479)
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
function bbp_maybe_create_group_forum_root() {
|
||||
|
||||
// Bail if no nonce
|
||||
if ( empty( $_GET['_wpnonce'] ) || ( empty( $_GET['create'] ) || ( 'bbp-group-forum-root' !== $_GET['create'] ) ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Bail if user cannot publish forums
|
||||
if ( ! current_user_can( 'publish_forums' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Bail if nonce check fails
|
||||
if ( ! wp_verify_nonce( $_GET['_wpnonce'], '_bbp_group_forums_root_id' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Create new forum
|
||||
$forum_id = bbp_insert_forum(
|
||||
|
||||
// Post
|
||||
array( 'post_title' => esc_html__( 'Group Forums', 'bbpress' ) ),
|
||||
|
||||
// Meta
|
||||
array( 'forum_type' => 'category' )
|
||||
);
|
||||
|
||||
// Update & redirect
|
||||
if ( ! empty( $forum_id ) ) {
|
||||
|
||||
// Create
|
||||
update_option( '_bbp_group_forums_root_id', $forum_id );
|
||||
|
||||
// Redirect
|
||||
bbp_redirect( add_query_arg( array(
|
||||
'page' => 'bbpress',
|
||||
'updated' => true
|
||||
), admin_url( 'options-general.php' ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
/** Forum/Group Sync **********************************************************/
|
||||
|
||||
/**
|
||||
* These functions are used to keep the many-to-many relationships between
|
||||
* groups and forums synchronized. Each forum and group stores pointers to each
|
||||
* other in their respective meta. This way if a group or forum is deleted
|
||||
* their associations can be updated without much effort.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Get forum ID's for a group
|
||||
*
|
||||
* @since 2.1.0 bbPress (r3653)
|
||||
*
|
||||
* @param int $group_id
|
||||
*/
|
||||
function bbp_get_group_forum_ids( $group_id = 0 ) {
|
||||
|
||||
// Assume no forums
|
||||
$forum_ids = array();
|
||||
|
||||
// Use current group if none is set
|
||||
if ( empty( $group_id ) ) {
|
||||
$group_id = bp_get_current_group_id();
|
||||
}
|
||||
|
||||
// Get the forums
|
||||
if ( ! empty( $group_id ) ) {
|
||||
$forum_ids = groups_get_groupmeta( $group_id, 'forum_id' );
|
||||
}
|
||||
|
||||
// Make sure result is an array of ints
|
||||
$forum_ids = array_filter( wp_parse_id_list( $forum_ids ) );
|
||||
|
||||
// Filter & return
|
||||
return (array) apply_filters( 'bbp_get_group_forum_ids', $forum_ids, $group_id );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get group ID's for a forum
|
||||
*
|
||||
* @since 2.1.0 bbPress (r3653)
|
||||
*
|
||||
* @param int $forum_id
|
||||
*/
|
||||
function bbp_get_forum_group_ids( $forum_id = 0 ) {
|
||||
|
||||
// Assume no forums
|
||||
$group_ids = array();
|
||||
|
||||
// Use current group if none is set
|
||||
if ( empty( $forum_id ) ) {
|
||||
$forum_id = bbp_get_forum_id();
|
||||
}
|
||||
|
||||
// Get the forums
|
||||
if ( ! empty( $forum_id ) ) {
|
||||
$group_ids = get_post_meta( $forum_id, '_bbp_group_ids', true );
|
||||
}
|
||||
|
||||
// Make sure result is an array of ints
|
||||
$group_ids = array_filter( wp_parse_id_list( $group_ids ) );
|
||||
|
||||
// Filter & return
|
||||
return (array) apply_filters( 'bbp_get_forum_group_ids', $group_ids, $forum_id );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get forum ID's for a group
|
||||
*
|
||||
* @since 2.1.0 bbPress (r3653)
|
||||
*
|
||||
* @param int $group_id
|
||||
*/
|
||||
function bbp_update_group_forum_ids( $group_id = 0, $forum_ids = array() ) {
|
||||
|
||||
// Use current group if none is set
|
||||
if ( empty( $group_id ) ) {
|
||||
$group_id = bp_get_current_group_id();
|
||||
}
|
||||
|
||||
// Trim out any empties
|
||||
$forum_ids = array_filter( wp_parse_id_list( $forum_ids ) );
|
||||
|
||||
// Get the forums
|
||||
return groups_update_groupmeta( $group_id, 'forum_id', $forum_ids );
|
||||
}
|
||||
|
||||
/**
|
||||
* Update group ID's for a forum
|
||||
*
|
||||
* @since 2.1.0 bbPress (r3653)
|
||||
*
|
||||
* @param int $forum_id
|
||||
*/
|
||||
function bbp_update_forum_group_ids( $forum_id = 0, $group_ids = array() ) {
|
||||
$forum_id = bbp_get_forum_id( $forum_id );
|
||||
|
||||
// Trim out any empties
|
||||
$group_ids = array_filter( wp_parse_id_list( $group_ids ) );
|
||||
|
||||
// Get the forums
|
||||
return update_post_meta( $forum_id, '_bbp_group_ids', $group_ids );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a group to a forum
|
||||
*
|
||||
* @since 2.1.0 bbPress (r3653)
|
||||
*
|
||||
* @param int $group_id
|
||||
*/
|
||||
function bbp_add_group_id_to_forum( $forum_id = 0, $group_id = 0 ) {
|
||||
|
||||
// Validate forum_id
|
||||
$forum_id = bbp_get_forum_id( $forum_id );
|
||||
|
||||
// Use current group if none is set
|
||||
if ( empty( $group_id ) ) {
|
||||
$group_id = bp_get_current_group_id();
|
||||
}
|
||||
|
||||
// Get current group IDs
|
||||
$group_ids = bbp_get_forum_group_ids( $forum_id );
|
||||
|
||||
// Maybe update the groups forums
|
||||
if ( ! in_array( $group_id, $group_ids, true ) ) {
|
||||
$group_ids[] = $group_id;
|
||||
return bbp_update_forum_group_ids( $forum_id, $group_ids );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a forum from a group
|
||||
*
|
||||
* @since 2.1.0 bbPress (r3653)
|
||||
*
|
||||
* @param int $group_id
|
||||
*/
|
||||
function bbp_add_forum_id_to_group( $group_id = 0, $forum_id = 0 ) {
|
||||
|
||||
// Validate forum_id
|
||||
$forum_id = bbp_get_forum_id( $forum_id );
|
||||
|
||||
// Use current group if none is set
|
||||
if ( empty( $group_id ) ) {
|
||||
$group_id = bp_get_current_group_id();
|
||||
}
|
||||
|
||||
// Get current group IDs
|
||||
$forum_ids = bbp_get_group_forum_ids( $group_id );
|
||||
|
||||
// Maybe update the groups forums
|
||||
if ( ! in_array( $forum_id, $forum_ids, true ) ) {
|
||||
$forum_ids[] = $forum_id;
|
||||
return bbp_update_group_forum_ids( $group_id, $forum_ids );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a group from a forum
|
||||
*
|
||||
* @since 2.1.0 bbPress (r3653)
|
||||
*
|
||||
* @param int $group_id
|
||||
*/
|
||||
function bbp_remove_group_id_from_forum( $forum_id = 0, $group_id = 0 ) {
|
||||
|
||||
// Validate forum_id
|
||||
$forum_id = bbp_get_forum_id( $forum_id );
|
||||
|
||||
// Use current group if none is set
|
||||
if ( empty( $group_id ) ) {
|
||||
$group_id = bp_get_current_group_id();
|
||||
}
|
||||
|
||||
// Get current group IDs
|
||||
$group_ids = bbp_get_forum_group_ids( $forum_id );
|
||||
|
||||
// Maybe update the groups forums
|
||||
if ( in_array( $group_id, $group_ids, true ) ) {
|
||||
$group_ids = array_diff( array_values( $group_ids ), (array) $group_id );
|
||||
return bbp_update_forum_group_ids( $forum_id, $group_ids );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a forum from a group
|
||||
*
|
||||
* @since 2.1.0 bbPress (r3653)
|
||||
*
|
||||
* @param int $group_id
|
||||
*/
|
||||
function bbp_remove_forum_id_from_group( $group_id = 0, $forum_id = 0 ) {
|
||||
|
||||
// Validate forum_id
|
||||
$forum_id = bbp_get_forum_id( $forum_id );
|
||||
|
||||
// Use current group if none is set
|
||||
if ( empty( $group_id ) ) {
|
||||
$group_id = bp_get_current_group_id();
|
||||
}
|
||||
|
||||
// Get current group IDs
|
||||
$forum_ids = bbp_get_group_forum_ids( $group_id );
|
||||
|
||||
// Maybe update the groups forums
|
||||
if ( in_array( $forum_id, $forum_ids, true ) ) {
|
||||
$forum_ids = array_diff( array_values( $forum_ids ), (array) $forum_id );
|
||||
return bbp_update_group_forum_ids( $group_id, $forum_ids );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a group from all forums
|
||||
*
|
||||
* @since 2.1.0 bbPress (r3653)
|
||||
*
|
||||
* @param int $group_id
|
||||
*/
|
||||
function bbp_remove_group_id_from_all_forums( $group_id = 0 ) {
|
||||
|
||||
// Use current group if none is set
|
||||
if ( empty( $group_id ) ) {
|
||||
$group_id = bp_get_current_group_id();
|
||||
}
|
||||
|
||||
// Get current group IDs
|
||||
$forum_ids = bbp_get_group_forum_ids( $group_id );
|
||||
|
||||
// Loop through forums and remove this group from each one
|
||||
foreach ( $forum_ids as $forum_id ) {
|
||||
bbp_remove_group_id_from_forum( $group_id, $forum_id );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a forum from all groups
|
||||
*
|
||||
* @since 2.1.0 bbPress (r3653)
|
||||
*
|
||||
* @param int $forum_id
|
||||
*/
|
||||
function bbp_remove_forum_id_from_all_groups( $forum_id = 0 ) {
|
||||
|
||||
// Validate
|
||||
$forum_id = bbp_get_forum_id( $forum_id );
|
||||
$group_ids = bbp_get_forum_group_ids( $forum_id );
|
||||
|
||||
// Loop through groups and remove this forum from each one
|
||||
foreach ( $group_ids as $group_id ) {
|
||||
bbp_remove_forum_id_from_group( $forum_id, $group_id );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if a forum is a group forum
|
||||
*
|
||||
* @since 2.3.0 bbPress (r4571)
|
||||
*
|
||||
* @param int $forum_id
|
||||
* @return bool True if it is a group forum, false if not
|
||||
*/
|
||||
function bbp_is_forum_group_forum( $forum_id = 0 ) {
|
||||
|
||||
// Validate
|
||||
$forum_id = bbp_get_forum_id( $forum_id );
|
||||
|
||||
// Check for group ID's
|
||||
$group_ids = bbp_get_forum_group_ids( $forum_id );
|
||||
|
||||
// Check if the forum has groups
|
||||
$retval = (bool) ! empty( $group_ids );
|
||||
|
||||
// Filter & return
|
||||
return (bool) apply_filters( 'bbp_is_forum_group_forum', $retval, $forum_id, $group_ids );
|
||||
}
|
||||
|
||||
/*** Group Member Status ******************************************************/
|
||||
|
||||
/**
|
||||
* Is the current user an admin of the current group
|
||||
*
|
||||
* @since 2.3.0 bbPress (r4632)
|
||||
*
|
||||
* @return bool If current user is an admin of the current group
|
||||
*/
|
||||
function bbp_group_is_admin() {
|
||||
|
||||
// Bail if user is not logged in or not looking at a group
|
||||
if ( ! is_user_logged_in() || ! bp_is_group() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$bbp = bbpress();
|
||||
|
||||
// Set the global if not set
|
||||
if ( ! isset( $bbp->current_user->is_group_admin ) ) {
|
||||
$bbp->current_user->is_group_admin = groups_is_user_admin( bp_loggedin_user_id(), bp_get_current_group_id() );
|
||||
}
|
||||
|
||||
// Return the value
|
||||
return (bool) $bbp->current_user->is_group_admin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the current user a moderator of the current group
|
||||
*
|
||||
* @since 2.3.0 bbPress (r4632)
|
||||
*
|
||||
* @return bool If current user is a moderator of the current group
|
||||
*/
|
||||
function bbp_group_is_mod() {
|
||||
|
||||
// Bail if user is not logged in or not looking at a group
|
||||
if ( ! is_user_logged_in() || ! bp_is_group() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$bbp = bbpress();
|
||||
|
||||
// Set the global if not set
|
||||
if ( ! isset( $bbp->current_user->is_group_mod ) ) {
|
||||
$bbp->current_user->is_group_mod = groups_is_user_mod( bp_loggedin_user_id(), bp_get_current_group_id() );
|
||||
}
|
||||
|
||||
// Return the value
|
||||
return (bool) $bbp->current_user->is_group_mod;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the current user a member of the current group
|
||||
*
|
||||
* @since 2.3.0 bbPress (r4632)
|
||||
*
|
||||
* @return bool If current user is a member of the current group
|
||||
*/
|
||||
function bbp_group_is_member() {
|
||||
|
||||
// Bail if user is not logged in or not looking at a group
|
||||
if ( ! is_user_logged_in() || ! bp_is_group() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$bbp = bbpress();
|
||||
|
||||
// Set the global if not set
|
||||
if ( ! isset( $bbp->current_user->is_group_member ) ) {
|
||||
$bbp->current_user->is_group_member = groups_is_user_member( bp_loggedin_user_id(), bp_get_current_group_id() );
|
||||
}
|
||||
|
||||
// Return the value
|
||||
return (bool) $bbp->current_user->is_group_member;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the current user banned from the current group
|
||||
*
|
||||
* @since 2.3.0 bbPress (r4632)
|
||||
*
|
||||
* @return bool If current user is banned from the current group
|
||||
*/
|
||||
function bbp_group_is_banned() {
|
||||
|
||||
// Bail if user is not logged in or not looking at a group
|
||||
if ( ! is_user_logged_in() || ! bp_is_group() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$bbp = bbpress();
|
||||
|
||||
// Set the global if not set
|
||||
if ( ! isset( $bbp->current_user->is_group_banned ) ) {
|
||||
$bbp->current_user->is_group_banned = groups_is_user_banned( bp_loggedin_user_id(), bp_get_current_group_id() );
|
||||
}
|
||||
|
||||
// Return the value
|
||||
return (bool) $bbp->current_user->is_group_banned;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the current user the creator of the current group
|
||||
*
|
||||
* @since 2.3.0 bbPress (r4632)
|
||||
*
|
||||
* @return bool If current user the creator of the current group
|
||||
*/
|
||||
function bbp_group_is_creator() {
|
||||
|
||||
// Bail if user is not logged in or not looking at a group
|
||||
if ( ! is_user_logged_in() || ! bp_is_group() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$bbp = bbpress();
|
||||
|
||||
// Set the global if not set
|
||||
if ( ! isset( $bbp->current_user->is_group_creator ) ) {
|
||||
$bbp->current_user->is_group_creator = groups_is_user_creator( bp_loggedin_user_id(), bp_get_current_group_id() );
|
||||
}
|
||||
|
||||
// Return the value
|
||||
return (bool) $bbp->current_user->is_group_creator;
|
||||
}
|
||||
|
||||
/* BuddyPress Activity Action Callbacks ***************************************/
|
||||
|
||||
/**
|
||||
* Return an array of allowed activity actions
|
||||
*
|
||||
* @since 2.6.0 bbPress (r6370)
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function bbp_get_activity_actions() {
|
||||
|
||||
// Filter & return
|
||||
return (array) apply_filters( 'bbp_get_activity_actions', array(
|
||||
'topic' => esc_html__( '%1$s started the topic %2$s in the forum %3$s', 'bbpress' ),
|
||||
'reply' => esc_html__( '%1$s replied to the topic %2$s in the forum %3$s', 'bbpress' )
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Generic function to format the dynamic BuddyPress activity action for new
|
||||
* topics/replies.
|
||||
*
|
||||
* @since 2.6.0 bbPress (r6370)
|
||||
*
|
||||
* @param string $type The type of post. Expects `topic` or `reply`.
|
||||
* @param string $action The current action string.
|
||||
* @param BP_Activity_Activity $activity The BuddyPress activity object.
|
||||
*
|
||||
* @return string The formatted activity action.
|
||||
*/
|
||||
function bbp_format_activity_action_new_post( $type = '', $action = '', $activity = false ) {
|
||||
|
||||
// Get actions
|
||||
$actions = bbp_get_activity_actions();
|
||||
|
||||
// Bail early if we don't have a valid type
|
||||
if ( ! in_array( $type, array_keys( $actions ), true ) ) {
|
||||
return $action;
|
||||
}
|
||||
|
||||
// Bail if intercepted
|
||||
$intercept = bbp_maybe_intercept( __FUNCTION__, func_get_args() );
|
||||
if ( bbp_is_intercepted( $intercept ) ) {
|
||||
return $intercept;
|
||||
}
|
||||
|
||||
// Groups component
|
||||
if ( 'groups' === $activity->component ) {
|
||||
if ( 'topic' === $type ) {
|
||||
$topic_id = bbp_get_topic_id( $activity->secondary_item_id );
|
||||
$forum_id = bbp_get_topic_forum_id( $topic_id );
|
||||
} else {
|
||||
$topic_id = bbp_get_reply_topic_id( $activity->secondary_item_id );
|
||||
$forum_id = bbp_get_topic_forum_id( $topic_id );
|
||||
}
|
||||
|
||||
// General component (bbpress/forums/other)
|
||||
} else {
|
||||
if ( 'topic' === $type ) {
|
||||
$topic_id = bbp_get_topic_id( $activity->item_id );
|
||||
$forum_id = bbp_get_forum_id( $activity->secondary_item_id );
|
||||
} else {
|
||||
$topic_id = bbp_get_topic_id( $activity->secondary_item_id );
|
||||
$forum_id = bbp_get_topic_forum_id( $topic_id );
|
||||
}
|
||||
}
|
||||
|
||||
// User link for topic author
|
||||
$user_link = bbp_get_user_profile_link( $activity->user_id );
|
||||
|
||||
// Topic link
|
||||
$topic_permalink = bbp_get_topic_permalink( $topic_id );
|
||||
$topic_title = get_post_field( 'post_title', $topic_id, 'raw' );
|
||||
$topic_link = '<a href="' . esc_url( $topic_permalink ) . '">' . esc_html( $topic_title ) . '</a>';
|
||||
|
||||
// Forum link
|
||||
$forum_permalink = bbp_get_forum_permalink( $forum_id );
|
||||
$forum_title = get_post_field( 'post_title', $forum_id, 'raw' );
|
||||
$forum_link = '<a href="' . esc_url( $forum_permalink ) . '">' . esc_html( $forum_title ) . '</a>';
|
||||
|
||||
// Format
|
||||
$activity_action = sprintf( $actions[ $type ], $user_link, $topic_link, $forum_link );
|
||||
|
||||
/**
|
||||
* Filters the formatted activity action new activity string.
|
||||
*
|
||||
* @since 2.6.0 bbPress (r6370)
|
||||
*
|
||||
* @param string $activity_action Activity action string value
|
||||
* @param string $type The type of post. Expects `topic` or `reply`.
|
||||
* @param string $action The current action string.
|
||||
* @param BP_Activity_Activity $activity The BuddyPress activity object.
|
||||
*/
|
||||
return apply_filters( 'bbp_format_activity_action_new_post', $activity_action, $type, $action, $activity );
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats the dynamic BuddyPress activity action for new topics.
|
||||
*
|
||||
* @since 2.6.0 bbPress (r6370)
|
||||
*
|
||||
* @param string $action The current action string
|
||||
* @param object $activity The BuddyPress activity object
|
||||
*
|
||||
* @return string The formatted activity action.
|
||||
*/
|
||||
function bbp_format_activity_action_new_topic( $action, $activity ) {
|
||||
$action = bbp_format_activity_action_new_post( bbp_get_topic_post_type(), $action, $activity );
|
||||
|
||||
/**
|
||||
* Filters the formatted activity action new topic string.
|
||||
*
|
||||
* @since 2.6.0 bbPress (r6370)
|
||||
*
|
||||
* @param string $action Activity action string value
|
||||
* @param BP_Activity_Activity $activity Activity item object
|
||||
*/
|
||||
return apply_filters( 'bbp_format_activity_action_new_topic', $action, $activity );
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats the dynamic BuddyPress activity action for new replies.
|
||||
*
|
||||
* @since 2.6.0 bbPress (r6370)
|
||||
*
|
||||
* @param string $action The current action string
|
||||
* @param object $activity The BuddyPress activity object
|
||||
*
|
||||
* @return string The formatted activity action
|
||||
*/
|
||||
function bbp_format_activity_action_new_reply( $action, $activity ) {
|
||||
$action = bbp_format_activity_action_new_post( bbp_get_reply_post_type(), $action, $activity );
|
||||
|
||||
/**
|
||||
* Filters the formatted activity action new reply string.
|
||||
*
|
||||
* @since 2.6.0 bbPress (r6370)
|
||||
*
|
||||
* @param string $action Activity action string value
|
||||
* @param BP_Activity_Activity $activity Activity item object
|
||||
*/
|
||||
return apply_filters( 'bbp_format_activity_action_new_reply', $action, $activity );
|
||||
}
|
||||
1730
wp-content/plugins/bbpress/includes/extend/buddypress/groups.php
Normal file
1730
wp-content/plugins/bbpress/includes/extend/buddypress/groups.php
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Do not modify the files in this folder.
|
||||
*/
|
||||
389
wp-content/plugins/bbpress/includes/extend/buddypress/loader.php
Normal file
389
wp-content/plugins/bbpress/includes/extend/buddypress/loader.php
Normal file
@@ -0,0 +1,389 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* bbPress BuddyPress Component Class
|
||||
*
|
||||
* bbPress and BuddyPress are designed to connect together seamlessly and
|
||||
* invisibly, and this is the hunk of code necessary to make that happen.
|
||||
*
|
||||
* The code in this BuddyPress Extension does some pretty complicated stuff,
|
||||
* far outside the realm of the simplicity bbPress is traditionally known for.
|
||||
*
|
||||
* While the rest of bbPress serves as an example of how to write pretty, simple
|
||||
* code, what's in these files is pure madness. It should not be used as an
|
||||
* example of anything other than successfully juggling chainsaws and puppy-dogs.
|
||||
*
|
||||
* @package bbPress
|
||||
* @subpackage BuddyPress
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
if ( ! class_exists( 'BBP_Forums_Component' ) ) :
|
||||
/**
|
||||
* Loads Forums Component
|
||||
*
|
||||
* @since 2.1.0 bbPress (r3552)
|
||||
*
|
||||
* @package bbPress
|
||||
* @subpackage BuddyPress
|
||||
*/
|
||||
class BBP_Forums_Component extends BP_Component {
|
||||
|
||||
/**
|
||||
* Start the forums component creation process
|
||||
*
|
||||
* @since 2.1.0 bbPress (r3552)
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::start(
|
||||
'forums',
|
||||
esc_html__( 'Forums', 'bbpress' ),
|
||||
bbpress()->includes_dir . 'extend/buddypress/'
|
||||
);
|
||||
$this->includes();
|
||||
$this->setup_globals();
|
||||
$this->setup_actions();
|
||||
$this->fully_loaded();
|
||||
}
|
||||
|
||||
/**
|
||||
* Include BuddyPress classes and functions
|
||||
*/
|
||||
public function includes( $includes = array() ) {
|
||||
|
||||
// Helper BuddyPress functions
|
||||
$includes[] = 'functions.php';
|
||||
|
||||
// Members modifications
|
||||
$includes[] = 'members.php';
|
||||
|
||||
// BuddyPress Notfications Extension functions
|
||||
if ( bp_is_active( 'notifications' ) ) {
|
||||
$includes[] = 'notifications.php';
|
||||
}
|
||||
|
||||
// BuddyPress Activity Extension class
|
||||
if ( bp_is_active( 'activity' ) ) {
|
||||
$includes[] = 'activity.php';
|
||||
}
|
||||
|
||||
// BuddyPress Group Extension class
|
||||
if ( bbp_is_group_forums_active() && bp_is_active( 'groups' ) ) {
|
||||
$includes[] = 'groups.php';
|
||||
}
|
||||
|
||||
// Require files if they exist
|
||||
foreach ( $includes as $file ) {
|
||||
if ( @is_file( $this->path . $file ) ) {
|
||||
require $this->path . $file;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook for plugins to include files, if necessary.
|
||||
*
|
||||
* @since 2.6.0 bbPress (r3552)
|
||||
*/
|
||||
do_action( "bp_{$this->id}_includes" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup globals
|
||||
*
|
||||
* The BP_FORUMS_SLUG constant is deprecated, and only used here for
|
||||
* backwards compatibility.
|
||||
*
|
||||
* @since 2.1.0 bbPress (r3552)
|
||||
*/
|
||||
public function setup_globals( $args = array() ) {
|
||||
$bp = buddypress();
|
||||
|
||||
// Define the parent forum ID
|
||||
if ( ! defined( 'BP_FORUMS_PARENT_FORUM_ID' ) ) {
|
||||
define( 'BP_FORUMS_PARENT_FORUM_ID', 1 );
|
||||
}
|
||||
|
||||
// Define a slug, if necessary
|
||||
if ( ! defined( 'BP_FORUMS_SLUG' ) ) {
|
||||
define( 'BP_FORUMS_SLUG', $this->id );
|
||||
}
|
||||
|
||||
// All arguments for forums component
|
||||
$args = array(
|
||||
'path' => BP_PLUGIN_DIR,
|
||||
'slug' => BP_FORUMS_SLUG,
|
||||
'root_slug' => isset( $bp->pages->forums->slug ) ? $bp->pages->forums->slug : BP_FORUMS_SLUG,
|
||||
'has_directory' => false,
|
||||
'search_string' => esc_html__( 'Search Forums...', 'bbpress' ),
|
||||
);
|
||||
|
||||
parent::setup_globals( $args );
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup the actions
|
||||
*
|
||||
* @since 2.0.0 bbPress (r3395)
|
||||
*
|
||||
* @access private
|
||||
* @link https://bbpress.trac.wordpress.org/ticket/2176
|
||||
*/
|
||||
public function setup_actions() {
|
||||
|
||||
// Setup the components
|
||||
add_action( 'bp_init', array( $this, 'setup_components' ), 7 );
|
||||
|
||||
parent::setup_actions();
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiate classes for BuddyPress integration
|
||||
*
|
||||
* @since 2.0.0 bbPress (r3395)
|
||||
*/
|
||||
public function setup_components() {
|
||||
|
||||
// Always load the members component
|
||||
bbpress()->extend->buddypress->members = new BBP_BuddyPress_Members();
|
||||
|
||||
// Create new activity class
|
||||
if ( bp_is_active( 'activity' ) ) {
|
||||
bbpress()->extend->buddypress->activity = new BBP_BuddyPress_Activity();
|
||||
}
|
||||
|
||||
// Register the group extension only if groups are active
|
||||
if ( bbp_is_group_forums_active() && bp_is_active( 'groups' ) ) {
|
||||
bp_register_group_extension( 'BBP_Forums_Group_Extension' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow the variables, actions, and filters to be modified by third party
|
||||
* plugins and themes.
|
||||
*
|
||||
* @since 2.1.0 bbPress (r3902)
|
||||
*/
|
||||
private function fully_loaded() {
|
||||
do_action_ref_array( 'bbp_buddypress_loaded', array( $this ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup BuddyBar navigation
|
||||
*
|
||||
* @since 2.1.0 bbPress (r3552)
|
||||
*/
|
||||
public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
|
||||
|
||||
// Stop if there is no user displayed or logged in
|
||||
if ( ! is_user_logged_in() && !bp_displayed_user_id() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Define local variable(s)
|
||||
$user_domain = '';
|
||||
|
||||
// Add 'Forums' to the main navigation
|
||||
$main_nav = array(
|
||||
'name' => esc_html__( 'Forums', 'bbpress' ),
|
||||
'slug' => $this->slug,
|
||||
'position' => 80,
|
||||
'screen_function' => 'bbp_member_forums_screen_topics',
|
||||
'default_subnav_slug' => bbp_get_topic_archive_slug(),
|
||||
'item_css_id' => $this->id
|
||||
);
|
||||
|
||||
// Determine user to use
|
||||
if ( bp_displayed_user_id() ) {
|
||||
$user_domain = bp_displayed_user_domain();
|
||||
} elseif ( bp_loggedin_user_domain() ) {
|
||||
$user_domain = bp_loggedin_user_domain();
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
// User link
|
||||
$forums_link = trailingslashit( $user_domain . $this->slug );
|
||||
|
||||
// Topics started
|
||||
$sub_nav[] = array(
|
||||
'name' => esc_html__( 'Topics Started', 'bbpress' ),
|
||||
'slug' => bbp_get_topic_archive_slug(),
|
||||
'parent_url' => $forums_link,
|
||||
'parent_slug' => $this->slug,
|
||||
'screen_function' => 'bbp_member_forums_screen_topics',
|
||||
'position' => 20,
|
||||
'item_css_id' => 'topics'
|
||||
);
|
||||
|
||||
// Replies to topics
|
||||
$sub_nav[] = array(
|
||||
'name' => esc_html__( 'Replies Created', 'bbpress' ),
|
||||
'slug' => bbp_get_reply_archive_slug(),
|
||||
'parent_url' => $forums_link,
|
||||
'parent_slug' => $this->slug,
|
||||
'screen_function' => 'bbp_member_forums_screen_replies',
|
||||
'position' => 40,
|
||||
'item_css_id' => 'replies'
|
||||
);
|
||||
|
||||
// Engagements
|
||||
if ( bbp_is_engagements_active() ) {
|
||||
$sub_nav[] = array(
|
||||
'name' => esc_html__( 'Engagements', 'bbpress' ),
|
||||
'slug' => bbp_get_user_engagements_slug(),
|
||||
'parent_url' => $forums_link,
|
||||
'parent_slug' => $this->slug,
|
||||
'screen_function' => 'bbp_member_forums_screen_engagements',
|
||||
'position' => 60,
|
||||
'item_css_id' => 'engagements'
|
||||
);
|
||||
}
|
||||
|
||||
// Favorite topics
|
||||
if ( bbp_is_favorites_active() ){
|
||||
$sub_nav[] = array(
|
||||
'name' => esc_html__( 'Favorites', 'bbpress' ),
|
||||
'slug' => bbp_get_user_favorites_slug(),
|
||||
'parent_url' => $forums_link,
|
||||
'parent_slug' => $this->slug,
|
||||
'screen_function' => 'bbp_member_forums_screen_favorites',
|
||||
'position' => 80,
|
||||
'item_css_id' => 'favorites'
|
||||
);
|
||||
}
|
||||
|
||||
// Subscribed topics (my profile only)
|
||||
if ( bp_is_my_profile() && bbp_is_subscriptions_active() ) {
|
||||
$sub_nav[] = array(
|
||||
'name' => esc_html__( 'Subscriptions', 'bbpress' ),
|
||||
'slug' => bbp_get_user_subscriptions_slug(),
|
||||
'parent_url' => $forums_link,
|
||||
'parent_slug' => $this->slug,
|
||||
'screen_function' => 'bbp_member_forums_screen_subscriptions',
|
||||
'position' => 100,
|
||||
'item_css_id' => 'subscriptions'
|
||||
);
|
||||
}
|
||||
|
||||
parent::setup_nav( $main_nav, $sub_nav );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up the admin bar
|
||||
*
|
||||
* @since 2.1.0 bbPress (r3552)
|
||||
*/
|
||||
public function setup_admin_bar( $wp_admin_nav = array() ) {
|
||||
|
||||
// Menus for logged in user
|
||||
if ( is_user_logged_in() ) {
|
||||
|
||||
// If BuddyPress is network activated and bbPress is
|
||||
// not activated on a the root blog but on any child one
|
||||
if ( ! bp_is_root_blog() ) {
|
||||
$user_id = bbp_get_current_user_id();
|
||||
$my_account_link = bbp_get_user_profile_url( $user_id );
|
||||
$my_topics_link = bbp_get_user_topics_created_url( $user_id );
|
||||
$my_replies_link = bbp_get_user_replies_created_url( $user_id );
|
||||
$my_engagements_link = bbp_get_user_engagements_url( $user_id );
|
||||
$my_favorites_link = bbp_get_favorites_permalink( $user_id );
|
||||
$my_subscriptions_link = bbp_get_subscriptions_permalink( $user_id );
|
||||
} else {
|
||||
|
||||
// Setup the logged in user variables
|
||||
$user_domain = bp_loggedin_user_domain();
|
||||
$forums_link = trailingslashit( $user_domain . $this->slug );
|
||||
|
||||
$my_account_link = trailingslashit( $forums_link );
|
||||
$my_topics_link = trailingslashit( $forums_link . bbp_get_topic_archive_slug() );
|
||||
$my_replies_link = trailingslashit( $forums_link . bbp_get_reply_archive_slug() );
|
||||
$my_engagements_link = trailingslashit( $forums_link . bbp_get_user_engagements_slug() );
|
||||
$my_favorites_link = trailingslashit( $forums_link . bbp_get_user_favorites_slug() );
|
||||
$my_subscriptions_link = trailingslashit( $forums_link . bbp_get_user_subscriptions_slug() );
|
||||
}
|
||||
|
||||
// Add the "My Account" sub menus
|
||||
$wp_admin_nav[] = array(
|
||||
'parent' => buddypress()->my_account_menu_id,
|
||||
'id' => 'my-account-' . $this->id,
|
||||
'title' => esc_html__( 'Forums', 'bbpress' ),
|
||||
'href' => $my_account_link
|
||||
);
|
||||
|
||||
// Topics
|
||||
$wp_admin_nav[] = array(
|
||||
'parent' => 'my-account-' . $this->id,
|
||||
'id' => 'my-account-' . $this->id . '-topics',
|
||||
'title' => esc_html__( 'Topics Started', 'bbpress' ),
|
||||
'href' => $my_topics_link
|
||||
);
|
||||
|
||||
// Replies
|
||||
$wp_admin_nav[] = array(
|
||||
'parent' => 'my-account-' . $this->id,
|
||||
'id' => 'my-account-' . $this->id . '-replies',
|
||||
'title' => esc_html__( 'Replies Created', 'bbpress' ),
|
||||
'href' => $my_replies_link
|
||||
);
|
||||
|
||||
// Engagements
|
||||
if ( bbp_is_engagements_active() ) {
|
||||
$wp_admin_nav[] = array(
|
||||
'parent' => 'my-account-' . $this->id,
|
||||
'id' => 'my-account-' . $this->id . '-engagements',
|
||||
'title' => esc_html__( 'Engagements', 'bbpress' ),
|
||||
'href' => $my_engagements_link
|
||||
);
|
||||
}
|
||||
|
||||
// Favorites
|
||||
if ( bbp_is_favorites_active() ) {
|
||||
$wp_admin_nav[] = array(
|
||||
'parent' => 'my-account-' . $this->id,
|
||||
'id' => 'my-account-' . $this->id . '-favorites',
|
||||
'title' => esc_html__( 'Favorite Topics', 'bbpress' ),
|
||||
'href' => $my_favorites_link
|
||||
);
|
||||
}
|
||||
|
||||
// Subscriptions
|
||||
if ( bbp_is_subscriptions_active() ) {
|
||||
$wp_admin_nav[] = array(
|
||||
'parent' => 'my-account-' . $this->id,
|
||||
'id' => 'my-account-' . $this->id . '-subscriptions',
|
||||
'title' => esc_html__( 'Subscribed Topics', 'bbpress' ),
|
||||
'href' => $my_subscriptions_link
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
parent::setup_admin_bar( $wp_admin_nav );
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up the title for pages and <title>
|
||||
*
|
||||
* @since 2.1.0 bbPress (r3552)
|
||||
*/
|
||||
public function setup_title() {
|
||||
$bp = buddypress();
|
||||
|
||||
// Adjust title based on view
|
||||
if ( bp_is_forums_component() ) {
|
||||
if ( bp_is_my_profile() ) {
|
||||
$bp->bp_options_title = esc_html__( 'Forums', 'bbpress' );
|
||||
} elseif ( bp_is_user() ) {
|
||||
$bp->bp_options_avatar = bp_core_fetch_avatar( array(
|
||||
'item_id' => bp_displayed_user_id(),
|
||||
'type' => 'thumb'
|
||||
) );
|
||||
$bp->bp_options_title = bp_get_displayed_user_fullname();
|
||||
}
|
||||
}
|
||||
|
||||
parent::setup_title();
|
||||
}
|
||||
}
|
||||
endif;
|
||||
@@ -0,0 +1,241 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* bbPress BuddyPress Members Class
|
||||
*
|
||||
* @package bbPress
|
||||
* @subpackage BuddyPress
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
if ( ! class_exists( 'BBP_Forums_Members' ) ) :
|
||||
/**
|
||||
* Member profile modifications
|
||||
*
|
||||
* @since 2.2.0 bbPress (r4395)
|
||||
* @since 2.6.0 bbPress (r6320) Add engagements support
|
||||
*
|
||||
* @package bbPress
|
||||
* @subpackage BuddyPress
|
||||
*/
|
||||
class BBP_BuddyPress_Members {
|
||||
|
||||
/**
|
||||
* Main constructor for modifying bbPress profile links
|
||||
*
|
||||
* @since 2.2.0 bbPress (r4395)
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->setup_actions();
|
||||
$this->setup_filters();
|
||||
$this->fully_loaded();
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup the actions
|
||||
*
|
||||
* @since 2.2.0 bbPress (r4395)
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
private function setup_actions() {
|
||||
|
||||
// Allow unsubscribe/unfavorite links to work
|
||||
add_action( 'bp_template_redirect', array( $this, 'set_member_forum_query_vars' ) );
|
||||
|
||||
/** Favorites *********************************************************/
|
||||
|
||||
// Move handler to 'bp_actions' - BuddyPress bypasses template_loader
|
||||
remove_action( 'bbp_get_request', 'bbp_favorites_handler', 1 );
|
||||
add_action( 'bp_actions', 'bbp_favorites_handler', 1 );
|
||||
|
||||
/** Subscriptions *****************************************************/
|
||||
|
||||
// Move handler to 'bp_actions' - BuddyPress bypasses template_loader
|
||||
remove_action( 'bbp_get_request', 'bbp_subscriptions_handler', 1 );
|
||||
add_action( 'bp_actions', 'bbp_subscriptions_handler', 1 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup the filters
|
||||
*
|
||||
* @since 2.2.0 bbPress (r4395)
|
||||
* @since 2.6.0 bbPress (r6320) Add engagements support
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
private function setup_filters() {
|
||||
add_filter( 'bbp_pre_get_user_profile_url', array( $this, 'get_user_profile_url' ) );
|
||||
add_filter( 'bbp_pre_get_user_topics_created_url', array( $this, 'get_topics_created_url' ) );
|
||||
add_filter( 'bbp_pre_get_user_replies_created_url', array( $this, 'get_replies_created_url' ) );
|
||||
add_filter( 'bbp_pre_get_user_engagements_url', array( $this, 'get_engagements_permalink' ) );
|
||||
add_filter( 'bbp_pre_get_favorites_permalink', array( $this, 'get_favorites_permalink' ) );
|
||||
add_filter( 'bbp_pre_get_subscriptions_permalink', array( $this, 'get_subscriptions_permalink' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow the variables, actions, and filters to be modified by third party
|
||||
* plugins and themes.
|
||||
*
|
||||
* @since 2.6.0 bbPress (r6808)
|
||||
*/
|
||||
private function fully_loaded() {
|
||||
do_action_ref_array( 'bbp_buddypress_members_loaded', array( $this ) );
|
||||
}
|
||||
|
||||
/** Filters ***************************************************************/
|
||||
|
||||
/**
|
||||
* Override bbPress profile URL with BuddyPress profile URL
|
||||
*
|
||||
* @since 2.0.0 bbPress (r3401)
|
||||
* @since 2.6.0 bbPress (r6320) Add engagements support
|
||||
*
|
||||
* @param int $user_id
|
||||
* @return string
|
||||
*/
|
||||
public function get_user_profile_url( $user_id = 0 ) {
|
||||
return $this->get_profile_url( $user_id );
|
||||
}
|
||||
|
||||
/**
|
||||
* Override bbPress topics created URL with BuddyPress profile URL
|
||||
*
|
||||
* @since 2.6.0 bbPress (r3721)
|
||||
* @since 2.6.0 bbPress (r6803) Use private method
|
||||
*
|
||||
* @param int $user_id
|
||||
* @return string
|
||||
*/
|
||||
public function get_topics_created_url( $user_id = 0 ) {
|
||||
return $this->get_profile_url( $user_id, bbp_get_topic_archive_slug() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Override bbPress replies created URL with BuddyPress profile URL
|
||||
*
|
||||
* @since 2.6.0 bbPress (r3721)
|
||||
* @since 2.6.0 bbPress (r6803) Use private method
|
||||
*
|
||||
* @param int $user_id
|
||||
* @return string
|
||||
*/
|
||||
public function get_replies_created_url( $user_id = 0 ) {
|
||||
return $this->get_profile_url( $user_id, bbp_get_reply_archive_slug() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Override bbPress favorites URL with BuddyPress profile URL
|
||||
*
|
||||
* @since 2.1.0 bbPress (r3721)
|
||||
* @since 2.6.0 bbPress (r6803) Use private method
|
||||
*
|
||||
* @param int $user_id
|
||||
* @return string
|
||||
*/
|
||||
public function get_favorites_permalink( $user_id = 0 ) {
|
||||
return $this->get_profile_url( $user_id, bbp_get_user_favorites_slug() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Override bbPress subscriptions URL with BuddyPress profile URL
|
||||
*
|
||||
* @since 2.1.0 bbPress (r3721)
|
||||
* @since 2.6.0 bbPress (r6803) Use private method
|
||||
*
|
||||
* @param int $user_id
|
||||
* @return string
|
||||
*/
|
||||
public function get_subscriptions_permalink( $user_id = 0 ) {
|
||||
return $this->get_profile_url( $user_id, bbp_get_user_subscriptions_slug() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Override bbPress engagements URL with BuddyPress profile URL
|
||||
*
|
||||
* @since 2.6.0 bbPress (r6320)
|
||||
*
|
||||
* @param int $user_id
|
||||
* @return string
|
||||
*/
|
||||
public function get_engagements_permalink( $user_id = 0 ) {
|
||||
return $this->get_profile_url( $user_id, bbp_get_user_engagements_slug() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set favorites and subscriptions query variables if viewing member profile
|
||||
* pages.
|
||||
*
|
||||
* @since 2.3.0 bbPress (r4615)
|
||||
* @since 2.6.0 bbPress (r6320) Support all profile sections
|
||||
*
|
||||
* @global WP_Query $wp_query
|
||||
* @return If not viewing your own profile
|
||||
*/
|
||||
public function set_member_forum_query_vars() {
|
||||
|
||||
// Special handling for forum component
|
||||
if ( ! bp_is_my_profile() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the main query object
|
||||
$wp_query = bbp_get_wp_query();
|
||||
|
||||
// 'topics' action
|
||||
if ( bp_is_current_action( bbp_get_topic_archive_slug() ) ) {
|
||||
$wp_query->bbp_is_single_user_topics = true;
|
||||
|
||||
// 'replies' action
|
||||
} elseif ( bp_is_current_action( bbp_get_reply_archive_slug() ) ) {
|
||||
$wp_query->bbp_is_single_user_replies = true;
|
||||
|
||||
// 'favorites' action
|
||||
} elseif ( bbp_is_favorites_active() && bp_is_current_action( bbp_get_user_favorites_slug() ) ) {
|
||||
$wp_query->bbp_is_single_user_favs = true;
|
||||
|
||||
// 'subscriptions' action
|
||||
} elseif ( bbp_is_subscriptions_active() && bp_is_current_action( bbp_get_user_subscriptions_slug() ) ) {
|
||||
$wp_query->bbp_is_single_user_subs = true;
|
||||
|
||||
// 'engagements' action
|
||||
} elseif ( bbp_is_engagements_active() && bp_is_current_action( bbp_get_user_engagements_slug() ) ) {
|
||||
$wp_query->bbp_is_single_user_engagements = true;
|
||||
}
|
||||
}
|
||||
|
||||
/** Private Methods *******************************************************/
|
||||
|
||||
/**
|
||||
* Private method used to concatenate user IDs and slugs into URLs
|
||||
*
|
||||
* @since 2.6.0 bbPress (r6803)
|
||||
*
|
||||
* @param int $user_id
|
||||
* @param string $slug
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function get_profile_url( $user_id = 0, $slug = '' ) {
|
||||
|
||||
// Do not filter if not on BuddyPress root blog
|
||||
if ( empty( $user_id ) || ! bp_is_root_blog() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Setup profile URL
|
||||
$url = array( bp_core_get_user_domain( $user_id ) );
|
||||
|
||||
// Maybe push slug to end of URL array
|
||||
if ( ! empty( $slug ) ) {
|
||||
array_push( $url, bbpress()->extend->buddypress->slug );
|
||||
array_push( $url, $slug );
|
||||
}
|
||||
|
||||
// Return
|
||||
return implode( '', array_map( 'trailingslashit', $url ) );
|
||||
}
|
||||
}
|
||||
endif;
|
||||
@@ -0,0 +1,244 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* bbPress BuddyPress Notifications
|
||||
*
|
||||
* @package bbPress
|
||||
* @subpackage BuddyPress
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
// Hooks
|
||||
add_filter( 'bp_notifications_get_registered_components', 'bbp_filter_notifications_get_registered_components', 10 );
|
||||
add_filter( 'bp_notifications_get_notifications_for_user', 'bbp_format_buddypress_notifications', 10, 8 );
|
||||
add_action( 'bbp_new_reply', 'bbp_buddypress_add_notification', 10, 7 );
|
||||
add_action( 'bbp_get_request', 'bbp_buddypress_mark_notifications', 1 );
|
||||
|
||||
/** BuddyPress Helpers ********************************************************/
|
||||
|
||||
/**
|
||||
* Filter registered notifications components, and add 'forums' to the queried
|
||||
* 'component_name' array.
|
||||
*
|
||||
* @since 2.6.0 bbPress (r5232)
|
||||
*
|
||||
* @see BP_Notifications_Notification::get()
|
||||
* @param array $component_names
|
||||
* @return array
|
||||
*/
|
||||
function bbp_filter_notifications_get_registered_components( $component_names = array() ) {
|
||||
|
||||
// Force $component_names to be an array
|
||||
if ( ! is_array( $component_names ) ) {
|
||||
$component_names = array();
|
||||
}
|
||||
|
||||
// Add 'forums' component to registered components array
|
||||
array_push( $component_names, bbp_get_component_name() );
|
||||
|
||||
// Return component's with 'forums' appended
|
||||
return $component_names;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the BuddyBar/Toolbar notifications
|
||||
*
|
||||
* @since 2.5.0 bbPress (r5155)
|
||||
*
|
||||
* @package bbPress
|
||||
*
|
||||
* @param string $content Component action. Deprecated. Do not do checks against this! Use
|
||||
* the 6th parameter instead - $component_action_name.
|
||||
* @param int $item_id Notification item ID.
|
||||
* @param int $secondary_item_id Notification secondary item ID.
|
||||
* @param int $action_item_count Number of notifications with the same action.
|
||||
* @param string $format Format of return. Either 'string' or 'object'.
|
||||
* @param string $component_action_name Canonical notification action.
|
||||
* @param string $component_name Notification component ID.
|
||||
* @param int $id Notification ID.
|
||||
*/
|
||||
function bbp_format_buddypress_notifications( $content, $item_id, $secondary_item_id, $action_item_count, $format, $component_action_name, $component_name, $id ) {
|
||||
|
||||
// Bail if not the notification action we are looking for
|
||||
if ( 0 !== strpos( $component_action_name, 'bbp_new_reply' ) ) {
|
||||
return $content;
|
||||
}
|
||||
|
||||
// New reply notifications
|
||||
$topic_id = bbp_get_reply_topic_id( $item_id );
|
||||
$topic_title = bbp_get_topic_title( $topic_id );
|
||||
$topic_link = wp_nonce_url(
|
||||
add_query_arg(
|
||||
array(
|
||||
'action' => 'bbp_mark_read',
|
||||
'topic_id' => $topic_id
|
||||
),
|
||||
bbp_get_reply_url( $item_id )
|
||||
),
|
||||
'bbp_mark_topic_' . $topic_id
|
||||
);
|
||||
|
||||
// Cast to int
|
||||
$action_item_count = (int) $action_item_count;
|
||||
|
||||
// Multiple
|
||||
if ( $action_item_count > 1 ) {
|
||||
$filter = 'bbp_multiple_new_subscription_notification';
|
||||
$text = sprintf( esc_html__( 'You have %1$d new replies to %2$s', 'bbpress' ), $action_item_count, $topic_title );
|
||||
|
||||
// Single
|
||||
} else {
|
||||
$filter = 'bbp_single_new_subscription_notification';
|
||||
$text = ! empty( $secondary_item_id )
|
||||
? sprintf( esc_html__( 'You have %1$d new reply to %2$s from %3$s', 'bbpress' ), $action_item_count, $topic_title, bp_core_get_user_displayname( $secondary_item_id ) )
|
||||
: sprintf( esc_html__( 'You have %1$d new reply to %2$s', 'bbpress' ), $action_item_count, $topic_title );
|
||||
}
|
||||
|
||||
// WordPress Toolbar
|
||||
if ( 'string' === $format ) {
|
||||
$return = apply_filters( $filter, '<a href="' . esc_url( $topic_link ) . '" title="' . esc_attr__( 'Topic Replies', 'bbpress' ) . '">' . esc_html( $text ) . '</a>', $action_item_count, $text, $topic_link );
|
||||
|
||||
// Deprecated BuddyBar
|
||||
} else {
|
||||
$return = apply_filters( $filter, array(
|
||||
'text' => $text,
|
||||
'link' => $topic_link
|
||||
), $topic_link, $action_item_count, $text, $topic_title );
|
||||
}
|
||||
|
||||
do_action( 'bbp_format_buddypress_notifications', $component_action_name, $item_id, $secondary_item_id, $action_item_count, $format, $component_action_name, $component_name, $id );
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hooked into the new reply function, this notification action is responsible
|
||||
* for notifying topic and hierarchical reply authors of topic replies.
|
||||
*
|
||||
* @since 2.5.0 bbPress (r5156)
|
||||
*
|
||||
* @param int $reply_id
|
||||
* @param int $topic_id
|
||||
* @param int $forum_id (not used)
|
||||
* @param array $anonymous_data (not used)
|
||||
* @param int $author_id
|
||||
* @param bool $is_edit Used to bail if this gets hooked to an edit action
|
||||
* @param int $reply_to
|
||||
*/
|
||||
function bbp_buddypress_add_notification( $reply_id = 0, $topic_id = 0, $forum_id = 0, $anonymous_data = array(), $author_id = 0, $is_edit = false, $reply_to = 0 ) {
|
||||
|
||||
// Bail if somehow this is hooked to an edit action
|
||||
if ( ! empty( $is_edit ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get author information
|
||||
$topic_author_id = bbp_get_topic_author_id( $topic_id );
|
||||
$secondary_item_id = $author_id;
|
||||
|
||||
// Hierarchical replies
|
||||
if ( ! empty( $reply_to ) ) {
|
||||
$reply_to_item_id = bbp_get_topic_author_id( $reply_to );
|
||||
}
|
||||
|
||||
// Get some reply information
|
||||
$args = array(
|
||||
'user_id' => $topic_author_id,
|
||||
'item_id' => $reply_id,
|
||||
'component_name' => bbp_get_component_name(),
|
||||
'component_action' => 'bbp_new_reply_' . $topic_id,
|
||||
'date_notified' => get_post( $reply_id )->post_date,
|
||||
);
|
||||
|
||||
// Notify the topic author if not the current reply author
|
||||
if ( $author_id !== $topic_author_id ) {
|
||||
$args['secondary_item_id'] = $secondary_item_id;
|
||||
|
||||
bp_notifications_add_notification( $args );
|
||||
}
|
||||
|
||||
// Notify the immediate reply author if not the current reply author
|
||||
if ( ! empty( $reply_to ) && ( $author_id !== $reply_to_item_id ) ) {
|
||||
$args['user_id'] = $reply_to_item_id;
|
||||
$args['secondary_item_id'] = $topic_author_id;
|
||||
|
||||
bp_notifications_add_notification( $args );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark notifications as read when reading a topic
|
||||
*
|
||||
* @since 2.5.0 bbPress (r5155)
|
||||
*
|
||||
* @return If not trying to mark a notification as read
|
||||
*/
|
||||
function bbp_buddypress_mark_notifications( $action = '' ) {
|
||||
|
||||
// Bail if no topic ID is passed
|
||||
if ( empty( $_GET['topic_id'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Bail if action is not for this function
|
||||
if ( 'bbp_mark_read' !== $action ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get required data
|
||||
$user_id = bp_loggedin_user_id();
|
||||
$topic_id = absint( $_GET['topic_id'] );
|
||||
|
||||
// By default, Redirect to this topic ID
|
||||
$redirect_id = $topic_id;
|
||||
|
||||
// Check nonce
|
||||
if ( ! bbp_verify_nonce_request( 'bbp_mark_topic_' . $topic_id ) ) {
|
||||
bbp_add_error( 'bbp_notification_topic_id', __( '<strong>Error</strong>: Are you sure you wanted to do that?', 'bbpress' ) );
|
||||
|
||||
// Check current user's ability to edit the user
|
||||
} elseif ( ! current_user_can( 'edit_user', $user_id ) ) {
|
||||
bbp_add_error( 'bbp_notification_permission', __( '<strong>Error</strong>: You do not have permission to mark notifications for that user.', 'bbpress' ) );
|
||||
}
|
||||
|
||||
// Bail if we have errors
|
||||
if ( ! bbp_has_errors() ) {
|
||||
|
||||
// Get these once
|
||||
$post_type = bbp_get_reply_post_type();
|
||||
$component = bbp_get_component_name();
|
||||
|
||||
// Attempt to clear notifications for this topic
|
||||
$marked = bp_notifications_mark_notifications_by_type( $user_id, $component, 'bbp_new_reply_' . $topic_id );
|
||||
|
||||
// Get all reply IDs for the topic
|
||||
$replies = bbp_get_all_child_ids( $topic_id, $post_type );
|
||||
|
||||
// If topic has replies
|
||||
if ( ! empty( $replies ) ) {
|
||||
|
||||
// Loop through each reply and attempt to mark it
|
||||
foreach ( $replies as $reply_id ) {
|
||||
|
||||
// Attempt to mark notification for this reply ID
|
||||
$marked = bp_notifications_mark_notifications_by_item_id( $user_id, $reply_id, $component, 'bbp_new_reply' );
|
||||
|
||||
// If marked, redirect to this reply ID
|
||||
if ( ! empty( $marked ) ) {
|
||||
$redirect_id = $reply_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Do additional subscriptions actions
|
||||
do_action( 'bbp_notifications_handler', $marked, $user_id, $topic_id, $action );
|
||||
}
|
||||
|
||||
// Redirect to the topic
|
||||
$redirect = bbp_get_reply_url( $redirect_id );
|
||||
|
||||
// Redirect
|
||||
bbp_redirect( $redirect );
|
||||
}
|
||||
5
wp-content/plugins/bbpress/includes/extend/index.php
Normal file
5
wp-content/plugins/bbpress/includes/extend/index.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Do not modify the files in this folder.
|
||||
*/
|
||||
Reference in New Issue
Block a user