-
-
Save imath/3fb1723697d4f8195d5f to your computer and use it in GitHub Desktop.
Author page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* BuddyPress Custom | |
* | |
* Activity & Blogs component activated. | |
*/ | |
// Exit if accessed directly | |
defined( 'ABSPATH' ) || exit; | |
// Set xProfile to be default component | |
define( 'BP_DEFAULT_COMPONENT', 'profile' ); | |
// Define the user's profile nav as first one | |
function imath_wp_profile_nav_position() { | |
if ( defined( 'BP_DEFAULT_COMPONENT' ) && 'profile' == BP_DEFAULT_COMPONENT ) { | |
buddypress()->bp_nav['profile']['position'] = 1; | |
} | |
} | |
add_action( 'bp_activity_setup_nav', 'imath_wp_profile_nav_position' ); | |
// Remove the admin nav if user is not a contributor | |
function imath_maybe_remove_activity_admin_nav( $wp_admin_nav = array() ) { | |
if ( ! bp_current_user_can( 'edit_posts' ) ) { | |
$wp_admin_nav = array(); | |
} | |
return $wp_admin_nav; | |
} | |
add_action( 'bp_activity_admin_nav', 'imath_maybe_remove_activity_admin_nav', 10, 1 ); | |
add_action( 'bp_xprofile_admin_nav', 'imath_maybe_remove_activity_admin_nav', 10, 1 ); | |
// Only activate members, activity and blogs components at install | |
function imath_restrict_default_component( $default = array() ) { | |
return array( | |
'members' => 1, | |
'activity' => 1, | |
'blogs' => 1, | |
); | |
} | |
add_filter( 'bp_new_install_default_components', 'imath_restrict_default_component', 10, 1 ); | |
// Disable BuddyPress directories from displaying | |
function imath_disable_directories( $bool, $component = '' ) { | |
if ( 'register' != $component && 'activate' != $component && ! bp_is_user() ) { | |
return false; | |
} | |
if ( bp_displayed_user_id() && ! user_can( bp_displayed_user_id(), 'edit_posts' ) ) { | |
return false; | |
} | |
return $bool; | |
} | |
add_filter( 'bp_is_current_component', 'imath_disable_directories', 10, 2 ); | |
// Exclude some directory pages from WordPress pages listing | |
function imath_exclude_directory_pages( $pages = array() ) { | |
$exclude = array( buddypress()->pages->members->id ); | |
if ( bp_is_active( 'activity' ) ) { | |
$exclude[] = buddypress()->pages->activity->id; | |
} | |
$pages = array_merge( $pages, $exclude ); | |
return $pages; | |
} | |
add_filter( 'bp_core_exclude_pages', 'imath_exclude_directory_pages', 10, 1 ); | |
// Make sure only author's profile will be displayed | |
function imath_disable_buddypress_front_end_parts() { | |
if ( is_buddypress() && ! bp_is_register_page() && ! bp_is_activation_page() && ! bp_is_user() ) { | |
bp_do_404(); | |
return; | |
} | |
if ( bp_displayed_user_id() && ! user_can( bp_displayed_user_id(), 'edit_posts' ) ) { | |
bp_do_404(); | |
return; | |
} | |
} | |
add_action( 'bp_actions', 'imath_disable_buddypress_front_end_parts', 1 ); | |
/** | |
* In wp-admin/extended profile remove not needed metaboxes for regular users | |
*/ | |
function imath_disable_members_admin_major_metabox() { | |
global $wp_meta_boxes; | |
if ( bp_is_active( 'xprofile' ) && bp_current_user_can( 'edit_posts' ) ) { | |
return; | |
} | |
// Only keep stat metabox for regular users | |
if ( ! empty( $wp_meta_boxes['profile_page_bp-profile-edit'] ) ) { | |
foreach ( $wp_meta_boxes['profile_page_bp-profile-edit'] as $meta_box_context => $meta_box_priorities ) { | |
foreach ( $meta_box_priorities as $priority => $meta_box ) { | |
foreach( $meta_box as $meta_box_id => $meta_box_content ) { | |
if ( 'bp_members_admin_user_stats' !== $meta_box_id ) { | |
remove_meta_box( $meta_box_id, get_current_screen(), $meta_box_context ); | |
} | |
} | |
} | |
} | |
} | |
} | |
add_action( 'bp_members_admin_user_metaboxes', 'imath_disable_members_admin_major_metabox' ); | |
// Disable Activity form | |
function imath_disable_activity_form( $templates, $slug, $name ) { | |
if ( bp_is_user() && 'activity/post-form' === $slug ) { | |
$templates = false; | |
} | |
return $templates; | |
} | |
add_filter( 'bp_get_template_part', 'imath_disable_activity_form', 10, 3 ); | |
// Disable mentions | |
add_filter( 'bp_activity_do_mentions', '__return_false' ); | |
// Disable favorites | |
add_filter( 'bp_activity_can_favorite', '__return_false' ); | |
// Remove Activity update actions | |
function imath_restrict_activity_actions( $action_params = array(), $component_id = '' ) { | |
if ( buddypress()->activity->id === $component_id ) { | |
$action_params['context'] = array_diff( $action_params['context'], array( 'member' ) ); | |
} | |
return $action_params; | |
} | |
add_filter( 'bp_activity_set_action', 'imath_restrict_activity_actions', 10, 2 ); | |
// Edit the author link | |
function imath_filter_author_link( $link = '', $author_id = 0, $author_nicename = '' ) { | |
if( ! empty( $author_id ) ) { | |
$link = bp_core_get_userlink( $author_id, false, true ); | |
} | |
return $link; | |
} | |
add_filter( 'author_link', 'imath_filter_author_link', 10, 3 ); | |
// Remove member's link if not a contributor | |
function imath_get_user_domain( $domain = '', $user_id = 0 ) { | |
if ( ! user_can( $user_id, 'edit_posts' ) ) { | |
return false; | |
} | |
return $domain; | |
} | |
add_filter( 'bp_core_get_user_domain', 'imath_get_user_domain', 10, 2 ); | |
// Keep WordPress admin profile if not a contributor | |
function imath_edit_profile_url( $profile_link = '', $url = '', $user_id = 0 ) { | |
if ( ! user_can( $user_id, 'edit_posts' ) ) { | |
$profile_link = $url; | |
} | |
return $profile_link; | |
} | |
add_filter( 'bp_members_edit_profile_url', 'imath_edit_profile_url', 10, 3 ); | |
function imath_add_author_descripton() { | |
if ( ! bp_is_active( 'xprofile' ) ) { | |
return; | |
} | |
// Display the regular WordPress description if xProfile is active | |
the_author_meta( 'description', bp_displayed_user_id() ); | |
// Remove the link to member's directory search for xProfile field data | |
remove_filter( 'bp_get_the_profile_field_value', 'xprofile_filter_link_profile_data', 9, 2 ); | |
} | |
add_action( 'bp_profile_header_meta', 'imath_add_author_descripton' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment