예제 #1
0
/**
 * Adds the User Admin top-level menu to user pages
 *
 * @package BuddyPress
 * @since 1.5
 */
function bp_members_admin_bar_user_admin_menu()
{
    global $bp, $wp_admin_bar;
    // Only show if viewing a user
    if (!bp_is_user()) {
        return false;
    }
    // Don't show this menu to non site admins or if you're viewing your own profile
    if (!current_user_can('edit_users') || bp_is_my_profile()) {
        return false;
    }
    // User avatar
    $avatar = bp_core_fetch_avatar(array('item_id' => $bp->displayed_user->id, 'email' => $bp->displayed_user->userdata->user_email, 'width' => 16, 'height' => 16));
    // Unique ID for the 'My Account' menu
    $bp->user_admin_menu_id = !empty($avatar) ? 'user-admin-with-avatar' : 'user-admin';
    // Add the top-level User Admin button
    $wp_admin_bar->add_menu(array('id' => $bp->user_admin_menu_id, 'title' => $avatar . bp_get_displayed_user_fullname(), 'href' => bp_displayed_user_domain()));
    // User Admin > Edit this user's profile
    $wp_admin_bar->add_menu(array('parent' => $bp->user_admin_menu_id, 'id' => 'edit-profile', 'title' => __("Edit Profile", 'buddypress'), 'href' => bp_get_members_component_link('profile', 'edit')));
    // User Admin > Edit this user's avatar
    $wp_admin_bar->add_menu(array('parent' => $bp->user_admin_menu_id, 'id' => 'change-avatar', 'title' => __("Edit Avatar", 'buddypress'), 'href' => bp_get_members_component_link('profile', 'change-avatar')));
    // User Admin > Spam/unspam
    if (!bp_core_is_user_spammer(bp_displayed_user_id())) {
        $wp_admin_bar->add_menu(array('parent' => $bp->user_admin_menu_id, 'id' => 'spam-user', 'title' => __('Mark as Spammer', 'buddypress'), 'href' => wp_nonce_url(bp_displayed_user_domain() . 'admin/mark-spammer/', 'mark-unmark-spammer'), 'meta' => array('onclick' => 'confirm(" ' . __('Are you sure you want to mark this user as a spammer?', 'buddypress') . '");')));
    } else {
        $wp_admin_bar->add_menu(array('parent' => $bp->user_admin_menu_id, 'id' => 'unspam-user', 'title' => __('Not a Spammer', 'buddypress'), 'href' => wp_nonce_url(bp_displayed_user_domain() . 'admin/unmark-spammer/', 'mark-unmark-spammer'), 'meta' => array('onclick' => 'confirm(" ' . __('Are you sure you want to mark this user as not a spammer?', 'buddypress') . '");')));
    }
    // User Admin > Delete Account
    $wp_admin_bar->add_menu(array('parent' => $bp->user_admin_menu_id, 'id' => 'delete-user', 'title' => __('Delete Account', 'buddypress'), 'href' => wp_nonce_url(bp_displayed_user_domain() . 'admin/delete-user/', 'delete-user'), 'meta' => array('onclick' => 'confirm(" ' . __("Are you sure you want to delete this user's account?", 'buddypress') . '");')));
}
예제 #2
0
 /**
  * Set up navigation.
  *
  * @param array $main_nav Array of main nav items.
  * @param array $sub_nav  Array of sub nav items.
  */
 public function setup_nav($main_nav = array(), $sub_nav = array())
 {
     // Determine user to use
     if (bp_displayed_user_domain()) {
         $user_domain = bp_displayed_user_domain();
     } elseif (bp_loggedin_user_domain()) {
         $user_domain = bp_loggedin_user_domain();
     } else {
         return;
     }
     $access = bp_core_can_edit_settings();
     $slug = bp_get_settings_slug();
     $settings_link = trailingslashit($user_domain . $slug);
     // Add the settings navigation item
     $main_nav = array('name' => __('Settings', 'buddypress'), 'slug' => $slug, 'position' => 100, 'show_for_displayed_user' => $access, 'screen_function' => 'bp_settings_screen_general', 'default_subnav_slug' => 'general');
     // Add General Settings nav item
     $sub_nav[] = array('name' => __('General', 'buddypress'), 'slug' => 'general', 'parent_url' => $settings_link, 'parent_slug' => $slug, 'screen_function' => 'bp_settings_screen_general', 'position' => 10, 'user_has_access' => $access);
     // Add Email nav item. Formerly called 'Notifications', we
     // retain the old slug and function names for backward compat
     $sub_nav[] = array('name' => __('Email', 'buddypress'), 'slug' => 'notifications', 'parent_url' => $settings_link, 'parent_slug' => $slug, 'screen_function' => 'bp_settings_screen_notification', 'position' => 20, 'user_has_access' => $access);
     // Add Spam Account nav item
     if (bp_current_user_can('bp_moderate')) {
         $sub_nav[] = array('name' => __('Capabilities', 'buddypress'), 'slug' => 'capabilities', 'parent_url' => $settings_link, 'parent_slug' => $slug, 'screen_function' => 'bp_settings_screen_capabilities', 'position' => 80, 'user_has_access' => !bp_is_my_profile());
     }
     // Add Delete Account nav item
     if (!bp_disable_account_deletion() && bp_is_my_profile() || bp_current_user_can('delete_users')) {
         $sub_nav[] = array('name' => __('Delete Account', 'buddypress'), 'slug' => 'delete-account', 'parent_url' => $settings_link, 'parent_slug' => $slug, 'screen_function' => 'bp_settings_screen_delete_account', 'position' => 90, 'user_has_access' => !is_super_admin(bp_displayed_user_id()));
     }
     parent::setup_nav($main_nav, $sub_nav);
 }
