Exemplo n.º 1
0
function friends_screen_requests()
{
    if (bp_is_action_variable('accept', 0) && is_numeric(bp_action_variable(1))) {
        // Check the nonce
        check_admin_referer('friends_accept_friendship');
        if (friends_accept_friendship(bp_action_variable(1))) {
            bp_core_add_message(__('Friendship accepted', 'buddypress'));
        } else {
            bp_core_add_message(__('Friendship could not be accepted', 'buddypress'), 'error');
        }
        bp_core_redirect(bp_loggedin_user_domain() . bp_current_component() . '/' . bp_current_action());
    } elseif (bp_is_action_variable('reject', 0) && is_numeric(bp_action_variable(1))) {
        // Check the nonce
        check_admin_referer('friends_reject_friendship');
        if (friends_reject_friendship(bp_action_variable(1))) {
            bp_core_add_message(__('Friendship rejected', 'buddypress'));
        } else {
            bp_core_add_message(__('Friendship could not be rejected', 'buddypress'), 'error');
        }
        bp_core_redirect(bp_loggedin_user_domain() . bp_current_component() . '/' . bp_current_action());
    }
    do_action('friends_screen_requests');
    if (isset($_GET['new'])) {
        bp_core_delete_notifications_by_type(bp_loggedin_user_id(), 'friends', 'friendship_request');
    }
    bp_core_load_template(apply_filters('friends_template_requests', 'members/single/home'));
}
Exemplo n.º 2
0
/**
 * Catch and process the Requests page.
 */
function friends_screen_requests()
{
    if (bp_is_action_variable('accept', 0) && is_numeric(bp_action_variable(1))) {
        // Check the nonce
        check_admin_referer('friends_accept_friendship');
        if (friends_accept_friendship(bp_action_variable(1))) {
            bp_core_add_message(__('Friendship accepted', 'buddypress'));
        } else {
            bp_core_add_message(__('Friendship could not be accepted', 'buddypress'), 'error');
        }
        bp_core_redirect(trailingslashit(bp_loggedin_user_domain() . bp_current_component() . '/' . bp_current_action()));
    } elseif (bp_is_action_variable('reject', 0) && is_numeric(bp_action_variable(1))) {
        // Check the nonce
        check_admin_referer('friends_reject_friendship');
        if (friends_reject_friendship(bp_action_variable(1))) {
            bp_core_add_message(__('Friendship rejected', 'buddypress'));
        } else {
            bp_core_add_message(__('Friendship could not be rejected', 'buddypress'), 'error');
        }
        bp_core_redirect(trailingslashit(bp_loggedin_user_domain() . bp_current_component() . '/' . bp_current_action()));
    } elseif (bp_is_action_variable('cancel', 0) && is_numeric(bp_action_variable(1))) {
        // Check the nonce
        check_admin_referer('friends_withdraw_friendship');
        if (friends_withdraw_friendship(bp_loggedin_user_id(), bp_action_variable(1))) {
            bp_core_add_message(__('Friendship request withdrawn', 'buddypress'));
        } else {
            bp_core_add_message(__('Friendship request could not be withdrawn', 'buddypress'), 'error');
        }
        bp_core_redirect(trailingslashit(bp_loggedin_user_domain() . bp_current_component() . '/' . bp_current_action()));
    }
    do_action('friends_screen_requests');
    bp_core_load_template(apply_filters('friends_template_requests', 'members/single/home'));
}
Exemplo n.º 3
0
/**
 * bp_groupblog_add_js()
 */
function bp_groupblog_add_js()
{
    if (bp_is_groups_component() && bp_is_action_variable('group-blog')) {
        if (file_exists(get_stylesheet_directory() . '/groupblog/js/general.js')) {
            wp_enqueue_script('bp-groupblog-js', get_stylesheet_directory_uri() . '/groupblog/js/general.js', array('jquery'));
        } else {
            wp_enqueue_script('bp-groupblog-js', plugins_url() . '/bp-groupblog/groupblog/js/general.js', array('jquery'));
        }
    }
}
/**
 * Check to see if a high five is being given, and if so, save it.
 *
 * Hooked to bp_actions, this function will fire before the screen function. We use our function
 * bp_is_example_component(), along with the bp_is_current_action() and bp_is_action_variable()
 * functions, to detect (based on the requested URL) whether the user has clicked on "send high
 * five". If so, we do a bit of simple logic to see what should happen next.
 *
 * @package BuddyPress_Skeleton_Component
 * @since 1.6
 */
function bp_example_high_five_save()
{
    if (bp_is_example_component() && bp_is_current_action('screen-one') && bp_is_action_variable('send-h5', 0)) {
        // The logged in user has clicked on the 'send high five' link
        if (bp_is_my_profile()) {
            // Don't let users high five themselves
            bp_core_add_message(__('No self-fives! :)', 'bp-example'), 'error');
        } else {
            if (bp_example_send_highfive(bp_displayed_user_id(), bp_loggedin_user_id())) {
                bp_core_add_message(__('High-five sent!', 'bp-example'));
            } else {
                bp_core_add_message(__('High-five could not be sent.', 'bp-example'), 'error');
            }
        }
        bp_core_redirect(bp_displayed_user_domain() . bp_get_example_slug() . '/screen-one');
    }
}
/**
 * This function runs when an action is set for a screen:
 * example.com/members/andy/profile/change-avatar/ [delete-avatar]
 *
 * The function will delete the active avatar for a user.
 *
 * @package BuddyPress Xprofile
 * @uses bp_core_delete_avatar() Deletes the active avatar for the logged in user.
 * @uses add_action() Runs a specific function for an action when it fires.
 */
function xprofile_action_delete_avatar()
{
    if (!bp_is_user_change_avatar() || !bp_is_action_variable('delete-avatar', 0)) {
        return false;
    }
    // Check the nonce
    check_admin_referer('bp_delete_avatar_link');
    if (!bp_is_my_profile() && !bp_current_user_can('bp_moderate')) {
        return false;
    }
    if (bp_core_delete_existing_avatar(array('item_id' => bp_displayed_user_id()))) {
        bp_core_add_message(__('Your avatar was deleted successfully!', 'buddypress'));
    } else {
        bp_core_add_message(__('There was a problem deleting that avatar, please try again.', 'buddypress'), 'error');
    }
    bp_core_redirect(wp_get_referer());
}
Exemplo n.º 6
0
/**
 * Catch and process the Requests page.
 */
