Tự động set ảnh đầu tiên là featured image cho module auto-upload-images
Sửa đoạn cuối, sau hàm foreach trong hàm save() trong /wp-content/plugins/auto-upload-images/src/WpAutoUpload.php
Và thêm hàm get_first_content_image_id trong file đó
- private function get_first_content_image_id ( $content ) {
- // set variables
- global $wpdb;
- // look for images in HTML code
- if ( $all_img_tags ) {
- foreach ( $all_img_tags[ 0 ] as $img_tag ) {
- // find class attribute and catch its value
- if ( $img_class ) {
- // Look for the WP image id
- // if first image id found: check whether is image
- if ( $found_id ) {
- $img_id = absint( $found_id[ 1 ] );
- // if is image: return its id
- if ( wp_attachment_is_image( $img_id ) ) {
- return $img_id;
- }
- } // if(found_id)
- } // if(img_class)
-
- // else: try to catch content image id by its url as stored in the database
- // find src attribute and catch its value
- if ( $img_src ) {
- // delete optional query string in img src
- // delete image dimensions data in img file name, just take base name and extension
- // if path is set relatively make it absolute
- $guid = home_url() . $guid;
- }
- // look up its ID in the db
- $found_id = $wpdb->get_var( $wpdb->prepare( "SELECT `ID` FROM $wpdb->posts WHERE `guid` = '%s'", $guid ) );
- // if first image id found: return it
- if ( $found_id ) {
- return absint( $found_id );
- } // if(found_id)
-
- } // if(img_src)
- } // foreach(img_tag)
- } // if(all_img_tags)
-
- // if nothing found: return 0
- return 0;
- }