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
protected function sideload_image( $post_id, $url, $return = 'src' ) { // Check if the image was previously sideloaded. $id = empty( $this->images[ $url ] ) ? false : $this->images[ $url ]; // Image was not previously sideloaded. if ( ! $id ) { $id = media_sideload_image( $url, $post_id, null, 'id' ); if ( is_wp_error( $id ) ) { return $id; } // Store the ID for future usage. $this->images[ $url ] = $id; } return 'src' === $return ? wp_get_attachment_url( $id ) : $id; }
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
4.7.0 | Introduced. |