/**
 * Update email notification settings for a specific user.
 *
 * @since 2.3.5
 *
 * @param int   $user_id  ID of the user whose settings are being updated.
 * @param array $settings Settings array.
 */
function bp_settings_update_notification_settings($user_id, $settings)
{
    $user_id = (int) $user_id;
    $settings = bp_settings_sanitize_notification_settings($settings);
    foreach ($settings as $setting_key => $setting_value) {
        bp_update_user_meta($user_id, $setting_key, $setting_value);
    }
}
 /**
  * Post a gallery or media Main comment on single page
  * 
  * @return type
  */
 public function post_comment()
 {
     // Bail if not a POST action
     if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) {
         return;
     }
     // Check the nonce
     check_admin_referer('post_update', '_wpnonce_post_update');
     if (!is_user_logged_in()) {
         exit('-1');
     }
     $mpp_type = $_POST['mpp-type'];
     $mpp_id = $_POST['mpp-id'];
     if (empty($_POST['content'])) {
         exit('-1<div id="message" class="error"><p>' . __('Please enter some content to post.', 'mediapress') . '</p></div>');
     }
     $activity_id = 0;
     if (empty($_POST['object']) && bp_is_active('activity')) {
         //we are preventing this comment to be set as the user's lastes_update
         $user_id = bp_loggedin_user_id();
         $old_latest_update = bp_get_user_meta($user_id, 'bp_latest_update', true);
         $activity_id = bp_activity_post_update(array('content' => $_POST['content']));
         //restore
         if (!empty($old_latest_update)) {
             bp_update_user_meta($user_id, 'bp_latest_update', $old_latest_update);
         }
     } elseif ($_POST['object'] == 'groups') {
         if (!empty($_POST['item_id']) && bp_is_active('groups')) {
             $activity_id = groups_post_update(array('content' => $_POST['content'], 'group_id' => $_POST['item_id']));
         }
     } else {
         $activity_id = apply_filters('bp_activity_custom_update', $_POST['object'], $_POST['item_id'], $_POST['content']);
     }
     if (empty($activity_id)) {
         exit('-1<div id="message" class="error"><p>' . __('There was a problem posting your update, please try again.', 'mediapress') . '</p></div>');
     }
     //if we have got activity id, let us add a meta key
     if ($mpp_type == 'gallery') {
         mpp_activity_update_gallery_id($activity_id, $mpp_id);
     } elseif ($mpp_type == 'media') {
         mpp_activity_update_media_id($activity_id, $mpp_id);
     }
     $activity = new BP_Activity_Activity($activity_id);
     // $activity->component = buddypress()->mediapress->id;
     $activity->type = 'mpp_media_upload';
     $activity->save();
     if (bp_has_activities('include=' . $activity_id)) {
         while (bp_activities()) {
             bp_the_activity();
             mpp_locate_template(array('activity/entry.php'), true);
         }
     }
     exit;
 }
Exemple #3
0
function qa_buddypress_activity_post($args)
{
    global $bp;
    $defaults = array('content' => false, 'user_id' => $bp->loggedin_user->id);
    $r = wp_parse_args($args, $defaults);
    extract($r, EXTR_SKIP);
    // Record this on the user's profile
    $from_user_link = bp_core_get_userlink($user_id);
    $activity_action = $action;
    $activity_content = $content;
    $primary_link = bp_core_get_userlink($user_id, false, true);
    // Now write the values
    $activity_id = bp_activity_add(array('user_id' => $user_id, 'action' => apply_filters('bp_activity_new_update_action', $activity_action), 'content' => apply_filters('bp_activity_new_update_content', $activity_content), 'primary_link' => apply_filters('bp_activity_new_update_primary_link', $primary_link), 'component' => $bp->activity->id, 'type' => $type));
    // Add this update to the "latest update" usermeta so it can be fetched anywhere.
    bp_update_user_meta($bp->loggedin_user->id, 'bp_latest_update', array('id' => $activity_id, 'content' => wp_filter_kses($content)));
    do_action('bp_activity_posted_update', $content, $user_id, $activity_id);
    return $activity_id;
}
 function total_friend_count($user_id = 0)
 {
     global $nxtdb, $bp;
     if (!$user_id) {
         $user_id = $bp->displayed_user->id ? $bp->displayed_user->id : $bp->loggedin_user->id;
     }
     /* This is stored in 'total_friend_count' usermeta.
        This function will recalculate, update and return. */
     $count = $nxtdb->get_var($nxtdb->prepare("SELECT COUNT(id) FROM {$bp->friends->table_name} WHERE (initiator_user_id = %d OR friend_user_id = %d) AND is_confirmed = 1", $user_id, $user_id));
     // Do not update meta if user has never had friends
     if (!$count && !bp_get_user_meta($user_id, 'total_friend_count', true)) {
         return 0;
     }
     bp_update_user_meta($user_id, 'total_friend_count', (int) $count);
     return (int) $count;
 }
 function save()
 {
     global $nxtdb, $bp;
     $this->subject = apply_filters('messages_notice_subject_before_save', $this->subject, $this->id);
     $this->message = apply_filters('messages_notice_message_before_save', $this->message, $this->id);
     do_action_ref_array('messages_notice_before_save', array(&$this));
     if (empty($this->id)) {
         $sql = $nxtdb->prepare("INSERT INTO {$bp->messages->table_name_notices} (subject, message, date_sent, is_active) VALUES (%s, %s, %s, %d)", $this->subject, $this->message, $this->date_sent, $this->is_active);
     } else {
         $sql = $nxtdb->prepare("UPDATE {$bp->messages->table_name_notices} SET subject = %s, message = %s, is_active = %d WHERE id = %d", $this->subject, $this->message, $this->is_active, $this->id);
     }
     if (!$nxtdb->query($sql)) {
         return false;
     }
     if (!($id = $this->id)) {
         $id = $nxtdb->insert_id;
     }
     // Now deactivate all notices apart from the new one.
     $nxtdb->query($nxtdb->prepare("UPDATE {$bp->messages->table_name_notices} SET is_active = 0 WHERE id != %d", $id));
     bp_update_user_meta($bp->loggedin_user->id, 'last_activity', bp_core_current_time());
     do_action_ref_array('messages_notice_after_save', array(&$this));
     return true;
 }
 function remove()
 {
     global $wpdb, $bp;
     $sql = $wpdb->prepare("DELETE FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d", $this->user_id, $this->group_id);
     if (!($result = $wpdb->query($sql))) {
         return false;
     }
     groups_update_groupmeta($this->group_id, 'total_member_count', (int) groups_get_groupmeta($this->group_id, 'total_member_count') - 1);
     $group_count = bp_get_user_meta($this->user_id, 'total_group_count', true);
     if (!empty($group_count)) {
         bp_update_user_meta($this->user_id, 'total_group_count', (int) $group_count - 1);
     }
     return $result;
 }
