Пример #1
1
function bphelp_pbpp_redirect()
{
    global $bp;
    //IMPORTANT: Do not alter the following line.
    $bphelp_my_redirect_slug = get_option('bphelp-my-redirect-slug', 'register');
    if (bp_is_activity_component() || bp_is_groups_component() || bp_is_group_forum() || bbp_is_single_forum() || bbp_is_single_topic() || bp_is_forums_component() || bp_is_blogs_component() || bp_is_members_component() || bp_is_profile_component()) {
        if (!is_user_logged_in()) {
            bp_core_redirect(get_option('home') . '/' . $bphelp_my_redirect_slug);
        }
    }
}
Пример #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'));
}
/**
 * Catch and process Remove Friendship requests.
 *
 * @since 1.0.1
 */
function friends_action_remove_friend()
{
    if (!bp_is_friends_component() || !bp_is_current_action('remove-friend')) {
        return false;
    }
    if (!($potential_friend_id = (int) bp_action_variable(0))) {
        return false;
    }
    if ($potential_friend_id == bp_loggedin_user_id()) {
        return false;
    }
    $friendship_status = BP_Friends_Friendship::check_is_friend(bp_loggedin_user_id(), $potential_friend_id);
    if ('is_friend' == $friendship_status) {
        if (!check_admin_referer('friends_remove_friend')) {
            return false;
        }
        if (!friends_remove_friend(bp_loggedin_user_id(), $potential_friend_id)) {
            bp_core_add_message(__('Friendship could not be canceled.', 'buddypress'), 'error');
        } else {
            bp_core_add_message(__('Friendship canceled', 'buddypress'));
        }
    } elseif ('is_friends' == $friendship_status) {
        bp_core_add_message(__('You are not yet friends with this user', 'buddypress'), 'error');
    } else {
        bp_core_add_message(__('You have a pending friendship request with this user', 'buddypress'), 'error');
    }
    bp_core_redirect(wp_get_referer());
    return false;
}
Пример #4
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'));
}
Пример #5
0
function bp_blogs_redirect_to_random_blog()
{
    global $bp, $nxtdb;
    if (bp_is_blogs_component() && isset($_GET['random-blog'])) {
        $blog = bp_blogs_get_random_blogs(1, 1);
        bp_core_redirect(get_site_url($blog['blogs'][0]->blog_id));
    }
}
function bp_forums_directory_forums_setup()
{
    global $bp;
    if (bp_is_forums_component() && (!bp_current_action() || 'tag' == bp_current_action() && bp_action_variables()) && !bp_current_item()) {
        if (!bp_forums_has_directory()) {
            return false;
        }
        if (!bp_forums_is_installed_correctly()) {
            bp_core_add_message(__('The forums component has not been set up yet.', 'buddypress'), 'error');
            bp_core_redirect(bp_get_root_domain());
        }
        bp_update_is_directory(true, 'forums');
        do_action('bbpress_init');
        // Check to see if the user has posted a new topic from the forums page.
        if (isset($_POST['submit_topic']) && bp_is_active('forums')) {
            check_admin_referer('bp_forums_new_topic');
            $bp->groups->current_group = groups_get_group(array('group_id' => $_POST['topic_group_id']));
            if (!empty($bp->groups->current_group->id)) {
                // Auto join this user if they are not yet a member of this group
                if (!is_super_admin() && 'public' == $bp->groups->current_group->status && !groups_is_user_member($bp->loggedin_user->id, $bp->groups->current_group->id)) {
                    groups_join_group($bp->groups->current_group->id);
                }
                $error_message = '';
                $forum_id = groups_get_groupmeta($bp->groups->current_group->id, 'forum_id');
                if (!empty($forum_id)) {
                    if (empty($_POST['topic_title'])) {
                        $error_message = __('Please provide a title for your forum topic.', 'buddypress');
                    } else {
                        if (empty($_POST['topic_text'])) {
                            $error_message = __('Forum posts cannot be empty. Please enter some text.', 'buddypress');
                        }
                    }
                    if ($error_message) {
                        bp_core_add_message($error_message, 'error');
                        $redirect = bp_get_group_permalink($bp->groups->current_group) . 'forum';
                    } else {
                        if (!($topic = groups_new_group_forum_topic($_POST['topic_title'], $_POST['topic_text'], $_POST['topic_tags'], $forum_id))) {
                            bp_core_add_message(__('There was an error when creating the topic', 'buddypress'), 'error');
                            $redirect = bp_get_group_permalink($bp->groups->current_group) . 'forum';
                        } else {
                            bp_core_add_message(__('The topic was created successfully', 'buddypress'));
                            $redirect = bp_get_group_permalink($bp->groups->current_group) . 'forum/topic/' . $topic->topic_slug . '/';
                        }
                    }
                    bp_core_redirect($redirect);
                } else {
                    bp_core_add_message(__('Please pick the group forum where you would like to post this topic.', 'buddypress'), 'error');
                    bp_core_redirect(add_query_arg('new', '', bp_get_forums_directory_permalink()));
                }
            } else {
                bp_core_add_message(__('Please pick the group forum where you would like to post this topic.', 'buddypress'), 'error');
                bp_core_redirect(add_query_arg('new', '', bp_get_forums_directory_permalink()));
            }
        }
        do_action('bp_forums_directory_forums_setup');
        bp_core_load_template(apply_filters('bp_forums_template_directory_forums_setup', 'forums/index'));
    }
}
/**
* Reject the curren page view. It currently only supports re-direction.
* But should perhaps support to just hide content and show a message or something?
*/
function reject_this_page_view()
{
    global $post;
    $redirect_page_id = get_option('wc_memberships_redirect_page_id');
    if ($post->ID == $redirect_page_id) {
        return;
    }
    $redirect_url = $redirect_page_id ? get_permalink($redirect_page_id) : home_url();
    bp_core_redirect($redirect_url);
    exit;
}
Пример #8
0
/**
 * Redirect to a random blog in the multisite network
 *
 * @since BuddyPress (1.0)
 * @package BuddyPress
 * @subpackage BlogsActions
 */
