Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

LLMS_Generator::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


Description Description


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

(void)


Top ↑

Source Source

File: includes/class.llms.generator.php

	private function set_featured_image( $url_or_raw, $post_id ) {

		$image_url = '';

		if ( is_array( $url_or_raw ) && isset( $url_or_raw['featured_image'] ) ) {
			$image_url = $url_or_raw['featured_image'];
		} elseif ( is_string( $url_or_raw ) ) {
			$image_url = $url_or_raw;
		}

		if ( ! empty( $image_url ) ) {

			global $wpdb;

			// save the image in the medialib
			$img_src = media_sideload_image( $image_url, $post_id, null, 'src' );

			if ( ! is_wp_error( $img_src ) ) {
				$id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE guid = %s", array( $img_src ) ) );
				set_post_thumbnail( $post_id, $id );
			}
		}

	}

Top ↑

Changelog Changelog

Changelog
Version Description
3.3.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

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