function bp_checkins_post_update($args = '')
{
    global $bp;
    $defaults = array('content' => false, 'user_id' => $bp->loggedin_user->id, 'type' => 'checkin', 'place_id' => false, 'place_name' => false, 'comment_id' => false, 'recorded_time' => bp_core_current_time());
    $r = wp_parse_args($args, $defaults);
    extract($r, EXTR_SKIP);
    if ($type == "checkin" && (empty($content) || !strlen(trim($content)))) {
        return false;
    }
    if (bp_is_user_spammer($user_id) || bp_is_user_deleted($user_id)) {
        return false;
    }
    // Record this on the user's profile
    $from_user_link = bp_core_get_userlink($user_id);
    $component = 'checkins';
    if ($type == 'checkin') {
        $activity_action = sprintf(__('%s added a checkin', 'bp-checkins'), $from_user_link);
        $activity_content = $content;
        $primary_link = bp_core_get_userlink($user_id, false, true);
        $checkin_type = 'activity_checkin';
        $item_id = false;
        $secondary_item_id = false;
    } else {
        if ($type == 'new_place' && !empty($place_id)) {
            $component = 'places';
            $place_permalink = '<a href="' . bp_get_checkins_places_the_permalink($place_id) . '" title="' . $place_name . '">' . $place_name . '</a>';
            $activity_action = sprintf(__('%s added a new place %s', 'bp-checkins'), $from_user_link, $place_permalink);
            $primary_link = bp_core_get_userlink($user_id, false, true);
            $checkin_type = 'new_place';
            $item_id = $place_id;
            $activity_content = $content;
            $secondary_item_id = false;
        } else {
            if ($type == 'place_checkin' && !empty($place_id)) {
                $place_permalink = '<a href="' . bp_get_checkins_places_the_permalink($place_id) . '" title="' . $place_name . '">' . $place_name . '</a>';
                $activity_action = sprintf(__('%s checked-in %s', 'bp-checkins'), $from_user_link, $place_permalink);
                $primary_link = bp_core_get_userlink($user_id, false, true);
                $checkin_type = 'place_checkin';
                $item_id = $place_id;
                $activity_content = false;
                $secondary_item_id = false;
            } else {
                if ($type == 'place_comment' && !empty($place_id) && !empty($comment_id)) {
                    $component = 'places';
                    $place_permalink = '<a href="' . bp_get_checkins_places_the_permalink($place_id) . '" title="' . $place_name . '">' . $place_name . '</a>';
                    $activity_action = sprintf(__('%s added a comment on %s', 'bp-checkins'), $from_user_link, $place_permalink);
                    $primary_link = bp_core_get_userlink($user_id, false, true);
                    $checkin_type = 'place_comment';
                    $activity_content = $content;
                    $item_id = $place_id;
                    $secondary_item_id = $comment_id;
                } else {
                    if ($type == 'place_checkin_comment' && !empty($place_id) && !empty($comment_id)) {
                        $component = 'places';
                        $place_permalink = '<a href="' . bp_get_checkins_places_the_permalink($place_id) . '" title="' . $place_name . '">' . $place_name . '</a>';
                        $activity_action = sprintf(__('%s checked-in and added a comment on %s', 'bp-checkins'), $from_user_link, $place_permalink);
                        $primary_link = bp_core_get_userlink($user_id, false, true);
                        $checkin_type = 'place_comment';
                        $activity_content = $content;
                        $item_id = $place_id;
                        $secondary_item_id = $comment_id;
                    }
                }
            }
        }
    }
    // Now write the values
    $activity_id = bp_activity_add(array('user_id' => $user_id, 'action' => apply_filters('bp_activity_new_update_action', $activity_action), 'content' => apply_filters('bp_activity_new_update_content', $activity_content), 'primary_link' => apply_filters('bp_activity_new_update_primary_link', $primary_link), 'component' => $component, 'type' => $checkin_type, 'item_id' => $item_id, 'secondary_item_id' => $secondary_item_id, 'recorded_time' => $recorded_time));
    if ($type == 'checkin') {
        bp_update_user_meta($bp->loggedin_user->id, 'bp_latest_update', array('id' => $activity_id, 'content' => wp_filter_kses($content)));
    }
    if ($checkin_type == 'place_comment') {
        update_comment_meta($comment_id, 'group_place_activity_id', $activity_id);
    }
    do_action('bp_activity_posted_checkin', $content, $user_id, $activity_id);
    return $activity_id;
}
Exemple #8
0
 public static function prepare_buddypress_data($user_id, $config, $entry)
 {
     // required for user to display in the directory
     if (function_exists('bp_update_user_last_activity')) {
         bp_update_user_last_activity($user_id);
     } else {
         bp_update_user_meta($user_id, 'last_activity', true);
     }
     $buddypress_meta = rgars($config, 'meta/buddypress_meta');
     if (empty($buddypress_meta)) {
         return;
     }
     self::log_debug(__METHOD__ . '(): starting.');
     $form = RGFormsModel::get_form_meta($entry['form_id']);
     $buddypress_row = array();
     $i = 0;
     foreach ($buddypress_meta as $meta_item) {
         if (empty($meta_item['meta_name']) || empty($meta_item['meta_value'])) {
             continue;
         }
         $buddypress_row[$i]['field_id'] = $meta_item['meta_name'];
         $buddypress_row[$i]['user_id'] = $user_id;
         // get GF and BP fields
         $gform_field = RGFormsModel::get_field($form, $meta_item['meta_value']);
         if (version_compare(BP_VERSION, '1.6', '<')) {
             $bp_field = new BP_XProfile_Field();
             $bp_field->bp_xprofile_field($meta_item['meta_name']);
         } else {
             require_once WP_PLUGIN_DIR . '/buddypress/bp-xprofile/bp-xprofile-classes.php';
             $bp_field = new BP_XProfile_Field($meta_item['meta_name']);
         }
         // if bp field is a checkbox AND gf field is a checkbox, get array of input values
         $input_type = RGFormsModel::get_input_type($gform_field);
         if (in_array($bp_field->type, array('checkbox', 'multiselectbox')) && in_array($input_type, array('checkbox', 'multiselect'))) {
             $meta_value = RGFormsModel::get_lead_field_value($entry, $gform_field);
             if (!is_array($meta_value)) {
                 $meta_value = explode(',', $meta_value);
             }
             $meta_value = self::maybe_get_category_name($gform_field, $meta_value);
             $meta_value = array_filter($meta_value, 'GFUser::not_empty');
         } else {
             if ($bp_field->type == 'datebox' && $gform_field['type'] == 'date') {
                 if (version_compare(BP_VERSION, '2.1.1', '<')) {
                     $meta_value = strtotime(self::get_prepared_value($gform_field, $meta_item['meta_value'], $entry));
                 } else {
                     $meta_value = self::get_prepared_value($gform_field, $meta_item['meta_value'], $entry) . ' 00:00:00';
                 }
             } else {
                 $meta_value = self::get_prepared_value($gform_field, $meta_item['meta_value'], $entry);
             }
         }
         self::log_debug(__METHOD__ . "(): Meta item: {$meta_item['meta_name']}. Value: {$meta_value}");
         $buddypress_row[$i]['value'] = $meta_value;
         $buddypress_row[$i]['last_update'] = date('Y-m-d H:i:s');
         $buddypress_row[$i]['field'] = $bp_field;
         $i++;
     }
     GFUserData::insert_buddypress_data($buddypress_row);
     self::log_debug(__METHOD__ . '(): finished.');
 }
