<commit_before><?php

function update_featured_image($post_id, $img_url) {
    // Get upload directory
    $uploads = wp_upload_dir();
    $upload_dir = $uploads['path'];
    $upload_url = $uploads['url'];

    // Download to the proper place
    $file_base = basename($img_url);
    $downloaded = "$upload_dir/$file_base";
    $downloaded_url = "$upload_url/$file_base";
    copy($img_url, $downloaded);

    // Check the type of tile. We'll use this as the 'post_mime_type'.
    $filetype = wp_check_filetype($downloaded, null);

    // Prepare an array of post data for the attachment.
    $attachment = array(
        'guid'           => $downloaded_url, 
        'post_mime_type' => $filetype['type'],
        'post_title'     => preg_replace( '/\.[^.]+$/', '', basename( $filename ) ),
        'post_content'   => '',
        'post_status'    => 'inherit'
    );

    // Insert the attachment.
    $attach_id = wp_insert_attachment($attachment, $downloaded, $post_id);

    // Make sure that this file is included, as wp_generate_attachment_metadata() depends on it.
    require_once( ABSPATH . 'wp-admin/includes/image.php' );

    // Generate the metadata for the attachment, and update the database record.
    $attach_data = wp_generate_attachment_metadata($attach_id, $downloaded);
    wp_update_attachment_metadata($attach_id, $attach_data);

    // Now set as the Featured Image (aka Post Thumbnail)
    set_post_thumbnail($post_id, $attach_id);
}

function update_post($url, $post_id, $args = array()) {
    if (wp_is_post_revision($post_id)) return false;

    $feed = fetch_feed($url);
    $entry = $feed->get_item();
    $post = get_post($post_id);

    $post->post_content = $entry->get_content();
    $post->post_modified_gmt = $entry->get_gmdate('Y-m-d H:i:s');
    $post->post_modified = get_date_from_gmt($post->post_modified_gmt);
    if (!empty($args['update_title'])) $post->post_title = $entry->get_title();

    wp_update_post($post);
    if (!empty($post->enclosure) && !empty($args['update_featured_image'])) {
        $e = $entry->get_enclosure();
        update_featured_image($post_id, $e->get_link());
    }
}
<commit_msg>Fix non-updating image<commit_after><?php

function update_featured_image($post_id, $img_url) {
    // Get upload directory
    $uploads = wp_upload_dir();
    $upload_dir = $uploads['path'];
    $upload_url = $uploads['url'];

    // Download to the proper place
    $file_base = basename($img_url);
    $downloaded = "$upload_dir/$file_base";
    $downloaded_url = "$upload_url/$file_base";
    copy($img_url, $downloaded);

    // Check the type of tile. We'll use this as the 'post_mime_type'.
    $filetype = wp_check_filetype($downloaded, null);

    // Prepare an array of post data for the attachment.
    $attachment = array(
        'guid'           => $downloaded_url, 
        'post_mime_type' => $filetype['type'],
        'post_title'     => preg_replace( '/\.[^.]+$/', '', basename( $filename ) ),
        'post_content'   => '',
        'post_status'    => 'inherit'
    );

    // Insert the attachment.
    $attach_id = wp_insert_attachment($attachment, $downloaded, $post_id);

    // Make sure that this file is included, as wp_generate_attachment_metadata() depends on it.
    require_once( ABSPATH . 'wp-admin/includes/image.php' );

    // Generate the metadata for the attachment, and update the database record.
    $attach_data = wp_generate_attachment_metadata($attach_id, $downloaded);
    wp_update_attachment_metadata($attach_id, $attach_data);

    // Now set as the Featured Image (aka Post Thumbnail)
    set_post_thumbnail($post_id, $attach_id);
}

function update_post($url, $post_id, $args = array()) {
    if (wp_is_post_revision($post_id)) return false;

    $feed = fetch_feed($url);
    $entry = $feed->get_item();
    $post = get_post($post_id);

    $post->post_content = $entry->get_content();
    $post->post_modified_gmt = $entry->get_gmdate('Y-m-d H:i:s');
    $post->post_modified = get_date_from_gmt($post->post_modified_gmt);
    if (!empty($args['update_title'])) $post->post_title = $entry->get_title();

    wp_update_post($post);
    if (!empty($args['update_featured_image'])) {
        $e = $entry->get_enclosure();
        if (!empty($e)) update_featured_image($post_id, $e->get_link());
    }
}

{'fraction_non_alphanumeric': 0.15532853494311585, 'fraction_numerical': 0.0, 'mean_word_length': 3.627282491944146, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 36, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5349625', 'n_tokens_mistral': 1445, 'n_tokens_neox': 1406, 'n_words': 293}