Changeset 3470201
- Timestamp:
- 02/26/2026 11:13:36 AM (4 weeks ago)
- Location:
- featured-image-from-content
- Files:
-
- 23 added
- 3 edited
-
assets/screenshot-1.png (modified) (previous)
-
tags/1.7 (added)
-
tags/1.7/assets (added)
-
tags/1.7/assets/js (added)
-
tags/1.7/assets/js/fifc-admin.js (added)
-
tags/1.7/featured-image-from-content.php (added)
-
tags/1.7/includes (added)
-
tags/1.7/includes/class-fifc-admin.php (added)
-
tags/1.7/includes/class-fifc-featured-image.php (added)
-
tags/1.7/includes/class-fifc-media-handler.php (added)
-
tags/1.7/includes/class-fifc-plugin.php (added)
-
tags/1.7/pro (added)
-
tags/1.7/pro/class-fifc-ai-generator.php (added)
-
tags/1.7/readme.txt (added)
-
trunk/assets (added)
-
trunk/assets/js (added)
-
trunk/assets/js/fifc-admin.js (added)
-
trunk/featured-image-from-content.php (modified) (2 diffs)
-
trunk/includes (added)
-
trunk/includes/class-fifc-admin.php (added)
-
trunk/includes/class-fifc-featured-image.php (added)
-
trunk/includes/class-fifc-media-handler.php (added)
-
trunk/includes/class-fifc-plugin.php (added)
-
trunk/pro (added)
-
trunk/pro/class-fifc-ai-generator.php (added)
-
trunk/readme.txt (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
featured-image-from-content/trunk/featured-image-from-content.php
r3469109 r3470201 4 4 * Plugin URI: https://wordpress.org/plugins/featured-image-from-content/ 5 5 * Description: This plugin is useful for automatically setting featured images from post content if no featured images are available. 6 * Version: 1. 66 * Version: 1.7 7 7 * Requires at least: 5.2 8 8 * Requires PHP: 5.6 … … 11 11 * License: GPL v2 or later 12 12 * License URI: https://www.gnu.org/licenses/gpl-2.0.html 13 * Text Domain: featured-image-from-content13 * Text Domain: FIFC 14 14 */ 15 16 if (!defined('ABSPATH')) { 17 exit; // Exit if accessed directly 15 if ( ! defined( 'ABSPATH' ) ) { 16 exit; 18 17 } 19 18 20 // Register the admin page 21 function fifc_featured_image_from_content_admin_page() { 22 add_submenu_page( 23 'options-general.php', 24 'Featured Image from Content', 25 'Featured Image from Content', 26 'manage_options', 27 'featured_image_from_content', 28 'fifc_featured_image_from_content_render_admin_page' 29 ); 30 } 31 add_action('admin_menu', 'fifc_featured_image_from_content_admin_page'); 19 define( 'FIFC_VERSION', '1.7' ); 20 define( 'FIFC_PATH', plugin_dir_path( __FILE__ ) ); 21 define( 'FIFC_URL', plugin_dir_url( __FILE__ ) ); 32 22 33 // Render the admin page 34 function fifc_featured_image_from_content_render_admin_page() { 35 ?> 36 <div class="wrap"> 37 <h1>Featured Image from Content</h1> 38 <form method="post" action="options.php"> 39 <?php settings_fields('fifc_featured_image_from_content_settings'); ?> 40 <?php do_settings_sections('fifc_featured_image_from_content_settings'); ?> 41 <table class="form-table"> 42 <tr valign="top"> 43 <th scope="row">Select Post Type:</th> 44 <td> 45 <?php 46 $post_types = get_post_types(['public' => true], 'objects'); 47 foreach ($post_types as $post_type) { 48 if ($post_type->name !== 'attachment') { 49 $checked = in_array($post_type->name, get_option('fifc_featured_image_from_content_post_types', [])) ? 'checked' : ''; 50 echo '<label><input type="checkbox" name="fifc_featured_image_from_content_post_types[]" value="' . esc_attr($post_type->name) . '" ' . $checked . '> ' . esc_html($post_type->label) . '</label><br>'; 51 } 52 } 53 ?> 54 </td> 55 </tr> 56 </table> 57 <?php submit_button(); ?> 58 </form> 59 </div> 60 <?php 23 require_once FIFC_PATH . 'includes/class-fifc-plugin.php'; 24 25 function fifc_run_plugin() { 26 $plugin = new FIFC_Plugin(); 27 $plugin->init(); 61 28 } 62 29 63 // Initialize plugin settings 64 function fifc_featured_image_from_content_init() { 65 register_setting( 66 'fifc_featured_image_from_content_settings', 67 'fifc_featured_image_from_content_post_types', 68 'fifc_featured_image_from_content_sanitize_post_types' 69 ); 70 } 71 add_action('admin_init', 'fifc_featured_image_from_content_init'); 72 73 // Sanitize selected post types 74 function fifc_featured_image_from_content_sanitize_post_types($input) { 75 $allowed_post_types = array_keys(get_post_types(['public' => true])); 76 $selected_post_types = []; 77 if (is_array($input)) { 78 foreach ($input as $post_type) { 79 if (in_array($post_type, $allowed_post_types)) { 80 $selected_post_types[] = $post_type; 81 } 82 } 83 } 84 return $selected_post_types; 85 } 86 87 // Set featured image from content 88 function fifc_set_featured_image_from_content($post_ID) { 89 $post = get_post($post_ID); 90 $post_types = get_option('fifc_featured_image_from_content_post_types', []); 91 if (in_array($post->post_type, $post_types) && !has_post_thumbnail($post_ID)) { 92 $content = $post->post_content; 93 preg_match('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $content, $matches); 94 if (!empty($matches)) { 95 $image_url = $matches[1]; 96 97 // Check if the image already exists in the media library 98 $existing_image_id = fifc_get_image_id_from_url($image_url); 99 if ($existing_image_id) { 100 set_post_thumbnail($post_ID, $existing_image_id); 101 } else { 102 // Download the image and create a new attachment 103 $upload_dir = wp_upload_dir(); 104 $image_data = wp_remote_get($image_url); 105 if (!is_wp_error($image_data) && $image_data['response']['code'] === 200) { 106 $image_name = basename($image_url); 107 $filename = $upload_dir['path'] . '/' . $image_name; 108 109 // Replace file_put_contents with wp_upload_bits to save the image in the upload directory 110 $file = wp_upload_bits($image_name, null, $image_data['body']); 111 if (!$file['error']) { 112 $attachment = array( 113 'post_mime_type' => $file['type'], 114 'post_title' => sanitize_file_name($image_name), 115 'post_content' => '', 116 'post_status' => 'inherit' 117 ); 118 $attach_id = wp_insert_attachment($attachment, $file['file'], $post_ID); 119 require_once(ABSPATH . 'wp-admin/includes/image.php'); 120 $attach_data = wp_generate_attachment_metadata($attach_id, $file['file']); 121 wp_update_attachment_metadata($attach_id, $attach_data); 122 set_post_thumbnail($post_ID, $attach_id); 123 } 124 } 125 } 126 } 127 } 128 } 129 add_action('save_post', 'fifc_set_featured_image_from_content'); 130 131 // Helper function to get image ID from its URL 132 function fifc_get_image_id_from_url($image_url) { 133 $image_id = attachment_url_to_postid($image_url); 134 return $image_id; 135 } 30 fifc_run_plugin(); -
featured-image-from-content/trunk/readme.txt
r3469299 r3470201 2 2 Contributors: dhrumilk, dhruvishah2203, mikinc860 3 3 Donate link: https://buymeacoffee.com/dhrumilk 4 Tags: featured image, auto featured image, set featured image automatically, image from content, auto set thumbnail4 Tags: auto featured image, set featured image automatically, image from content, ai featured image, openai image generator 5 5 Requires at least: 5.2 6 6 Tested up to: 6.9 7 7 Requires PHP: 5.6 8 Stable tag: 1. 68 Stable tag: 1.7 9 9 License: GPLv2 or later 10 10 License URI: https://www.gnu.org/licenses/gpl-2.0.html 11 11 12 Automatically set the featured image from the first image inside your post content. Save time and streamline your WordPress publishing workflow.12 Automatically set the featured image from the first image inside your post content. If no image exists, generate one using OpenAI. Save time and streamline your WordPress publishing workflow. 13 13 14 14 == Description == … … 16 16 Featured Image from Content is a lightweight and powerful WordPress plugin that automatically sets the featured image (post thumbnail) using the first image found inside your post content. 17 17 18 If you manage a blog, news website, magazine, affiliate site, or high-volume content website, manually assigning featured images to every post can be time-consuming. This plugin eliminates that manual work and ensures every post has a visually appealing featured image.18 NEW: If your post does not contain any image, the plugin can automatically generate a featured image using OpenAI. 19 19 20 Perfect for bloggers, agencies, developers, and automated content websites. 20 If you manage a blog, news website, magazine, affiliate site, or high-volume content website, manually assigning featured images to every post can be time-consuming. This plugin eliminates that manual work and ensures every post always has a visually appealing featured image. 21 22 Perfect for bloggers, agencies, developers, AI-powered websites, and automated content platforms. 21 23 22 24 = Why Use This Plugin? = 23 25 24 26 • Automatically assigns featured images 27 • AI generates featured images when none exist 25 28 • Prevents publishing posts without thumbnails 26 29 • Improves SEO and social media sharing … … 34 37 The plugin scans your post content and automatically selects the first image to set as the featured image when you publish or update a post. 35 38 39 = AI Featured Image Generation (OpenAI Integration) = 40 If no image is found in the content, the plugin can generate a relevant featured image using OpenAI. 41 42 To use this feature: 43 1. Add your OpenAI API Key in the plugin settings. 44 2. Enable AI image generation. 45 3. When a post has no image, the plugin automatically generates one based on the post content or title. 46 47 This ensures every post always has a featured image. 48 36 49 = Supports Multiple Post Types = 37 Choose which post types (Posts, Pages, Custom Post Types) should have featured images automatically assigned .50 Choose which post types (Posts, Pages, Custom Post Types) should have featured images automatically assigned or generated. 38 51 39 52 = SEO Friendly = … … 44 57 • Overall content engagement 45 58 46 = Perfect for Automated Websites =59 = Perfect for Automated & AI Websites = 47 60 Works great with: 48 61 • Auto blogging websites 62 • AI content generation websites 49 63 • Content importers 50 64 • News websites … … 57 71 = How It Works = 58 72 73 Case 1: Post Contains Image 59 74 1. Write or import content that contains at least one image. 60 75 2. Publish or update the post. … … 62 77 4. That image is set as the featured image. 63 78 79 Case 2: Post Has No Image 80 1. Write or import content without any image. 81 2. Make sure OpenAI API Key is added in settings. 82 3. Publish or update the post. 83 4. The plugin generates a relevant image using OpenAI. 84 5. The generated image is automatically set as the featured image. 85 64 86 No manual action required. 87 88 = OpenAI API Setup = 89 90 1. Go to Settings → Featured Image from Content. 91 2. Enter your OpenAI API Key. 92 3. Save changes. 93 4. Enable AI Image Generation option. 94 95 Note: OpenAI usage may incur charges based on your OpenAI account plan. 65 96 66 97 = Compatibility = … … 75 106 76 107 • Automatically assign featured images for bulk imported posts 108 • Generate AI images for text-only posts 77 109 • Ensure consistent blog archive layouts 78 110 • Maintain professional content presentation … … 85 117 3. Go to Settings → Featured Image from Content. 86 118 4. Select the post types where you want to automatically set featured images. 87 5. Save changes. 88 6. Done! 119 5. (Optional) Add your OpenAI API Key to enable AI image generation. 120 6. Save changes. 121 7. Done! 89 122 90 123 == Frequently Asked Questions == 91 124 92 125 = Does this overwrite existing featured images? = 93 No. The plugin only sets a featured image if one is not already assigned.126 No. The plugin only sets or generates a featured image if one is not already assigned. 94 127 95 128 = Does it work with custom post types? = … … 97 130 98 131 = What if a post has no images? = 99 The plugin will not assign a featured image if no image is found in the content. 132 If OpenAI API Key is configured, the plugin will generate a featured image automatically. Otherwise, no image will be assigned. 133 134 = Is the OpenAI feature mandatory? = 135 No. The plugin works perfectly without OpenAI. AI image generation is optional. 100 136 101 137 = Does it affect website performance? = … … 106 142 107 143 == Changelog == 144 145 = 1.7 = 146 * Added OpenAI-powered AI featured image generation for posts without images. 147 * Added OpenAI API Key configuration option in the settings page. 148 * Improved overall performance and code optimization. 149 * Minor bug fixes and general improvements. 108 150 109 151 = 1.6 = … … 129 171 130 172 == Screenshots == 131 132 1. Plugin settings page where you can select post types. 133 2. Example showing automatic featured image assignment. 173 1. Plugin settings page where you can select post types and OpenAI API key configuration.
Note: See TracChangeset
for help on using the changeset viewer.