LLMS_Abstract_Generator_Posts::sideload_image( int $post_id, string $url,  $return = 'src' )

Sideload an image from a url

Parameters Parameters


(int) (Required) WP_Post ID of the post where the image will be attached.


(string) (Required) The image's URL.

Top ↑

Return Return

(string|int|WP_Error) Returns a WP_Error on failure, the image's new URL when $return is "src", otherwise returns the image's attachment ID.

Top ↑

Source Source

File: includes/abstracts/llms-abstract-generator-posts.php

	 * @param array           $raw  Array of raw data.
	 * @return void
	protected function set_metadata( $post, $raw ) {

		// Set all metadata.
		foreach ( array_keys( $post->get_properties() ) as $key ) {
			if ( isset( $raw[ $key ] ) ) {
				$post->set( $key, $raw[ $key ] );


	 * Sideload an image from a url
	 * @since 4.7.0
	 * @link https://developer.wordpress.org/reference/hooks/http_request_host_is_external/ If exporting from a local site and importing into another local site, images *will not* be side loaded as a result of this condition in the WP Core

Top ↑

Changelog Changelog

Version Description
4.7.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.