예제 #3
0
/**
 * Maps XProfile caps to built in WordPress caps
 *
 * @since 1.6
 *
 * @param array $caps Capabilities for meta capability
 * @param string $cap Capability name
 * @param int $user_id User id
 * @param mixed $args Arguments
 * @uses get_post() To get the post
 * @uses get_post_type_object() To get the post type object
 * @uses apply_filters() Calls 'bp_map_meta_caps' with caps, cap, user id and
 *                        args
 * @return array Actual capabilities for meta capability
 */
function bp_xprofile_map_meta_caps($caps, $cap, $user_id, $args)
{
    switch ($cap) {
        case 'bp_xprofile_change_field_visibility':
            $caps = array('exist');
            // Must allow for logged-out users during registration
            // You may pass args manually: $field_id, $profile_user_id
            $field_id = isset($args[0]) ? (int) $args[0] : bp_get_the_profile_field_id();
            $profile_user_id = isset($args[1]) ? (int) $args[1] : bp_displayed_user_id();
            // Visibility on the fullname field is not editable
            if (1 == $field_id) {
                $caps[] = 'do_not_allow';
                break;
            }
            // Has the admin disabled visibility modification for this field?
            if ('disabled' == bp_xprofile_get_meta($field_id, 'field', 'allow_custom_visibility')) {
                $caps[] = 'do_not_allow';
                break;
            }
            // Friends don't let friends edit each other's visibility
            if ($profile_user_id != bp_displayed_user_id() && !bp_current_user_can('bp_moderate')) {
                $caps[] = 'do_not_allow';
                break;
            }
            break;
    }
    return apply_filters('bp_xprofile_map_meta_caps', $caps, $cap, $user_id, $args);
}
/**
 * Filter the activity loop.
 *
 * Specifically, when on the activity directory and clicking on the "Followed
 * Sites" tab.
 *
 * @param str $qs The querystring for the BP loop
 * @param str $object The current object for the querystring
 * @return str Modified querystring
 */
function bp_follow_blogs_add_activity_scope_filter($qs, $object)
{
    // not on the blogs object? stop now!
    if ($object != 'activity') {
        return $qs;
    }
    // parse querystring into an array
    $r = wp_parse_args($qs);
    if (bp_is_current_action(constant('BP_FOLLOW_BLOGS_USER_ACTIVITY_SLUG'))) {
        $r['scope'] = 'followblogs';
    }
    if (!isset($r['scope'])) {
        return $qs;
    }
    if ('followblogs' !== $r['scope']) {
        return $qs;
    }
    // get blog IDs that the user is following
    $following_ids = bp_get_following_ids(array('user_id' => bp_displayed_user_id() ? bp_displayed_user_id() : bp_loggedin_user_id(), 'follow_type' => 'blogs'));
    // if $following_ids is empty, pass a negative number so no blogs can be found
    $following_ids = empty($following_ids) ? -1 : $following_ids;
    $args = array('user_id' => 0, 'object' => 'blogs', 'primary_id' => $following_ids);
    // make sure we add a separator if we have an existing querystring
    if (!empty($qs)) {
        $qs .= '&';
    }
    // add our follow parameters to the end of the querystring
    $qs .= build_query($args);
    // support BP Groupblog
    // We need to filter the WHERE SQL conditions to do this
    if (function_exists('bp_groupblog_init')) {
        add_filter('bp_activity_get_where_conditions', 'bp_follow_blogs_groupblog_activity_where_conditions', 10, 2);
    }
    return $qs;
}
        public function edit_field_html(array $raw_properties = array())
        {
            $user_id = bp_displayed_user_id();
            if (isset($raw_properties['user_id'])) {
                $user_id = (int) $raw_properties['user_id'];
                unset($raw_properties['user_id']);
            }
            // HTML5 required attribute.
            if (bp_get_the_profile_field_is_required()) {
                $raw_properties['required'] = 'required';
                $required = true;
            } else {
                $required = false;
            }
            ?>
            <label for="<?php 
            bp_the_profile_field_input_name();
            ?>
"><?php 
            bp_the_profile_field_name();
            ?>
 <?php 
            if (bp_get_the_profile_field_is_required()) {
                esc_html_e('(required)', 'buddypress');
            }
            ?>
</label>
            <?php 
            do_action(bp_get_the_profile_field_errors_action());
            ?>
            <?php 
            bp_the_profile_field_options("user_id={$user_id}&required={$required}");
            ?>
        <?php 
        }
