Commit 9800a0b0 authored by johnjamesjacoby's avatar johnjamesjacoby

Bump Swifter to 2.0.0

* Remove BuddyPress & bbPress support
* Bump versions
* General cleanup
parent 7a0e9124
<?php
/**
* bbPress Common Filters & Functions
*
* @package Swifter
* @subpackage BBP_Theme_Compat
* @since Swifter (1.0.0)
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
// Remove core theme function lookup
remove_action( 'bbp_after_setup_theme', 'bbp_load_theme_functions', 10 );
// Remove core template notices
remove_action( 'bbp_template_notices', 'bbp_template_notices' );
remove_action( 'bbp_template_notices', 'bbp_notice_edit_user_success' );
remove_action( 'bbp_template_notices', 'bbp_notice_edit_user_pending_email' );
remove_action( 'bbp_template_notices', 'bbp_notice_edit_user_is_super_admin', 2 );
function swifter_bbp_template_notices() {
// Bail if no notices or errors
if ( !bbp_has_errors() ) {
return;
}
// Define local variable(s)
$errors = $messages = array();
// Get bbPress
$bbp = bbpress();
// Loop through notices
foreach ( $bbp->errors->get_error_codes() as $code ) {
// Get notice severity
$severity = $bbp->errors->get_error_data( $code );
// Loop through notices and separate errors from messages
foreach ( $bbp->errors->get_error_messages( $code ) as $error ) {
if ( 'message' === $severity ) {
$messages[] = $error;
} else {
$errors[] = $error;
}
}
}
// Display errors first...
if ( ! empty( $errors ) ) : ?>
<div class="alert alert-danger" role="alert" tabindex="-1">
<?php echo implode( '<br>', $errors ); ?>
</div>
<?php endif;
// ...and messages last
if ( ! empty( $messages ) ) : ?>
<div class="alert alert-info">
<?php echo implode( '<br>', $messages ); ?>
</div>
<?php endif;
}
add_action( 'bbp_template_notices', 'swifter_bbp_template_notices' );
function swifter_bbp_breadcrumb() {
return array(
// HTML
'before' => '<ol class="breadcrumb">',
'after' => '</ol>',
// Separator
'sep' => '',
'pad_sep' => 0,
'sep_before' => '',
'sep_after' => '',
// Crumbs
'crumb_before' => '<li>',
'crumb_after' => '</li>'
);
}
add_filter( 'bbp_before_get_breadcrumb_parse_args', 'swifter_bbp_breadcrumb' );
function swifter_prepend_dropdown_divider( $link = '' ) {
return '<li role="presentation" class="divider"></li>' . $link;
}
add_filter( 'bbp_get_topic_trash_link', 'swifter_prepend_dropdown_divider' );
add_filter( 'bbp_get_reply_trash_link', 'swifter_prepend_dropdown_divider' );
add_filter( 'bbp_get_topic_stick_link', 'swifter_prepend_dropdown_divider' );
/**
* Output the Groups directory search form.
*/
function swifter_directory_forums_search_form() {
echo swifter_get_directory_forums_search_form();
}
function swifter_get_directory_forums_search_form() {
$search_value = ! empty( $_REQUEST[ 's' ] )
? stripslashes( $_REQUEST[ 's' ] )
: esc_html__( 'Search Forums&hellip;', 'swifter' );
ob_start(); ?>
<form action="<?php bbp_search_url(); ?>" method="get" id="search-forums-form" class="navbar-form navbar-right">
<div class="form-group input-group">
<input name="s" id="forums_search" type="text" class="form-control" placeholder="<?php echo esc_attr( $search_value ); ?>">
<span class="input-group-btn">
<button type="submit" id="forums_search_submit" class="btn btn-default">
<span class="dashicons dashicons-search"></span>
</button>
</span>
</div>
</form>
<?php return ob_get_clean();
}
<?php
/**
* bbPress Forums Filters & Functions
*
* @package Swifter
* @subpackage BBP_Theme_Compat
* @since Swifter (1.0.0)
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/**
* Filter forum descriptions and wrap them in Bootstrap alerts
*
* @since Flox (1.0.0)
* @return array
*/
function swifter_bbp_forum_description() {
return array(
'before' => '<div class="alert alert-info">',
'after' => '</div>',
'size' => 20
);
}
add_filter( 'bbp_before_get_single_forum_description_parse_args', 'swifter_bbp_forum_description' );
<?php
/**
* bbPress Replies Filters & Functions
*
* @package Swifter
* @subpackage BBP_Theme_Compat
* @since Swifter (1.0.0)
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/**
* Output admin links used for topics & replies
*
* @since Swifter (1.0.0)
* @return string
*/
function swifter_reply_admin_links() {
return bbp_reply_admin_links( array(
'sep' => '',
'before' => '<div class="dropdown dropdown-right pull-right">
<button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" aria-expanded="false">
#' . bbp_get_reply_id() . '
</button>
<ul class="dropdown-menu dropdown-menu-right" role="menu" aria-labelledby="replyMenu1">
<li role="presentation"><a href="' . bbp_get_reply_url() . '">' . __( 'Permalink', 'swifter' ) . '</a></li><li role="presentation" class="divider"></li>',
'after' => '</ul></div>',
'link_before' => '<li role="presentation">',
'link_after' => '</li>'
) );
}
/**
* Add Bootstrap class to reply-to dropdown
*
* @since Swifter (1.0.0)
*
* @param string $dropdown
* @return string
*/
function swifter_bbp_get_reply_to_dropdown( $dropdown = '' ) {
return str_replace( 'bbp_dropdown', 'form-control', $dropdown );
}
add_filter( 'bbp_get_reply_to_dropdown', 'swifter_bbp_get_reply_to_dropdown' );
This diff is collapsed.
<?php
/**
* bbPress Topics Filters & Functions
*
* @package Swifter
* @subpackage BBP_Theme_Compat
* @since Swifter (1.0.0)
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/**
* Filter topic descriptions and wrap them in Bootstrap alerts
*
* @since Swifter (1.0.0)
* @return array
*/
function swifter_bbp_topic_description() {
return array(
'before' => '<div class="alert alert-info">',
'after' => '</div>',
'size' => 20
);
}
add_filter( 'bbp_before_get_single_topic_description_parse_args', 'swifter_bbp_topic_description' );
/**
* Filter sticky links and use more intuitive text
*
* @since Swifter (1.0.0)
* @return array
*/
function swifter_get_topic_stick_link_args( $args = array() ) {
$args['stick_text'] = __( 'Stick to Forum', 'swifter' );
$args['super_text'] = __( 'Stick to Front', 'swifter' );
return $args;
}
add_filter( 'bbp_before_get_topic_stick_link_parse_args', 'swifter_get_topic_stick_link_args' );
<?php
/**
* bbPress Users Functions
*
* @package Swifter
* @subpackage BBP_Theme_Compat
* @since Swifter (1.0.0)
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/**
* Drop down for selecting the user's display name
*/
function swifter_edit_user_display_name() {
$bbp = bbpress();
$public_display = array();
$public_display['display_username'] = $bbp->displayed_user->user_login;
if ( ! empty( $bbp->displayed_user->nickname ) ) {
$public_display['display_nickname'] = $bbp->displayed_user->nickname;
}
if ( ! empty( $bbp->displayed_user->first_name ) ) {
$public_display['display_firstname'] = $bbp->displayed_user->first_name;
}
if ( ! empty( $bbp->displayed_user->last_name ) ) {
$public_display['display_lastname'] = $bbp->displayed_user->last_name;
}
if ( ! empty( $bbp->displayed_user->first_name ) && ! empty( $bbp->displayed_user->last_name ) ) {
$public_display['display_firstlast'] = $bbp->displayed_user->first_name . ' ' . $bbp->displayed_user->last_name;
$public_display['display_lastfirst'] = $bbp->displayed_user->last_name . ' ' . $bbp->displayed_user->first_name;
}
// Only add this if it isn't duplicated elsewhere
if ( ! in_array( $bbp->displayed_user->display_name, $public_display ) ) {
$public_display = array( 'display_displayname' => $bbp->displayed_user->display_name ) + $public_display;
}
$public_display = array_map( 'trim', $public_display );
$public_display = array_unique( $public_display ); ?>
<select name="display_name" id="display_name" class="form-control">
<?php foreach ( $public_display as $id => $item ) : ?>
<option id="<?php echo $id; ?>" value="<?php echo esc_attr( $item ); ?>"<?php selected( $bbp->displayed_user->display_name, $item ); ?>><?php echo $item; ?></option>
<?php endforeach; ?>
</select>
<?php
}
/**
* Output blog role selector (for user edit)
*
* @since Swifter (1.0.0)
*/
function swifter_edit_user_blog_role() {
// Return if no user is being edited
if ( ! bbp_is_single_user_edit() ) {
return;
}
// Get users current blog role
$user_role = bbp_get_user_blog_role( bbp_get_displayed_user_id() );
// Get the blog roles
$blog_roles = bbp_get_blog_roles(); ?>
<select name="role" id="role" class="form-control">
<option value=""><?php esc_html_e( '&mdash; No role for this site &mdash;', 'swifter' ); ?></option>
<?php foreach ( $blog_roles as $role => $details ) : ?>
<option <?php selected( $user_role, $role ); ?> value="<?php echo esc_attr( $role ); ?>"><?php echo translate_user_role( $details['name'] ); ?></option>
<?php endforeach; ?>
</select>
<?php
}
/**
* Output forum role selector (for user edit)
*
* @since Swifter (1.0.0)
*/
function swifter_edit_user_forums_role() {
// Return if no user is being edited
if ( ! bbp_is_single_user_edit() ) {
return;
}
// Get the user's current forum role
$user_role = bbp_get_user_role( bbp_get_displayed_user_id() );
// Get the folum roles
$dynamic_roles = bbp_get_dynamic_roles();
// Only keymasters can set other keymasters
if ( ! bbp_is_user_keymaster() ) {
unset( $dynamic_roles[ bbp_get_keymaster_role() ] );
} ?>
<select name="bbp-forums-role" id="bbp-forums-role" class="form-control">
<option value=""><?php esc_html_e( '&mdash; No role for these forums &mdash;', 'swifter' ); ?></option>
<?php foreach ( $dynamic_roles as $role => $details ) : ?>
<option <?php selected( $user_role, $role ); ?> value="<?php echo esc_attr( $role ); ?>"><?php echo translate_user_role( $details['name'] ); ?></option>
<?php endforeach; ?>
</select>
<?php
}
<?php
/**
* BuddyPress Activity Functions
*
* @package Swifter
* @subpackage BP_Theme_Compat
* @since Swifter (1.0.0)
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
// No activity wrappers
add_filter( 'bp_activity_recurse_comments_start_ul', '__return_false' );
add_filter( 'bp_activity_recurse_comments_end_ul', '__return_false' );
remove_filter( 'bp_get_activity_action', 'wpautop' );
/**
* Filter the activity action and manipulate the content a bit
*
* @global object $activities_template
* @param string $action
* @return string
*/
function swifter_activity_filter_action( $action = '' ) {
global $activities_template;
// Bail if in wp-admin
if ( is_admin() ) {
return $action;
}
$date = isset( $activities_template->activity->date_recorded )
? $activities_template->activity->date_recorded
: $activities_template->activity->current_comment->date_recorded;
$date_recorded = bp_format_time( strtotime( $date ) );
$new_action = str_replace( 'title="' . esc_attr__( 'View Discussion', 'swifter' ) . '"', '', $action );
$new_action = str_replace( '</span>', '</small>', $action );
$new_action = str_replace( 'span class="time-since"', 'small class="time-since pull-right" data-toggle="tooltip" data-placement="top" title="' . $date_recorded . '"', $new_action );
return $new_action;
}
add_filter( 'bp_get_activity_action', 'swifter_activity_filter_action' );
/**
* Filter the activity permalink and naipulate the string output
*
* @param string $action
* @return string
*/
function swifter_activity_filter_permalink( $action = '' ) {
// Bail if in wp-admin
if ( is_admin() ) {
return $action;
}
return str_replace( 'title="' . esc_attr__( 'View Discussion', 'swifter' ) . '"', '', $action );
}
add_filter( 'bp_activity_permalink', 'swifter_activity_filter_permalink' );
/**
* Get available filters depending on the scope.
*
* @param string $context The current context. 'activity', 'member',
* 'member_groups', 'group'
* @return string HTML for <option> values.
*/
function swifter_activity_show_filters( $context = '' ) {
// Set default context based on current page
if ( empty( $context ) ) {
// On member pages, default to 'member', unless this
// is a user's Groups activity
if ( bp_is_user() ) {
if ( bp_is_active( 'groups' ) && bp_is_current_action( bp_get_groups_slug() ) ) {
$context = 'member_groups';
} else {
$context = 'member';
}
// On individual group pages, default to 'group'
} elseif ( bp_is_active( 'groups' ) && bp_is_group() ) {
$context = 'group';
// 'activity' everywhere else
} else {
$context = 'activity';
}
}
$filters = array();
// Walk through the registered actions, and prepare an the
// select box options.
foreach ( bp_activity_get_actions() as $actions ) {
foreach ( $actions as $action ) {
if ( !in_array( $context, ( array ) $action[ 'context' ] ) ) {
continue;
}
// Friends activity collapses two filters into one
if ( in_array( $action[ 'key' ], array( 'friendship_accepted', 'friendship_created' ) ) ) {
$action[ 'key' ] = 'friendship_accepted,friendship_created';
}
$filters[ $action[ 'key' ] ] = $action[ 'label' ];
}
}
/**
* Filters the options available in the activity filter dropdown.
*
* @since Swifter (1.0.0)
*
* @param array $filters Array of filter options for the given context, in the following format: $option_value => $option_name.
* @param string $context Context for the filter. 'activity', 'member', 'member_groups', 'group'.
*/
$filters = apply_filters( 'bp_get_activity_show_filters_options', $filters, $context );
// Build the options output
$output = '';
if ( ! empty( $filters ) ) {
foreach ( $filters as $value => $filter ) {
$output .= '<li role="presentation"><a role="menuitem" data-value="' . esc_html( $value ) . '" tabindex="-1" href="#' . esc_attr( $value ) . '">' . esc_html( $filter ) . '</a></li>' . "\n";
}
}
echo $output;
}
This diff is collapsed.
<?php
/**
* BuddyPress Avatar functions
*
* @package Swifter
* @subpackage BP_Theme_Compat
* @since Swifter (1.0.0)
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/**
* Filter avatars and make rounded
*
* @since Swifter (1.0.0)
*
* @param string $class
* @return string
*/
function swifter_rounded_avatars( $class = '' ) {
return $class . ' img-rounded';
}
add_filter( 'bp_core_avatar_class', 'swifter_rounded_avatars' );
This diff is collapsed.
<?php
/**
* BuddyPress Common Filters & Functions
*
* @package Swifter
* @subpackage BP_Theme_Compat
* @since Swifter (1.0.0)
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
// No new avatar UI for now
remove_action( 'bp_enqueue_scripts', 'bp_core_avatar_scripts' );
// Remove core theme function lookup
remove_action( 'bp_after_setup_theme', 'bp_load_theme_functions', 1 );
/** Buttons *******************************************************************/
add_filter( 'bp_get_activity_delete_link', function( $link = '' ) {
return str_replace( 'button', 'button btn btn-default', $link );
}, 10 );
add_filter( 'bp_get_group_create_button', function( $button_args ) {
$button_args[ 'link_class' ] .= '';
return $button_args;
} );
add_filter( 'bp_get_blog_create_button', function( $button_args ) {
$button_args[ 'link_class' ] .= ' btn btn-default btn-success';
return $button_args;
} );
add_filter( 'bp_get_blogs_visit_blog_button', function( $button ) {
$button[ 'link_class' ] .= ' btn btn-sm btn-primary';
return $button;
});
add_filter( 'bp_get_send_message_button_args', function( $args ) {
$args[ 'link_class' ] .= ' btn btn-sm btn-primary';
return $args;
} );
add_filter( 'bp_get_send_public_message_button', function( $args ) {
$args[ 'link_class' ] .= ' btn btn-sm btn-primary';
return $args;
} );
add_filter( 'bp_get_group_join_button', function( $button ) {
global $groups_template;
$group = & $groups_template->group;
switch ( $group->status ) {
case 'public' :
if ( $group->is_member ) :
$button[ 'link_class' ] .= ' btn btn-sm btn-warning';
else :
$button[ 'link_class' ] .= ' btn btn-sm btn-primary';
endif;
break;
case 'private' :
if ( $group->is_pending || $group->is_invited ) :
$button[ 'link_class' ] .= ' btn btn-sm btn-success'; // this colour and others need review
endif;
default:
$button[ 'link_class' ] .= ' btn btn-sm btn-primary';
}