bp_avatar_ajax_set()

Ajax为特定对象和项目ID设置了一个化身。

描述

返回

(字符串|空)一个包含成功数据的JSON对象,如果作物/捕获成功错误消息否则。

文件:BP-Core / BP-Core-Avatars.php

函数bp_avatar_ajax_set() {if (!Bp_is_post_request ()) {wp_send_json_error();} //检查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();} //能力检查。如果(!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' => esc_url( 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'], ); /** * Fires if the new avatar was successfully captured. * * @since BuddyPress 1.1.0 Used to inform the avatar was successfully cropped * @since BuddyPress 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') * Move the action at the right place, once the avatar is set * @since BuddyPress 2.8.0 Added the `$avatar_data` parameter. * * @param string $item_id Inform about the user id the avatar was set for. * @param string $type Inform about the way the avatar was set ('camera'). * @param array $avatar_data Array of parameters passed to the avatar handler. */ do_action( 'xprofile_avatar_uploaded', (int) $avatar_data['item_id'], $avatar_data['type'], $avatar_data ); 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' => esc_url( 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'] ) { /** This action is documented in bp-core/bp-core-avatars.php */ do_action( 'xprofile_avatar_uploaded', (int) $avatar_data['item_id'], $avatar_data['type'], $r ); } elseif ( 'group' === $avatar_data['object'] ) { /** This action is documented in bp-groups/bp-groups-screens.php */ do_action( 'groups_avatar_uploaded', (int) $avatar_data['item_id'], $avatar_data['type'], $r ); } wp_send_json_success( $return ); } else { wp_send_json_error( array( 'feedback_code' => 1, ) ); } }

变更乐

变更乐
版本 描述
BuddyPress tripwire 介绍了。

问题吗?

我们总是很乐意帮助您解决代码或其他问题!搜索我们的开发人员文档联络支持,或与我们联系销售团队