예제 #6
0
 function setup_nav()
 {
     global $bp;
     $link = bp_displayed_user_id() ? bp_displayed_user_domain() : bp_loggedin_user_domain();
     $reshare_nav = array('name' => __('Reshares', 'bp-reshare'), 'link' => $link . bp_get_activity_slug() . '/reshares/', 'slug' => 'reshares', 'css_id' => 'activity-reshares', 'user_has_access' => true, 'position' => 50, 'screen_function' => false);
     $bp->bp_options_nav['activity']['reshares'] = $reshare_nav;
 }
/**
 * When a site admin selects "Mark as Spammer/Not Spammer" from the admin menu
 * this action will fire and mark or unmark the user and their blogs as spam.
 * Must be a site admin for this function to run.
 *
 * @package BuddyPress Core
 * @param int $user_id Optional user ID to mark as spam
 * @global object $nxtdb Global NXTClass Database object
 */
function bp_core_action_set_spammer_status($user_id = 0)
{
    // Use displayed user if it's not yourself
    if (empty($user_id)) {
        $user_id = bp_displayed_user_id();
    }
    if (bp_is_current_component('admin') && in_array(bp_current_action(), array('mark-spammer', 'unmark-spammer'))) {
        // Check the nonce
        check_admin_referer('mark-unmark-spammer');
        // To spam or not to spam
        $status = bp_is_current_action('mark-spammer') ? 'spam' : 'ham';
        // The heavy lifting
        bp_core_process_spammer_status($user_id, $status);
        // Add feedback message. @todo - Error reporting
        if ('spam' == $status) {
            bp_core_add_message(__('User marked as spammer. Spam users are visible only to site admins.', 'buddypress'));
        } else {
            bp_core_add_message(__('User removed as spammer.', 'buddypress'));
        }
        // Deprecated. Use bp_core_process_spammer_status.
        $is_spam = 'spam' == $status;
        do_action('bp_core_action_set_spammer_status', bp_displayed_user_id(), $is_spam);
        // Redirect back to where we came from
        bp_core_redirect(nxt_get_referer());
    }
}
    /**
     * Output the edit field HTML for this field type.
     *
     * Must be used inside the {@link bp_profile_fields()} template loop.
     *
     * @since 2.0.0
     *
     * @param array $raw_properties Optional key/value array of
     *                              {@link http://dev.w3.org/html5/markup/input.checkbox.html permitted attributes}
     *                              that you want to add.
     */
    public function edit_field_html(array $raw_properties = array())
    {
        // User_id is a special optional parameter that we pass to
        // {@link bp_the_profile_field_options()}.
        if (isset($raw_properties['user_id'])) {
            $user_id = (int) $raw_properties['user_id'];
            unset($raw_properties['user_id']);
        } else {
            $user_id = bp_displayed_user_id();
        }
        ?>

		<fieldset class="checkbox">
			<legend>
				<?php 
        bp_the_profile_field_name();
        ?>
				<?php 
        bp_the_profile_field_required_label();
        ?>
			</legend>

			<?php 
        /** This action is documented in bp-xprofile/bp-xprofile-classes */
        do_action(bp_get_the_profile_field_errors_action());
        ?>

			<?php 
        bp_the_profile_field_options(array('user_id' => $user_id));
        ?>

		</fieldset>

		<?php 
    }
/**
 * Filter the activity loop when we're on a "Following" page
 *
 * This is done:
 *   - On the activity directory and clicking on the "Following" tab
 *   - On a user's "Activity > Following" page
 *
 * @since 1.0.0
 *
 * @param string|array Current activity querystring
 * @param string $object The current object or component
 * @return array
 */