/**
 * Syncs Xprofile data to the standard built in WordPress profile data.
 *
 * @package BuddyPress Core
 */
function xprofile_sync_wp_profile($user_id = 0)
{
    // Bail if profile syncing is disabled
    if (bp_disable_profile_sync()) {
        return true;
    }
    if (empty($user_id)) {
        $user_id = bp_loggedin_user_id();
    }
    if (empty($user_id)) {
        return false;
    }
    $fullname = xprofile_get_field_data(bp_xprofile_fullname_field_id(), $user_id);
    $space = strpos($fullname, ' ');
    if (false === $space) {
        $firstname = $fullname;
        $lastname = '';
    } else {
        $firstname = substr($fullname, 0, $space);
        $lastname = trim(substr($fullname, $space, strlen($fullname)));
    }
    bp_update_user_meta($user_id, 'nickname', $fullname);
    bp_update_user_meta($user_id, 'first_name', $firstname);
    bp_update_user_meta($user_id, 'last_name', $lastname);
    global $wpdb;
    $wpdb->query($wpdb->prepare("UPDATE {$wpdb->users} SET display_name = %s WHERE ID = %d", $fullname, $user_id));
}
/**
 * Process data submitted at user registration and convert to a signup object.
 *
 * @since 1.2.0
 *
 * @todo There appears to be a bug in the return value on success.
 *
 * @param string $user_login    Login name requested by the user.
 * @param string $user_password Password requested by the user.
 * @param string $user_email    Email address entered by the user.
 * @param array  $usermeta      Miscellaneous metadata about the user (blog-specific
 *                              signup data, xprofile data, etc).
 * @return bool|WP_Error True on success, WP_Error on failure.
 */
function bp_core_signup_user($user_login, $user_password, $user_email, $usermeta)
{
    $bp = buddypress();
    // We need to cast $user_id to pass to the filters.
    $user_id = false;
    // Multisite installs have their own install procedure.
    if (is_multisite()) {
        wpmu_signup_user($user_login, $user_email, $usermeta);
    } else {
        // Format data.
        $user_login = preg_replace('/\\s+/', '', sanitize_user($user_login, true));
        $user_email = sanitize_email($user_email);
        $activation_key = wp_generate_password(32, false);
        /**
         * WordPress's default behavior is to create user accounts
         * immediately at registration time. BuddyPress uses a system
         * borrowed from WordPress Multisite, where signups are stored
         * separately and accounts are only created at the time of
         * activation. For backward compatibility with plugins that may
         * be anticipating WP's default behavior, BP silently creates
         * accounts for registrations (though it does not use them). If
         * you know that you are not running any plugins dependent on
         * these pending accounts, you may want to save a little DB
         * clutter by defining setting the BP_SIGNUPS_SKIP_USER_CREATION
         * to true in your wp-config.php file.
         */
        if (!defined('BP_SIGNUPS_SKIP_USER_CREATION') || !BP_SIGNUPS_SKIP_USER_CREATION) {
            $user_id = BP_Signup::add_backcompat($user_login, $user_password, $user_email, $usermeta);
            if (is_wp_error($user_id)) {
                return $user_id;
            }
            bp_update_user_meta($user_id, 'activation_key', $activation_key);
        }
        $args = array('user_login' => $user_login, 'user_email' => $user_email, 'activation_key' => $activation_key, 'meta' => $usermeta);
        BP_Signup::add($args);
        /**
         * Filters if BuddyPress should send an activation key for a new signup.
         *
         * @since 1.2.3
         *
         * @param bool   $value          Whether or not to send the activation key.
         * @param int    $user_id        User ID to send activation key to.
         * @param string $user_email     User email to send activation key to.
         * @param string $activation_key Activation key to be sent.
         * @param array  $usermeta       Miscellaneous metadata about the user (blog-specific
         *                               signup data, xprofile data, etc).
         */
        if (apply_filters('bp_core_signup_send_activation_key', true, $user_id, $user_email, $activation_key, $usermeta)) {
            bp_core_signup_send_validation_email($user_id, $user_email, $activation_key, $user_login);
        }
    }
    $bp->signup->username = $user_login;
    /**
     * Fires at the end of the process to sign up a user.
     *
     * @since 1.2.2
     *
     * @param bool|WP_Error   $user_id       True on success, WP_Error on failure.
     * @param string          $user_login    Login name requested by the user.
     * @param string          $user_password Password requested by the user.
     * @param string          $user_email    Email address requested by the user.
     * @param array           $usermeta      Miscellaneous metadata about the user (blog-specific
     *                                       signup data, xprofile data, etc).
     */
    do_action('bp_core_signup_user', $user_id, $user_login, $user_password, $user_email, $usermeta);
    return $user_id;
}
 function update_meta($args = '')
 {
     $defaults = array('id' => 0, 'meta_key' => null, 'meta_value' => null, 'meta_table' => 'usermeta', 'meta_field' => 'user_id', 'cache_group' => 'users');
     $args = wp_parse_args($args, $defaults);
     extract($args, EXTR_SKIP);
     return bp_update_user_meta($id, $meta_key, $meta_value);
 }
 /**
  * Refresh the total_group_count for a user.
  *
  * @since BuddyPress (1.8.0)
  *
  * @param int $user_id ID of the user.
  *
  * @return bool True on success, false on failure.
  */
 public static function refresh_total_group_count_for_user($user_id)
 {
     return bp_update_user_meta($user_id, 'total_group_count', (int) self::total_group_count($user_id));
 }
 /**
  * @group meta
  * @group BP5904
  */
 public function test_bp_user_query_with_user_meta_argument()
 {
     $u1 = $this->factory->user->create();
     $u2 = $this->factory->user->create();
     bp_update_user_meta($u2, 'foo', 'bar');
     $q = new BP_User_Query(array('meta_key' => 'foo', 'meta_value' => 'bar'));
     $found_user_ids = array_values(wp_parse_id_list(wp_list_pluck($q->results, 'ID')));
     // Do a assertNotContains because there are weird issues with user #1 as created by WP
     $this->assertNotContains($u1, $found_user_ids);
     $this->assertEquals(array($u2), $found_user_ids);
 }