function friends_screen_requests()
{
    if (bp_is_action_variable('accept', 0) && is_numeric(bp_action_variable(1))) {
        // Check the nonce
        check_admin_referer('friends_accept_friendship');
        if (friends_accept_friendship(bp_action_variable(1))) {
            bp_core_add_message(__('Friendship accepted', 'buddypress'));
        } else {
            bp_core_add_message(__('Friendship could not be accepted', 'buddypress'), 'error');
        }
        bp_core_redirect(trailingslashit(bp_loggedin_user_domain() . bp_current_component() . '/' . bp_current_action()));
    } elseif (bp_is_action_variable('reject', 0) && is_numeric(bp_action_variable(1))) {
        // Check the nonce
        check_admin_referer('friends_reject_friendship');
        if (friends_reject_friendship(bp_action_variable(1))) {
            bp_core_add_message(__('Friendship rejected', 'buddypress'));
        } else {
            bp_core_add_message(__('Friendship could not be rejected', 'buddypress'), 'error');
        }
        bp_core_redirect(trailingslashit(bp_loggedin_user_domain() . bp_current_component() . '/' . bp_current_action()));
    } elseif (bp_is_action_variable('cancel', 0) && is_numeric(bp_action_variable(1))) {
        // Check the nonce
        check_admin_referer('friends_withdraw_friendship');
        if (friends_withdraw_friendship(bp_loggedin_user_id(), bp_action_variable(1))) {
            bp_core_add_message(__('Friendship request withdrawn', 'buddypress'));
        } else {
            bp_core_add_message(__('Friendship request could not be withdrawn', 'buddypress'), 'error');
        }
        bp_core_redirect(trailingslashit(bp_loggedin_user_domain() . bp_current_component() . '/' . bp_current_action()));
    }
    /**
     * Fires before the loading of template for the friends requests page.
     *
     * @since BuddyPress (1.0.0)
     */
    do_action('friends_screen_requests');
    /**
     * Filters the template used to display the My Friends page.
     *
     * @since BuddyPress (1.0.0)
     *
     * @param string $template Path to the friends request template to load.
     */
    bp_core_load_template(apply_filters('friends_template_requests', 'members/single/home'));
}
 /**
  * Sets up the current view when viewing a user page
  *
  * @since 1.2
  */
 function get_current_view($view, $item_type)
 {
     global $wp_rewrite;
     if ($item_type == 'user') {
         $current_action = bp_current_action();
         if (empty($current_action) || in_array($current_action, array(BP_DOCS_STARTED_SLUG, BP_DOCS_EDITED_SLUG))) {
             // An empty $bp->action_variables[0] means that you're looking at a list.
             // A url like members/terry/docs/started/page/3 also means you're looking at a list.
             $view = 'list';
         } else {
             if ($current_action == BP_DOCS_CATEGORY_SLUG) {
                 // Category view
                 $view = 'category';
             } else {
                 if ($current_action == BP_DOCS_CREATE_SLUG) {
                     // Create new doc
                     $view = 'create';
                 } else {
                     if (!bp_action_variable(0)) {
                         // $bp->action_variables[1] is the slug for this doc. If there's no
                         // further chunk, then we're attempting to view a single item
                         $view = 'single';
                     } else {
                         if (bp_is_action_variable(BP_DOCS_EDIT_SLUG, 0)) {
                             // This is an edit page
                             $view = 'edit';
                         } else {
                             if (bp_is_action_variable(BP_DOCS_DELETE_SLUG, 0)) {
                                 // This is an delete request
                                 $view = 'delete';
                             } else {
                                 if (bp_is_action_variable(BP_DOCS_HISTORY_SLUG, 0)) {
                                     // This is a history request
                                     $view = 'history';
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     return $view;
 }
function messages_action_bulk_delete()
{
    if (!bp_is_messages_component() || !bp_is_action_variable('bulk-delete', 0)) {
        return false;
    }
    $thread_ids = $_POST['thread_ids'];
    if (!$thread_ids || !messages_check_thread_access($thread_ids)) {
        bp_core_redirect(trailingslashit(bp_displayed_user_domain() . bp_get_messages_slug() . '/' . bp_current_action()));
    } else {
        if (!check_admin_referer('messages_delete_thread')) {
            return false;
        }
        if (!messages_delete_thread($thread_ids)) {
            bp_core_add_message(__('There was an error deleting messages.', 'buddypress'), 'error');
        } else {
            bp_core_add_message(__('Messages deleted.', 'buddypress'));
        }
        bp_core_redirect(trailingslashit(bp_displayed_user_domain() . bp_get_messages_slug() . '/' . bp_current_action()));
    }
}
Exemplo n.º 9
0
 /**
  * Sets up the current view when viewing a user page
  *
  * @since 1.2
  */
 function get_current_view($view, $item_type)
 {
     if ($item_type == 'user') {
         if (!bp_current_action()) {
             // An empty $bp->action_variables[0] means that you're looking at a list
             $view = 'list';
         } else {
             if (bp_is_current_action(BP_DOCS_CATEGORY_SLUG)) {
                 // Category view
                 $view = 'category';
             } else {
                 if (bp_is_current_action(BP_DOCS_CREATE_SLUG)) {
                     // Create new doc
                     $view = 'create';
                 } else {
                     if (!bp_action_variable(0)) {
                         // $bp->action_variables[1] is the slug for this doc. If there's no
                         // further chunk, then we're attempting to view a single item
                         $view = 'single';
                     } else {
                         if (bp_is_action_variable(BP_DOCS_EDIT_SLUG, 0)) {
                             // This is an edit page
                             $view = 'edit';
                         } else {
                             if (bp_is_action_variable(BP_DOCS_DELETE_SLUG, 0)) {
                                 // This is an delete request
                                 $view = 'delete';
                             } else {
                                 if (bp_is_action_variable(BP_DOCS_HISTORY_SLUG, 0)) {
                                     // This is a history request
                                     $view = 'history';
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     return $view;
 }
 public function view_single()
 {
     $bp = buddypress();
     if (function_exists('bp_is_group') && !bp_is_group()) {
         return;
     }
     //do not catch the request for creating new post
     if (bp_is_action_variable('create', 0)) {
         return;
     }
     $current_group = groups_get_current_group();
     if (bcg_is_disabled($current_group->id)) {
         return;
     }
     //if the group is private/hidden and user is not member, return
     if (($current_group->status == 'private' || $current_group->status == 'hidden') && (!is_user_logged_in() || !groups_is_user_member(bp_loggedin_user_id(), $current_group->id))) {
         return;
         //avoid prioivacy troubles
     }
     if (bcg_is_component() && !empty($bp->action_variables[0])) {
         //should we check for the existence of the post?
         add_action('bp_template_content', array($this, 'get_single_post_contents'));
     }
 }
Exemplo n.º 11
0
/**
 * Initiate the loop for a single topic's posts.
 *
 * @param array $args {
 *     Arguments for limiting the contents of the topic posts loop.
 *     @type int $topic_id ID of the topic to which the posts belong.
 *     @type int $per_page Number of items to return per page. Default: 15.
 *     @type int $max Max items to return. Default: false.
 *     @type string $order 'ASC' or 'DESC'.
 * }
 * @return bool True when posts are found corresponding to the args,
 *         otherwise false.
 */
function bp_has_forum_topic_posts( $args = '' ) {
	global $topic_template;

	$defaults = array(
		'topic_id' => false,
		'per_page' => 15,
		'max'      => false,
		'order'    => 'ASC'
	);

	$r = bp_parse_args( $args, $defaults, 'has_forum_topic_posts' );
	extract( $r, EXTR_SKIP );

	if ( empty( $topic_id ) && bp_is_groups_component() && bp_is_current_action( 'forum' ) && bp_is_action_variable( 'topic', 0 ) && bp_action_variable( 1 ) )
		$topic_id = bp_forums_get_topic_id_from_slug( bp_action_variable( 1 ) );
	elseif ( empty( $topic_id ) && bp_is_forums_component() && bp_is_current_action( 'topic' ) && bp_action_variable( 0 ) )
		$topic_id = bp_forums_get_topic_id_from_slug( bp_action_variable( 0 ) );

	if ( empty( $topic_id ) ) {
		return false;

	} else {
		$topic_template = new BP_Forums_Template_Topic( (int) $topic_id, $per_page, $max, $order );

		// Current topic forum_id needs to match current_group forum_id
		if ( bp_is_groups_component() && $topic_template->forum_id != groups_get_groupmeta( bp_get_current_group_id(), 'forum_id' ) )
			return false;
	}

	/**
	 * Filters whether or not there are topics to display.
	 *
	 * @since BuddyPress (1.1.0)
	 *
	 * @param bool                     $value          Whether or not there are topics.
	 * @param BP_Forums_Template_Topic $topic_template Topic template global to use when rendering.
	 */
	return apply_filters( 'bp_has_topic_posts', $topic_template->has_posts(), $topic_template );
}
Exemplo n.º 12
0
/**
 * Displays Friends header tabs
 *
 * @deprecated 1.6.0
 * @deprecated No longer used
 */
function bp_friends_header_tabs()
{
    _deprecated_function(__FUNCTION__, '1.6', 'Since BuddyPress 1.2, BP has not supported ordering of friend lists by URL parameters.');
    ?>

	<li<?php 
    if (!bp_action_variable(0) || bp_is_action_variable('recently-active', 0)) {
        ?>
 class="current"<?php 
    }
    ?>
><a href="<?php 
    echo trailingslashit(bp_displayed_user_domain() . bp_get_friends_slug() . '/my-friends/recently-active');
    ?>
"><?php 
    _e('Recently Active', 'buddypress');
    ?>
</a></li>
	<li<?php 
    if (bp_is_action_variable('newest', 0)) {
        ?>
 class="current"<?php 
    }
    ?>
><a href="<?php 
    echo trailingslashit(bp_displayed_user_domain() . bp_get_friends_slug() . '/my-friends/newest');
    ?>
"><?php 
    _e('Newest', 'buddypress');
    ?>
</a></li>
	<li<?php 
    if (bp_is_action_variable('alphabetically', 0)) {
        ?>
 class="current"<?php 
    }
    ?>
><a href="<?php 
    echo trailingslashit(bp_displayed_user_domain() . bp_get_friends_slug() . '/my-friends/alphabetically');
    ?>
"><?php 
    _e('Alphabetically', 'buddypress');
    ?>
</a></li>

<?php 
    do_action('friends_header_tabs');
}
Exemplo n.º 13
0
/**
 * This function handles actions related to member management on the group admin.
 */
function groups_screen_group_admin_manage_members()
{
    if ('manage-members' != bp_get_group_current_admin_tab()) {
        return false;
    }
    if (!bp_is_item_admin()) {
        return false;
    }
    $bp = buddypress();
    if (bp_action_variable(1) && bp_action_variable(2) && bp_action_variable(3)) {
        if (bp_is_action_variable('promote', 1) && (bp_is_action_variable('mod', 2) || bp_is_action_variable('admin', 2)) && is_numeric(bp_action_variable(3))) {
            $user_id = bp_action_variable(3);
            $status = bp_action_variable(2);
            // Check the nonce first.
            if (!check_admin_referer('groups_promote_member')) {
                return false;
            }
            // Promote a user.
            if (!groups_promote_member($user_id, $bp->groups->current_group->id, $status)) {
                bp_core_add_message(__('There was an error when promoting that user. Please try again.', 'buddypress'), 'error');
            } else {
                bp_core_add_message(__('User promoted successfully', 'buddypress'));
            }
            /**
             * Fires before the redirect after a group member has been promoted.
             *
             * @since 1.0.0
             *
             * @param int $user_id ID of the user being promoted.
             * @param int $id      ID of the group user is promoted within.
             */
            do_action('groups_promoted_member', $user_id, $bp->groups->current_group->id);
            bp_core_redirect(bp_get_group_permalink(groups_get_current_group()) . 'admin/manage-members/');
        }
    }
    if (bp_action_variable(1) && bp_action_variable(2)) {
        if (bp_is_action_variable('demote', 1) && is_numeric(bp_action_variable(2))) {
            $user_id = bp_action_variable(2);
            // Check the nonce first.
            if (!check_admin_referer('groups_demote_member')) {
                return false;
            }
            // Stop sole admins from abandoning their group.
            $group_admins = groups_get_group_admins($bp->groups->current_group->id);
            if (1 == count($group_admins) && $group_admins[0]->user_id == $user_id) {
                bp_core_add_message(__('This group must have at least one admin', 'buddypress'), 'error');
            } elseif (!groups_demote_member($user_id, $bp->groups->current_group->id)) {
                bp_core_add_message(__('There was an error when demoting that user. Please try again.', 'buddypress'), 'error');
            } else {
                bp_core_add_message(__('User demoted successfully', 'buddypress'));
            }
            /**
             * Fires before the redirect after a group member has been demoted.
             *
             * @since 1.0.0
             *
             * @param int $user_id ID of the user being demoted.
             * @param int $id      ID of the group user is demoted within.
             */
            do_action('groups_demoted_member', $user_id, $bp->groups->current_group->id);
            bp_core_redirect(bp_get_group_permalink(groups_get_current_group()) . 'admin/manage-members/');
        }
        if (bp_is_action_variable('ban', 1) && is_numeric(bp_action_variable(2))) {
            $user_id = bp_action_variable(2);
            // Check the nonce first.
            if (!check_admin_referer('groups_ban_member')) {
                return false;
            }
            // Ban a user.
            if (!groups_ban_member($user_id, $bp->groups->current_group->id)) {
                bp_core_add_message(__('There was an error when banning that user. Please try again.', 'buddypress'), 'error');
            } else {
                bp_core_add_message(__('User banned successfully', 'buddypress'));
            }
            /**
             * Fires before the redirect after a group member has been banned.
             *
             * @since 1.0.0
             *
             * @param int $user_id ID of the user being banned.
             * @param int $id      ID of the group user is banned from.
             */
            do_action('groups_banned_member', $user_id, $bp->groups->current_group->id);
            bp_core_redirect(bp_get_group_permalink(groups_get_current_group()) . 'admin/manage-members/');
        }
        if (bp_is_action_variable('unban', 1) && is_numeric(bp_action_variable(2))) {
            $user_id = bp_action_variable(2);
            // Check the nonce first.
            if (!check_admin_referer('groups_unban_member')) {
                return false;
            }
            // Remove a ban for user.
            if (!groups_unban_member($user_id, $bp->groups->current_group->id)) {
                bp_core_add_message(__('There was an error when unbanning that user. Please try again.', 'buddypress'), 'error');
            } else {
                bp_core_add_message(__('User ban removed successfully', 'buddypress'));
            }
            /**
             * Fires before the redirect after a group member has been unbanned.
             *
             * @since 1.0.0
             *
             * @param int $user_id ID of the user being unbanned.
             * @param int $id      ID of the group user is unbanned from.
             */
            do_action('groups_unbanned_member', $user_id, $bp->groups->current_group->id);
            bp_core_redirect(bp_get_group_permalink(groups_get_current_group()) . 'admin/manage-members/');
        }
        if (bp_is_action_variable('remove', 1) && is_numeric(bp_action_variable(2))) {
            $user_id = bp_action_variable(2);
            // Check the nonce first.
            if (!check_admin_referer('groups_remove_member')) {
                return false;
            }
            // Remove a user.
            if (!groups_remove_member($user_id, $bp->groups->current_group->id)) {
                bp_core_add_message(__('There was an error removing that user from the group. Please try again.', 'buddypress'), 'error');
            } else {
                bp_core_add_message(__('User removed successfully', 'buddypress'));
            }
            /**
             * Fires before the redirect after a group member has been removed.
             *
             * @since 1.2.6
             *
             * @param int $user_id ID of the user being removed.
             * @param int $id      ID of the group the user is removed from.
             */
            do_action('groups_removed_member', $user_id, $bp->groups->current_group->id);
            bp_core_redirect(bp_get_group_permalink(groups_get_current_group()) . 'admin/manage-members/');
        }
    }
    /**
     * Fires before the loading of a group's manage members template.
     *
     * @since 1.0.0
     *
     * @param int $id ID of the group whose manage members page is being displayed.
     */
    do_action('groups_screen_group_admin_manage_members', $bp->groups->current_group->id);
    /**
     * Filters the template to load for a group's manage members page.
     *
     * @since 1.0.0
     *
     * @param string $value Path to a group's manage members template.
     */
    bp_core_load_template(apply_filters('groups_template_group_admin_manage_members', 'groups/single/home'));
}
Exemplo n.º 14
0
/**
 * bp_forums_add_forum_topic_to_page_title( $title )
 *
 * Append forum topic to page title
 *
 * @global object $bp
 * @param string $title New page title; see bp_modify_page_title()
 * @param string $title Original page title
 * @param string $sep How to separate the various items within the page title.
 * @param string $seplocation Direction to display title
 * @return string
 * @see bp_modify_page_title()
 */
function bp_forums_add_forum_topic_to_page_title($title, $original_title, $sep, $seplocation)
{
    global $bp;
    if (bp_is_current_action('forum') && bp_is_action_variable('topic', 0)) {
        if (bp_has_forum_topic_posts()) {
            $title .= bp_get_the_topic_title() . " {$sep} ";
        }
    }
    return $title;
}
Exemplo n.º 15
0
/**
 * Add RSS feed support for a user's following activity.
 *
 * eg. example.com/members/USERNAME/activity/following/feed/
 *
 * Only available in BuddyPress 1.8+.
 *
 * @since 1.2.1
 * @author r-a-y
 */
function bp_follow_my_following_feed()
{
    // only available in BP 1.8+
    if (!class_exists('BP_Activity_Feed')) {
        return;
    }
    if (!bp_is_user_activity() || !bp_is_current_action(constant('BP_FOLLOWING_SLUG')) || !bp_is_action_variable('feed', 0)) {
        return false;
    }
    global $bp;
    // setup the feed
    $bp->activity->feed = new BP_Activity_Feed(array('id' => 'myfollowing', 'title' => sprintf(__('%1$s | %2$s | Following Activity', 'bp-follow'), bp_get_site_name(), bp_get_displayed_user_fullname()), 'link' => trailingslashit(bp_displayed_user_domain() . bp_get_activity_slug() . '/' . constant('BP_FOLLOWING_SLUG')), 'description' => sprintf(__("Activity feed for people that %s is following.", 'buddypress'), bp_get_displayed_user_fullname()), 'activity_args' => array('user_id' => bp_get_following_ids(), 'display_comments' => 'threaded')));
}
Exemplo n.º 16
0
function groups_screen_group_admin_delete_group()
{
    global $bp;
    if (bp_is_groups_component() && bp_is_action_variable('delete-group', 0)) {
        if (!$bp->is_item_admin && !bp_current_user_can('bp_moderate')) {
            return false;
        }
        if (isset($_REQUEST['delete-group-button']) && isset($_REQUEST['delete-group-understand'])) {
            // Check the nonce first.
            if (!check_admin_referer('groups_delete_group')) {
                return false;
            }
            do_action('groups_before_group_deleted', $bp->groups->current_group->id);
            // Group admin has deleted the group, now do it.
            if (!groups_delete_group($bp->groups->current_group->id)) {
                bp_core_add_message(__('There was an error deleting the group, please try again.', 'buddypress'), 'error');
            } else {
                bp_core_add_message(__('The group was deleted successfully', 'buddypress'));
                do_action('groups_group_deleted', $bp->groups->current_group->id);
                bp_core_redirect(bp_loggedin_user_domain() . bp_get_groups_slug() . '/');
            }
            bp_core_redirect(bp_loggedin_user_domain() . bp_get_groups_slug());
        }
        do_action('groups_screen_group_admin_delete_group', $bp->groups->current_group->id);
        bp_core_load_template(apply_filters('groups_template_group_admin_delete_group', 'groups/single/home'));
    }
}
Exemplo n.º 17
0
/**
 * Catch and process email sends.
 *
 * @since 1.1.0
 */
function invite_anyone_catch_send()
{
    global $bp;
    if (!bp_is_current_component($bp->invite_anyone->slug)) {
        return;
    }
    if (!bp_is_current_action('sent-invites')) {
        return;
    }
    if (!bp_is_action_variable('send', 0)) {
        return;
    }
    if (!invite_anyone_process_invitations(stripslashes_deep($_POST))) {
        bp_core_add_message(__('Sorry, there was a problem sending your invitations. Please try again.', 'invite-anyone'), 'error');
    }
    bp_core_redirect(bp_displayed_user_domain() . $bp->invite_anyone->slug . '/sent-invites');
}
function bp_is_course_creation_step($step_slug)
{
    global $bp;
    /* Make sure we are in the courses component */
    if (!bp_is_courses_component() || !bp_is_current_action('create')) {
        return false;
    }
    /* If this the first step, we can just accept and return true */
    $keys = array_keys($bp->courses->course_creation_steps);
    if (!bp_action_variable(1) && array_shift($keys) == $step_slug) {
        return true;
    }
    /* Before allowing a user to see a course creation step we must make sure previous steps are completed */
    if (!bp_is_first_course_creation_step()) {
        if (!bp_are_previous_course_creation_steps_complete($step_slug)) {
            return false;
        }
    }
    /* Check the current step against the step parameter */
    if (bp_is_action_variable($step_slug)) {
        return true;
    }
    return false;
}
Exemplo n.º 19
0
 /**
  * RSS handler for a user's followed sites.
  *
  * When a user lands on /members/USERNAME/activity/followblogs/feed/, this
  * method generates the RSS feed for their followed sites.
  */
 public static function rss_handler()
 {
     // only available in BP 1.8+
     if (!class_exists('BP_Activity_Feed')) {
         return;
     }
     if (!bp_is_user_activity() || !bp_is_current_action(constant('BP_FOLLOW_BLOGS_USER_ACTIVITY_SLUG')) || !bp_is_action_variable('feed', 0)) {
         return;
     }
     // get blog IDs that the user is following
     $following_ids = bp_get_following_ids(array('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);
     // setup the feed
     buddypress()->activity->feed = new BP_Activity_Feed(array('id' => 'followedsites', 'title' => sprintf(__('%1$s | %2$s | Followed Site Activity', 'bp-follow'), bp_get_site_name(), bp_get_displayed_user_fullname()), 'link' => trailingslashit(bp_displayed_user_domain() . bp_get_activity_slug() . '/' . constant('BP_FOLLOW_BLOGS_USER_ACTIVITY_SLUG')), 'description' => sprintf(__("Activity feed for sites that %s is following.", 'buddypress'), bp_get_displayed_user_fullname()), 'activity_args' => $args));
 }
 /**
  * Hook this extension's Edit panel into BuddyPress, if necessary.
  *
  * @since BuddyPress (1.8.0)
  */
 protected function setup_edit_hooks()
 {
     // Bail if not in a group
     if (!bp_is_group()) {
         return;
     }
     // Bail if not an edit screen
     if (!$this->is_screen_enabled('edit') || !bp_is_item_admin()) {
         return;
     }
     $screen = $this->screens['edit'];
     $position = isset($screen['position']) ? (int) $screen['position'] : 10;
     $position += 40;
     $current_group = groups_get_current_group();
     $admin_link = trailingslashit(bp_get_group_permalink($current_group) . 'admin');
     $subnav_args = array('name' => $screen['name'], 'slug' => $screen['slug'], 'parent_slug' => $current_group->slug . '_manage', 'parent_url' => trailingslashit(bp_get_group_permalink($current_group) . 'admin'), 'user_has_access' => bp_is_item_admin(), 'position' => $position, 'screen_function' => 'groups_screen_group_admin');
     // Should we add a menu to the Group's WP Admin Bar
     if (!empty($screen['show_in_admin_bar'])) {
         $subnav_args['show_in_admin_bar'] = true;
     }
     // Add the tab to the manage navigation
     bp_core_new_subnav_item($subnav_args);
     // Catch the edit screen and forward it to the plugin template
     if (bp_is_groups_component() && bp_is_current_action('admin') && bp_is_action_variable($screen['slug'], 0)) {
         $this->call_edit_screen_save($this->group_id);
         add_action('groups_custom_edit_steps', array(&$this, 'call_edit_screen'));
         // Determine the proper template and save for later
         // loading
         if ('' !== bp_locate_template(array('groups/single/home.php'), false)) {
             $this->edit_screen_template = '/groups/single/home';
         } else {
             add_action('bp_template_content_header', create_function('', 'echo "<ul class=\\"content-header-nav\\">"; bp_group_admin_tabs(); echo "</ul>";'));
             add_action('bp_template_content', array(&$this, 'call_edit_screen'));
             $this->edit_screen_template = '/groups/single/plugins';
         }
         // We load the template at bp_screens, to give all
         // extensions a chance to load
         add_action('bp_screens', array($this, 'call_edit_screen_template_loader'));
     }
 }
/**
 * Handles the display of the profile edit page by loading the correct template file.
 * Also checks to make sure this can only be accessed for the logged in users profile.
 *
 * @package BuddyPress XProfile
 * @uses bp_is_my_profile() Checks to make sure the current user being viewed equals the logged in user
 * @uses bp_core_load_template() Looks for and loads a template file within the current member theme (folder/filename)
 */
function xprofile_screen_edit_profile()
{
    global $bp;
    if (!bp_is_my_profile() && !is_super_admin()) {
        return false;
    }
    // Make sure a group is set.
    if (!bp_action_variable(1)) {
        bp_core_redirect(bp_displayed_user_domain() . $bp->profile->slug . '/edit/group/1');
    }
    // Check the field group exists
    if (!bp_is_action_variable('group') || !xprofile_get_field_group(bp_action_variable(1))) {
        bp_do_404();
        return;
    }
    // Check to see if any new information has been submitted
    if (isset($_POST['field_ids'])) {
        // Check the nonce
        check_admin_referer('bp_xprofile_edit');
        // Check we have field ID's
        if (empty($_POST['field_ids'])) {
            bp_core_redirect(trailingslashit($bp->displayed_user->domain . $bp->profile->slug . '/edit/group/' . bp_action_variable(1)));
        }
        // Explode the posted field IDs into an array so we know which
        // fields have been submitted
        $posted_field_ids = explode(',', $_POST['field_ids']);
        $is_required = array();
        // Loop through the posted fields formatting any datebox values
        // then validate the field
        foreach ((array) $posted_field_ids as $field_id) {
            if (!isset($_POST['field_' . $field_id])) {
                if (!empty($_POST['field_' . $field_id . '_day']) && !empty($_POST['field_' . $field_id . '_month']) && !empty($_POST['field_' . $field_id . '_year'])) {
                    // Concatenate the values
                    $date_value = $_POST['field_' . $field_id . '_day'] . ' ' . $_POST['field_' . $field_id . '_month'] . ' ' . $_POST['field_' . $field_id . '_year'];
                    // Turn the concatenated value into a timestamp
                    $_POST['field_' . $field_id] = date('Y-m-d H:i:s', strtotime($date_value));
                }
            }
            $is_required[$field_id] = xprofile_check_is_required_field($field_id);
            if ($is_required[$field_id] && empty($_POST['field_' . $field_id])) {
                $errors = true;
            }
        }
        // There are errors
        if (!empty($errors)) {
            bp_core_add_message(__('Please make sure you fill in all required fields in this profile field group before saving.', 'buddypress'), 'error');
            // No errors
        } else {
            // Reset the errors var
            $errors = false;
            // Now we've checked for required fields, lets save the values.
            foreach ((array) $posted_field_ids as $field_id) {
                // Certain types of fields (checkboxes, multiselects) may come through empty. Save them as an empty array so that they don't get overwritten by the default on the next edit.
                if (empty($_POST['field_' . $field_id])) {
                    $value = array();
                } else {
                    $value = $_POST['field_' . $field_id];
                }
                if (!xprofile_set_field_data($field_id, $bp->displayed_user->id, $value, $is_required[$field_id])) {
                    $errors = true;
                } else {
                    do_action('xprofile_profile_field_data_updated', $field_id, $value);
                }
            }
            do_action('xprofile_updated_profile', $bp->displayed_user->id, $posted_field_ids, $errors);
            // Set the feedback messages
            if ($errors) {
                bp_core_add_message(__('There was a problem updating some of your profile information, please try again.', 'buddypress'), 'error');
            } else {
                bp_core_add_message(__('Changes saved.', 'buddypress'));
            }
            // Redirect back to the edit screen to display the updates and message
            bp_core_redirect(trailingslashit(bp_displayed_user_domain() . $bp->profile->slug . '/edit/group/' . bp_action_variable(1)));
        }
    }
    do_action('xprofile_screen_edit_profile');
    bp_core_load_template(apply_filters('xprofile_template_edit_profile', 'members/single/home'));
}
Exemplo n.º 22
0
function bp_is_group_forum_topic_edit()
{
    if (bp_is_single_item() && bp_is_groups_component() && bp_is_current_action('forum') && bp_is_action_variable('topic', 0) && bp_is_action_variable('edit', 2)) {
        return true;
    }
    return false;
}
/**
 * Is the current page a specific group admin screen?
 *
 * @since 1.1.0
 *
 * @param string $slug Admin screen slug.
 * @return bool
 */
function bp_is_group_admin_screen($slug = '')
{
    return (bool) (bp_is_group_admin_page() && bp_is_action_variable($slug));
}
    /**
     * Hook this extension's Edit panel into BuddyPress, if necessary
     *
     * @since BuddyPress (1.8)
     */
    protected function setup_edit_hooks()
    {
        // Bail if not an edit screen
        if (!$this->is_screen_enabled('edit') || !bp_is_item_admin()) {
            return;
        }
        $screen = $this->screens['edit'];
        $position = isset($screen['position']) ? (int) $screen['position'] : 10;
        // Add the tab
        // @todo BP should be using bp_core_new_subnav_item()
        add_action('groups_admin_tabs', create_function('$current, $group_slug', '$selected = "";
			if ( "' . esc_attr($screen['slug']) . '" == $current )
				$selected = " class=\\"current\\"";
			echo "<li{$selected}><a href=\\"' . trailingslashit(bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/{$group_slug}/admin/' . esc_attr($screen['slug'])) . '\\">' . esc_attr($screen['name']) . '</a></li>";'), $position, 2);
        // Catch the edit screen and forward it to the plugin template
        if (bp_is_groups_component() && bp_is_current_action('admin') && bp_is_action_variable($screen['slug'], 0)) {
            $this->call_edit_screen_save($this->group_id);
            add_action('groups_custom_edit_steps', array(&$this, 'call_edit_screen'));
            // Determine the proper template and save for later
            // loading
            if ('' !== bp_locate_template(array('groups/single/home.php'), false)) {
                $this->edit_screen_template = '/groups/single/home';
            } else {
                add_action('bp_template_content_header', create_function('', 'echo "<ul class=\\"content-header-nav\\">"; bp_group_admin_tabs(); echo "</ul>";'));
                add_action('bp_template_content', array(&$this, 'call_edit_screen'));
                $this->edit_screen_template = '/groups/single/plugins';
            }
            // We load the template at bp_screens, to give all
            // extensions a chance to load
            add_action('bp_screens', array($this, 'call_edit_screen_template_loader'));
        }
    }
Exemplo n.º 25
0
/**
 * Initiate the loop for a single topic's posts.
 *
 * @param array $args {
 *     Arguments for limiting the contents of the topic posts loop.
 *     @type int $topic_id ID of the topic to which the posts belong.
 *     @type int $per_page Number of items to return per page. Default: 15.
 *     @type int $max Max items to return. Default: false.
 *     @type string $order 'ASC' or 'DESC'.
 * }
 * @return bool True when posts are found corresponding to the args,
 *         otherwise false.
 */
function bp_has_forum_topic_posts($args = '')
{
    global $topic_template;
    $defaults = array('topic_id' => false, 'per_page' => 15, 'max' => false, 'order' => 'ASC');
    $r = bp_parse_args($args, $defaults, 'has_forum_topic_posts');
    extract($r, EXTR_SKIP);
    if (empty($topic_id) && bp_is_groups_component() && bp_is_current_action('forum') && bp_is_action_variable('topic', 0) && bp_action_variable(1)) {
        $topic_id = bp_forums_get_topic_id_from_slug(bp_action_variable(1));
    } elseif (empty($topic_id) && bp_is_forums_component() && bp_is_current_action('topic') && bp_action_variable(0)) {
        $topic_id = bp_forums_get_topic_id_from_slug(bp_action_variable(0));
    }
    if (empty($topic_id)) {
        return false;
    } else {
        $topic_template = new BP_Forums_Template_Topic((int) $topic_id, $per_page, $max, $order);
        // Current topic forum_id needs to match current_group forum_id
        if (bp_is_groups_component() && $topic_template->forum_id != groups_get_groupmeta(bp_get_current_group_id(), 'forum_id')) {
            return false;
        }
    }
    return apply_filters('bp_has_topic_posts', $topic_template->has_posts(), $topic_template);
}
Exemplo n.º 26
0
/**
 * This function handles actions related to member management on the group admin.
 */
function groups_screen_group_admin_manage_members()
{
    if ('manage-members' != bp_get_group_current_admin_tab()) {
        return false;
    }
    if (!bp_is_item_admin()) {
        return false;
    }
    $bp = buddypress();
    if (bp_action_variable(1) && bp_action_variable(2) && bp_action_variable(3)) {
        if (bp_is_action_variable('promote', 1) && (bp_is_action_variable('mod', 2) || bp_is_action_variable('admin', 2)) && is_numeric(bp_action_variable(3))) {
            $user_id = bp_action_variable(3);
            $status = bp_action_variable(2);
            // Check the nonce first.
            if (!check_admin_referer('groups_promote_member')) {
                return false;
            }
            // Promote a user.
            if (!groups_promote_member($user_id, $bp->groups->current_group->id, $status)) {
                bp_core_add_message(__('There was an error when promoting that user. Please try again.', 'buddypress'), 'error');
            } else {
                bp_core_add_message(__('User promoted successfully', 'buddypress'));
            }
            do_action('groups_promoted_member', $user_id, $bp->groups->current_group->id);
            bp_core_redirect(bp_get_group_permalink(groups_get_current_group()) . 'admin/manage-members/');
        }
    }
    if (bp_action_variable(1) && bp_action_variable(2)) {
        if (bp_is_action_variable('demote', 1) && is_numeric(bp_action_variable(2))) {
            $user_id = bp_action_variable(2);
            // Check the nonce first.
            if (!check_admin_referer('groups_demote_member')) {
                return false;
            }
            // Stop sole admins from abandoning their group
            $group_admins = groups_get_group_admins($bp->groups->current_group->id);
            if (1 == count($group_admins) && $group_admins[0]->user_id == $user_id) {
                bp_core_add_message(__('This group must have at least one admin', 'buddypress'), 'error');
            } elseif (!groups_demote_member($user_id, $bp->groups->current_group->id)) {
                bp_core_add_message(__('There was an error when demoting that user. Please try again.', 'buddypress'), 'error');
            } else {
                bp_core_add_message(__('User demoted successfully', 'buddypress'));
            }
            do_action('groups_demoted_member', $user_id, $bp->groups->current_group->id);
            bp_core_redirect(bp_get_group_permalink(groups_get_current_group()) . 'admin/manage-members/');
        }
        if (bp_is_action_variable('ban', 1) && is_numeric(bp_action_variable(2))) {
            $user_id = bp_action_variable(2);
            // Check the nonce first.
            if (!check_admin_referer('groups_ban_member')) {
                return false;
            }
            // Ban a user.
            if (!groups_ban_member($user_id, $bp->groups->current_group->id)) {
                bp_core_add_message(__('There was an error when banning that user. Please try again.', 'buddypress'), 'error');
            } else {
                bp_core_add_message(__('User banned successfully', 'buddypress'));
            }
            do_action('groups_banned_member', $user_id, $bp->groups->current_group->id);
            bp_core_redirect(bp_get_group_permalink(groups_get_current_group()) . 'admin/manage-members/');
        }
        if (bp_is_action_variable('unban', 1) && is_numeric(bp_action_variable(2))) {
            $user_id = bp_action_variable(2);
            // Check the nonce first.
            if (!check_admin_referer('groups_unban_member')) {
                return false;
            }
            // Remove a ban for user.
            if (!groups_unban_member($user_id, $bp->groups->current_group->id)) {
                bp_core_add_message(__('There was an error when unbanning that user. Please try again.', 'buddypress'), 'error');
            } else {
                bp_core_add_message(__('User ban removed successfully', 'buddypress'));
            }
            do_action('groups_unbanned_member', $user_id, $bp->groups->current_group->id);
            bp_core_redirect(bp_get_group_permalink(groups_get_current_group()) . 'admin/manage-members/');
        }
        if (bp_is_action_variable('remove', 1) && is_numeric(bp_action_variable(2))) {
            $user_id = bp_action_variable(2);
            // Check the nonce first.
            if (!check_admin_referer('groups_remove_member')) {
                return false;
            }
            // Remove a user.
            if (!groups_remove_member($user_id, $bp->groups->current_group->id)) {
                bp_core_add_message(__('There was an error removing that user from the group. Please try again.', 'buddypress'), 'error');
            } else {
                bp_core_add_message(__('User removed successfully', 'buddypress'));
            }
            do_action('groups_removed_member', $user_id, $bp->groups->current_group->id);
            bp_core_redirect(bp_get_group_permalink(groups_get_current_group()) . 'admin/manage-members/');
        }
    }
    do_action('groups_screen_group_admin_manage_members', $bp->groups->current_group->id);
    bp_core_load_template(apply_filters('groups_template_group_admin_manage_members', 'groups/single/home'));
}
function bp_is_group_admin_screen($slug)
{
    if (!bp_is_groups_component() || !bp_is_current_action('admin')) {
        return false;
    }
    if (bp_is_action_variable($slug)) {
        return true;
    }
    return false;
}
/**
 * Is the current page a group forum topic edit page?
 *
 * Only applies to legacy bbPress (1.x) forums.
 *
 * @since 1.2.0
 *
 * @return bool True if the current page is part of a group forum topic edit page.
 */
function bp_is_group_forum_topic_edit()
{
    return (bool) (bp_is_single_item() && bp_is_groups_component() && bp_is_current_action('forum') && bp_is_action_variable('topic', 0) && bp_is_action_variable('edit', 2));
}
Exemplo n.º 29
0
 function _register()
 {
     global $bp;
     // If admin/create names and slugs are not provided, they fall back on the main
     // name and slug for the extension
     if (!$this->admin_name) {
         $this->admin_name = $this->name;
     }
     if (!$this->admin_slug) {
         $this->admin_slug = $this->slug;
     }
     if (!$this->create_name) {
         $this->create_name = $this->name;
     }
     if (!$this->create_slug) {
         $this->create_slug = $this->slug;
     }
     if (!empty($this->enable_create_step)) {
         // Insert the group creation step for the new group extension
         $bp->groups->group_creation_steps[$this->create_slug] = array('name' => $this->create_name, 'slug' => $this->create_slug, 'position' => $this->create_step_position);
         // Attach the group creation step display content action
         add_action('groups_custom_create_steps', array(&$this, 'create_screen'));
         // Attach the group creation step save content action
         add_action('groups_create_group_step_save_' . $this->create_slug, array(&$this, 'create_screen_save'));
     }
     // When we are viewing a single group, add the group extension nav item
     if (bp_is_group()) {
         if ($this->visibility == 'public' || $this->visibility != 'public' && $bp->groups->current_group->user_has_access) {
             if ($this->enable_nav_item) {
                 bp_core_new_subnav_item(array('name' => !$this->nav_item_name ? $this->name : $this->nav_item_name, 'slug' => $this->slug, 'parent_slug' => $bp->groups->current_group->slug, 'parent_url' => bp_get_group_permalink($bp->groups->current_group), 'position' => $this->nav_item_position, 'item_css_id' => 'nav-' . $this->slug, 'screen_function' => array(&$this, '_display_hook'), 'user_has_access' => $this->enable_nav_item));
                 // When we are viewing the extension display page, set the title and options title
                 if (bp_is_current_action($this->slug)) {
                     add_action('bp_template_content_header', create_function('', 'echo "' . esc_attr($this->name) . '";'));
                     add_action('bp_template_title', create_function('', 'echo "' . esc_attr($this->name) . '";'));
                 }
             }
             // Hook the group home widget
             if (!bp_current_action() && bp_is_current_action('home')) {
                 add_action($this->display_hook, array(&$this, 'widget_display'));
             }
         }
     }
     // Construct the admin edit tab for the new group extension
     if (!empty($this->enable_edit_item) && bp_is_item_admin()) {
         add_action('groups_admin_tabs', create_function('$current, $group_slug', '$selected = ""; if ( "' . esc_attr($this->admin_slug) . '" == $current ) $selected = " class=\\"current\\""; echo "<li{$selected}><a href=\\"' . trailingslashit(bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/{$group_slug}/admin/' . esc_attr($this->admin_slug)) . '\\">' . esc_attr($this->admin_name) . '</a></li>";'), 10, 2);
         // Catch the edit screen and forward it to the plugin template
         if (bp_is_groups_component() && bp_is_current_action('admin') && bp_is_action_variable($this->admin_slug, 0)) {
             // Check whether the user is saving changes
             $this->edit_screen_save();
             add_action('groups_custom_edit_steps', array(&$this, 'edit_screen'));
             if ('' != locate_template(array('groups/single/home.php'), false)) {
                 bp_core_load_template(apply_filters('groups_template_group_home', 'groups/single/home'));
             } else {
                 add_action('bp_template_content_header', create_function('', 'echo "<ul class=\\"content-header-nav\\">"; bp_group_admin_tabs(); echo "</ul>";'));
                 add_action('bp_template_content', array(&$this, 'edit_screen'));
                 bp_core_load_template(apply_filters('bp_core_template_plugin', '/groups/single/plugins'));
             }
         }
     }
 }
Exemplo n.º 30
0
/**
 * Handles the display of the profile edit page by loading the correct template file.
 * Also checks to make sure this can only be accessed for the logged in users profile.
 *
 * @package BuddyPress XProfile
 * @uses bp_is_my_profile() Checks to make sure the current user being viewed equals the logged in user
 * @uses bp_core_load_template() Looks for and loads a template file within the current member theme (folder/filename)
 */
function xprofile_screen_edit_profile()
{
    if (!bp_is_my_profile() && !bp_current_user_can('bp_moderate')) {
        return false;
    }
    $bp = buddypress();
    // Make sure a group is set.
    if (!bp_action_variable(1)) {
        bp_core_redirect(trailingslashit(bp_displayed_user_domain() . $bp->profile->slug . '/edit/group/1'));
    }
    // Check the field group exists
    if (!bp_is_action_variable('group') || !xprofile_get_field_group(bp_action_variable(1))) {
        bp_do_404();
        return;
    }
    // No errors
    $errors = false;
    // Check to see if any new information has been submitted
    if (isset($_POST['field_ids'])) {
        // Check the nonce
        check_admin_referer('bp_xprofile_edit');
        // Check we have field ID's
        if (empty($_POST['field_ids'])) {
            bp_core_redirect(trailingslashit(bp_displayed_user_domain() . $bp->profile->slug . '/edit/group/' . bp_action_variable(1)));
        }
        // Explode the posted field IDs into an array so we know which
        // fields have been submitted
        $posted_field_ids = wp_parse_id_list($_POST['field_ids']);
        $is_required = array();
        // Loop through the posted fields formatting any datebox values
        // then validate the field
        foreach ((array) $posted_field_ids as $field_id) {
            if (!isset($_POST['field_' . $field_id])) {
                if (!empty($_POST['field_' . $field_id . '_day']) && !empty($_POST['field_' . $field_id . '_month']) && !empty($_POST['field_' . $field_id . '_year'])) {
                    // Concatenate the values
                    $date_value = $_POST['field_' . $field_id . '_day'] . ' ' . $_POST['field_' . $field_id . '_month'] . ' ' . $_POST['field_' . $field_id . '_year'];
                    // Turn the concatenated value into a timestamp
                    $_POST['field_' . $field_id] = date('Y-m-d H:i:s', strtotime($date_value));
                }
            }
            $is_required[$field_id] = xprofile_check_is_required_field($field_id);
            if ($is_required[$field_id] && empty($_POST['field_' . $field_id])) {
                $errors = true;
            }
        }
        // There are errors
        if (!empty($errors)) {
            bp_core_add_message(__('Please make sure you fill in all required fields in this profile field group before saving.', 'buddypress'), 'error');
            // No errors
        } else {
            // Reset the errors var
            $errors = false;
            // Now we've checked for required fields, lets save the values.
            $old_values = $new_values = array();
            foreach ((array) $posted_field_ids as $field_id) {
                // Certain types of fields (checkboxes, multiselects) may come through empty. Save them as an empty array so that they don't get overwritten by the default on the next edit.
                $value = isset($_POST['field_' . $field_id]) ? $_POST['field_' . $field_id] : '';
                $visibility_level = !empty($_POST['field_' . $field_id . '_visibility']) ? $_POST['field_' . $field_id . '_visibility'] : 'public';
                // Save the old and new values. They will be
                // passed to the filter and used to determine
                // whether an activity item should be posted
                $old_values[$field_id] = array('value' => xprofile_get_field_data($field_id, bp_displayed_user_id()), 'visibility' => xprofile_get_field_visibility_level($field_id, bp_displayed_user_id()));
                // Update the field data and visibility level
                xprofile_set_field_visibility_level($field_id, bp_displayed_user_id(), $visibility_level);
                $field_updated = xprofile_set_field_data($field_id, bp_displayed_user_id(), $value, $is_required[$field_id]);
                $value = xprofile_get_field_data($field_id, bp_displayed_user_id());
                $new_values[$field_id] = array('value' => $value, 'visibility' => xprofile_get_field_visibility_level($field_id, bp_displayed_user_id()));
                if (!$field_updated) {
                    $errors = true;
                } else {
                    /**
                     * Fires on each iteration of an XProfile field being saved with no error.
                     *
                     * @since BuddyPress (1.1.0)
                     *
                     * @param int    $field_id ID of the field that was saved.
                     * @param string $value    Value that was saved to the field.
                     */
                    do_action('xprofile_profile_field_data_updated', $field_id, $value);
                }
            }
            /**
             * Fires after all XProfile fields have been saved for the current profile.
             *
             * @since BuddyPress (1.0.0)
             *
             * @param int   $value            Displayed user ID.
             * @param array $posted_field_ids Array of field IDs that were edited.
             * @param bool  $errors           Whether or not any errors occurred.
             * @param array $old_values       Array of original values before updated.
             * @param array $new_values       Array of newly saved values after update.
             */
            do_action('xprofile_updated_profile', bp_displayed_user_id(), $posted_field_ids, $errors, $old_values, $new_values);
            // Set the feedback messages
            if (!empty($errors)) {
                bp_core_add_message(__('There was a problem updating some of your profile information. Please try again.', 'buddypress'), 'error');
            } else {
                bp_core_add_message(__('Changes saved.', 'buddypress'));
            }
            // Redirect back to the edit screen to display the updates and message
            bp_core_redirect(trailingslashit(bp_displayed_user_domain() . $bp->profile->slug . '/edit/group/' . bp_action_variable(1)));
        }
    }
    /**
     * Fires right before the loading of the XProfile edit screen template file.
     *
     * @since BuddyPress (1.0.0)
     */
    do_action('xprofile_screen_edit_profile');
    /**
     * Filters the template to load for the XProfile edit screen.
     *
     * @since BuddyPress (1.0.0)
     *
     * @param string $template Path to the XProfile edit template to load.
     */
    bp_core_load_template(apply_filters('xprofile_template_edit_profile', 'members/single/home'));
}