function bp_follow_add_activity_scope_filter($qs, $object)
{
    global $bp;
    // not on the activity object? stop now!
    if ($object != 'activity') {
        return $qs;
    }
    $set = false;
    // activity directory
    // can't use bp_is_activity_directory() yet since that's a BP 2.0 function
    if (!bp_displayed_user_id() && bp_is_activity_component() && !bp_current_action()) {
        // check if activity scope is following before manipulating
        if (isset($_COOKIE['bp-activity-scope']) && 'following' === $_COOKIE['bp-activity-scope']) {
            $set = true;
        }
        // user's activity following page
    } elseif (bp_is_user_activity() && bp_is_current_action('following')) {
        $set = true;
    }
    // not on a user page? stop now!
    if (!$set) {
        return $qs;
    }
    // set internal marker noting that our activity scope is applied
    $bp->follow->activity_scope_set = 1;
    $qs = wp_parse_args($qs);
    $following_ids = bp_get_following_ids(array('user_id' => bp_displayed_user_id() ? bp_displayed_user_id() : bp_loggedin_user_id()));
    // if $following_ids is empty, pass a negative number so no activity can be found
    $following_ids = empty($following_ids) ? -1 : $following_ids;
    $qs['user_id'] = $following_ids;
    return apply_filters('bp_follow_add_activity_scope_filter', $qs, false);
}
예제 #10
0
 /**
  * Setup BuddyBar navigation
  */
 function setup_nav()
 {
     // Define local variable
     $sub_nav = array();
     // Add the settings navigation item
     $main_nav = array('name' => __('Settings', 'buddypress'), 'slug' => $this->slug, 'position' => 100, 'show_for_displayed_user' => bp_core_can_edit_settings(), 'screen_function' => 'bp_settings_screen_general', 'default_subnav_slug' => 'general');
     // Determine user to use
     if (bp_displayed_user_domain()) {
         $user_domain = bp_displayed_user_domain();
     } elseif (bp_loggedin_user_domain()) {
         $user_domain = bp_loggedin_user_domain();
     } else {
         return;
     }
     $settings_link = trailingslashit($user_domain . $this->slug);
     // Add General Settings nav item
     $sub_nav[] = array('name' => __('General', 'buddypress'), 'slug' => 'general', 'parent_url' => $settings_link, 'parent_slug' => $this->slug, 'screen_function' => 'bp_settings_screen_general', 'position' => 10, 'user_has_access' => bp_core_can_edit_settings());
     // Add Notifications nav item
     $sub_nav[] = array('name' => __('Notifications', 'buddypress'), 'slug' => 'notifications', 'parent_url' => $settings_link, 'parent_slug' => $this->slug, 'screen_function' => 'bp_settings_screen_notification', 'position' => 20, 'user_has_access' => bp_core_can_edit_settings());
     // Add Spam Account nav item
     if (bp_current_user_can('bp_moderate')) {
         $sub_nav[] = array('name' => __('Capabilities', 'buddypress'), 'slug' => 'capabilities', 'parent_url' => $settings_link, 'parent_slug' => $this->slug, 'screen_function' => 'bp_settings_screen_capabilities', 'position' => 80, 'user_has_access' => !bp_is_my_profile());
     }
     // Add Delete Account nav item
     if (!bp_disable_account_deletion() || bp_current_user_can('delete_users')) {
         $sub_nav[] = array('name' => __('Delete Account', 'buddypress'), 'slug' => 'delete-account', 'parent_url' => $settings_link, 'parent_slug' => $this->slug, 'screen_function' => 'bp_settings_screen_delete_account', 'position' => 90, 'user_has_access' => bp_is_my_profile() || !is_super_admin(bp_displayed_user_id()));
     }
     parent::setup_nav($main_nav, $sub_nav);
 }
예제 #11
0
 public function setup_current_component_id_for_members($component_id)
 {
     if (bp_is_user()) {
         return bp_displayed_user_id();
     }
     return $component_id;
 }
예제 #12
0
파일: BuddyPress.php 프로젝트: hemangsk/TCB
 /**
  * User's questions list loop.
  */
 static function profile_questions_loop()
 {
     global $dwqa_options;
     $submit_question_link = get_post_type_archive_link(CMA_AnswerThread::POST_TYPE);
     $questions = get_posts(array('posts_per_page' => -1, 'author' => bp_displayed_user_id(), 'post_type' => CMA_AnswerThread::POST_TYPE));
     include CMA_PATH . '/views/frontend/buddypress/user-questions-loop.phtml';
 }
    /**
     * Output the edit field HTML for this field type.
     *
     * Must be used inside the {@link bp_profile_fields()} template loop.
     *
     * @param array $raw_properties Optional key/value array of {@link http://dev.w3.org/html5/markup/input.radio.html permitted attributes} that you want to add.
     * @since 2.0.0
     */
    public function edit_field_html(array $raw_properties = array())
    {
        // user_id is a special optional parameter that we pass to
        // {@link bp_the_profile_field_options()}.
        if (isset($raw_properties['user_id'])) {
            $user_id = (int) $raw_properties['user_id'];
            unset($raw_properties['user_id']);
        } else {
            $user_id = bp_displayed_user_id();
        }
        ?>

		<div class="radio">

			<label for="<?php 
        bp_the_profile_field_input_name();
        ?>
">
				<?php 
        bp_the_profile_field_name();
        ?>
				<?php 
        if (bp_get_the_profile_field_is_required()) {
            ?>
					<?php 
            esc_html_e('(required)', 'buddypress');
            ?>
				<?php 
        }
        ?>
			</label>

			<?php 
        /** This action is documented in bp-xprofile/bp-xprofile-classes */
        do_action(bp_get_the_profile_field_errors_action());
        ?>

			<?php 
        bp_the_profile_field_options(array('user_id' => $user_id));
        if (!bp_get_the_profile_field_is_required()) {
            ?>

				<a class="clear-value" href="javascript:clear( '<?php 
            echo esc_js(bp_get_the_profile_field_input_name());
            ?>
' );">
					<?php 
            esc_html_e('Clear', 'buddypress');
            ?>
				</a>

			<?php 
        }
        ?>

		</div>

		<?php 
    }