/**
 * Post an activity update
 *
 * @since 1.2.0
 *
 * @param array $args See docs for $defaults for details
 *
 * @global object $bp BuddyPress global settings
 * @uses nxt_parse_args()
 * @uses bp_core_is_user_spammer()
 * @uses bp_core_is_user_deleted()
 * @uses bp_core_get_userlink()
 * @uses bp_activity_add()
 * @uses apply_filters() To call the 'bp_activity_new_update_action' hook
 * @uses apply_filters() To call the 'bp_activity_new_update_content' hook
 * @uses apply_filters() To call the 'bp_activity_new_update_primary_link' hook
 * @uses bp_update_user_meta()
 * @uses nxt_filter_kses()
 * @uses do_action() To call the 'bp_activity_posted_update' hook
 *
 * @return int $activity_id The activity id
 */
function bp_activity_post_update($args = '')
{
    global $bp;
    $defaults = array('content' => false, 'user_id' => $bp->loggedin_user->id);
    $r = nxt_parse_args($args, $defaults);
    extract($r, EXTR_SKIP);
    if (empty($content) || !strlen(trim($content))) {
        return false;
    }
    if (bp_core_is_user_spammer($user_id) || bp_core_is_user_deleted($user_id)) {
        return false;
    }
    // Record this on the user's profile
    $from_user_link = bp_core_get_userlink($user_id);
    $activity_action = sprintf(__('%s posted an update', 'buddypress'), $from_user_link);
    $activity_content = $content;
    $primary_link = bp_core_get_userlink($user_id, false, true);
    // Now write the values
    $activity_id = bp_activity_add(array('user_id' => $user_id, 'action' => apply_filters('bp_activity_new_update_action', $activity_action), 'content' => apply_filters('bp_activity_new_update_content', $activity_content), 'primary_link' => apply_filters('bp_activity_new_update_primary_link', $primary_link), 'component' => $bp->activity->id, 'type' => 'activity_update'));
    // Add this update to the "latest update" usermeta so it can be fetched anywhere.
    bp_update_user_meta($bp->loggedin_user->id, 'bp_latest_update', array('id' => $activity_id, 'content' => nxt_filter_kses($content)));
    do_action('bp_activity_posted_update', $content, $user_id, $activity_id);
    return $activity_id;
}
	function delete_media(){
		global $bp_media_count;
		bp_media_init_count($this->owner);
		switch ($this->type) {
			case 'image':
				$bp_media_count['images'] = intval($bp_media_count['images']) - 1;
				break;
			case 'video':
				$bp_media_count['videos'] = intval($bp_media_count['videos']) - 1;
				break;
			case 'audio':
				$bp_media_count['audio'] = intval($bp_media_count['audio']) - 1;
				break;
		}
		
		wp_delete_attachment($this->attachment_id);
//		$activity_id = get_post_meta($post_id, 'bp_media_child_activity', true);
//		if($activity_id)
//			bp_activity_delete_by_activity_id($activity_id);
		wp_delete_post($this->id);
		bp_update_user_meta($this->owner, 'bp_media_count', $bp_media_count);
	}
 /**
  * Update `bp_latest_update` user meta with lasted public update.
  *
  * @param $content
  * @param $user_id
  * @param $activity_id
  */
 function manage_user_last_activity_update($content, $user_id, $activity_id)
 {
     global $wpdb, $bp;
     // do not proceed if not allowed
     if (!apply_filters('rtm_manage_user_last_activity_update', true, $activity_id)) {
         return;
     }
     $rtm_activity_model = new RTMediaActivityModel();
     $rtm_activity_obj = $rtm_activity_model->get(array('activity_id' => $activity_id));
     if (!empty($rtm_activity_obj)) {
         if (isset($rtm_activity_obj[0]->privacy) && $rtm_activity_obj[0]->privacy > 0) {
             $get_columns = array('activity_id' => array('compare' => '<', 'value' => $activity_id), 'user_id' => $user_id, 'privacy' => array('compare' => '<=', 'value' => 0));
             // get user's latest public activity update
             $new_last_activity_obj = $rtm_activity_model->get($get_columns, 0, 1);
             if (!empty($new_last_activity_obj)) {
                 // latest public activity id
                 $public_activity_id = $new_last_activity_obj[0]->activity_id;
                 // latest public activity content
                 $activity_content = bp_activity_get_meta($public_activity_id, 'bp_activity_text');
                 if (empty($activity_content)) {
                     $activity_content = $wpdb->get_var("SELECT content FROM {$bp->activity->table_name} WHERE id = {$public_activity_id}");
                 }
                 $activity_content = apply_filters('bp_activity_latest_update_content', $activity_content, $activity_content);
                 // update user's latest update
                 bp_update_user_meta($user_id, 'bp_latest_update', array('id' => $public_activity_id, 'content' => $activity_content));
             }
         }
     }
 }
Exemple #17
0
/**
 * Close and keep closed site wide notices from an admin in the sidebar, via a POST request.
 *
 * @return mixed String on error, void on success
 * @since BuddyPress (1.2)
 */
function bp_dtheme_ajax_close_notice()
{
    // Bail if not a POST action
    if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) {
        return;
    }
    if (!isset($_POST['notice_id'])) {
        echo "-1<div id='message' class='error'><p>" . __('There was a problem closing the notice.', 'logicalboneshug') . '</p></div>';
    } else {
        $user_id = get_current_user_id();
        $notice_ids = bp_get_user_meta($user_id, 'closed_notices', true);
        $notice_ids[] = (int) $_POST['notice_id'];
        bp_update_user_meta($user_id, 'closed_notices', $notice_ids);
    }
    exit;
}
Exemple #18
0
function bp_dtheme_ajax_close_notice()
{
    global $userdata;
    // Bail if not a POST action
    if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) {
        return;
    }
    if (!isset($_POST['notice_id'])) {
        echo "-1<div id='message' class='error'><p>" . __('There was a problem closing the notice.', 'buddypress') . '</p></div>';
    } else {
        $notice_ids = bp_get_user_meta($userdata->ID, 'closed_notices', true);
        $notice_ids[] = (int) $_POST['notice_id'];
        bp_update_user_meta($userdata->ID, 'closed_notices', $notice_ids);
    }
}
/**
 * Shows the media count of a user in the tabs
 * 
 * @since BP Media 2.0
 */
function bp_media_init_count($user = null)
{
    global $bp_media_count;
    if (!$user) {
        $user = bp_displayed_user_id();
    }
    if ($user < 1) {
        $bp_media_count = null;
        return false;
    }
    $count = bp_get_user_meta($user, 'bp_media_count', true);
    if (!$count) {
        $bp_media_count = array('images' => 0, 'videos' => 0, 'audio' => 0);
        bp_update_user_meta($user, 'bp_media_count', $bp_media_count);
    } else {
        $bp_media_count = $count;
    }
    add_filter('bp_get_displayed_user_nav_' . BP_MEDIA_SLUG, 'bp_media_items_count_filter', 10, 2);
    if (bp_current_component() == BP_MEDIA_SLUG) {
        add_filter('bp_get_options_nav_' . BP_MEDIA_IMAGES_SLUG, 'bp_media_items_count_filter', 10, 2);
        add_filter('bp_get_options_nav_' . BP_MEDIA_VIDEOS_SLUG, 'bp_media_items_count_filter', 10, 2);
        add_filter('bp_get_options_nav_' . BP_MEDIA_AUDIO_SLUG, 'bp_media_items_count_filter', 10, 2);
    }
    return true;
}
/**
 * Post an activity update.
 *
 * @since 1.2.0
 *
 * @uses wp_parse_args()
 * @uses bp_is_user_inactive()
 * @uses bp_core_get_userlink()
 * @uses bp_activity_add()
 * @uses apply_filters() To call the 'bp_activity_new_update_action' hook.
 * @uses apply_filters() To call the 'bp_activity_new_update_content' hook.
 * @uses apply_filters() To call the 'bp_activity_new_update_primary_link' hook.
 * @uses bp_update_user_meta()
 * @uses wp_filter_kses()
 * @uses do_action() To call the 'bp_activity_posted_update' hook.
 *
 * @param array|string $args {
 *     @type string $content The content of the activity update.
 *     @type int    $user_id Optional. Defaults to the logged-in user.
 * }
 * @return int $activity_id The activity id.
 */
function bp_activity_post_update($args = '')
{
    $r = wp_parse_args($args, array('content' => false, 'user_id' => bp_loggedin_user_id()));
    if (empty($r['content']) || !strlen(trim($r['content']))) {
        return false;
    }
    if (bp_is_user_inactive($r['user_id'])) {
        return false;
    }
    // Record this on the user's profile.
    $activity_content = $r['content'];
    $primary_link = bp_core_get_userlink($r['user_id'], false, true);
    /**
     * Filters the new activity content for current activity item.
     *
     * @since 1.2.0
     *
     * @param string $activity_content Activity content posted by user.
     */
    $add_content = apply_filters('bp_activity_new_update_content', $activity_content);
    /**
     * Filters the activity primary link for current activity item.
     *
     * @since 1.2.0
     *
     * @param string $primary_link Link to the profile for the user who posted the activity.
     */
    $add_primary_link = apply_filters('bp_activity_new_update_primary_link', $primary_link);
    // Now write the values.
    $activity_id = bp_activity_add(array('user_id' => $r['user_id'], 'content' => $add_content, 'primary_link' => $add_primary_link, 'component' => buddypress()->activity->id, 'type' => 'activity_update'));
    /**
     * Filters the latest update content for the activity item.
     *
     * @since 1.6.0
     *
     * @param string $r                Content of the activity update.
     * @param string $activity_content Content of the activity update.
     */
    $activity_content = apply_filters('bp_activity_latest_update_content', $r['content'], $activity_content);
    // Add this update to the "latest update" usermeta so it can be fetched anywhere.
    bp_update_user_meta(bp_loggedin_user_id(), 'bp_latest_update', array('id' => $activity_id, 'content' => $activity_content));
    /**
     * Fires at the end of an activity post update, before returning the updated activity item ID.
     *
     * @since 1.2.0
     *
     * @param string $content     Content of the activity post update.
     * @param int    $user_id     ID of the user posting the activity update.
     * @param int    $activity_id ID of the activity item being updated.
     */
    do_action('bp_activity_posted_update', $r['content'], $r['user_id'], $activity_id);
    return $activity_id;
}
/**
 * Syncs Xprofile data to the standard built in WordPress profile data.
 *
 * @since 1.0.0
 *
 * @param int $user_id ID of the user to sync.
 * @return bool
 */
function xprofile_sync_wp_profile($user_id = 0)
{
    // Bail if profile syncing is disabled.
    if (bp_disable_profile_sync()) {
        return true;
    }
    if (empty($user_id)) {
        $user_id = bp_loggedin_user_id();
    }
    if (empty($user_id)) {
        return false;
    }
    $fullname = xprofile_get_field_data(bp_xprofile_fullname_field_id(), $user_id);
    $space = strpos($fullname, ' ');
    if (false === $space) {
        $firstname = $fullname;
        $lastname = '';
    } else {
        $firstname = substr($fullname, 0, $space);
        $lastname = trim(substr($fullname, $space, strlen($fullname)));
    }
    bp_update_user_meta($user_id, 'nickname', $fullname);
    bp_update_user_meta($user_id, 'first_name', $firstname);
    bp_update_user_meta($user_id, 'last_name', $lastname);
    wp_update_user(array('ID' => $user_id, 'display_name' => $fullname));
    wp_cache_delete('bp_core_userdata_' . $user_id, 'bp');
}
 public function handle_crop()
 {
     require_once ABSPATH . '/wp-admin/includes/image.php';
     $user_id = bp_displayed_user_id();
     $cover_photo = get_transient('profile_cover_photo_' . $user_id);
     // Get the file extension
     $data = @getimagesize($cover_photo);
     $ext = $data['mime'] == 'image/png' ? 'png' : 'jpg';
     $base_filename = basename($cover_photo, '.' . $ext);
     // create a new filename but, if it's already been cropped, strip out the -cropped
     $new_filename = str_replace('-cropped', '', $base_filename) . '-cropped.' . $ext;
     $new_filepath = bp_core_avatar_upload_path() . '/cover-photo/' . $user_id . '/' . $new_filename;
     $new_fileurl = bp_core_avatar_url() . '/cover-photo/' . $user_id . '/' . $new_filename;
     $crop_fileurl = str_replace(trailingslashit(get_home_url()), '', bp_core_avatar_url()) . '/cover-photo/' . $user_id . '/' . $new_filename;
     // delete the old cover photo if it exists
     if (file_exists($new_filepath)) {
         @unlink($new_filepath);
     }
     $cropped_header = wp_crop_image($cover_photo, $_POST['x'], $_POST['y'], $_POST['w'], $_POST['h'], $this->width, $this->height, false, $crop_fileurl);
     if (!is_wp_error($cropped_header)) {
         $old_file_path = get_user_meta(bp_loggedin_user_id(), 'profile_cover_photo_path', true);
         if (file_exists($old_file_path)) {
             @unlink($old_file_path);
         }
         // update with the new image and path
         bp_update_user_meta(bp_loggedin_user_id(), 'profile_cover_photo', $new_fileurl);
         bp_update_user_meta(bp_loggedin_user_id(), 'profile_cover_photo_path', $new_filepath);
         delete_transient('is_cover_photo_uploaded_' . bp_displayed_user_id());
         delete_transient('profile_cover_photo_' . bp_displayed_user_id());
     }
 }
/**
 * Handles the changing and saving of user email addresses and passwords.
 *
 * We do quite a bit of logic and error handling here to make sure that users
 * do not accidentally lock themselves out of their accounts. We also try to
 * provide as accurate of feedback as possible without exposing anyone else's
 * information to them.
 *
 * Special considerations are made for super admins that are able to edit any
 * users accounts already, without knowing their existing password.
 *
 * @global BuddyPress $bp
 */
