Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php defined( 'ABSPATH' ) or die( header( 'HTTP/1.0 403 Forbidden' ) );
class BP_Me_Component extends BP_Component
{
public function __construct()
{
global $bp;
parent::start( 'me', __( 'Me', 'buddypress-me' ) );
$bp->active_components[$this->id] = '1';
if ( ! is_admin() ) {
add_filter( 'bp_members_edit_profile_url', array( $this, 'bp_members_edit_profile_url' ), 12, 4 );
}
add_filter( 'bp_me_url', array( $this, 'url' ) );
}
public function setup_globals( $args = array() )
{
parent::setup_globals( array(
'slug' => 'me',
'root_slug' => 'me',
'has_directory' => TRUE,
) );
if ( ! bp_is_current_component( $this->id ) )
return;
$this->current_action = bp_current_action();
if ( empty( $this->current_action ) )
$this->current_action = 'profile';
if ( 'logout' == $this->current_action && ! bp_loggedin_user_id() )
bp_core_redirect( bp_get_root_domain() );
if ( ! bp_loggedin_user_id() )
bp_core_redirect( wp_login_url( Utilities::currentURL() ) );
$actions = apply_filters( 'bp_me_actions', array(
'profile' => array( $this, 'me_action_profile' ),
'settings' => array( $this, 'me_action_settings' ),
'edit' => array( $this, 'me_action_edit' ),
'avatar' => array( $this, 'me_action_avatar' ),
'logout' => array( $this, 'me_action_logout' ),
) );
if ( array_key_exists( $this->current_action, $actions )
&& is_callable( $actions[$this->current_action] ) )
call_user_func_array( $actions[$this->current_action], array( bp_action_variables() ) );
$this->me_action_profile();
}
public function me_action_profile( $vars = FALSE )
{
bp_core_redirect( bp_get_loggedin_user_link() );
die();
}
public function me_action_settings( $vars = FALSE )
{
global $bp;
if ( bp_is_active( 'settings' ) )
bp_core_redirect( bp_loggedin_user_domain().bp_get_settings_slug() );
$this->me_action_profile();
}
public function me_action_edit( $vars = FALSE )
{
global $bp;
if ( bp_is_active( 'xprofile' ) )
bp_core_redirect( bp_loggedin_user_domain().$bp->profile->slug.'/edit' );
$this->me_action_profile();
}
public function me_action_avatar( $vars = FALSE )
{
global $bp;
if ( ! (int) $bp->site_options['bp-disable-avatar-uploads'] )
bp_core_redirect( bp_loggedin_user_domain().$bp->profile->slug.'/change-avatar/' );
$this->me_action_profile();
}
public function me_action_logout( $vars = FALSE )
{
$redirect = bp_get_loggedin_user_link();
wp_logout();
bp_core_redirect( $redirect );
exit();
}
public function url( $link = '' )
{
return trailingslashit( bp_get_root_domain().'/'.$this->root_slug.'/'.$link );
}
public function bp_members_edit_profile_url( $profile_link, $url, $user_id, $scheme )
{
return $this->url( 'edit' );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.