我想在用户配置文件>封面图像页面上说一个按钮,只是说“删除封面图像”。他们正在使用的主题是覆盖图像的模板覆盖,如下所示:http://pastebin.com/XQPpiVYs删除buddypress封面图像按钮
我知道Buddypress在用户上传封面图片后有此选项,那么在上传后立即删除它的选项是可用的,但如何我可以添加一个按钮,允许他们随时删除封面照片,而不是直接上传后删除?
我知道我不想编辑核心,但我发现这个行为是负责任的。有没有一种方法可以创建一个按钮来调用此操作并删除用户封面照片?
在BuddyPress的/ BP-芯/ BP-芯attachments.php:
/**
* Ajax delete a cover image for a given object and item id.
*
* @since 2.4.0
*
* @return string|null A json object containing success data if the cover image was deleted
* error message otherwise.
*/
function bp_attachments_cover_image_ajax_delete() {
// Bail if not a POST action.
if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) {
wp_send_json_error();
}
$cover_image_data = $_POST;
if (empty($cover_image_data['object']) || empty($cover_image_data['item_id'])) {
wp_send_json_error();
}
// Check the nonce
check_admin_referer('bp_delete_cover_image', 'nonce');
// Capability check
if (! bp_attachments_current_user_can('edit_cover_image', $cover_image_data)) {
wp_send_json_error();
}
// Set object for the user's case
if ('user' === $cover_image_data['object']) {
$component = 'xprofile';
$dir = 'members';
// Set it for any other cases
} else {
$component = $cover_image_data['object'] . 's';
$dir = $component;
}
// Handle delete
if (bp_attachments_delete_file(array('item_id' => $cover_image_data['item_id'], 'object_dir' => $dir, 'type' => 'cover-image'))) {
// Defaults no cover image
$response = array(
'reset_url' => '',
'feedback_code' => 3 ,
);
// Get cover image settings in case there's a default header
$cover_params = bp_attachments_get_cover_image_settings($component);
// Check if there's a default cover
if (! empty($cover_params['default_cover'])) {
$response['reset_url'] = $cover_params['default_cover'];
}
// Finally send the reset url
wp_send_json_success($response);
} else {
wp_send_json_error(array(
'feedback_code' => 2,
));
}
}
add_action('wp_ajax_bp_cover_image_delete', 'bp_attachments_cover_image_ajax_delete');
,最后我知道封面图片通常存储在成员/ {ID} /覆盖图像/更糟糕的情况是当他们点击按钮时,它只是抓住他们的用户ID并删除相应的文件或目录?