bp_core_avatar_handle_upload (数组美元的文件字符串upload_dir_filter美元

处理上传《阿凡达》。

描述

这些函数首先检查文件是否已正确上载bp_core_check_avatar_upload ().然后检查文件大小是否在限制范围内,以及是否有可接受的文件扩展名(jpg、gif、png)。如果一切检查出来,裁剪图像并移动到它的真实位置。

另请参阅

参数

美元的文件

数组(必需)适当的条目从$_FILES超全局。

upload_dir_filter美元

字符串(必需)应用于'upload_dir'的过滤器。

返回

(保龄球)成功时真,失败时假。

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

function bp_core_avatar_handle_upload($file, $upload_dir_filter){/** *过滤是否处理上传。* *如果你想覆盖这个函数,确保你返回false。* * @since BuddyPress 1.2.4 * * @param bool $value是否裁剪。* @param数组$file从$_FILES superglobal适当的条目。* @parma string $upload_dir_filter用于过滤'upload_dir'。*/ if (!Apply_filters ('bp_core_pre_avatar_handle_upload', true, $file, $upload_dir_filter)){返回true;} //设置变量。英国石油美元= buddypress ();$ upload_path = bp_core_avatar_upload_path (); // Upload the file. $avatar_attachment = new BP_Attachment_Avatar(); $bp->avatar_admin->original = $avatar_attachment->upload( $file, $upload_dir_filter ); // In case of an error, stop the process and display a feedback to the user. if ( ! empty( $bp->avatar_admin->original['error'] ) ) { bp_core_add_message( sprintf( __( 'Upload Failed! Error was: %s', 'buddyboss' ), $bp->avatar_admin->original['error'] ), 'error' ); return false; } // The Avatar UI available width. $ui_available_width = 0; // Try to set the ui_available_width using the avatar_admin global. if ( isset( $bp->avatar_admin->ui_available_width ) ) { $ui_available_width = $bp->avatar_admin->ui_available_width; } // Maybe resize. $bp->avatar_admin->resized = $avatar_attachment->shrink( $bp->avatar_admin->original['file'], $ui_available_width ); $bp->avatar_admin->image = new stdClass(); // We only want to handle one image after resize. if ( empty( $bp->avatar_admin->resized ) ) { $bp->avatar_admin->image->file = $bp->avatar_admin->original['file']; $bp->avatar_admin->image->dir = str_replace( $upload_path, '', $bp->avatar_admin->original['file'] ); } else { $bp->avatar_admin->image->file = $bp->avatar_admin->resized['path']; $bp->avatar_admin->image->dir = str_replace( $upload_path, '', $bp->avatar_admin->resized['path'] ); @unlink( $bp->avatar_admin->original['file'] ); } // Check for WP_Error on what should be an image. if ( is_wp_error( $bp->avatar_admin->image->dir ) ) { bp_core_add_message( sprintf( __( 'Upload Error: %s', 'buddyboss' ), $bp->avatar_admin->image->dir->get_error_message() ), 'error' ); return false; } // If the uploaded image is smaller than the "full" dimensions, throw a warning. if ( $avatar_attachment->is_too_small( $bp->avatar_admin->image->file ) ) { bp_core_add_message( sprintf( __( 'For best results, upload an image that is %1$spx by %2$spx or larger.', 'buddyboss' ), bp_core_avatar_full_width(), bp_core_avatar_full_height() ), 'error' ); } // Set the url value for the image. $bp->avatar_admin->image->url = bp_core_avatar_url() . $bp->avatar_admin->image->dir; return true; }

更新日志

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

问题吗?

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