Custom_Background::gc_set_background_image()
最后更新于:2021-11-25 19:40:53
Custom_Background::gc_set_background_image()源文件
文件: gc-admin/includes/class-custom-background.php
public function gc_set_background_image() {
check_ajax_referer( 'custom-background' );
if ( ! current_user_can( 'edit_theme_options' ) || ! isset( $_POST['attachment_id'] ) ) {
exit;
}
$attachment_id = absint( $_POST['attachment_id'] );
$sizes = array_keys(
/** This filter is documented in gc-admin/includes/media.php */
apply_filters(
'image_size_names_choose',
array(
'thumbnail' => __( 'Thumbnail' ),
'medium' => __( 'Medium' ),
'large' => __( 'Large' ),
'full' => __( 'Full Size' ),
)
)
);
$size = 'thumbnail';
if ( in_array( $_POST['size'], $sizes, true ) ) {
$size = esc_attr( $_POST['size'] );
}
update_post_meta( $attachment_id, '_gc_attachment_is_custom_background', get_option( 'stylesheet' ) );
$url = gc_get_attachment_image_src( $attachment_id, $size );
$thumbnail = gc_get_attachment_image_src( $attachment_id, 'thumbnail' );
set_theme_mod( 'background_image', esc_url_raw( $url[0] ) );
set_theme_mod( 'background_image_thumb', esc_url_raw( $thumbnail[0] ) );
exit;
}