예제 #14
0
function mpp_current_component_id_for_user($component_id)
{
    if (mediapress()->is_bp_active() && bp_is_user()) {
        return bp_displayed_user_id();
        //that is displayed user id
    }
    return $component_id;
}
예제 #15
0
function bp_reshare_is_user_profile_reshares()
{
    if (bp_is_activity_component() && bp_displayed_user_id() && bp_is_current_action('reshares')) {
        return true;
    } else {
        return false;
    }
}
예제 #16
0
function mpp_current_component_id_for_user($component_id)
{
    if (bp_is_user()) {
        return bp_displayed_user_id();
    }
    //that is displayed user id
    return $component_id;
}
/**
 * Activity screen index
 *
 * @since 1.5.0
 *
 * @uses bp_displayed_user_id()
 * @uses bp_is_activity_component()
 * @uses bp_current_action()
 * @uses bp_update_is_directory()
 * @uses do_action() To call the 'bp_activity_screen_index' hook
 * @uses bp_core_load_template()
 * @uses apply_filters() To call the 'bp_activity_screen_index' hook
 */
function bp_activity_screen_index()
{
    if (!bp_displayed_user_id() && bp_is_activity_component() && !bp_current_action()) {
        bp_update_is_directory(true, 'activity');
        do_action('bp_activity_screen_index');
        bp_core_load_template(apply_filters('bp_activity_screen_index', 'activity/index'));
    }
}
function bp_checkins_if_category_place()
{
    if (!bp_displayed_user_id() && bp_is_current_component('checkins') && bp_is_current_action('place') && bp_action_variable(0) && 'category' == bp_action_variable(0) && bp_action_variable(1)) {
        return true;
    } else {
        return false;
    }
}
예제 #19
0
/**
 * Return the user ID whose profile we are in.
 * 
 * If BP integration is enabled, this will return bp_displayed_user_id().
 * If BP integration is not enabled, this will return get_queried_object()->ID.
 * 
 * This function should be used in conjunction with dpa_is_single_user_achievements().
 * 
 * @return int|false Returns user ID; if we aren't looking at a user's profile, return false.
 * @since Achievements (3.2)
 */
function dpa_get_displayed_user_id()
{
    $retval = get_queried_object()->ID;
    if (dpa_integrate_into_buddypress() && function_exists('bp_displayed_user_id')) {
        $retval = bp_displayed_user_id();
    }
    return apply_filters('dpa_get_displayed_user_id', $retval);
}
    /**
     * Output the edit field HTML for this field type.
     *
     * Must be used inside the {@link bp_profile_fields()} template loop.
     *
     * @param array $raw_properties Optional key/value array of {@link http://dev.w3.org/html5/markup/select.html permitted attributes} that you want to add.
     * @since 2.0.0
     */
    public function edit_field_html(array $raw_properties = array())
    {
        // user_id is a special optional parameter that we pass to
        // {@link bp_the_profile_field_options()}.
        if (isset($raw_properties['user_id'])) {
            $user_id = (int) $raw_properties['user_id'];
            unset($raw_properties['user_id']);
        } else {
            $user_id = bp_displayed_user_id();
        }
        $r = bp_parse_args($raw_properties, array('multiple' => 'multiple', 'id' => bp_get_the_profile_field_input_name() . '[]', 'name' => bp_get_the_profile_field_input_name() . '[]'));
        ?>

		<label for="<?php 
        bp_the_profile_field_input_name();
        ?>
[]"><?php 
        bp_the_profile_field_name();
        ?>
 <?php 
        if (bp_get_the_profile_field_is_required()) {
            _e('(required)', 'buddypress');
        }
        ?>
</label>

		<?php 
        /** This action is documented in bp-xprofile/bp-xprofile-classes */
        do_action(bp_get_the_profile_field_errors_action());
        ?>

		<select <?php 
        echo $this->get_edit_field_html_elements($r);
        ?>
>
			<?php 
        bp_the_profile_field_options(array('user_id' => $user_id));
        ?>
		</select>

		<?php 
        if (!bp_get_the_profile_field_is_required()) {
            ?>

			<a class="clear-value" href="javascript:clear( '<?php 
            echo esc_js(bp_get_the_profile_field_input_name());
            ?>
[]' );">
				<?php 
            esc_html_e('Clear', 'buddypress');
            ?>
			</a>

		<?php 
        }
        ?>
	<?php 
    }
 /**
  * Initializes the Nav belonging to the specified object.
  *
  * @since 2.6.0
  *
  * @param int $object_id The item ID to build the nav for. Default is the displayed user ID.
  */
 public function __construct($object_id = 0)
 {
     if (empty($object_id)) {
         $this->object_id = (int) bp_displayed_user_id();
     } else {
         $this->object_id = (int) $object_id;
     }
     $this->nav[$this->object_id] = array();
 }
