LLMS_Abstract_Generator_Posts::sideload_image( int $post_id, string $url, $return = 'src' )
Sideload an image from a url
Parameters Parameters
- $post_id
-
(int) (Required) WP_Post ID of the post where the image will be attached.
- $url
-
(string) (Required) The image's URL.
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.
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
*
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
| Version | Description |
|---|---|
| 4.7.0 | Introduced. |