function bp_blogs_redirect_to_random_blog()
{
    // Bail if not looking for a random blog
    if (!bp_is_blogs_component() || !isset($_GET['random-blog'])) {
        return;
    }
    // Multisite is active so find a random blog
    if (is_multisite()) {
        $blog = bp_blogs_get_random_blogs(1, 1);
        bp_core_redirect(get_site_url($blog['blogs'][0]->blog_id));
        // No multisite and still called, always redirect to root
    } else {
        bp_core_redirect(bp_core_get_root_domain());
    }
}
/**
 * Delte an item 
 */
function bp_portfolio_item_delete()
{
    if (bp_is_portfolio_component() and bp_is_current_action('delete') and bp_displayed_user_id() == bp_loggedin_user_id()) {
        if ($project_id = bp_action_variable() and wp_verify_nonce($_REQUEST['_wpnonce'], 'delete_project')) {
            if (bp_portfolio_delete_item($project_id)) {
                bp_core_add_message(__('Project deleted !', 'bp-portfolio'));
            } else {
                bp_core_add_message(__('An error occured, please try again.', 'bp-portfolio'), 'error');
            }
        } else {
            bp_core_add_message(__('An error occured, please try again.', 'bp-portfolio'), 'error');
        }
        bp_core_redirect(bp_core_get_user_domain(bp_loggedin_user_id()) . bp_get_portfolio_slug());
    }
}
 public function edit_screen_save($group_id = null)
 {
     $bp = buddypress();
     if (!isset($_POST['save'])) {
         return false;
     }
     check_admin_referer('groups_edit_save_' . $this->slug);
     $group_id = $bp->groups->current_group->id;
     $cats = $_POST['blog_cats'];
     if (!bcg_update_categories($group_id, $cats)) {
         bp_core_add_message(__('There was an error updating Group Blog Categories settings, please try again.', 'bcg'), 'error');
     } else {
         bp_core_add_message(__('Group Blog Categories settings were successfully updated.', 'bcg'));
     }
     bp_core_redirect(bp_get_group_permalink($bp->groups->current_group) . '/admin/' . $this->slug);
 }
/**
 * 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());
}
Пример #13
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'));
}
Пример #14
0
function bp_forums_directory_forums_setup() {
	global $bp;

	if ( $bp->current_component == $bp->forums->slug ) {
		if ( (int) $bp->site_options['bp-disable-forum-directory'] || !function_exists( 'groups_install' ) )
			return false;

		if ( !bp_forums_is_installed_correctly() ) {
			bp_core_add_message( __( 'The forums component has not been set up yet.', 'buddypress' ), 'error' );
			bp_core_redirect( $bp->root_domain );
		}

		$bp->is_directory = true;

		do_action( 'bbpress_init' );

		/* Check to see if the user has posted a new topic from the forums page. */
		if ( isset( $_POST['submit_topic'] ) && function_exists( 'bp_forums_new_topic' ) ) {
			/* Check the nonce */
			check_admin_referer( 'bp_forums_new_topic' );

			if ( $bp->groups->current_group = groups_get_group( array( 'group_id' => $_POST['topic_group_id'] ) ) ) {
				/* Auto join this user if they are not yet a member of this group */
				if ( !is_super_admin() && 'public' == $bp->groups->current_group->status && !groups_is_user_member( $bp->loggedin_user->id, $bp->groups->current_group->id ) )
					groups_join_group( $bp->groups->current_group->id, $bp->groups->current_group->id );

				if ( $forum_id = groups_get_groupmeta( $bp->groups->current_group->id, 'forum_id' ) ) {
					if ( !$topic = groups_new_group_forum_topic( $_POST['topic_title'], $_POST['topic_text'], $_POST['topic_tags'], $forum_id ) )
						bp_core_add_message( __( 'There was an error when creating the topic', 'buddypress'), 'error' );
					else
						bp_core_add_message( __( 'The topic was created successfully', 'buddypress') );

					bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) . '/forum/topic/' . $topic->topic_slug . '/' );
				} else {
					bp_core_add_message( __( 'Please pick the group forum where you would like to post this topic.', 'buddypress' ), 'error' );
				}
			}
		}

		do_action( 'bp_forums_directory_forums_setup' );

		bp_core_load_template( apply_filters( 'bp_forums_template_directory_forums_setup', 'forums/index' ) );
	}
}
Пример #15
0
 function bp_group_reviews_extension()
 {
     global $bp;
     $this->group_id = BP_Groups_Group::group_exists($bp->current_item);
     $this->name = __('Reviews', 'bpgr');
     $this->slug = $bp->group_reviews->slug;
     $this->nav_item_position = 22;
     $this->enable_create_step = false;
     $this->enable_nav_item = BP_Group_Reviews::current_group_is_available();
     $this->enable_edit_item = false;
     if (isset($_POST['review_submit'])) {
         check_admin_referer('review_submit');
         $has_posted = '';
         if (empty($_POST['review_content']) || !(int) $_POST['rating']) {
             // Something has gone wrong. Save the user's submitted data to reinsert into the post box after redirect
             $cookie_data = array('review_content' => $_POST['review_content'], 'rating' => $_POST['rating']);
             $cookie = json_encode($cookie_data);
             setcookie('bpgr-data', $cookie, time() + 60 * 60 * 24, COOKIEPATH);
             bp_core_add_message(__("Please make sure you fill in the review, and don't forget to provide a rating!", 'bpgr'), 'error');
         } else {
             /* Auto join this user if they are not yet a member of this group */
             if (!is_super_admin() && 'public' == $bp->groups->current_group->status && !groups_is_user_member($bp->loggedin_user->id, $bp->groups->current_group->id)) {
                 groups_join_group($bp->groups->current_group->id, $bp->loggedin_user->id);
             }
             if ($rating_id = $this->post_review(array('content' => $_POST['review_content'], 'rating' => (int) $_POST['rating']))) {
                 bp_core_add_message("Your review was posted successfully!");
                 $has_posted = groups_get_groupmeta($bp->groups->current_group->id, 'posted_review');
                 if (!in_array((int) $bp->loggedin_user->id, (array) $has_posted)) {
                     $has_posted[] = (int) $bp->loggedin_user->id;
                 }
                 groups_update_groupmeta($bp->groups->current_group->id, 'posted_review', $has_posted);
                 if ((int) $_POST['rating'] < 0) {
                     $_POST['rating'] = 1;
                 }
                 if ((int) $_POST['rating'] > 5) {
                     $_POST['rating'] = 5;
                 }
             } else {
                 bp_core_add_message("There was a problem posting your review, please try again.", 'error');
             }
         }
         bp_core_redirect(apply_filters('bpgr_after_post_redirect', trailingslashit(bp_get_group_permalink($bp->groups->current_group) . $this->slug, $has_posted)));
     }
 }
