LLMS_Abstract_Generator_Posts::set_featured_image( string $url_or_raw, int $post_id )

Saves an image (from URL) to the media library and sets it as the featured image for a given post


Parameters Parameters

$url_or_raw

(string) (Required) Array of raw data or URL to an image.

$post_id

(int) (Required) WP Post ID.


Top ↑

Return Return

(null|false|int) Returns null if sideloading is disabled, WP Post ID of the attachment on success, false on error.


Top ↑

Source Source

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

	protected function set_featured_image( $url_or_raw, $post_id ) {

		// Sideloading is disabled.
		if ( ! $this->is_image_sideloading_enabled() ) {
			return null;
		}

		$image_url = ( is_array( $url_or_raw ) && ! empty( $url_or_raw['featured_image'] ) ) ? $url_or_raw['featured_image'] : $url_or_raw;

		if ( $image_url && is_string( $image_url ) ) {

			$id = $this->sideload_image( $post_id, $image_url, 'id' );
			if ( ! is_wp_error( $id ) ) {
				set_post_thumbnail( $post_id, $id );
				return $id;
			}
		}

		return false;

	}


Top ↑

Changelog Changelog

Changelog
Version Description
4.7.0 Moved from LLMS_Generator and made protected instead of private. Add a return instead of void; Don't import if sideloading is disabled; Use $this->sideload_image() sideloading.
3.3.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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