function bp_settings_action_general()
{
    // Bail if not a POST action
    if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) {
        return;
    }
    // Bail if no submit action
    if (!isset($_POST['submit'])) {
        return;
    }
    // Bail if not in settings
    if (!bp_is_settings_component() || !bp_is_current_action('general')) {
        return;
    }
    // 404 if there are any additional action variables attached
    if (bp_action_variables()) {
        bp_do_404();
        return;
    }
    // Define local defaults
    $bp = buddypress();
    // The instance
    $email_error = false;
    // invalid|blocked|taken|empty|nochange
    $pass_error = false;
    // invalid|mismatch|empty|nochange
    $pass_changed = false;
    // true if the user changes their password
    $email_changed = false;
    // true if the user changes their email
    $feedback_type = 'error';
    // success|error
    $feedback = array();
    // array of strings for feedback
    // Nonce check
    check_admin_referer('bp_settings_general');
    // Validate the user again for the current password when making a big change
    if (is_super_admin() || !empty($_POST['pwd']) && wp_check_password($_POST['pwd'], $bp->displayed_user->userdata->user_pass, bp_displayed_user_id())) {
        $update_user = get_userdata(bp_displayed_user_id());
        /** Email Change Attempt ******************************************/
        if (!empty($_POST['email'])) {
            // What is missing from the profile page vs signup -
            // let's double check the goodies
            $user_email = sanitize_email(esc_html(trim($_POST['email'])));
            $old_user_email = $bp->displayed_user->userdata->user_email;
            // User is changing email address
            if ($old_user_email != $user_email) {
                // Run some tests on the email address
                $email_checks = bp_core_validate_email_address($user_email);
                if (true !== $email_checks) {
                    if (isset($email_checks['invalid'])) {
                        $email_error = 'invalid';
                    }
                    if (isset($email_checks['domain_banned']) || isset($email_checks['domain_not_allowed'])) {
                        $email_error = 'blocked';
                    }
                    if (isset($email_checks['in_use'])) {
                        $email_error = 'taken';
                    }
                }
                // Store a hash to enable email validation
                if (false === $email_error) {
                    $hash = wp_hash($_POST['email']);
                    $pending_email = array('hash' => $hash, 'newemail' => $user_email);
                    bp_update_user_meta(bp_displayed_user_id(), 'pending_email_change', $pending_email);
                    $email_text = sprintf(__('Dear %1$s,

You recently changed the email address associated with your account on %2$s.
If this is correct, please click on the following link to complete the change:
%3$s

You can safely ignore and delete this email if you do not want to take this action or if you have received this email in error.

This email has been sent to %4$s.

Regards,
%5$s
%6$s', 'buddypress'), bp_core_get_user_displayname(bp_displayed_user_id()), bp_get_site_name(), esc_url(bp_displayed_user_domain() . bp_get_settings_slug() . '/?verify_email_change=' . $hash), $user_email, bp_get_site_name(), bp_get_root_domain());
                    /**
                     * Filter the email text sent when a user changes emails.
                     *
                     * @since 2.1.0
                     *
                     * @param string  $email_text     Text of the email.
                     * @param string  $new_user_email New user email that the
                     *                                current user has changed to.
                     * @param string  $old_user_email Existing email address
                     *                                for the current user.
                     * @param WP_User $update_user    Userdata object for the current user.
                     */
                    $content = apply_filters('bp_new_user_email_content', $email_text, $user_email, $old_user_email, $update_user);
                    // Send the verification email
                    wp_mail($user_email, sprintf(__('[%s] Verify your new email address', 'buddypress'), wp_specialchars_decode(bp_get_site_name())), $content);
                    // We mark that the change has taken place so as to ensure a
                    // success message, even though verification is still required
                    $_POST['email'] = $update_user->user_email;
                    $email_changed = true;
                }
                // No change
            } else {
                $email_error = false;
            }
            // Email address cannot be empty
        } else {
            $email_error = 'empty';
        }
        /** Password Change Attempt ***************************************/
        if (!empty($_POST['pass1']) && !empty($_POST['pass2'])) {
            if ($_POST['pass1'] == $_POST['pass2'] && !strpos(" " . $_POST['pass1'], "\\")) {
                // Password change attempt is successful
                if (!empty($_POST['pwd']) && $_POST['pwd'] != $_POST['pass1'] || is_super_admin()) {
                    $update_user->user_pass = $_POST['pass1'];
                    $pass_changed = true;
                    // The new password is the same as the current password
                } else {
                    $pass_error = 'same';
                }
                // Password change attempt was unsuccessful
            } else {
                $pass_error = 'mismatch';
            }
            // Both password fields were empty
        } elseif (empty($_POST['pass1']) && empty($_POST['pass2'])) {
            $pass_error = false;
            // One of the password boxes was left empty
        } elseif (empty($_POST['pass1']) && !empty($_POST['pass2']) || !empty($_POST['pass1']) && empty($_POST['pass2'])) {
            $pass_error = 'empty';
        }
        // The structure of the $update_user object changed in WP 3.3, but
        // wp_update_user() still expects the old format
        if (isset($update_user->data) && is_object($update_user->data)) {
            $update_user = $update_user->data;
            $update_user = get_object_vars($update_user);
            // Unset the password field to prevent it from emptying out the
            // user's user_pass field in the database.
            // @see wp_update_user()
            if (false === $pass_changed) {
                unset($update_user['user_pass']);
            }
        }
        // Clear cached data, so that the changed settings take effect
        // on the current page load
        if (false === $email_error && false === $pass_error && wp_update_user($update_user)) {
            wp_cache_delete('bp_core_userdata_' . bp_displayed_user_id(), 'bp');
            $bp->displayed_user->userdata = bp_core_get_core_userdata(bp_displayed_user_id());
        }
        // Password Error
    } else {
        $pass_error = 'invalid';
    }
    // Email feedback
    switch ($email_error) {
        case 'invalid':
            $feedback['email_invalid'] = __('That email address is invalid. Check the formatting and try again.', 'buddypress');
            break;
        case 'blocked':
            $feedback['email_blocked'] = __('That email address is currently unavailable for use.', 'buddypress');
            break;
        case 'taken':
            $feedback['email_taken'] = __('That email address is already taken.', 'buddypress');
            break;
        case 'empty':
            $feedback['email_empty'] = __('Email address cannot be empty.', 'buddypress');
            break;
        case false:
            // No change
            break;
    }
    // Password feedback
    switch ($pass_error) {
        case 'invalid':
            $feedback['pass_error'] = __('Your current password is invalid.', 'buddypress');
            break;
        case 'mismatch':
            $feedback['pass_mismatch'] = __('The new password fields did not match.', 'buddypress');
            break;
        case 'empty':
            $feedback['pass_empty'] = __('One of the password fields was empty.', 'buddypress');
            break;
        case 'same':
            $feedback['pass_same'] = __('The new password must be different from the current password.', 'buddypress');
            break;
        case false:
            // No change
            break;
    }
    // No errors so show a simple success message
    if ((false === $email_error || false == $pass_error) && (true === $pass_changed || true === $email_changed)) {
        $feedback[] = __('Your settings have been saved.', 'buddypress');
        $feedback_type = 'success';
        // Some kind of errors occurred
    } elseif ((false === $email_error || false === $pass_error) && (false === $pass_changed || false === $email_changed)) {
        if (bp_is_my_profile()) {
            $feedback['nochange'] = __('No changes were made to your account.', 'buddypress');
        } else {
            $feedback['nochange'] = __('No changes were made to this account.', 'buddypress');
        }
    }
    // Set the feedback
    bp_core_add_message(implode("\n", $feedback), $feedback_type);
    /**
     * Fires after the general settings have been saved, and before redirect.
     *
     * @since 1.5.0
     */
    do_action('bp_core_general_settings_after_save');
    // Redirect to prevent issues with browser back button
    bp_core_redirect(trailingslashit(bp_displayed_user_domain() . bp_get_settings_slug() . '/general'));
}
/**
 * Record user activity to the database. Many functions use a "last active" feature to
 * show the length of time since the user was last active.
 * This function will update that time as a usermeta setting for the user every 5 minutes.
 *
 * @package BuddyPress Core
 * @global $userdata WordPress user data for the current logged in user.
 * @uses bp_update_user_meta() BP function to update user metadata in the usermeta table.
 */
function bp_core_record_activity()
{
    if (!is_user_logged_in()) {
        return false;
    }
    $user_id = bp_loggedin_user_id();
    if (bp_is_user_inactive($user_id)) {
        return false;
    }
    $activity = bp_get_user_meta($user_id, 'last_activity', true);
    if (!is_numeric($activity)) {
        $activity = strtotime($activity);
    }
    // Get current time
    $current_time = bp_core_current_time();
    // Use this action to detect the very first activity for a given member
    if (empty($activity)) {
        do_action('bp_first_activity_for_member', $user_id);
    }
    if (empty($activity) || strtotime($current_time) >= strtotime('+5 minutes', $activity)) {
        bp_update_user_meta($user_id, 'last_activity', $current_time);
    }
}
/** Notifications *************************************************************/
function bp_core_screen_notification_settings()
{
    global $bp;
    if (bp_action_variables()) {
        bp_do_404();
        return;
    }
    if (isset($_POST['submit'])) {
        check_admin_referer('bp_settings_notifications');
        if (isset($_POST['notifications'])) {
            foreach ((array) $_POST['notifications'] as $key => $value) {
                if ($meta_key = bp_get_user_meta_key($key)) {
                    bp_update_user_meta((int) $bp->displayed_user->id, $meta_key, $value);
                }
            }
        }
        bp_core_add_message(__('Changes saved.', 'buddypress'), 'success');
        do_action('bp_core_notification_settings_after_save');
    }
    bp_core_load_template(apply_filters('bp_core_screen_notification_settings', 'members/single/settings/notifications'));
}
function ass_digest_record_activity($activity_id, $user_id, $group_id, $type = 'dig')
{
    global $bp;
    if (!$activity_id || !$user_id || !$group_id) {
        return;
    }
    // get the digest/summary items for all groups for this user
    $group_activity_ids = bp_get_user_meta($user_id, 'ass_digest_items', true);
    // update multi-dimensional array with the current activity_id
    $group_activity_ids[$type][$group_id][] = $activity_id;
    // re-save it
    bp_update_user_meta($user_id, 'ass_digest_items', $group_activity_ids);
}
Exemple #27
0
function bp_dtheme_ajax_close_notice()
{
    global $userdata;
    if (!isset($_POST['notice_id'])) {
        echo "-1<div id='message' class='error'><p>" . __('There was a problem closing the notice.', 'buddypress') . '</p></div>';
    } else {
        $notice_ids = bp_get_user_meta($userdata->ID, 'closed_notices', true);
        $notice_ids[] = (int) $_POST['notice_id'];
        bp_update_user_meta($userdata->ID, 'closed_notices', $notice_ids);
    }
}
Exemple #28
0
/**
 * Post an activity update.
 *
 * @since BuddyPress (1.2.0)
 *
 * @uses wp_parse_args()
 * @uses bp_is_user_inactive()
 * @uses bp_core_get_userlink()
 * @uses bp_activity_add()
 * @uses apply_filters() To call the 'bp_activity_new_update_action' hook.
 * @uses apply_filters() To call the 'bp_activity_new_update_content' hook.
 * @uses apply_filters() To call the 'bp_activity_new_update_primary_link' hook.
 * @uses bp_update_user_meta()
 * @uses wp_filter_kses()
 * @uses do_action() To call the 'bp_activity_posted_update' hook.
 *
 * @param array $args {
 *     @type string $content The content of the activity update.
 *     @type int $user_id Optional. Defaults to the logged-in user.
 * }
 * @return int $activity_id The activity id
 */
function bp_activity_post_update($args = '')
{
    $r = wp_parse_args($args, array('content' => false, 'user_id' => bp_loggedin_user_id()));
    if (empty($r['content']) || !strlen(trim($r['content']))) {
        return false;
    }
    if (bp_is_user_inactive($r['user_id'])) {
        return false;
    }
    // Record this on the user's profile
    $activity_content = $r['content'];
    $primary_link = bp_core_get_userlink($r['user_id'], false, true);
    // Now write the values
    $activity_id = bp_activity_add(array('user_id' => $r['user_id'], 'content' => apply_filters('bp_activity_new_update_content', $activity_content), 'primary_link' => apply_filters('bp_activity_new_update_primary_link', $primary_link), 'component' => buddypress()->activity->id, 'type' => 'activity_update'));
    $activity_content = apply_filters('bp_activity_latest_update_content', $r['content'], $activity_content);
    // Add this update to the "latest update" usermeta so it can be fetched anywhere.
    bp_update_user_meta(bp_loggedin_user_id(), 'bp_latest_update', array('id' => $activity_id, 'content' => $activity_content));
    do_action('bp_activity_posted_update', $r['content'], $r['user_id'], $activity_id);
    return $activity_id;
}
/**
 * Handles the changing and saving of user notification settings
 */
function bp_settings_action_notifications()
{
    // Bail if not a POST action
    if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) {
        return;
    }
    // Bail if no submit action
    if (!isset($_POST['submit'])) {
        return;
    }
    // Bail if not in settings
    if (!bp_is_settings_component() || !bp_is_current_action('notifications')) {
        return false;
    }
    // 404 if there are any additional action variables attached
    if (bp_action_variables()) {
        bp_do_404();
        return;
    }
    check_admin_referer('bp_settings_notifications');
    if (isset($_POST['notifications'])) {
        foreach ((array) $_POST['notifications'] as $key => $value) {
            bp_update_user_meta((int) bp_displayed_user_id(), $key, $value);
        }
    }
    // Switch feedback for super admins
    if (bp_is_my_profile()) {
        bp_core_add_message(__('Your notification settings have been saved.', 'buddypress'), 'success');
    } else {
        bp_core_add_message(__("This user's notification settings have been saved.", 'buddypress'), 'success');
    }
    do_action('bp_core_notification_settings_after_save');
    bp_core_redirect(bp_displayed_user_domain() . bp_get_settings_slug() . '/notifications/');
}
Exemple #30
0
/**
 * Update user friend counts.
 *
 * Friend counts are cached in usermeta for performance reasons. After a
 * friendship event (acceptance, deletion), call this function to regenerate
 * the cached values.
 *
 * @param int $initiator_user_id ID of the first user.
 * @param int $friend_user_id ID of the second user.
 * @param string $status Optional. The friendship event that's been triggered.
 *        'add' will ++ each user's friend counts, while any other string
 *        will --.
 */
function friends_update_friend_totals($initiator_user_id, $friend_user_id, $status = 'add')
{
    if ('add' == $status) {
        bp_update_user_meta($initiator_user_id, 'total_friend_count', (int) bp_get_user_meta($initiator_user_id, 'total_friend_count', true) + 1);
        bp_update_user_meta($friend_user_id, 'total_friend_count', (int) bp_get_user_meta($friend_user_id, 'total_friend_count', true) + 1);
    } else {
        bp_update_user_meta($initiator_user_id, 'total_friend_count', (int) bp_get_user_meta($initiator_user_id, 'total_friend_count', true) - 1);
        bp_update_user_meta($friend_user_id, 'total_friend_count', (int) bp_get_user_meta($friend_user_id, 'total_friend_count', true) - 1);
    }
}