bp_avatar_ajax_upload ()

Ajax上传化身。

描述

返回

(字符串|空)如果上传成功,则返回包含成功数据的JSON对象。

文件:bp-core / bp-core-avatars.php

函数bp_avatar_ajax_upload() {if (!Bp_is_post_request ()) {wp_die();} /** *如果当前Plupload运行时是html4,则发送json响应将是不同的。*/ $is_html4 = false;如果(!$_POST['html4']) {$is_html4 = true;} //检查nonce。check_admin_referer(“bp-uploader”);//初始化BuddyPress参数。数组$ bp_params = (); // We need it to carry on. if ( ! empty( $_POST['bp_params' ] ) ) { $bp_params = $_POST['bp_params' ]; } else { bp_attachments_json_response( false, $is_html4 ); } // We need the object to set the uploads dir filter. if ( empty( $bp_params['object'] ) ) { bp_attachments_json_response( false, $is_html4 ); } // Capability check. if ( ! bp_attachments_current_user_can( 'edit_avatar', $bp_params ) ) { bp_attachments_json_response( false, $is_html4 ); } $bp = buddypress(); $bp_params['upload_dir_filter'] = ''; $needs_reset = array(); if ( 'user' === $bp_params['object'] && bp_is_active( 'xprofile' ) ) { $bp_params['upload_dir_filter'] = 'xprofile_avatar_upload_dir'; if ( ! bp_displayed_user_id() && ! empty( $bp_params['item_id'] ) ) { $needs_reset = array( 'key' => 'displayed_user', 'value' => $bp->displayed_user ); $bp->displayed_user->id = $bp_params['item_id']; } } elseif ( 'group' === $bp_params['object'] && bp_is_active( 'groups' ) ) { $bp_params['upload_dir_filter'] = 'groups_avatar_upload_dir'; if ( ! bp_get_current_group_id() && ! empty( $bp_params['item_id'] ) ) { $needs_reset = array( 'component' => 'groups', 'key' => 'current_group', 'value' => $bp->groups->current_group ); $bp->groups->current_group = groups_get_group( $bp_params['item_id'] ); } } else { /** * Filter here to deal with other components. * * @since BuddyPress 2.3.0 * * @var array $bp_params the BuddyPress Ajax parameters. */ $bp_params = apply_filters( 'bp_core_avatar_ajax_upload_params', $bp_params ); } if ( ! isset( $bp->avatar_admin ) ) { $bp->avatar_admin = new stdClass(); } /** * The BuddyPress upload parameters is including the Avatar UI Available width, * add it to the avatar_admin global for a later use. */ if ( isset( $bp_params['ui_available_width'] ) ) { $bp->avatar_admin->ui_available_width = (int) $bp_params['ui_available_width']; } // Upload the avatar. $avatar = bp_core_avatar_handle_upload( $_FILES, $bp_params['upload_dir_filter'] ); // Reset objects. if ( ! empty( $needs_reset ) ) { if ( ! empty( $needs_reset['component'] ) ) { $bp->{$needs_reset['component']}->{$needs_reset['key']} = $needs_reset['value']; } else { $bp->{$needs_reset['key']} = $needs_reset['value']; } } // Init the feedback message. $feedback_message = false; if ( ! empty( $bp->template_message ) ) { $feedback_message = $bp->template_message; // Remove template message. $bp->template_message = false; $bp->template_message_type = false; @setcookie( 'bp-message', false, time() - 1000, COOKIEPATH, COOKIE_DOMAIN, is_ssl() ); @setcookie( 'bp-message-type', false, time() - 1000, COOKIEPATH, COOKIE_DOMAIN, is_ssl() ); } if ( empty( $avatar ) ) { // Default upload error. $message = __( 'Upload failed.', 'buddyboss' ); // Use the template message if set. if ( ! empty( $feedback_message ) ) { $message = $feedback_message; } // Upload error reply. bp_attachments_json_response( false, $is_html4, array( 'type' => 'upload_error', 'message' => $message, ) ); } if ( empty( $bp->avatar_admin->image->file ) ) { bp_attachments_json_response( false, $is_html4 ); } $uploaded_image = @getimagesize( $bp->avatar_admin->image->file ); // Set the name of the file. $name = $_FILES['file']['name']; $name_parts = pathinfo( $name ); $name = trim( substr( $name, 0, - ( 1 + strlen( $name_parts['extension'] ) ) ) ); // Finally return the avatar to the editor. bp_attachments_json_response( true, $is_html4, array( 'name' => $name, 'url' => $bp->avatar_admin->image->url, 'width' => $uploaded_image[0], 'height' => $uploaded_image[1], 'feedback' => $feedback_message, ) ); }

更新日志

更新日志
版本 描述
BuddyPress tripwire 介绍了。

问题吗?

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