예제 #22
0
 function __construct($id = null)
 {
     global $bp, $nxtdb;
     $user_id = bp_displayed_user_id();
     if ($id) {
         $this->id = $id;
         $this->populate();
     }
 }
예제 #23
0
/**
 * Adds a navigation item to the main navigation array used in BuddyPress themes.
 *
 * @package BuddyPress Core
 * @global object $bp Global BuddyPress settings object
 */
function bp_core_new_nav_item($args = '')
{
    global $bp;
    $defaults = array('name' => false, 'slug' => false, 'item_css_id' => false, 'show_for_displayed_user' => true, 'site_admin_only' => false, 'position' => 99, 'screen_function' => false, 'default_subnav_slug' => false);
    $r = nxt_parse_args($args, $defaults);
    extract($r, EXTR_SKIP);
    // If we don't have the required info we need, don't create this subnav item
    if (empty($name) || empty($slug)) {
        return false;
    }
    // If this is for site admins only and the user is not one, don't create the subnav item
    if ($site_admin_only && !is_super_admin()) {
        return false;
    }
    if (empty($item_css_id)) {
        $item_css_id = $slug;
    }
    $bp->bp_nav[$slug] = array('name' => $name, 'slug' => $slug, 'link' => $bp->loggedin_user->domain . $slug . '/', 'css_id' => $item_css_id, 'show_for_displayed_user' => $show_for_displayed_user, 'position' => $position, 'screen_function' => &$screen_function);
    /***
     * If this nav item is hidden for the displayed user, and
     * the logged in user is not the displayed user
     * looking at their own profile, don't create the nav item.
     */
    if (!$show_for_displayed_user && !bp_user_has_access()) {
        return false;
    }
    /***
     * If the nav item is visible, we are not viewing a user, and this is a root
     * component, don't attach the default subnav function so we can display a
     * directory or something else.
     */
    if (-1 != $position && bp_is_root_component($slug) && !bp_displayed_user_id()) {
        return;
    }
    // Look for current component
    if (bp_is_current_component($slug) && !bp_current_action()) {
        if (!is_object($screen_function[0])) {
            add_action('bp_screens', $screen_function);
        } else {
            add_action('bp_screens', array(&$screen_function[0], $screen_function[1]), 3);
        }
        if (!empty($default_subnav_slug)) {
            $bp->current_action = apply_filters('bp_default_component_subnav', $default_subnav_slug, $r);
        }
        // Look for current item
    } elseif (bp_is_current_item($slug) && !bp_current_action()) {
        if (!is_object($screen_function[0])) {
            add_action('bp_screens', $screen_function);
        } else {
            add_action('bp_screens', array(&$screen_function[0], $screen_function[1]), 3);
        }
        if (!empty($default_subnav_slug)) {
            $bp->current_action = apply_filters('bp_default_component_subnav', $default_subnav_slug, $r);
        }
    }
    do_action('bp_core_new_nav_item', $r, $args, $defaults);
}
예제 #24
0
/**
 * Adds an activity stream item when a user has uploaded a new avatar.
 *
 * @package BuddyPress XProfile
 * @global BuddyPress $bp The one true BuddyPress instance
 * @uses bp_activity_add() Adds an entry to the activity component tables for a specific activity
 */
function bp_xprofile_new_avatar_activity()
{
    if (!bp_is_active('activity')) {
        return false;
    }
    $user_id = apply_filters('bp_xprofile_new_avatar_user_id', bp_displayed_user_id());
    $userlink = bp_core_get_userlink($user_id);
    bp_activity_add(array('user_id' => $user_id, 'action' => apply_filters('bp_xprofile_new_avatar_action', sprintf(__('%s changed their profile picture', 'buddypress'), $userlink), $user_id), 'component' => 'profile', 'type' => 'new_avatar'));
}
예제 #25
0
 public function test_member_activity_page()
 {
     $url = home_url($this->u->user_nicename) . '/' . bp_get_activity_slug();
     $this->go_to($url);
     $this->assertTrue(bp_is_user());
     $this->assertTrue(bp_is_my_profile());
     $this->assertEquals($this->u->ID, bp_displayed_user_id());
     $this->assertTrue(bp_is_activity_component());
 }
