Skip to content

Instantly share code, notes, and snippets.

@modemlooper
Created December 12, 2014 18:52
Show Gist options
  • Select an option

  • Save modemlooper/92cce37e1bb16409fda3 to your computer and use it in GitHub Desktop.

Select an option

Save modemlooper/92cce37e1bb16409fda3 to your computer and use it in GitHub Desktop.
<?php
/*
*
* place BP customizations in this here
*
*/
define( 'BP_AVATAR_THUMB_WIDTH', 100 );
define( 'BP_AVATAR_THUMB_HEIGHT', 100 );
define( 'BP_AVATAR_FULL_WIDTH', 250 );
define( 'BP_AVATAR_FULL_HEIGHT', 250 );
define( 'BP_DEFAULT_COMPONENT', 'profile');
/**
* nps_change_profile_tab_order function.
*
* @access public
* @return void
*/
function nps_change_profile_tab_order() {
global $bp;
if( bp_is_user() )
$user_domain = bp_displayed_user_domain ( );
else
$user_domain = bp_loggedin_user_domain ( );
$count = friends_get_total_friend_count();
$class = ( 0 === $count ) ? 'no-count' : 'count';
$bp->bp_nav['profile']['position'] = 10;
$bp->bp_nav['activity']['position'] = 20;
$bp->bp_nav['sites'] = false;
$bp->bp_nav['blogs'] = false;
$bp->bp_nav['invite-anyone'] = false;
$bp->bp_nav['gallery']['name'] = 'Media';
$bp->bp_nav['friends']['name'] = 'Colleagues';
$bp->bp_nav['colleagues']['name'] = sprintf( __( 'Colleagues <span class="%s">%s</span>', 'buddypress' ), esc_attr( $class ), number_format_i18n( $count ) );
$bp->bp_nav['activity-friends']['name'] = 'My Colleagues';
bp_core_new_subnav_item( array(
'name' => __( 'Media', 'buddypress' ),
'slug' => 'media',
'parent_url' => trailingslashit( $user_domain . 'activity' ),
'parent_slug' => 'activity',
'screen_function' => 'bp_activity_screen_media',
'position' => 50,
'item_css_id' => 'activity-media'
)
);
}
add_action( 'bp_setup_nav', 'nps_change_profile_tab_order', 999 );
/**
* nps_bp_sidebar_title function.
*
* @access public
* @return void
*/
function nps_bp_sidebar_title() {
echo '<h3 class="bp-sidebar-title">' . __( 'My Commons', 'nps' ) . '</h3>';
}
/**
* nps_bp_sidebar_small_menu function.
*
* @access public
* @return void
*/
function nps_bp_sidebar_small_menu() {
$output = '<ul class="bp-small-menu">';
$output .= '<li class="small-menu-item">' . __( 'FAQs', 'nps' ) . '</li>';
$output .= '<li class="small-menu-item">' . __( 'Take a Tour', 'nps' ) . '</li>';
$output .= '</ul>';
echo $output;
}
/**
* nps_do_bp_sidebar_header function.
*
* @access public
* @return void
*/
function nps_do_bp_sidebar_header() {
nps_bp_sidebar_title();
nps_bp_sidebar_small_menu();
get_search_form();
}
//add_action( 'bp_before_member_header', 'nps_do_bp_sidebar_header' );
/**
* nps_attach_file_button function.
*
* @access public
* @return void
*/
function nps_attach_file_button() {
return '<span class="icon_paperclip"></span><span class="screen-reader">Attach File</span>';
}
add_action( 'rtmedia_attach_file_message', 'nps_attach_file_button' );
/**
* nps_add_video_above_registration function.
*
* adds video above registration form
*
* @access public
* @return void
*/
function nps_add_video_above_registration() {
?>
<div class="registration-video">
<?php
$url = esc_html( cmb2_get_option( 'nps_options', 'registration_video_url' ) );
$embed_code = wp_oembed_get( $url, array( 'width' => 1090, 'height' => 613 ) );
echo $embed_code;
?>
</div>
<?php
}
add_action( 'bp_before_register_page', 'nps_add_video_above_registration' );
/**
* nps_add_content_registration_sidebar function.
*
* adds cmb registration options ro register page sidebar
*
* @access public
* @return void
*/
function nps_add_content_registration_sidebar(){
?>
<h4 class="slide-title"><?php echo esc_html( cmb2_get_option( 'nps_options', 'registration_title' ) ); ?></h4>
<p class="slide-title"><?php echo esc_html( cmb2_get_option( 'nps_options', 'registation_box_content' ) ); ?></p>
<?php
}
add_action( 'bp_register_sidebar', 'nps_add_content_registration_sidebar' );
/**
* nps_bp_activities_filter function.
*
* filters activity to only updates and images
*
* @access public
* @param $activity
* @return $activity
*/
function nps_bp_activities_filter( $activity ) {
if( bp_is_activity_component() ){
$activity['object'] = 'gallery,activity';
}
return $activity;
}
if ( empty( $qs ) && empty( $_POST ) ) {
add_filter( 'bp_after_has_activities_parse_args', 'nps_bp_activities_filter' );
}
/**
* nps_redirect_to_register function.
*
* @access public
* @return register slug
*/
function nps_redirect_to_register() {
return get_option('siteurl') . '/' . BP_REGISTER_SLUG;
}
add_filter( 'pbp_redirect_login_page', 'nps_redirect_to_register' );
/**
* This is the custom filter to create links
*/
function nps_xprofile_filter_link_profile_data( $field_value, $field_type = 'textbox' ) {
// Access the field you are going to display value.
global $field;
// In this array you write the ids of the fields you want to hide the link.
$excluded_field_ids = array(1);
// If the id of this $field is in the array, we return the value only and not the link.
if (in_array($field->id, $excluded_field_ids))
return $field_value;
if ( 'datebox' == $field_type )
return $field_value;
if ( !strpos( $field_value, ',' ) && ( count( explode( ' ', $field_value ) ) > 5 ) )
return $field_value;
$values = explode( ',', $field_value );
if ( !empty( $values ) ) {
foreach ( (array) $values as $value ) {
$value = trim( $value );
// If the value is a URL, skip it and just make it clickable.
if ( preg_match( '@(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)@', $value ) ) {
$new_values[] = make_clickable( $value );
// Is not clickable
} else {
// More than 5 spaces
if ( count( explode( ' ', $value ) ) > 5 ) {
$new_values[] = $value;
// Less than 5 spaces
} else {
$search_url = add_query_arg( array( 's' => urlencode( $value ) ), bp_get_members_directory_permalink() );
$new_values[] = '<a href="' . $search_url . '" rel="nofollow">' . $value . '</a>';
}
}
}
$values = implode( ', ', $new_values );
}
return $values;
}
/**
* We remove the buddypress filter and add our custom filter.
*/
function nps_remove_xprofile_links() {
// Remove the old filter.
remove_filter( 'bp_get_the_profile_field_value', 'xprofile_filter_link_profile_data', 9, 2 );
// Add your custom filter.
add_filter( 'bp_get_the_profile_field_value', 'nps_xprofile_filter_link_profile_data', 9, 2);
}
add_action('bp_setup_globals', 'nps_remove_xprofile_links');
/**
* Remove the Notifications from the nav if we're not on our own profile
*/
function nps_remove_notifications_from_other_profiles() {
if ( bp_displayed_user_id() !== bp_loggedin_user_id() ) {
error_log( bp_core_remove_nav_item( 'notifications' ) );
}
}
add_filter( 'bp_setup_nav', 'nps_remove_notifications_from_other_profiles', 15 );
/**
* activity screen for media.
*/
function bp_activity_screen_media(){
do_action( 'bp_activity_screen_my_media' );
bp_core_load_template( apply_filters( 'bp_activity_template_my_media', 'members/single/home' ) );
add_filter( 'bp_after_has_activities_parse_args', 'filtering_activity_default' );
}
/**
* mpp_media_upload activity filter
*/
function filtering_activity_default( $retval ) {
$retval['action'] = 'mpp_media_upload';
return $retval;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment