“Faça o upload do arquivo no WP do URL” Respostas de código

Faça o upload do arquivo no WP do URL

//first, get the image, and store it in your upload-directory:
$uploaddir = wp_upload_dir();
$uploadfile = $uploaddir['path'] . '/' . $filename;

$contents= file_get_contents('http://mydomain.com/folder/image.jpg');
$savefile = fopen($uploadfile, 'w');
fwrite($savefile, $contents);
fclose($savefile);
//after that, we can insert the image into the media library:
$wp_filetype = wp_check_filetype(basename($filename), null );

$attachment = array(
    'post_mime_type' => $wp_filetype['type'],
    'post_title' => $filename,
    'post_content' => '',
    'post_status' => 'inherit'
);

$attach_id = wp_insert_attachment( $attachment, $uploadfile );

$imagenew = get_post( $attach_id );
$fullsizepath = get_attached_file( $imagenew->ID );
$attach_data = wp_generate_attachment_metadata( $attach_id, $fullsizepath );
wp_update_attachment_metadata( $attach_id, $attach_data );
uzii

Carregue o webp para o WordPress

// add this code into your function.php file in theme editor

function webp_upload_mimes( $existing_mimes ) {
	// add webp to the list of mime types
	$existing_mimes['webp'] = 'image/webp';

	// return the array back to the function with our added mime type
	return $existing_mimes;
}
add_filter( 'mime_types', 'webp_upload_mimes' );
Charming Constrictor

WordPress Get Uploads Images Url

wp_get_attachment_image_src( int $attachment_id, string|int[] $size = 'thumbnail', bool $icon = false )
Lokesh003Coding

Respostas semelhantes a “Faça o upload do arquivo no WP do URL”

Perguntas semelhantes a “Faça o upload do arquivo no WP do URL”

Mais respostas relacionadas para “Faça o upload do arquivo no WP do URL” em PHP

Procure respostas de código populares por idioma

Procurar outros idiomas de código