Пример #16
0
 /**
  * Check user access and redirect if access denied
  */
 public function maybe_redirect()
 {
     // always allow access to blog, registration and activation pages
     if (bp_is_blog_page() || bp_is_register_page() || bp_is_activation_page()) {
         return;
     }
     // grab toggle option from registry
     $opt_toggle = $this->get_suboption('toggle');
     // is option toggled on?
     if ($opt_toggle && true == $opt_toggle->get()) {
         // protection is enabled, is user logged in?
         if (!is_user_logged_in()) {
             // not logged in, redirect to registration page
             bp_core_redirect(bp_get_root_domain() . '/' . bp_get_root_slug('register'));
             // exit to avoid any accidental output
             exit;
         }
     }
 }
Пример #17
0
function bp_autologin_on_activation($user_id, $key, $user)
{
    global $bp, $wpdb;
    //simulate Bp activation
    /* Check for an uploaded avatar and move that to the correct user folder, just do what bp does */
    if (is_multisite()) {
        $hashed_key = wp_hash($key);
    } else {
        $hashed_key = wp_hash($user_id);
    }
    /* Check if the avatar folder exists. If it does, move rename it, move it and delete the signup avatar dir */
    if (file_exists(BP_AVATAR_UPLOAD_PATH . '/avatars/signups/' . $hashed_key)) {
        @rename(BP_AVATAR_UPLOAD_PATH . '/avatars/signups/' . $hashed_key, BP_AVATAR_UPLOAD_PATH . '/avatars/' . $user_id);
    }
    bp_core_add_message(__('Your account is now active!', 'buddypress'));
    $bp->activation_complete = true;
    //now login and redirect
    wp_set_auth_cookie($user_id, true, false);
    bp_core_redirect(apply_filters("bpdev_autoactivate_redirect_url", bp_core_get_user_domain($user_id), $user_id));
}
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()));
    }
}
function buatp_directory_setup()
{
    $buatp_general_settings = get_option('buatp_basic_setting', true);
    global $bp;
    if (bp_is_buatp_component() && !$bp->current_action) {
        if ($buatp_general_settings['buatp_default_type_selection']) {
            bp_core_redirect(buatp_get_type_directory_url($buatp_general_settings['buatp_default_type_selection']));
        } else {
            bp_core_redirect(site_url());
        }
    } else {
        if (bp_is_buatp_component() && $bp->current_action) {
            if ($bp->buatp->directory_id) {
                do_action('buatp_directory_setup');
                bp_core_load_template(apply_filters('buatp_directory_template', 'members/members-loop'));
            } else {
                bp_core_redirect(site_url());
            }
        }
    }
}
Пример #20
0
/**
* let's delete reshare update if js is disabled
*/
function bp_reshare_delete_reshare()
{
    if (!empty($_GET['delete_reshare']) && is_numeric($_GET['delete_reshare'])) {
        check_admin_referer('_reshare_delete');
        $redirect = remove_query_arg(array('delete_reshare', '_wpnonce'), wp_get_referer());
        $reshare_id = intval($_GET['delete_reshare']);
        $reshare_to_delete = bp_activity_get_specific('activity_ids=' . $reshare_id);
        $reshare = $reshare_to_delete['activities'][0];
        bp_reshare_delete($reshare->secondary_item_id, $reshare->user_id);
        $deleted_reshare = bp_activity_delete(array('type' => 'reshare_update', 'id' => $reshare_id));
        if (!empty($deleted_reshare)) {
            do_action('bp_reshare_handle_nojs_deleted', $reshare_id);
            bp_core_add_message(__('Reshare deleted !', 'bp-reshare'));
            bp_core_redirect($redirect);
        } else {
            do_action('bp_reshare_handle_nojs_missed', $reshare_id);
            bp_core_add_message(__('OOps, error while trying to reshare..', 'bp-reshare'), 'error');
            bp_core_redirect($redirect);
        }
    }
}
/**
 * Catches clicks on a "Unfollow" button and tries to make that happen.
 *
 * @uses check_admin_referer() Checks to make sure the WP security nonce matches.
 * @uses bp_follow_is_following() Checks to see if a user is following another user already.
 * @uses bp_follow_stop_following() Stops a user following another user.
 * @uses bp_core_add_message() Adds an error/success message to be displayed after redirect.
 * @uses bp_core_redirect() Safe redirects the user to a particular URL.
 */
function bp_follow_action_stop()
{
    global $bp;
    if (!bp_is_current_component($bp->follow->followers->slug) || !bp_is_current_action('stop')) {
        return;
    }
    if (bp_displayed_user_id() == bp_loggedin_user_id()) {
        return;
    }
    check_admin_referer('stop_following');
    if (!bp_follow_is_following(array('leader_id' => bp_displayed_user_id(), 'follower_id' => bp_loggedin_user_id()))) {
        bp_core_add_message(sprintf(__('You are not following %s.', 'bp-follow'), bp_get_displayed_user_fullname()), 'error');
    } else {
        if (!bp_follow_stop_following(array('leader_id' => bp_displayed_user_id(), 'follower_id' => bp_loggedin_user_id()))) {
            bp_core_add_message(sprintf(__('There was a problem when trying to stop following %s, please try again.', 'bp-follow'), bp_get_displayed_user_fullname()), 'error');
        } else {
            bp_core_add_message(sprintf(__('You are no longer following %s.', 'bp-follow'), bp_get_displayed_user_fullname()));
        }
    }
    // it's possible that wp_get_referer() returns false, so let's fallback to the displayed user's page
    $redirect = wp_get_referer() ? wp_get_referer() : bp_displayed_user_domain();
    bp_core_redirect($redirect);
}
Пример #22
0
/**
 * Set up the Groups admin page.
 *
 * Loaded before the page is rendered, this function does all initial setup,
 * including: processing form requests, registering contextual help, and
 * setting up screen options.
 *
 * @since 1.7.0
 *
 * @global BP_Groups_List_Table $bp_groups_list_table Groups screen list table.
 */
