WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru
функция не описана

Custom_Background::handle_upload() public WP 3.0.0

Handle an Image upload for the background image.

Это метод класса: Custom_Background{}

Хуки из метода
Возвращает

Null. Ничего.

Использование

$Custom_Background = new Custom_Background();
$Custom_Background->handle_upload();

Список изменений

С версии 3.0.0 Введена.

Код Custom_Background::handle_upload() WP 5.5.1

wp-admin/includes/class-custom-background.php
<?php
public function handle_upload() {
	if ( empty( $_FILES ) ) {
		return;
	}

	check_admin_referer( 'custom-background-upload', '_wpnonce-custom-background-upload' );
	$overrides = array( 'test_form' => false );

	$uploaded_file = $_FILES['import'];
	$wp_filetype   = wp_check_filetype_and_ext( $uploaded_file['tmp_name'], $uploaded_file['name'] );
	if ( ! wp_match_mime_types( 'image', $wp_filetype['type'] ) ) {
		wp_die( __( 'The uploaded file is not a valid image. Please try again.' ) );
	}

	$file = wp_handle_upload( $uploaded_file, $overrides );

	if ( isset( $file['error'] ) ) {
		wp_die( $file['error'] );
	}

	$url      = $file['url'];
	$type     = $file['type'];
	$file     = $file['file'];
	$filename = wp_basename( $file );

	// Construct the object array.
	$object = array(
		'post_title'     => $filename,
		'post_content'   => $url,
		'post_mime_type' => $type,
		'guid'           => $url,
		'context'        => 'custom-background',
	);

	// Save the data.
	$id = wp_insert_attachment( $object, $file );

	// Add the metadata.
	wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );
	update_post_meta( $id, '_wp_attachment_is_custom_background', get_option( 'stylesheet' ) );

	set_theme_mod( 'background_image', esc_url_raw( $url ) );

	$thumbnail = wp_get_attachment_image_src( $id, 'thumbnail' );
	set_theme_mod( 'background_image_thumb', esc_url_raw( $thumbnail[0] ) );

	/** This action is documented in wp-admin/includes/class-custom-image-header.php */
	do_action( 'wp_create_file_in_uploads', $file, $id ); // For replication.
	$this->updated = true;
}