예제 #26
0
/**
 * Get allowed no. of posts
 * Use this filter
 * @param type $user_id
 * @return type 
 */
function buddyblog_get_allowed_no_of_posts($user_id = false)
{
    if (!$user_id) {
        $user_id = bp_displayed_user_id();
    }
    //filter on this hook to change the no. of posts allowed
    return apply_filters('buddyblog_allowed_posts_count', buddyblog_get_option('max_allowed_posts'), $user_id);
    //by default no. posts allowed
}
/**
 * Get the mutual friend count of a current user.
 *
 * @params $friend_user_id int
 *
 * @return mixed|void
 */
function bp_mutual_friend_total_count($friend_user_id = 0)
{
    $current_user_friends = friends_get_friend_user_ids(get_current_user_id());
    if (empty($friend_user_id)) {
        $friend_user_id = bp_displayed_user_id();
    }
    $displayed_user_friends = friends_get_friend_user_ids($friend_user_id);
    $result = count(array_intersect($current_user_friends, $displayed_user_friends));
    return apply_filters('bp_mutual_friend_total_count', $result);
}
 /**
  * Set up the navigation.
  *
  * @since 1.0.0
  * @access public
  *
  * @param array $main_nav Optional. See BP_Component::setup_nav().
  * @param array $sub_nav Optional. See BP_Component::setup_nav().
  */
 function setup_nav($main_nav = array(), $sub_nav = array())
 {
     $count = Mute::get_count(bp_displayed_user_id());
     $class = $count === 0 ? 'no-count' : 'count';
     $main_nav = array('name' => sprintf(__('Mute <span class="%s">%s</span>', 'buddypress-mute'), esc_attr($class), number_format_i18n($count)), 'position' => 80, 'default_subnav_slug' => 'all', 'slug' => $this->slug, 'item_css_id' => $this->id, 'show_for_displayed_user' => bp_core_can_edit_settings(), 'screen_function' => 'bp_mute_all_screen');
     $sub_nav[] = array('name' => __('All', 'buddypress-mute'), 'slug' => 'all', 'position' => 10, 'parent_slug' => $this->slug, 'parent_url' => trailingslashit(bp_displayed_user_domain() . $this->slug), 'user_has_access' => bp_core_can_edit_settings(), 'screen_function' => 'bp_mute_all_screen');
     if (bp_is_active('friends')) {
         $sub_nav[] = array('name' => __('Friends', 'buddypress-mute'), 'slug' => 'friends', 'position' => 20, 'parent_slug' => $this->slug, 'parent_url' => trailingslashit(bp_displayed_user_domain() . $this->slug), 'user_has_access' => bp_core_can_edit_settings(), 'screen_function' => 'bp_mute_friends_screen');
     }
     parent::setup_nav($main_nav, $sub_nav);
 }
예제 #29
0
/**
 * Add an item to the main BuddyPress navigation array.
 *
 * @global BuddyPress $bp The one true BuddyPress instance.
 *
 * @param array $args {
 *     Array describing the new nav item.
 *     @type string $name Display name for the nav item.
 *     @type string $slug Unique URL slug for the nav item.
 *     @type bool|string $item_css_id Optional. 'id' attribute for the nav
 *           item. Default: the value of $slug.
 *     @type bool $show_for_displayed_user Optional. Whether the nav item
 *           should be visible when viewing a member profile other than your
 *           own. Default: true.
 *     @type bool $site_admin_only Optional. Whether the nav item should be
 *           visible only to site admins (those with the 'bp_moderate' cap).
 *           Default: false.
 *     @type int $position Optional. Numerical index specifying where the item
 *           should appear in the nav array. Default: 99.
 *     @type callable $screen_function The callback function that will run
 *           when the nav item is clicked.
 *     @type bool|string $default_subnav_slug Optional. The slug of the default
 *           subnav item to select when the nav item is clicked.
 * }
 * @return bool|null Returns false on failure.
 */
