本文整理汇总了PHP中bp_core_avatar_handle_crop函数的典型用法代码示例。如果您正苦于以下问题:PHP bp_core_avatar_handle_crop函数的具体用法?PHP bp_core_avatar_handle_crop怎么用?PHP bp_core_avatar_handle_crop使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了bp_core_avatar_handle_crop函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: groups_screen_group_admin_avatar
/**
* Handle the display of a group's Change Avatar page.
*/
function groups_screen_group_admin_avatar()
{
if ('group-avatar' != bp_get_group_current_admin_tab()) {
return false;
}
// If the logged-in user doesn't have permission or if avatar uploads are disabled, then stop here.
if (!bp_is_item_admin() || bp_disable_group_avatar_uploads() || !buddypress()->avatar->show_avatars) {
return false;
}
$bp = buddypress();
// If the group admin has deleted the admin avatar.
if (bp_is_action_variable('delete', 1)) {
// Check the nonce.
check_admin_referer('bp_group_avatar_delete');
if (bp_core_delete_existing_avatar(array('item_id' => $bp->groups->current_group->id, 'object' => 'group'))) {
bp_core_add_message(__('The group profile photo was deleted successfully!', 'buddypress'));
} else {
bp_core_add_message(__('There was a problem deleting the group profile photo. Please try again.', 'buddypress'), 'error');
}
}
if (!isset($bp->avatar_admin)) {
$bp->avatar_admin = new stdClass();
}
$bp->avatar_admin->step = 'upload-image';
if (!empty($_FILES)) {
// Check the nonce.
check_admin_referer('bp_avatar_upload');
// Pass the file to the avatar upload handler.
if (bp_core_avatar_handle_upload($_FILES, 'groups_avatar_upload_dir')) {
$bp->avatar_admin->step = 'crop-image';
// Make sure we include the jQuery jCrop file for image cropping.
add_action('wp_print_scripts', 'bp_core_add_jquery_cropper');
}
}
// If the image cropping is done, crop the image and save a full/thumb version.
if (isset($_POST['avatar-crop-submit'])) {
// Check the nonce.
check_admin_referer('bp_avatar_cropstore');
$args = array('object' => 'group', 'avatar_dir' => 'group-avatars', 'item_id' => $bp->groups->current_group->id, 'original_file' => $_POST['image_src'], 'crop_x' => $_POST['x'], 'crop_y' => $_POST['y'], 'crop_w' => $_POST['w'], 'crop_h' => $_POST['h']);
if (!bp_core_avatar_handle_crop($args)) {
bp_core_add_message(__('There was a problem cropping the group profile photo.', 'buddypress'), 'error');
} else {
bp_core_add_message(__('The new group profile photo was uploaded successfully.', 'buddypress'));
}
}
/**
* Fires before the loading of the group Change Avatar page template.
*
* @since 1.0.0
*
* @param int $id ID of the group that is being displayed.
*/
do_action('groups_screen_group_admin_avatar', $bp->groups->current_group->id);
/**
* Filters the template to load for a group's Change Avatar page.
*
* @since 1.0.0
*
* @param string $value Path to a group's Change Avatar template.
*/
bp_core_load_template(apply_filters('groups_template_group_admin_avatar', 'groups/single/home'));
}
示例2: bp_attachments_create_item_type
//.........这里部分代码省略.........
* @type int $crop_y The vertical starting point of the crop. Default: 0.
* }
* @return bool True on success, false otherwise.
*/
function bp_attachments_create_item_type($type = 'avatar', $args = array())
{
if (empty($type) || $type !== 'avatar' && $type !== 'cover_image') {
return false;
}
$r = bp_parse_args($args, array('item_id' => 0, 'object' => 'user', 'component' => '', 'image' => '', 'crop_w' => 0, 'crop_h' => 0, 'crop_x' => 0, 'crop_y' => 0), 'create_item_' . $type);
if (empty($r['item_id']) || empty($r['object']) || !file_exists($r['image']) || !@getimagesize($r['image'])) {
return false;
}
// Make sure the file path is safe
if (0 !== validate_file($r['image'])) {
return false;
}
// Set the component if not already done
if (empty($r['component'])) {
if ('user' === $r['object']) {
$r['component'] = 'xprofile';
} else {
$r['component'] = $r['object'] . 's';
}
}
// Get allowed mimes for the Attachment type and check the image one is.
$allowed_mimes = bp_attachments_get_allowed_mimes($type);
$is_allowed = wp_check_filetype($r['image'], $allowed_mimes);
// It's not an image.
if (!$is_allowed['ext']) {
return false;
}
// Init the Attachment data
$attachment_data = array();
if ('avatar' === $type) {
// Set crop width for the avatar if not given
if (empty($r['crop_w'])) {
$r['crop_w'] = bp_core_avatar_full_width();
}
// Set crop height for the avatar if not given
if (empty($r['crop_h'])) {
$r['crop_h'] = bp_core_avatar_full_height();
}
if (is_callable($r['component'] . '_avatar_upload_dir')) {
$dir_args = array($r['item_id']);
// In case of xprofile, we need an extra argument
if ('xprofile' === $r['component']) {
$dir_args = array(false, $r['item_id']);
}
$attachment_data = call_user_func_array($r['component'] . '_avatar_upload_dir', $dir_args);
}
} elseif ('cover_image' === $type) {
$attachment_data = bp_attachments_uploads_dir_get();
// The BP Attachments Uploads Dir is not set, stop.
if (!$attachment_data) {
return false;
}
// Default to members for xProfile
$object_subdir = 'members';
if ('xprofile' !== $r['component']) {
$object_subdir = sanitize_key($r['component']);
}
// Set Subdir
$attachment_data['subdir'] = $object_subdir . '/' . $r['item_id'] . '/cover-image';
// Set Path
$attachment_data['path'] = trailingslashit($attachment_data['basedir']) . $attachment_data['subdir'];
}
if (!isset($attachment_data['path']) || !isset($attachment_data['subdir'])) {
return false;
}
// It's not a regular upload, we may need to create some folders
if (!is_dir($attachment_data['path'])) {
if (!wp_mkdir_p($attachment_data['path'])) {
return false;
}
}
// Set the image name and path
$image_file_name = wp_unique_filename($attachment_data['path'], basename($r['image']));
$image_file_path = $attachment_data['path'] . '/' . $image_file_name;
// Copy the image file into the avatar dir
if (!copy($r['image'], $image_file_path)) {
return false;
}
// Init the response
$created = false;
// It's an avatar, we need to crop it.
if ('avatar' === $type) {
$created = bp_core_avatar_handle_crop(array('object' => $r['object'], 'avatar_dir' => trim(dirname($attachment_data['subdir']), '/'), 'item_id' => (int) $r['item_id'], 'original_file' => trailingslashit($attachment_data['subdir']) . $image_file_name, 'crop_w' => $r['crop_w'], 'crop_h' => $r['crop_h'], 'crop_x' => $r['crop_x'], 'crop_y' => $r['crop_y']));
// It's a cover image we need to fit it to feature's dimensions
} elseif ('cover_image' === $type) {
$cover_image = bp_attachments_cover_image_generate_file(array('file' => $image_file_path, 'component' => $r['component'], 'cover_image_dir' => $attachment_data['path']));
$created = !empty($cover_image['cover_file']);
}
// Remove copied file if it fails
if (!$created) {
@unlink($image_file_path);
}
// Return the response
return $created;
}
示例3: save_course_settings
function save_course_settings()
{
$user_id = get_current_user_id();
$course_id = $_POST['course_id'];
$course_setting['vibe_course_auto_eval'] = $_POST['vibe_course_auto_eval'];
$course_setting['vibe_duration'] = $_POST['vibe_duration'];
$course_setting['vibe_pre_course'] = $_POST['vibe_pre_course'];
$course_setting['vibe_course_drip'] = $_POST['vibe_course_drip'];
$course_setting['vibe_course_drip_duration'] = $_POST['vibe_course_drip_duration'];
$course_setting['vibe_course_certificate'] = $_POST['vibe_certificate'];
$course_setting['vibe_course_passing_percentage'] = $_POST['vibe_course_passing_percentage'];
$course_setting['vibe_certificate_template'] = $_POST['vibe_certificate_template'];
$course_setting['vibe_badge'] = $_POST['vibe_badge'];
$course_setting['vibe_course_badge_percentage'] = $_POST['vibe_course_badge_percentage'];
$course_setting['vibe_course_badge_title'] = $_POST['vibe_course_badge_title'];
$course_setting['vibe_course_badge'] = $_POST['vibe_course_badge'];
$course_setting['vibe_max_students'] = $_POST['vibe_max_students'];
$course_setting['vibe_start_date'] = $_POST['vibe_start_date'];
$course_setting['vibe_course_retakes'] = $_POST['vibe_course_retakes'];
$course_setting['vibe_group'] = $_POST['vibe_group'];
$course_setting['vibe_forum'] = $_POST['vibe_forum'];
$course_setting['vibe_course_instructions'] = $_POST['vibe_course_instructions'];
$course_setting['vibe_course_message'] = $_POST['vibe_course_message'];
$flag = 0;
//Error Flag
if (!isset($_POST['security']) || !wp_verify_nonce($_POST['security'], 'create_course' . $user_id) || !current_user_can('edit_posts')) {
_e('Security check Failed. Contact Administrator.', 'wplms-front-end');
die;
}
if (!is_numeric($course_id) || get_post_type($course_id) != 'course') {
_e('Invalid Course id, please edit a course', 'wplms-front-end');
die;
}
$the_post = get_post($course_id);
if ($the_post->post_author != $user_id && !current_user_can('manage_options')) {
_e('Invalid Course Instructor', 'wplms-front-end');
die;
}
if ($course_setting['vibe_badge'] == 'H') {
$course_setting['vibe_course_badge'] = '';
}
foreach ($course_setting as $key => $value) {
$prev_val = get_post_meta($course_id, $key, true);
if ($prev_val != $value) {
update_post_meta($course_id, $key, $value);
}
}
if ($course_setting['vibe_group'] == 'add_new' && !$flag) {
$the_course = get_post($course_id);
$t = wp_get_attachment_image_src(get_post_thumbnail_id($course_id, 'thumbnail'));
$f = wp_get_attachment_image_src(get_post_thumbnail_id($course_id, 'full'));
$group_slug = $the_course->post_name;
//groups_check_slug( sanitize_title( esc_attr( $the_course->post_name ) ) );
$group_settings = array('creator_id' => $user_id, 'name' => $the_course->post_title, 'slug' => $group_slug, 'description' => $the_course->post_excerpt, 'status' => 'private', 'date_created' => current_time('mysql'));
$group_settings = apply_filters('wplms_front_end_group_vars', $group_settings);
if ($course_setting['vibe_forum'] == 'add_group_forum') {
$group_settings['enable_forum'] = 1;
}
global $bp;
$new_group_id = groups_create_group($group_settings);
bp_core_avatar_handle_crop(array('object' => 'group', 'avatar_dir' => 'group-avatars', 'item_id' => $new_group_id, 'original_file' => $f[0], 'crop_x' => 0, 'crop_y' => 0, 'crop_w' => $f[1], 'crop_h' => $f[2]));
groups_update_groupmeta($new_group_id, 'total_member_count', 1);
groups_update_groupmeta($new_group_id, 'last_activity', gmdate("Y-m-d H:i:s"));
update_post_meta($course_id, 'vibe_group', $new_group_id);
if ($course_setting['vibe_forum'] == 'add_group_forum') {
$forum_settings = array('post_title' => stripslashes($the_course->post_title), 'post_content' => stripslashes($the_course->post_excerpt), 'post_name' => $the_course->post_name, 'post_status' => 'private', 'post_type' => 'forum');
$forum_settings = apply_filters('wplms_front_end_forum_vars', $forum_settings);
$new_forum_id = wp_insert_post($forum_settings);
//Linkage
$linkage = vibe_get_option('linkage');
if (isset($linkage) && $linkage) {
$course_linkage = wp_get_post_terms($course_id, 'linkage', array("fields" => "names"));
if (isset($course_linkage) && is_array($course_linkage)) {
wp_set_post_terms($new_forum_id, $course_linkage, 'linkage');
}
}
groups_update_groupmeta($new_group_id, 'forum_id', array($new_forum_id));
update_post_meta($course_id, 'vibe_forum', $new_forum_id);
}
}
if ($course_setting['vibe_forum'] == 'add_new' && !$flag) {
$forum_settings = array('post_title' => stripslashes($the_post->post_title), 'post_content' => stripslashes($the_post->post_excerpt), 'post_name' => $the_post->post_name, 'post_status' => 'private', 'post_type' => 'forum');
$forum_settings = apply_filters('wplms_front_end_forum_vars', $forum_settings);
$new_forum_id = wp_insert_post($forum_settings);
update_post_meta($course_id, 'vibe_forum', $new_forum_id);
}
if (isset($_POST['level']) && $_POST['level']) {
$level = $_POST['level'];
if (is_numeric($level)) {
wp_set_post_terms($course_id, $level, 'level');
}
}
if ($flag) {
echo $message;
} else {
echo $course_id;
do_action('wplms_course_settings_updated', $course_id);
}
die;
}
示例4: xprofile_screen_change_avatar
/**
* Handles the uploading and cropping of a user avatar. Displays the change avatar page.
*
* @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_change_avatar()
{
// Bail if not the correct screen
if (!bp_is_my_profile() && !bp_current_user_can('bp_moderate')) {
return false;
}
// Bail if there are action variables
if (bp_action_variables()) {
bp_do_404();
return;
}
$bp = buddypress();
if (!isset($bp->avatar_admin)) {
$bp->avatar_admin = new stdClass();
}
$bp->avatar_admin->step = 'upload-image';
if (!empty($_FILES)) {
// Check the nonce
check_admin_referer('bp_avatar_upload');
// Pass the file to the avatar upload handler
if (bp_core_avatar_handle_upload($_FILES, 'xprofile_avatar_upload_dir')) {
$bp->avatar_admin->step = 'crop-image';
// Make sure we include the jQuery jCrop file for image cropping
add_action('wp_print_scripts', 'bp_core_add_jquery_cropper');
}
}
// If the image cropping is done, crop the image and save a full/thumb version
if (isset($_POST['avatar-crop-submit'])) {
// Check the nonce
check_admin_referer('bp_avatar_cropstore');
$args = array('item_id' => bp_displayed_user_id(), 'original_file' => $_POST['image_src'], 'crop_x' => $_POST['x'], 'crop_y' => $_POST['y'], 'crop_w' => $_POST['w'], 'crop_h' => $_POST['h']);
if (!bp_core_avatar_handle_crop($args)) {
bp_core_add_message(__('There was a problem cropping your profile photo.', 'buddypress'), 'error');
} else {
/**
* Fires right before the redirect, after processing a new avatar.
*
* @since 1.1.0
* @since 2.3.4 Add two new parameters to inform about the user id and
* about the way the avatar was set (eg: 'crop' or 'camera')
*
* @param string $item_id Inform about the user id the avatar was set for
* @param string $value Inform about the way the avatar was set ('crop')
*/
do_action('xprofile_avatar_uploaded', (int) $args['item_id'], 'crop');
bp_core_add_message(__('Your new profile photo was uploaded successfully.', 'buddypress'));
bp_core_redirect(bp_displayed_user_domain());
}
}
/**
* Fires right before the loading of the XProfile change avatar screen template file.
*
* @since BuddyPress (1.0.0)
*/
do_action('xprofile_screen_change_avatar');
/**
* Filters the template to load for the XProfile change avatar screen.
*
* @since BuddyPress (1.0.0)
*
* @param string $template Path to the XProfile change avatar template to load.
*/
bp_core_load_template(apply_filters('xprofile_template_change_avatar', 'members/single/home'));
}
示例5: groups_action_create_group
//.........这里部分代码省略.........
bp_core_add_message(__('There was an error saving group details, please try again.', 'buddypress'), 'error');
bp_core_redirect(bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/step/' . bp_get_groups_current_create_step() . '/');
}
// Set the invite status
// Checked against a whitelist for security
$allowed_invite_status = apply_filters('groups_allowed_invite_status', array('members', 'mods', 'admins'));
$invite_status = !empty($_POST['group-invite-status']) && in_array($_POST['group-invite-status'], (array) $allowed_invite_status) ? $_POST['group-invite-status'] : 'members';
groups_update_groupmeta($bp->groups->new_group_id, 'invite_status', $invite_status);
}
if ('group-invites' === bp_get_groups_current_create_step()) {
if (!empty($_POST['friends'])) {
foreach ((array) $_POST['friends'] as $friend) {
groups_invite_user(array('user_id' => $friend, 'group_id' => $bp->groups->new_group_id));
}
}
groups_send_invites(bp_loggedin_user_id(), $bp->groups->new_group_id);
}
do_action('groups_create_group_step_save_' . bp_get_groups_current_create_step());
do_action('groups_create_group_step_complete');
// Mostly for clearing cache on a generic action name
/**
* Once we have successfully saved the details for this step of the creation process
* we need to add the current step to the array of completed steps, then update the cookies
* holding the information
*/
$completed_create_steps = isset($bp->groups->completed_create_steps) ? $bp->groups->completed_create_steps : array();
if (!in_array(bp_get_groups_current_create_step(), $completed_create_steps)) {
$bp->groups->completed_create_steps[] = bp_get_groups_current_create_step();
}
// Reset cookie info
setcookie('bp_new_group_id', $bp->groups->new_group_id, time() + 60 * 60 * 24, COOKIEPATH);
setcookie('bp_completed_create_steps', base64_encode(json_encode($bp->groups->completed_create_steps)), time() + 60 * 60 * 24, COOKIEPATH);
// If we have completed all steps and hit done on the final step we
// can redirect to the completed group
$keys = array_keys($bp->groups->group_creation_steps);
if (count($bp->groups->completed_create_steps) == count($keys) && bp_get_groups_current_create_step() == array_pop($keys)) {
unset($bp->groups->current_create_step);
unset($bp->groups->completed_create_steps);
// Once we compelete all steps, record the group creation in the activity stream.
groups_record_activity(array('type' => 'created_group', 'item_id' => $bp->groups->new_group_id));
do_action('groups_group_create_complete', $bp->groups->new_group_id);
bp_core_redirect(bp_get_group_permalink($bp->groups->current_group));
} else {
/**
* Since we don't know what the next step is going to be (any plugin can insert steps)
* we need to loop the step array and fetch the next step that way.
*/
foreach ($keys as $key) {
if ($key == bp_get_groups_current_create_step()) {
$next = 1;
continue;
}
if (isset($next)) {
$next_step = $key;
break;
}
}
bp_core_redirect(bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/step/' . $next_step . '/');
}
}
// Remove invitations
if ('group-invites' === bp_get_groups_current_create_step() && !empty($_REQUEST['user_id']) && is_numeric($_REQUEST['user_id'])) {
if (!check_admin_referer('groups_invite_uninvite_user')) {
return false;
}
$message = __('Invite successfully removed', 'buddypress');
$error = false;
if (!groups_uninvite_user((int) $_REQUEST['user_id'], $bp->groups->new_group_id)) {
$message = __('There was an error removing the invite', 'buddypress');
$error = 'error';
}
bp_core_add_message($message, $error);
bp_core_redirect(bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/step/group-invites/');
}
// Group avatar is handled separately
if ('group-avatar' == bp_get_groups_current_create_step() && isset($_POST['upload'])) {
if (!isset($bp->avatar_admin)) {
$bp->avatar_admin = new stdClass();
}
if (!empty($_FILES) && isset($_POST['upload'])) {
// Normally we would check a nonce here, but the group save nonce is used instead
// Pass the file to the avatar upload handler
if (bp_core_avatar_handle_upload($_FILES, 'groups_avatar_upload_dir')) {
$bp->avatar_admin->step = 'crop-image';
// Make sure we include the jQuery jCrop file for image cropping
add_action('wp_print_scripts', 'bp_core_add_jquery_cropper');
}
}
// If the image cropping is done, crop the image and save a full/thumb version
if (isset($_POST['avatar-crop-submit']) && isset($_POST['upload'])) {
// Normally we would check a nonce here, but the group save nonce is used instead
if (!bp_core_avatar_handle_crop(array('object' => 'group', 'avatar_dir' => 'group-avatars', 'item_id' => $bp->groups->current_group->id, 'original_file' => $_POST['image_src'], 'crop_x' => $_POST['x'], 'crop_y' => $_POST['y'], 'crop_w' => $_POST['w'], 'crop_h' => $_POST['h']))) {
bp_core_add_message(__('There was an error saving the group profile photo, please try uploading again.', 'buddypress'), 'error');
} else {
bp_core_add_message(__('The group profile photo was uploaded successfully!', 'buddypress'));
}
}
}
bp_core_load_template(apply_filters('groups_template_create_group', 'groups/create'));
}
示例6: xprofile_screen_change_avatar
/**
* Handles the uploading and cropping of a user avatar. Displays the change avatar page.
*
* @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_change_avatar()
{
// Bail if not the correct screen
if (!bp_is_my_profile() && !bp_current_user_can('bp_moderate')) {
return false;
}
// Bail if there are action variables
if (bp_action_variables()) {
bp_do_404();
return;
}
$bp = buddypress();
if (!isset($bp->avatar_admin)) {
$bp->avatar_admin = new stdClass();
}
$bp->avatar_admin->step = 'upload-image';
if (!empty($_FILES)) {
// Check the nonce
check_admin_referer('bp_avatar_upload');
// Pass the file to the avatar upload handler
if (bp_core_avatar_handle_upload($_FILES, 'xprofile_avatar_upload_dir')) {
$bp->avatar_admin->step = 'crop-image';
// Make sure we include the jQuery jCrop file for image cropping
add_action('wp_print_scripts', 'bp_core_add_jquery_cropper');
}
}
// If the image cropping is done, crop the image and save a full/thumb version
if (isset($_POST['avatar-crop-submit'])) {
// Check the nonce
check_admin_referer('bp_avatar_cropstore');
$args = array('item_id' => bp_displayed_user_id(), 'original_file' => $_POST['image_src'], 'crop_x' => $_POST['x'], 'crop_y' => $_POST['y'], 'crop_w' => $_POST['w'], 'crop_h' => $_POST['h']);
if (!bp_core_avatar_handle_crop($args)) {
bp_core_add_message(__('There was a problem cropping your profile photo.', 'buddypress'), 'error');
} else {
do_action('xprofile_avatar_uploaded');
bp_core_add_message(__('Your new profile photo was uploaded successfully.', 'buddypress'));
bp_core_redirect(bp_displayed_user_domain());
}
}
do_action('xprofile_screen_change_avatar');
bp_core_load_template(apply_filters('xprofile_template_change_avatar', 'members/single/home'));
}
示例7: tv_handle_avatar_upload_crop
function tv_handle_avatar_upload_crop()
{
global $bp, $wpdb;
/* If the image cropping is done, crop the image and save a full/thumb version */
if (isset($_POST['avatar_crop_submit'])) {
if (!bp_core_avatar_handle_crop(array('original_file' => $_POST['image_src'], 'crop_x' => $_POST['x'], 'crop_y' => $_POST['y'], 'crop_w' => $_POST['w'], 'crop_h' => $_POST['h']))) {
echo 'There was a problem cropping your avatar, please try uploading it again';
} else {
echo bp_core_fetch_avatar(array('item_id' => $_POST['user_id'], 'type' => 'full', 'width' => 150, 'height' => 150, 'html' => true));
printf('<br><a href="#" data-confirm="%s" class="tutviet-button button avatar-delete">%s</a>', __('Are you sure?', 'tutviet'), __('Delete', 'tutviet'));
}
exit;
}
}
示例8: bp_ning_import_create_user
function bp_ning_import_create_user($userdata)
{
global $wpdb;
$email = preg_replace('#(@.*)/#i', '$1', $userdata->email);
// Check for existing member
if ($user = get_user_by('email', $email)) {
$bp_member = array();
$bp_member['user_login'] = $user->user_login;
$bp_member['user_name'] = $user->user_name;
$bp_member['user_email'] = $user->user_email;
$bp_member['display_name'] = $user->display_name;
$bp_member['id'] = $user->ID;
$bp_member['already_exists'] = 1;
return $bp_member;
}
$username = strtolower(preg_replace("/\\s+/", '', $userdata->fullName));
$username = str_replace('@', '', $username);
$username = str_replace('.', '', $username);
$username = str_replace(')', '', $username);
$username = str_replace('(', '', $username);
$username = str_replace("'", '', $username);
$username = str_replace(':', '', $username);
$username = preg_replace("/[^\t\n\r -]/", "", $username);
$table = array('Š' => 'S', 'š' => 's', 'Đ' => 'Dj', 'đ' => 'dj', 'Ž' => 'Z', 'ž' => 'z', 'Č' => 'C', 'č' => 'c', 'Ć' => 'C', 'ć' => 'c', 'À' => 'A', 'Á' => 'A', 'Â' => 'A', 'Ã' => 'A', 'Ä' => 'A', 'Å' => 'A', 'Æ' => 'A', 'Ç' => 'C', 'È' => 'E', 'É' => 'E', 'Ê' => 'E', 'Ë' => 'E', 'Ì' => 'I', 'Í' => 'I', 'Î' => 'I', 'Ï' => 'I', 'Ñ' => 'N', 'Ò' => 'O', 'Ó' => 'O', 'Ô' => 'O', 'Õ' => 'O', 'Ö' => 'O', 'Ø' => 'O', 'Ù' => 'U', 'Ú' => 'U', 'Û' => 'U', 'Ü' => 'U', 'Ý' => 'Y', 'Þ' => 'B', 'ß' => 'Ss', 'à' => 'a', 'á' => 'a', 'â' => 'a', 'ã' => 'a', 'ä' => 'a', 'å' => 'a', 'æ' => 'a', 'ç' => 'c', 'è' => 'e', 'é' => 'e', 'ê' => 'e', 'ë' => 'e', 'ì' => 'i', 'í' => 'i', 'î' => 'i', 'ï' => 'i', 'ð' => 'o', 'ñ' => 'n', 'ò' => 'o', 'ó' => 'o', 'ô' => 'o', 'õ' => 'o', 'ö' => 'o', 'ø' => 'o', 'ù' => 'u', 'ú' => 'u', 'û' => 'u', 'ý' => 'y', 'ý' => 'y', 'þ' => 'b', 'ÿ' => 'y', 'Ŕ' => 'R', 'ŕ' => 'r');
$username = strtr($username, $table);
if (empty($username)) {
$username = 'unnamed';
}
// Autogenerates username by adding an integer to the end of it
if (username_exists($username)) {
$i = 1;
while (username_exists($username . $i)) {
$i++;
}
$username = $username . $i;
}
// Autogenerate password
$password = substr(md5(uniqid(microtime())), 0, 7);
$bp_member = array("user_email" => $email, "user_name" => $userdata->fullName, "already_exists" => 0);
// create user
$args = array("user_login" => $username, "display_name" => $userdata->fullName, "nickname" => $userdata->fullName, "user_pass" => $password, "user_email" => $email);
$bp_member['id'] = wp_insert_user($args);
if (is_wp_error($bp_member['id'])) {
var_dump($username, $userdata, $bp_member['id']);
die;
}
$bp_member['user_login'] = $username;
$bp_member['display_name'] = $userdata->fullName;
$bp_member['password'] = $password;
#echo "<br />" . $bp_member['id'] . ") $userdata->fullName created";
$f = explode("?", $userdata->profilePhoto);
$g = explode("members/", $f[0]);
$oldfilepath = WP_CONTENT_DIR . '/ning-files/' . $f[0];
if (!file_exists($oldfilepath)) {
return;
}
$filename = $g[1];
if (strpos($filename, '/')) {
$fn = explode("/", $filename);
$filename = array_pop($fn);
}
if (!preg_match('/png|gif|jpg|jpeg|bmp|PNG|GIF|JPG|JPEG|BMP/', $filename)) {
return;
}
$newfilepath = BP_AVATAR_UPLOAD_PATH . '/' . $filename;
if (!file_exists(BP_AVATAR_UPLOAD_PATH . '/avatars/')) {
mkdir(BP_AVATAR_UPLOAD_PATH . '/avatars/');
}
if (!file_exists(BP_AVATAR_UPLOAD_PATH . '/avatars/' . $bp_member['id'])) {
mkdir(BP_AVATAR_UPLOAD_PATH . '/avatars/' . $bp_member['id']);
}
copy($oldfilepath, $newfilepath);
// Rudimentary squaring algorithm
$size = getimagesize($newfilepath);
$args = array('item_id' => $bp_member['id'], 'original_file' => '/' . $filename);
if ($size[0] > $size[1]) {
$diff = $size[0] - $size[1];
$cropx = $diff / 2;
$args['crop_w'] = $size[1];
$args['crop_h'] = $size[1];
$args['crop_x'] = $cropx;
} else {
$diff = $size[1] - $size[0];
$cropy = $diff / 2;
$args['crop_w'] = $size[0];
$args['crop_h'] = $size[0];
$args['crop_y'] = $cropy;
}
bp_core_avatar_handle_crop($args);
// todo - find a good way to check for avatar import. bp_core_get_avatar()?
// Store the Ning ID for association with content later on
// update_user_meta( $bp_member['id'], 'ning_id', $userdata->contributerName );
return $bp_member;
}
示例9: groups_action_create_group
//.........这里部分代码省略.........
} else {
/* Create the forum if enable_forum = 1 */
if ( function_exists( 'bp_forums_setup' ) && '' == groups_get_groupmeta( $bp->groups->new_group_id, 'forum_id' ) ) {
groups_new_group_forum();
}
}
if ( 'private' == $_POST['group-status'] )
$group_status = 'private';
else if ( 'hidden' == $_POST['group-status'] )
$group_status = 'hidden';
if ( !$bp->groups->new_group_id = groups_create_group( array( 'group_id' => $bp->groups->new_group_id, 'status' => $group_status, 'enable_forum' => $group_enable_forum ) ) ) {
bp_core_add_message( __( 'There was an error saving group details, please try again.', 'buddypress' ), 'error' );
bp_core_redirect( $bp->root_domain . '/' . $bp->groups->slug . '/create/step/' . $bp->groups->current_create_step . '/' );
}
}
if ( 'group-invites' == $bp->groups->current_create_step ) {
groups_send_invites( $bp->loggedin_user->id, $bp->groups->new_group_id );
}
do_action( 'groups_create_group_step_save_' . $bp->groups->current_create_step );
do_action( 'groups_create_group_step_complete' ); // Mostly for clearing cache on a generic action name
/**
* Once we have successfully saved the details for this step of the creation process
* we need to add the current step to the array of completed steps, then update the cookies
* holding the information
*/
if ( !in_array( $bp->groups->current_create_step, (array)$bp->groups->completed_create_steps ) )
$bp->groups->completed_create_steps[] = $bp->groups->current_create_step;
/* Reset cookie info */
setcookie( 'bp_new_group_id', $bp->groups->new_group_id, time()+60*60*24, COOKIEPATH );
setcookie( 'bp_completed_create_steps', serialize( $bp->groups->completed_create_steps ), time()+60*60*24, COOKIEPATH );
/* If we have completed all steps and hit done on the final step we can redirect to the completed group */
if ( count( $bp->groups->completed_create_steps ) == count( $bp->groups->group_creation_steps ) && $bp->groups->current_create_step == array_pop( array_keys( $bp->groups->group_creation_steps ) ) ) {
unset( $bp->groups->current_create_step );
unset( $bp->groups->completed_create_steps );
/* Once we compelete all steps, record the group creation in the activity stream. */
groups_record_activity( array(
'action' => apply_filters( 'groups_activity_created_group_action', sprintf( __( '%s created the group %s', 'buddypress'), bp_core_get_userlink( $bp->loggedin_user->id ), '<a href="' . bp_get_group_permalink( $bp->groups->current_group ) . '">' . esc_attr( $bp->groups->current_group->name ) . '</a>' ) ),
'type' => 'created_group',
'item_id' => $bp->groups->new_group_id
) );
do_action( 'groups_group_create_complete', $bp->groups->new_group_id );
bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) );
} else {
/**
* Since we don't know what the next step is going to be (any plugin can insert steps)
* we need to loop the step array and fetch the next step that way.
*/
foreach ( (array)$bp->groups->group_creation_steps as $key => $value ) {
if ( $key == $bp->groups->current_create_step ) {
$next = 1;
continue;
}
if ( $next ) {
$next_step = $key;
break;
}
}
bp_core_redirect( $bp->root_domain . '/' . $bp->groups->slug . '/create/step/' . $next_step . '/' );
}
}
/* Group avatar is handled separately */
if ( 'group-avatar' == $bp->groups->current_create_step && isset( $_POST['upload'] ) ) {
if ( !empty( $_FILES ) && isset( $_POST['upload'] ) ) {
/* Normally we would check a nonce here, but the group save nonce is used instead */
/* Pass the file to the avatar upload handler */
if ( bp_core_avatar_handle_upload( $_FILES, 'groups_avatar_upload_dir' ) ) {
$bp->avatar_admin->step = 'crop-image';
/* Make sure we include the jQuery jCrop file for image cropping */
add_action( 'wp', 'bp_core_add_jquery_cropper' );
}
}
/* If the image cropping is done, crop the image and save a full/thumb version */
if ( isset( $_POST['avatar-crop-submit'] ) && isset( $_POST['upload'] ) ) {
/* Normally we would check a nonce here, but the group save nonce is used instead */
if ( !bp_core_avatar_handle_crop( array( 'object' => 'group', 'avatar_dir' => 'group-avatars', 'item_id' => $bp->groups->current_group->id, 'original_file' => $_POST['image_src'], 'crop_x' => $_POST['x'], 'crop_y' => $_POST['y'], 'crop_w' => $_POST['w'], 'crop_h' => $_POST['h'] ) ) )
bp_core_add_message( __( 'There was an error saving the group avatar, please try uploading again.', 'buddypress' ), 'error' );
else
bp_core_add_message( __( 'The group avatar was uploaded successfully!', 'buddypress' ) );
}
}
bp_core_load_template( apply_filters( 'groups_template_create_group', 'groups/create' ) );
}
示例10: bp_caver_avatar_handle_upload
function bp_caver_avatar_handle_upload()
{
global $bp;
if ($_POST['encodedimg']) {
$user_id = !empty($_POST['user_id']) ? $_POST['user_id'] : bp_displayed_user_id();
$imgresponse = array();
$uploaddir = bp_core_avatar_upload_path() . '/avatars';
if (!file_exists($uploaddir)) {
mkdir($uploaddir);
}
$img = $_POST['encodedimg'];
$img = str_replace('data:' . $_POST['imgtype'] . ';base64,', '', $img);
$img = str_replace(' ', '+', $img);
$data = base64_decode($img);
$filepath = $uploaddir . '/' . $user_id;
if (!file_exists($filepath)) {
mkdir($filepath);
}
$imgname = wp_unique_filename($uploaddir, $_POST['imgname']);
$fileurl = $filepath . '/' . $imgname;
$siteurl = trailingslashit(get_blog_option(1, 'siteurl'));
$url = str_replace(ABSPATH, $siteurl, $fileurl);
$success = file_put_contents($fileurl, $data);
$file = $_POST['imgsize'];
$max_upload_size = bp_cover_get_max_media_size();
if ($max_upload_size > $file) {
if ($success) {
$imgresponse[0] = "1";
$imgresponse[1] = $fileurl;
$size = getimagesize($fileurl);
/* Check image size and shrink if too large */
if ($size[0] > 150) {
$original_file = image_resize($fileurl, 150, 150, true);
//$ava_file = image_resize( $fileurl, 250, 250, true );
/* Check for thumbnail creation errors */
if (is_wp_error($original_file)) {
$imgresponse[0] = "0";
$imgresponse[1] = sprintf(__('Upload Failed! Error was: %s', 'bp-cover'), $original_file->get_error_message());
die;
}
$avatar_to_crop = str_replace(bp_core_avatar_upload_path(), '', $original_file);
bp_core_delete_existing_avatar(array('item_id' => $user_id, 'avatar_path' => bp_core_avatar_upload_path() . '/avatars/' . $user_id));
$crop_args = array('item_id' => $user_id, 'original_file' => $avatar_to_crop, 'crop_w' => 0, 'crop_h' => 0);
bp_core_avatar_handle_crop($crop_args);
//$url = str_replace(ABSPATH,$siteurl,$ava_file);
update_user_meta(bp_loggedin_user_id(), 'profile_avatar', $url);
do_action('xprofile_avatar_uploaded');
} else {
$imgresponse[0] = "0";
$imgresponse[1] = __('Upload Failed! Your photo must be larger than 150px', 'bp-cover');
}
} else {
$imgresponse[0] = "0";
$imgresponse[1] = __('Upload Failed! Unable to write the image on server', 'bp-cover');
}
} else {
$imgresponse[0] = "0";
$imgresponse[1] = sprintf(__('The file you uploaded is too big. Please upload a file under %s', 'bp-cover'), size_format($max_upload_size));
}
} else {
$imgresponse[0] = "0";
$imgresponse[1] = __('Upload Failed! No image sent', 'bp-cover');
}
/* if everything is ok, we send back url to thumbnail and to full image */
echo json_encode($imgresponse);
die;
}
示例11: bp_core_screen_signup
//.........这里部分代码省略.........
add_action( 'bp_' . $fieldname . '_errors', create_function( '', 'echo "<div class=\"error\">' . $error_message . '</div>";' ) );
} else {
$bp->signup->step = 'save-details';
/* No errors! Let's register those deets. */
$active_signup = $bp->site_options['registration'];
if ( 'none' != $active_signup ) {
/* Let's compact any profile field info into usermeta */
$profile_field_ids = explode( ',', $_POST['signup_profile_field_ids'] );
/* Loop through the posted fields formatting any datebox values then add to usermeta */
foreach ( (array) $profile_field_ids as $field_id ) {
if ( !isset( $_POST['field_' . $field_id] ) ) {
if ( isset( $_POST['field_' . $field_id . '_day'] ) )
$_POST['field_' . $field_id] = strtotime( $_POST['field_' . $field_id . '_day'] . $_POST['field_' . $field_id . '_month'] . $_POST['field_' . $field_id . '_year'] );
}
if ( !empty( $_POST['field_' . $field_id] ) )
$usermeta['field_' . $field_id] = $_POST['field_' . $field_id];
}
/* Store the profile field ID's in usermeta */
$usermeta['profile_field_ids'] = $_POST['signup_profile_field_ids'];
/* Hash and store the password */
$usermeta['password'] = wp_hash_password( $_POST['signup_password'] );
/* If the user decided to create a blog, save those details to usermeta */
if ( 'blog' == $active_signup || 'all' == $active_signup ) {
$usermeta['public'] = ( 'public' == $_POST['signup_blog_privacy'] ) ? true : false;
}
$usermeta = apply_filters( 'bp_signup_usermeta', $usermeta );
/* Finally, sign up the user and/or blog */
if ( isset( $_POST['signup_with_blog'] ) && bp_core_is_multisite() )
bp_core_signup_blog( $blog_details['domain'], $blog_details['path'], $blog_details['blog_title'], $_POST['signup_username'], $_POST['signup_email'], $usermeta );
else {
bp_core_signup_user( $_POST['signup_username'], $_POST['signup_password'], $_POST['signup_email'], $usermeta );
}
$bp->signup->step = 'completed-confirmation';
}
do_action( 'bp_complete_signup' );
}
}
$bp->avatar_admin->step = 'upload-image';
/* If user has uploaded a new avatar */
if ( !empty( $_FILES ) ) {
/* Check the nonce */
check_admin_referer( 'bp_avatar_upload' );
$bp->signup->step = 'completed-confirmation';
if ( bp_core_is_multisite() ) {
/* Get the activation key */
if ( !$bp->signup->key = $wpdb->get_var( $wpdb->prepare( "SELECT activation_key FROM {$wpdb->signups} WHERE user_login = %s AND user_email = %s", $_POST[ 'signup_username' ], $_POST[ 'signup_email' ] ) ) ) {
bp_core_add_message( __( 'There was a problem uploading your avatar, please try uploading it again', 'buddypress' ) );
} else {
/* Hash the key to create the upload folder (added security so people don't sniff the activation key) */
$bp->signup->avatar_dir = wp_hash( $bp->signup->key );
}
} else {
$user_id = bp_core_get_userid( $_POST['signup_username'] );
$bp->signup->avatar_dir = wp_hash( $user_id );
}
/* Pass the file to the avatar upload handler */
if ( bp_core_avatar_handle_upload( $_FILES, 'bp_core_signup_avatar_upload_dir' ) ) {
$bp->avatar_admin->step = 'crop-image';
/* Make sure we include the jQuery jCrop file for image cropping */
add_action( 'wp', 'bp_core_add_jquery_cropper' );
}
}
/* If the image cropping is done, crop the image and save a full/thumb version */
if ( isset( $_POST['avatar-crop-submit'] ) ) {
/* Check the nonce */
check_admin_referer( 'bp_avatar_cropstore' );
/* Reset the avatar step so we can show the upload form again if needed */
$bp->signup->step = 'completed-confirmation';
$bp->avatar_admin->step = 'upload-image';
if ( !bp_core_avatar_handle_crop( array( 'original_file' => $_POST['image_src'], 'crop_x' => $_POST['x'], 'crop_y' => $_POST['y'], 'crop_w' => $_POST['w'], 'crop_h' => $_POST['h'] ) ) )
bp_core_add_message( __( 'There was a problem cropping your avatar, please try uploading it again', 'buddypress' ), 'error' );
else
bp_core_add_message( __( 'Your new avatar was uploaded successfully', 'buddypress' ) );
}
bp_core_load_template( 'registration/register' );
}
示例12: bp_avatar_ajax_set
/**
* Ajax set an avatar for a given object and item id
*
* @since BuddyPress (2.3.0)
*
* @return string a json object containing success data if the crop/capture succeeded
* error message otherwise
*/
function bp_avatar_ajax_set()
{
// Bail if not a POST action
if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) {
wp_send_json_error();
}
// Check the nonce
check_admin_referer('bp_avatar_cropstore', 'nonce');
$avatar_data = wp_parse_args($_POST, array('crop_w' => bp_core_avatar_full_width(), 'crop_h' => bp_core_avatar_full_height(), 'crop_x' => 0, 'crop_y' => 0));
if (empty($avatar_data['object']) || empty($avatar_data['item_id']) || empty($avatar_data['original_file'])) {
wp_send_json_error();
}
// Capability check
if (!bp_attachments_current_user_can('edit_avatar', $avatar_data)) {
wp_send_json_error();
}
if (!empty($avatar_data['type']) && 'camera' === $avatar_data['type'] && 'user' === $avatar_data['object']) {
$webcam_avatar = false;
if (!empty($avatar_data['original_file'])) {
$webcam_avatar = str_replace(array('data:image/png;base64,', ' '), array('', '+'), $avatar_data['original_file']);
$webcam_avatar = base64_decode($webcam_avatar);
}
if (!bp_avatar_handle_capture($webcam_avatar, $avatar_data['item_id'])) {
wp_send_json_error(array('feedback_code' => 1));
} else {
$return = array('avatar' => html_entity_decode(bp_core_fetch_avatar(array('object' => $avatar_data['object'], 'item_id' => $avatar_data['item_id'], 'html' => false, 'type' => 'full'))), 'feedback_code' => 2, 'item_id' => $avatar_data['item_id']);
do_action('xprofile_screen_change_avatar');
wp_send_json_success($return);
}
return;
}
$original_file = str_replace(bp_core_avatar_url(), '', $avatar_data['original_file']);
// Set avatars dir & feedback part
if ('user' === $avatar_data['object']) {
$avatar_dir = 'avatars';
// Defaults to object-avatars dir
} else {
$avatar_dir = sanitize_key($avatar_data['object']) . '-avatars';
}
// Crop args
$r = array('item_id' => $avatar_data['item_id'], 'object' => $avatar_data['object'], 'avatar_dir' => $avatar_dir, 'original_file' => $original_file, 'crop_w' => $avatar_data['crop_w'], 'crop_h' => $avatar_data['crop_h'], 'crop_x' => $avatar_data['crop_x'], 'crop_y' => $avatar_data['crop_y']);
// Handle crop
if (bp_core_avatar_handle_crop($r)) {
$return = array('avatar' => html_entity_decode(bp_core_fetch_avatar(array('object' => $avatar_data['object'], 'item_id' => $avatar_data['item_id'], 'html' => false, 'type' => 'full'))), 'feedback_code' => 2, 'item_id' => $avatar_data['item_id']);
if ('user' === $avatar_data['object']) {
do_action('xprofile_screen_change_avatar');
}
wp_send_json_success($return);
} else {
wp_send_json_error(array('feedback_code' => 1));
}
}
示例13: bfox_bp_plans_update_plan_avatar
function bfox_bp_plans_update_plan_avatar(BfoxReadingPlan $plan, $is_create = false)
{
global $bp;
bfox_bp_plans_must_own($plan);
if (!$is_create) {
/* If the group admin has deleted the admin avatar */
if ('delete' == $bp->action_variables[0]) {
/* Check the nonce */
check_admin_referer('bfox_bp_plan_avatar_delete');
if (bp_core_delete_existing_avatar(array('item_id' => $plan->id, 'object' => 'plan'))) {
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($plan->url() . 'avatar/');
}
}
$bp->avatar_admin->step = 'upload-image';
if (!empty($_FILES) && isset($_POST['upload'])) {
if ($is_create) {
check_admin_referer('plans_create_save_plan-avatar');
} else {
check_admin_referer('bp_avatar_upload');
}
/* Pass the file to the avatar upload handler */
if (bp_core_avatar_handle_upload($_FILES, 'bfox_bp_plans_avatar_upload_dir')) {
$bp->avatar_admin->step = 'crop-image';
/* Make sure we include the jQuery jCrop file for image cropping */
add_action('wp', 'bp_core_add_jquery_cropper');
}
}
/* If the image cropping is done, crop the image and save a full/thumb version */
if (isset($_POST['avatar-crop-submit'])) {
if ($is_create) {
check_admin_referer('plans_create_save_plan-avatar');
} else {
check_admin_referer('bp_avatar_cropstore');
}
if (!bp_core_avatar_handle_crop(array('object' => 'plan', 'avatar_dir' => 'plan-avatars', 'item_id' => $plan->id, 'original_file' => $_POST['image_src'], 'crop_x' => $_POST['x'], 'crop_y' => $_POST['y'], 'crop_w' => $_POST['w'], 'crop_h' => $_POST['h']))) {
bp_core_add_message(__('There was a problem cropping the avatar, please try uploading it again', 'buddypress'));
} else {
bp_core_add_message(__('The new reading plan avatar was uploaded successfully!', 'buddypress'));
}
}
}
示例14: xprofile_screen_change_avatar
/**
* Handles the uploading and cropping of a user avatar. Displays the change avatar page.
*
* @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_change_avatar()
{
global $bp;
if (!bp_is_my_profile() && !is_super_admin()) {
return false;
}
if (bp_action_variables()) {
bp_do_404();
return;
}
$bp->avatar_admin->step = 'upload-image';
if (!empty($_FILES)) {
// Check the nonce
check_admin_referer('bp_avatar_upload');
// Pass the file to the avatar upload handler
if (bp_core_avatar_handle_upload($_FILES, 'xprofile_avatar_upload_dir')) {
$bp->avatar_admin->step = 'crop-image';
// Make sure we include the jQuery jCrop file for image cropping
add_action('nxt_print_scripts', 'bp_core_add_jquery_cropper');
}
}
// If the image cropping is done, crop the image and save a full/thumb version
if (isset($_POST['avatar-crop-submit'])) {
// Check the nonce
check_admin_referer('bp_avatar_cropstore');
if (!bp_core_avatar_handle_crop(array('item_id' => $bp->displayed_user->id, 'original_file' => $_POST['image_src'], 'crop_x' => $_POST['x'], 'crop_y' => $_POST['y'], 'crop_w' => $_POST['w'], 'crop_h' => $_POST['h']))) {
bp_core_add_message(__('There was a problem cropping your avatar, please try uploading it again', 'buddypress'), 'error');
} else {
bp_core_add_message(__('Your new avatar was uploaded successfully!', 'buddypress'));
do_action('xprofile_avatar_uploaded');
}
}
do_action('xprofile_screen_change_avatar');
bp_core_load_template(apply_filters('xprofile_template_change_avatar', 'members/single/home'));
}
示例15: groups_screen_group_admin_avatar
function groups_screen_group_admin_avatar()
{
global $bp;
if (bp_is_groups_component() && bp_is_action_variable('group-avatar', 0)) {
// If the logged-in user doesn't have permission or if avatar uploads are disabled, then stop here
if (!$bp->is_item_admin || (int) bp_get_option('bp-disable-avatar-uploads')) {
return false;
}
// If the group admin has deleted the admin avatar
if (bp_is_action_variable('delete', 1)) {
// Check the nonce
check_admin_referer('bp_group_avatar_delete');
if (bp_core_delete_existing_avatar(array('item_id' => $bp->groups->current_group->id, 'object' => 'group'))) {
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->avatar_admin->step = 'upload-image';
if (!empty($_FILES)) {
// Check the nonce
check_admin_referer('bp_avatar_upload');
// Pass the file to the avatar upload handler
if (bp_core_avatar_handle_upload($_FILES, 'groups_avatar_upload_dir')) {
$bp->avatar_admin->step = 'crop-image';
// Make sure we include the jQuery jCrop file for image cropping
add_action('wp_print_scripts', 'bp_core_add_jquery_cropper');
}
}
// If the image cropping is done, crop the image and save a full/thumb version
if (isset($_POST['avatar-crop-submit'])) {
// Check the nonce
check_admin_referer('bp_avatar_cropstore');
if (!bp_core_avatar_handle_crop(array('object' => 'group', 'avatar_dir' => 'group-avatars', 'item_id' => $bp->groups->current_group->id, 'original_file' => $_POST['image_src'], 'crop_x' => $_POST['x'], 'crop_y' => $_POST['y'], 'crop_w' => $_POST['w'], 'crop_h' => $_POST['h']))) {
bp_core_add_message(__('There was a problem cropping the avatar, please try uploading it again', 'buddypress'));
} else {
bp_core_add_message(__('The new group avatar was uploaded successfully!', 'buddypress'));
}
}
do_action('groups_screen_group_admin_avatar', $bp->groups->current_group->id);
bp_core_load_template(apply_filters('groups_template_group_admin_avatar', 'groups/single/home'));
}
}