LLMS_Abstract_Generator_Posts::sideload_images( LLMS_Post_Model $post, array $raw )
Sideload images found in a given post
Description Description
This attempts to sideload the src
attribute of every element found in the post_content
of the supplied post.
Parameters Parameters
- $post
-
(LLMS_Post_Model) (Required) Post object.
- $raw
-
(array) (Required) Array of raw data.
Return Return
(null|boolean) Returns true
on success, false
if there were no images to update, or null
if sideloading is disabled.
Source Source
File: includes/abstracts/llms-abstract-generator-posts.php
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; } /** * Sideload images found in a given post * * This attempts to sideload the `src` attribute of every <img> element * found in the `post_content` of the supplied post. * * @since 4.7.0 * * @param LLMS_Post_Model $post Post object. * @param array $raw Array of raw data. * @return null|boolean Returns `true` on success, `false` if there were no images to update, or `null` if sideloading is disabled. */ protected function sideload_images( $post, $raw ) { // Sideloading is disabled. if ( ! $this->is_image_sideloading_enabled() ) { return null; } // No images to sideload. if ( empty( $raw['_extras']['images'] ) ) { return false; } /** * List of hostnames from which sideloading is explicitly disabled * * If the source url of an image is from a host in this list, the image will not be sideloaded * during generation. * * By default the current site is included in the blocklist ensuring that images aren't * sideloaded into the same site. * * @since 4.7.0 * * @param string[] $blocked_hosts Array of hostnames. */ $blocked_hosts = apply_filters( 'llms_generator_sideload_hosts_blocklist', array( parse_url( get_site_url(), PHP_URL_HOST ), ) );
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
4.7.0 | Introduced. |