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.


Top ↑

Parameters Parameters

$post

(LLMS_Post_Model) (Required) Post object.

$raw

(array) (Required) Array of raw data.


Top ↑

Return Return

(null|boolean) Returns true on success, false if there were no images to update, or null if sideloading is disabled.


Top ↑

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 ),
			)
		);



Top ↑

Changelog 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.