function bp_groups_admin_load()
{
    global $bp_groups_list_table;
    // Build redirection URL
    $redirect_to = remove_query_arg(array('action', 'action2', 'gid', 'deleted', 'error', 'updated', 'success_new', 'error_new', 'success_modified', 'error_modified'), $_SERVER['REQUEST_URI']);
    // Decide whether to load the dev version of the CSS and JavaScript
    $min = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : 'min.';
    $doaction = bp_admin_list_table_current_bulk_action();
    /**
     * Fires at top of groups admin page.
     *
     * @since 1.7.0
     *
     * @param string $doaction Current $_GET action being performed in admin screen.
     */
    do_action('bp_groups_admin_load', $doaction);
    // Edit screen
    if ('do_delete' == $doaction && !empty($_GET['gid'])) {
        check_admin_referer('bp-groups-delete');
        $group_ids = wp_parse_id_list($_GET['gid']);
        $count = 0;
        foreach ($group_ids as $group_id) {
            if (groups_delete_group($group_id)) {
                $count++;
            }
        }
        $redirect_to = add_query_arg('deleted', $count, $redirect_to);
        bp_core_redirect($redirect_to);
    } elseif ('edit' == $doaction && !empty($_GET['gid'])) {
        // columns screen option
        add_screen_option('layout_columns', array('default' => 2, 'max' => 2));
        get_current_screen()->add_help_tab(array('id' => 'bp-group-edit-overview', 'title' => __('Overview', 'buddypress'), 'content' => '<p>' . __('This page is a convenient way to edit the details associated with one of your groups.', 'buddypress') . '</p>' . '<p>' . __('The Name and Description box is fixed in place, but you can reposition all the other boxes using drag and drop, and can minimize or expand them by clicking the title bar of each box. Use the Screen Options tab to hide or unhide, or to choose a 1- or 2-column layout for this screen.', 'buddypress') . '</p>'));
        // Help panel - sidebar links
        get_current_screen()->set_help_sidebar('<p><strong>' . __('For more information:', 'buddypress') . '</strong></p>' . '<p><a href="https://buddypress.org/support">' . __('Support Forums', 'buddypress') . '</a></p>');
        // Register metaboxes for the edit screen.
        add_meta_box('submitdiv', _x('Save', 'group admin edit screen', 'buddypress'), 'bp_groups_admin_edit_metabox_status', get_current_screen()->id, 'side', 'high');
        add_meta_box('bp_group_settings', _x('Settings', 'group admin edit screen', 'buddypress'), 'bp_groups_admin_edit_metabox_settings', get_current_screen()->id, 'side', 'core');
        add_meta_box('bp_group_add_members', _x('Add New Members', 'group admin edit screen', 'buddypress'), 'bp_groups_admin_edit_metabox_add_new_members', get_current_screen()->id, 'normal', 'core');
        add_meta_box('bp_group_members', _x('Manage Members', 'group admin edit screen', 'buddypress'), 'bp_groups_admin_edit_metabox_members', get_current_screen()->id, 'normal', 'core');
        /**
         * Fires after the registration of all of the default group meta boxes.
         *
         * @since 1.7.0
         */
        do_action('bp_groups_admin_meta_boxes');
        // Enqueue JavaScript files
        wp_enqueue_script('postbox');
        wp_enqueue_script('dashboard');
        // Index screen
    } else {
        // Create the Groups screen list table
        $bp_groups_list_table = new BP_Groups_List_Table();
        // per_page screen option
        add_screen_option('per_page', array('label' => _x('Groups', 'Groups per page (screen options)', 'buddypress')));
        // Help panel - overview text
        get_current_screen()->add_help_tab(array('id' => 'bp-groups-overview', 'title' => __('Overview', 'buddypress'), 'content' => '<p>' . __('You can manage groups much like you can manage comments and other content. This screen is customizable in the same ways as other management screens, and you can act on groups by using the on-hover action links or the Bulk Actions.', 'buddypress') . '</p>'));
        get_current_screen()->add_help_tab(array('id' => 'bp-groups-overview-actions', 'title' => __('Group Actions', 'buddypress'), 'content' => '<p>' . __('Clicking "Visit" will take you to the group&#8217;s public page. Use this link to see what the group looks like on the front end of your site.', 'buddypress') . '</p>' . '<p>' . __('Clicking "Edit" will take you to a Dashboard panel where you can manage various details about the group, such as its name and description, its members, and other settings.', 'buddypress') . '</p>' . '<p>' . __('If you click "Delete" under a specific group, or select a number of groups and then choose Delete from the Bulk Actions menu, you will be led to a page where you&#8217;ll be asked to confirm the permanent deletion of the group(s).', 'buddypress') . '</p>'));
        // Help panel - sidebar links
        get_current_screen()->set_help_sidebar('<p><strong>' . __('For more information:', 'buddypress') . '</strong></p>' . '<p>' . __('<a href="https://buddypress.org/support/">Support Forums</a>', 'buddypress') . '</p>');
    }
    $bp = buddypress();
    // Enqueue CSS and JavaScript
    wp_enqueue_script('bp_groups_admin_js', $bp->plugin_url . "bp-groups/admin/js/admin.{$min}js", array('jquery', 'wp-ajax-response', 'jquery-ui-autocomplete'), bp_get_version(), true);
    wp_localize_script('bp_groups_admin_js', 'BP_Group_Admin', array('add_member_placeholder' => __('Start typing a username to add a new member.', 'buddypress'), 'warn_on_leave' => __('If you leave this page, you will lose any unsaved changes you have made to the group.', 'buddypress')));
    wp_enqueue_style('bp_groups_admin_css', $bp->plugin_url . "bp-groups/admin/css/admin.{$min}css", array(), bp_get_version());
    wp_style_add_data('bp_groups_admin_css', 'rtl', true);
    if ($min) {
        wp_style_add_data('bp_groups_admin_css', 'suffix', $min);
    }
    if ($doaction && 'save' == $doaction) {
        // Get group ID
        $group_id = isset($_REQUEST['gid']) ? (int) $_REQUEST['gid'] : '';
        $redirect_to = add_query_arg(array('gid' => (int) $group_id, 'action' => 'edit'), $redirect_to);
        // Check this is a valid form submission
        check_admin_referer('edit-group_' . $group_id);
        // Get the group from the database
        $group = groups_get_group('group_id=' . $group_id);
        // If the group doesn't exist, just redirect back to the index
        if (empty($group->slug)) {
            wp_redirect($redirect_to);
            exit;
        }
        // Check the form for the updated properties
        // Store errors
        $error = 0;
        $success_new = $error_new = $success_modified = $error_modified = array();
        // Group name and description are handled with
        // groups_edit_base_group_details()
        if (!groups_edit_base_group_details($group_id, $_POST['bp-groups-name'], $_POST['bp-groups-description'], 0)) {
            $error = $group_id;
            // using negative integers for different error messages... eek!
            if (empty($_POST['bp-groups-name']) && empty($_POST['bp-groups-description'])) {
                $error = -3;
            } elseif (empty($_POST['bp-groups-name'])) {
                $error = -1;
            } elseif (empty($_POST['bp-groups-description'])) {
                $error = -2;
            }
        }
        // Enable discussion forum
        $enable_forum = isset($_POST['group-show-forum']) ? 1 : 0;
        /**
         * Filters the allowed status values for the group.
         *
         * @since 1.0.2
         *
         * @param array $value Array of allowed group statuses.
         */
        $allowed_status = apply_filters('groups_allowed_status', array('public', 'private', 'hidden'));
        $status = in_array($_POST['group-status'], (array) $allowed_status) ? $_POST['group-status'] : 'public';
        /**
         * Filters the allowed invite status values for the group.
         *
         * @since 1.5.0
         *
         * @param array $value Array of allowed invite statuses.
         */
        $allowed_invite_status = apply_filters('groups_allowed_invite_status', array('members', 'mods', 'admins'));
        $invite_status = in_array($_POST['group-invite-status'], (array) $allowed_invite_status) ? $_POST['group-invite-status'] : 'members';
        if (!groups_edit_group_settings($group_id, $enable_forum, $status, $invite_status)) {
            $error = $group_id;
        }
        // Process new members
        $user_names = array();
        if (!empty($_POST['bp-groups-new-members'])) {
            $user_names = array_merge($user_names, explode(',', $_POST['bp-groups-new-members']));
        }
        if (!empty($user_names)) {
            foreach (array_values($user_names) as $user_name) {
                $un = trim($user_name);
                // Make sure the user exists before attempting
                // to add to the group
                $user = get_user_by('slug', $un);
                if (empty($user)) {
                    $error_new[] = $un;
                } else {
                    if (!groups_join_group($group_id, $user->ID)) {
                        $error_new[] = $un;
                    } else {
                        $success_new[] = $un;
                    }
                }
            }
        }
        // Process member role changes
        if (!empty($_POST['bp-groups-role']) && !empty($_POST['bp-groups-existing-role'])) {
            // Before processing anything, make sure you're not
            // attempting to remove the all user admins
            $admin_count = 0;
            foreach ((array) $_POST['bp-groups-role'] as $new_role) {
                if ('admin' == $new_role) {
                    $admin_count++;
                    break;
                }
            }
            if (!$admin_count) {
                $redirect_to = add_query_arg('no_admins', 1, $redirect_to);
                $error = $group_id;
            } else {
                // Process only those users who have had their roles changed
                foreach ((array) $_POST['bp-groups-role'] as $user_id => $new_role) {
                    $existing_role = isset($_POST['bp-groups-existing-role'][$user_id]) ? $_POST['bp-groups-existing-role'][$user_id] : '';
                    if ($existing_role != $new_role) {
                        switch ($new_role) {
                            case 'mod':
                                // Admin to mod is a demotion. Demote to
                                // member, then fall through
                                if ('admin' == $existing_role) {
                                    groups_demote_member($user_id, $group_id);
                                }
                            case 'admin':
                                // If the user was banned, we must
                                // unban first
                                if ('banned' == $existing_role) {
                                    groups_unban_member($user_id, $group_id);
                                }
                                // At this point, each existing_role
                                // is a member, so promote
                                $result = groups_promote_member($user_id, $group_id, $new_role);
                                break;
                            case 'member':
                                if ('admin' == $existing_role || 'mod' == $existing_role) {
                                    $result = groups_demote_member($user_id, $group_id);
                                } elseif ('banned' == $existing_role) {
                                    $result = groups_unban_member($user_id, $group_id);
                                }
                                break;
                            case 'banned':
                                $result = groups_ban_member($user_id, $group_id);
                                break;
                            case 'remove':
                                $result = groups_remove_member($user_id, $group_id);
                                break;
                        }
                        // Store the success or failure
                        if ($result) {
                            $success_modified[] = $user_id;
                        } else {
                            $error_modified[] = $user_id;
                        }
                    }
                }
            }
        }
        /**
         * Fires before redirect so plugins can do something first on save action.
         *
         * @since 1.6.0
         *
         * @param int $group_id ID of the group being edited.
         */
        do_action('bp_group_admin_edit_after', $group_id);
        // Create the redirect URL
        if ($error) {
            // This means there was an error updating group details
            $redirect_to = add_query_arg('error', (int) $error, $redirect_to);
        } else {
            // Group details were update successfully
            $redirect_to = add_query_arg('updated', 1, $redirect_to);
        }
        if (!empty($success_new)) {
            $success_new = implode(',', array_filter($success_new, 'urlencode'));
            $redirect_to = add_query_arg('success_new', $success_new, $redirect_to);
        }
        if (!empty($error_new)) {
            $error_new = implode(',', array_filter($error_new, 'urlencode'));
            $redirect_to = add_query_arg('error_new', $error_new, $redirect_to);
        }
        if (!empty($success_modified)) {
            $success_modified = implode(',', array_filter($success_modified, 'urlencode'));
            $redirect_to = add_query_arg('success_modified', $success_modified, $redirect_to);
        }
        if (!empty($error_modified)) {
            $error_modified = implode(',', array_filter($error_modified, 'urlencode'));
            $redirect_to = add_query_arg('error_modified', $error_modified, $redirect_to);
        }
        /**
         * Filters the URL to redirect to after successfully editing a group.
         *
         * @since 1.7.0
         *
         * @param string $redirect_to URL to redirect user to.
         */
        wp_redirect(apply_filters('bp_group_admin_edit_redirect', $redirect_to));
        exit;
        // If a referrer and a nonce is supplied, but no action, redirect back.
    } elseif (!empty($_GET['_wp_http_referer'])) {
        wp_redirect(remove_query_arg(array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI'])));
        exit;
    }
}
/**
 * Handles the deleting of a user
 */
function bp_settings_action_delete_account()
{
    // Bail if not a POST action
    if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) {
        return;
    }
    // Bail if no submit action
    if (!isset($_POST['delete-account-understand'])) {
        return;
    }
    // Bail if not in settings
    if (!bp_is_settings_component() || !bp_is_current_action('delete-account')) {
        return false;
    }
    // 404 if there are any additional action variables attached
    if (bp_action_variables()) {
        bp_do_404();
        return;
    }
    // Bail if account deletion is disabled
    if (bp_disable_account_deletion() && !bp_current_user_can('delete_users')) {
        return false;
    }
    // Nonce check
    check_admin_referer('delete-account');
    // Get username now because it might be gone soon!
    $username = bp_get_displayed_user_fullname();
    // delete the users account
    if (bp_core_delete_account(bp_displayed_user_id())) {
        // Add feedback ater deleting a user
        bp_core_add_message(sprintf(__('%s was successfully deleted.', 'buddypress'), $username), 'success');
        // Redirect to the root domain
        bp_core_redirect(bp_get_root_domain());
    }
}
function buatp_page_restriction()
{
    global $bp;
    $page_id = get_the_ID();
    $current_url = buatp_prepare_url('current');
    if (!$page_id) {
        return;
    }
    $access = get_option('buatp_access_setting', true);
    $current_basic_setting = get_option('buatp_basic_setting', true);
    $field_name = $current_basic_setting['buatp_type_field_selection'];
    $field_id = buatp_get_field_id_by_name($field_name);
    $type_names = buatp_get_all_types($field_id);
    if (!$field_name) {
        return;
    }
    if (!isset($access['buatp_restrict_redirect_general']) || $access['buatp_restrict_redirect_general'] == false) {
        return;
    }
    foreach ((array) $type_names as $val) {
        $user_type = $val['id'];
        $restricted_pages = isset($access['buatp_restrict_page_for_' . $user_type]) ? $access['buatp_restrict_page_for_' . $user_type] : '';
        $pages = explode(',', trim($restricted_pages));
        $url = preg_split('/[\\r\\n]+/', buatp_prepare_url(trim($restricted_pages)), -1, PREG_SPLIT_NO_EMPTY);
        $urls = array_merge((array) $urls, (array) $url);
        $all_restricted_pages = array_merge((array) $all_restricted_pages, (array) $pages, (array) $urls);
        if (isset($access['buatp_restrict_page_for_' . $val['id']]) || count($urls)) {
            $resricted = true;
        }
    }
    if ($current_url && in_array($current_url, $all_restricted_pages)) {
        $url_redirect = true;
    }
    if (!in_array($page_id, $all_restricted_pages) && !$url_redirect) {
        return;
    }
    if (!is_user_logged_in() && $resricted) {
        wp_redirect(get_permalink($access['buatp_restrict_redirect_general']), 302);
        return;
    }
    $do_redirect = false;
    $user_id = $bp->loggedin_user->id;
    $current_user_type = buatp_get_field_id_by_name(buatp_get_field_data($field_name, $user_id));
    if (current_user_can('create_users') || is_super_admin($user_id)) {
        return;
    }
    foreach ((array) $type_names as $val) {
        $user_type = $val['id'];
        $restricted_pages = isset($access['buatp_restrict_page_for_' . $user_type]) ? $access['buatp_restrict_page_for_' . $user_type] : '';
        $page_arr = explode(',', trim($restricted_pages));
        $url = (array) preg_split('/[\\r\\n]+/', buatp_prepare_url(trim($restricted_pages)), -1, PREG_SPLIT_NO_EMPTY);
        if (in_array($current_url, $url) && $user_type == $current_user_type) {
            $do_redirect = true;
            $redirect_to = isset($access['buatp_restrict_redirect_for_' . $user_type]) ? $access['buatp_restrict_redirect_for_' . $user_type] : false;
            break;
        }
        if (in_array($page_id, $page_arr) && $user_type == $current_user_type) {
            $do_redirect = true;
            $redirect_to = isset($access['buatp_restrict_redirect_for_' . $user_type]) ? $access['buatp_restrict_redirect_for_' . $user_type] : false;
            break;
        }
    }
    if ($do_redirect) {
        bp_core_redirect(get_permalink($redirect_to), 302);
    }
    return;
}
 /**
  * Set up the signups admin page.
  *
  * Loaded before the page is rendered, this function does all initial
  * setup, including: processing form requests, registering contextual
  * help, and setting up screen options.
  *
  * @since 2.0.0
  *
  * @global $bp_members_signup_list_table
  */
 public function signups_admin_load()
 {
     global $bp_members_signup_list_table;
     // Build redirection URL.
     $redirect_to = remove_query_arg(array('action', 'error', 'updated', 'activated', 'notactivated', 'deleted', 'notdeleted', 'resent', 'notresent', 'do_delete', 'do_resend', 'do_activate', '_wpnonce', 'signup_ids'), $_SERVER['REQUEST_URI']);
     $doaction = bp_admin_list_table_current_bulk_action();
     /**
      * Fires at the start of the signups admin load.
      *
      * @since 2.0.0
      *
      * @param string $doaction Current bulk action being processed.
      * @param array  $_REQUEST Current $_REQUEST global.
      */
     do_action('bp_signups_admin_load', $doaction, $_REQUEST);
     /**
      * Filters the allowed actions for use in the user signups admin page.
      *
      * @since 2.0.0
      *
      * @param array $value Array of allowed actions to use.
      */
     $allowed_actions = apply_filters('bp_signups_admin_allowed_actions', array('do_delete', 'do_activate', 'do_resend'));
     // Prepare the display of the Community Profile screen.
     if (!in_array($doaction, $allowed_actions) || -1 == $doaction) {
         if (is_network_admin()) {
             $bp_members_signup_list_table = self::get_list_table_class('BP_Members_MS_List_Table', 'ms-users');
         } else {
             $bp_members_signup_list_table = self::get_list_table_class('BP_Members_List_Table', 'users');
         }
         // The per_page screen option.
         add_screen_option('per_page', array('label' => _x('Pending Accounts', 'Pending Accounts per page (screen options)', 'buddypress')));
         get_current_screen()->add_help_tab(array('id' => 'bp-signups-overview', 'title' => __('Overview', 'buddypress'), 'content' => '<p>' . __('This is the administration screen for pending accounts on your site.', 'buddypress') . '</p>' . '<p>' . __('From the screen options, you can customize the displayed columns and the pagination of this screen.', 'buddypress') . '</p>' . '<p>' . __('You can reorder the list of your pending accounts by clicking on the Username, Email or Registered column headers.', 'buddypress') . '</p>' . '<p>' . __('Using the search form, you can find pending accounts more easily. The Username and Email fields will be included in the search.', 'buddypress') . '</p>'));
         get_current_screen()->add_help_tab(array('id' => 'bp-signups-actions', 'title' => __('Actions', 'buddypress'), 'content' => '<p>' . __('Hovering over a row in the pending accounts list will display action links that allow you to manage pending accounts. You can perform the following actions:', 'buddypress') . '</p>' . '<ul><li>' . __('"Email" takes you to the confirmation screen before being able to send the activation link to the desired pending account. You can only send the activation email once per day.', 'buddypress') . '</li>' . '<li>' . __('"Delete" allows you to delete a pending account from your site. You will be asked to confirm this deletion.', 'buddypress') . '</li></ul>' . '<p>' . __('By clicking on a Username you will be able to activate a pending account from the confirmation screen.', 'buddypress') . '</p>' . '<p>' . __('Bulk actions allow you to perform these 3 actions for the selected rows.', 'buddypress') . '</p>'));
         // Help panel - sidebar links.
         get_current_screen()->set_help_sidebar('<p><strong>' . __('For more information:', 'buddypress') . '</strong></p>' . '<p>' . __('<a href="https://buddypress.org/support/">Support Forums</a>', 'buddypress') . '</p>');
         // Add accessible hidden headings and text for the Pending Users screen.
         if (bp_get_major_wp_version() >= 4.4) {
             get_current_screen()->set_screen_reader_content(array('heading_views' => __('Filter users list', 'buddypress'), 'heading_pagination' => __('Pending users list navigation', 'buddypress'), 'heading_list' => __('Pending users list', 'buddypress')));
         }
     } else {
         if (!empty($_REQUEST['signup_ids'])) {
             $signups = wp_parse_id_list($_REQUEST['signup_ids']);
         }
         // Handle resent activation links.
         if ('do_resend' == $doaction) {
             // Nonce check.
             check_admin_referer('signups_resend');
             $resent = BP_Signup::resend($signups);
             if (empty($resent)) {
                 $redirect_to = add_query_arg('error', $doaction, $redirect_to);
             } else {
                 $query_arg = array('updated' => 'resent');
                 if (!empty($resent['resent'])) {
                     $query_arg['resent'] = count($resent['resent']);
                 }
                 if (!empty($resent['errors'])) {
                     $query_arg['notsent'] = count($resent['errors']);
                     set_transient('_bp_admin_signups_errors', $resent['errors'], 30);
                 }
                 $redirect_to = add_query_arg($query_arg, $redirect_to);
             }
             bp_core_redirect($redirect_to);
             // Handle activated accounts.
         } elseif ('do_activate' == $doaction) {
             // Nonce check.
             check_admin_referer('signups_activate');
             $activated = BP_Signup::activate($signups);
             if (empty($activated)) {
                 $redirect_to = add_query_arg('error', $doaction, $redirect_to);
             } else {
                 $query_arg = array('updated' => 'activated');
                 if (!empty($activated['activated'])) {
                     $query_arg['activated'] = count($activated['activated']);
                 }
                 if (!empty($activated['errors'])) {
                     $query_arg['notactivated'] = count($activated['errors']);
                     set_transient('_bp_admin_signups_errors', $activated['errors'], 30);
                 }
                 $redirect_to = add_query_arg($query_arg, $redirect_to);
             }
             bp_core_redirect($redirect_to);
             // Handle sign-ups delete.
         } elseif ('do_delete' == $doaction) {
             // Nonce check.
             check_admin_referer('signups_delete');
             $deleted = BP_Signup::delete($signups);
             if (empty($deleted)) {
                 $redirect_to = add_query_arg('error', $doaction, $redirect_to);
             } else {
                 $query_arg = array('updated' => 'deleted');
                 if (!empty($deleted['deleted'])) {
                     $query_arg['deleted'] = count($deleted['deleted']);
                 }
                 if (!empty($deleted['errors'])) {
                     $query_arg['notdeleted'] = count($deleted['errors']);
                     set_transient('_bp_admin_signups_errors', $deleted['errors'], 30);
                 }
                 $redirect_to = add_query_arg($query_arg, $redirect_to);
             }
             bp_core_redirect($redirect_to);
             // Plugins can update other stuff from here.
         } else {
             $this->redirect = $redirect_to;
             /**
              * Fires at end of signups admin load if doaction does not match any actions.
              *
              * @since 2.0.0
              *
              * @param string $doaction Current bulk action being processed.
              * @param array  $_REQUEST Current $_REQUEST global.
              * @param string $redirect Determined redirect url to send user to.
              */
             do_action('bp_members_admin_update_signups', $doaction, $_REQUEST, $this->redirect);
             bp_core_redirect($this->redirect);
         }
     }
 }
Пример #26
0
/**
 * Handle the loading of the Activate screen.
 *
 * @todo Move the actual activation process into an action in bp-members-actions.php
 */
function bp_core_screen_activation()
{
    // Bail if not viewing the activation page
    if (!bp_is_current_component('activate')) {
        return false;
    }
    // If the user is already logged in, redirect away from here
    if (is_user_logged_in()) {
        // If activation page is also front page, set to members directory to
        // avoid an infinite loop. Otherwise, set to root domain.
        $redirect_to = bp_is_component_front_page('activate') ? bp_get_root_domain() . '/' . bp_get_members_root_slug() : bp_get_root_domain();
        // Trailing slash it, as we expect these URL's to be
        $redirect_to = trailingslashit($redirect_to);
        /**
         * Filters the URL to redirect logged in users to when visiting activation page.
         *
         * @since BuddyPress (1.9.0)
         *
         * @param string $redirect_to URL to redirect user to.
         */
        $redirect_to = apply_filters('bp_loggedin_activate_page_redirect_to', $redirect_to);
        // Redirect away from the activation page
        bp_core_redirect($redirect_to);
    }
    // grab the key (the old way)
    $key = isset($_GET['key']) ? $_GET['key'] : '';
    // grab the key (the new way)
    if (empty($key)) {
        $key = bp_current_action();
    }
    // Get BuddyPress
    $bp = buddypress();
    // we've got a key; let's attempt to activate the signup
    if (!empty($key)) {
        /**
         * Filters the activation signup.
         *
         * @since BuddyPress (1.1.0)
         *
         * @param bool|int $value Value returned by activation.
         *                        Integer on success, boolean on failure.
         */
        $user = apply_filters('bp_core_activate_account', bp_core_activate_signup($key));
        // If there were errors, add a message and redirect
        if (!empty($user->errors)) {
            bp_core_add_message($user->get_error_message(), 'error');
            bp_core_redirect(trailingslashit(bp_get_root_domain() . '/' . $bp->pages->activate->slug));
        }
        $hashed_key = wp_hash($key);
        // Check if the signup avatar folder exists. If it does, move the folder to
        // the BP user avatars directory
        if (file_exists(bp_core_avatar_upload_path() . '/avatars/signups/' . $hashed_key)) {
            @rename(bp_core_avatar_upload_path() . '/avatars/signups/' . $hashed_key, bp_core_avatar_upload_path() . '/avatars/' . $user);
        }
        bp_core_add_message(__('Your account is now active!', 'buddypress'));
        $bp->activation_complete = true;
    }
    /**
     * Filters the template to load for the Member activation page screen.
     *
     * @since BuddyPress (1.1.1)
     *
     * @param string $value Path to the Member activation template to load.
     */
    bp_core_load_template(apply_filters('bp_core_template_activate', array('activate', 'registration/activate')));
}
Пример #27
0
function messages_action_bulk_delete() {
	global $bp, $thread_ids;

	if ( $bp->current_component != $bp->messages->slug || $bp->action_variables[0] != 'bulk-delete' )
		return false;

	$thread_ids = $_POST['thread_ids'];

	if ( !$thread_ids || !messages_check_thread_access($thread_ids) ) {
		bp_core_redirect( $bp->displayed_user->domain . $bp->current_component . '/' . $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( $bp->loggedin_user->domain . $bp->current_component . '/' . $bp->current_action );
	}
}
Пример #28
0
 /**
  * Action handler when a follow blogs button is clicked.
  *
  * Handles both following and unfollowing a blog.
  */
 public static function action_handler()
 {
     if (empty($_GET['blog_id']) || !is_user_logged_in()) {
         return;
     }
     $action = false;
     if (!empty($_GET['bpfb-follow']) || !empty($_GET['bpfb-unfollow'])) {
         $nonce = !empty($_GET['bpfb-follow']) ? $_GET['bpfb-follow'] : $_GET['bpfb-unfollow'];
         $action = !empty($_GET['bpfb-follow']) ? 'follow' : 'unfollow';
         $save = !empty($_GET['bpfb-follow']) ? 'bp_follow_start_following' : 'bp_follow_stop_following';
     }
     if (!$action) {
         return;
     }
     if (!wp_verify_nonce($nonce, "bp_follow_blog_{$action}")) {
         return;
     }
     if (!$save(array('leader_id' => (int) $_GET['blog_id'], 'follower_id' => bp_loggedin_user_id(), 'follow_type' => 'blogs'))) {
         if ('follow' == $action) {
             $message = __('You are already following that blog.', 'bp-follow');
         } else {
             $message = __('You are not following that blog.', 'bp-follow');
         }
         bp_core_add_message($message, 'error');
         // success on follow action
     } else {
         $blog_name = bp_blogs_get_blogmeta((int) $_GET['blog_id'], 'name');
         // blog has never been recorded into BP; record it now
         if ('' === $blog_name && apply_filters('bp_follow_blogs_record_blog', true, (int) $_GET['blog_id'])) {
             // get the admin of the blog
             $admin = get_users(array('blog_id' => get_current_blog_id(), 'role' => 'administrator', 'orderby' => 'ID', 'number' => 1, 'fields' => array('ID')));
             // record the blog
             $record_site = bp_blogs_record_blog((int) $_GET['blog_id'], $admin[0]->ID, true);
             // now refetch the blog name from blogmeta
             if (false !== $record_site) {
                 $blog_name = bp_blogs_get_blogmeta((int) $_GET['blog_id'], 'name');
             }
         }
         if ('follow' == $action) {
             if (!empty($blog_name)) {
                 $message = sprintf(__('You are now following the site, %s.', 'bp-follow'), $blog_name);
             } else {
                 $message = __('You are now following that site.', 'bp-follow');
             }
         } else {
             if (!empty($blog_name)) {
                 $message = sprintf(__('You are no longer following the site, %s.', 'bp-follow'), $blog_name);
             } else {
                 $message = __('You are no longer following that site.', 'bp-follow');
             }
         }
         bp_core_add_message($message);
     }
     // it's possible that wp_get_referer() returns false, so let's fallback to the displayed user's page
     $redirect = wp_get_referer() ? wp_get_referer() : bp_displayed_user_domain() . bp_get_blogs_slug() . '/' . constant('BP_FOLLOW_BLOGS_USER_FOLLOWING_SLUG') . '/';
     bp_core_redirect($redirect);
 }
Пример #29
0
 function bp_core_wpsignup_redirect()
 {
     if ((!isset($_SERVER['SCRIPT_NAME']) || false === strpos($_SERVER['SCRIPT_NAME'], 'wp-signup.php')) && (!isset($_GET['action']) || $_GET['action'] != 'register')) {
         return false;
     }
     if (gconnect_locate_template(array('registration/register.php'), false) || gconnect_locate_template(array('register.php'), false)) {
         bp_core_redirect(bp_get_root_domain() . '/' . BP_REGISTER_SLUG . '/');
     }
 }
/**
 * 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'));
}