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.
Return Return
(null|false|int) Returns null if sideloading is disabled, WP Post ID of the attachment on success, false on error.
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;
}
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
| Version | Description |
|---|---|
| 4.7.0 | Moved from LLMS_Generator and made protected instead of private.<br> Add a return instead of void; Don't import if sideloading is disabled; Use $this->sideload_image() sideloading. |
| 3.3.0 | Introduced. |