function bp_core_new_nav_item($args = '')
{
    global $bp;
    $defaults = array('name' => false, 'slug' => false, 'item_css_id' => false, 'show_for_displayed_user' => true, 'site_admin_only' => false, 'position' => 99, 'screen_function' => false, 'default_subnav_slug' => false);
    $r = wp_parse_args($args, $defaults);
    extract($r, EXTR_SKIP);
    // If we don't have the required info we need, don't create this subnav item
    if (empty($name) || empty($slug)) {
        return false;
    }
    // If this is for site admins only and the user is not one, don't create the subnav item
    if (!empty($site_admin_only) && !bp_current_user_can('bp_moderate')) {
        return false;
    }
    if (empty($item_css_id)) {
        $item_css_id = $slug;
    }
    $bp->bp_nav[$slug] = array('name' => $name, 'slug' => $slug, 'link' => trailingslashit(bp_loggedin_user_domain() . $slug), 'css_id' => $item_css_id, 'show_for_displayed_user' => $show_for_displayed_user, 'position' => $position, 'screen_function' => &$screen_function, 'default_subnav_slug' => $default_subnav_slug);
    /**
     * If this nav item is hidden for the displayed user, and
     * the logged in user is not the displayed user
     * looking at their own profile, don't create the nav item.
     */
    if (empty($show_for_displayed_user) && !bp_user_has_access()) {
        return false;
    }
    /**
     * If the nav item is visible, we are not viewing a user, and this is a root
     * component, don't attach the default subnav function so we can display a
     * directory or something else.
     */
    if (-1 != $position && bp_is_root_component($slug) && !bp_displayed_user_id()) {
        return;
    }
    // Look for current component
    if (bp_is_current_component($slug) || bp_is_current_item($slug)) {
        // The requested URL has explicitly included the default subnav
        // (eg: http://example.com/members/membername/activity/just-me/)
        // The canonical version will not contain this subnav slug.
        if (!empty($default_subnav_slug) && bp_is_current_action($default_subnav_slug) && !bp_action_variable(0)) {
            unset($bp->canonical_stack['action']);
        } elseif (!bp_current_action()) {
            // Add our screen hook if screen function is callable
            if (is_callable($screen_function)) {
                add_action('bp_screens', $screen_function, 3);
            }
            if (!empty($default_subnav_slug)) {
                $bp->current_action = apply_filters('bp_default_component_subnav', $default_subnav_slug, $r);
            }
        }
    }
    do_action('bp_core_new_nav_item', $r, $args, $defaults);
}
예제 #30
0
/**
 * Sets up and displays the screen output for the sub nav item "portfolio/edit/%d"
 */
function bp_portfolio_screen_edit()
{
    if (bp_is_portfolio_component() and bp_is_current_action('edit') and bp_displayed_user_id() == bp_loggedin_user_id()) {
        if (isset($_POST['edit'])) {
            // Check to see if the project belong to the logged_in user
            global $project;
            $project_id = bp_action_variable();
            $project = new BP_Portfolio_Item();
            $project->get(array('id' => $project_id));
            if ($project->query->post->post_author != bp_loggedin_user_id()) {
                bp_core_add_message(__('There was an error recording the project, please try again', 'bp-portfolio'), 'error');
                bp_core_load_template(apply_filters('bp_portfolio_template_screen_add', BP_PORTFOLIO_TEMPLATE . '/personal'));
            }
            // Check the nonce
            if (!wp_verify_nonce($_POST['_wpnonce'], 'project_form_nonce')) {
                bp_core_add_message(__('There was an error recording the project, please try again', 'bp-portfolio'), 'error');
                bp_core_load_template(apply_filters('bp_portfolio_template_screen_add', BP_PORTFOLIO_TEMPLATE . '/personal'));
            }
            if (empty($_POST['title-input']) or empty($_POST['url-input']) or empty($_POST['description'])) {
                bp_core_add_message(__('All fields are required', 'bp-portfolio'), 'error');
                $project_id = bp_action_variable();
                global $project;
                $project = new BP_Portfolio_Item();
                $project->get(array('id' => $project_id));
            } else {
                // Edit the post
                $posts = array('id' => bp_action_variable(), 'author_id' => bp_loggedin_user_id(), 'title' => $_POST['title-input'], 'description' => $_POST['description'], 'url' => $_POST['url-input']);
                // Is that a capture has been sent ?
                if (isset($_FILES['screenshot-input']) and $_FILES['screenshot-input']['error'] == 0) {
                    $posts['screenshot'] = $_FILES['screenshot-input'];
                }
                if ($item = bp_portfolio_save_item($posts)) {
                    bp_core_add_message(__('Project has been edited', 'bp-portfolio'));
                    bp_core_redirect(bp_core_get_user_domain(bp_loggedin_user_id()) . bp_get_portfolio_slug());
                } else {
                    bp_core_add_message(__('There was an error recording the item, please try again', 'bp-portfolio'), 'error');
                }
            }
        } else {
            // Create a global $project, so template will know that this is the edit page
            if ($project_id = bp_action_variable()) {
                global $project;
                $project_id = bp_action_variable();
                $project = new BP_Portfolio_Item();
                $project->get(array('id' => $project_id));
                if ($project->query->post->post_author == bp_loggedin_user_id()) {
                    bp_core_load_template(apply_filters('bp_portfolio_template_screen_one', BP_PORTFOLIO_TEMPLATE . '/add'));
                }
            }
        }
    }
}