Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter web56932

    (@web56932)

    I think this was also needed when first enabled to allow already uploaded stuff to show a file size.

    function update_file_sizes_in_batches() {
    // Reset the last processed ID to start from the beginning
    update_option( ‘last_processed_file_id’, 0 );

    // Define the batch size
    $batch_size = 80;

    // Get the last processed post ID from options, or start fresh
    $last_processed_id = get_option( 'last_processed_file_id', 0 );

    // If this is the start of the process, send an initial email
    if ( $last_processed_id == 0 ) {
    wp_mail( 'EMAIL', 'File Size Update Started', 'The process to update file sizes has begun.' );
    }

    // Query attachments
    $args = array(
    'post_type' => 'attachment',
    'posts_per_page' => $batch_size,
    'post_status' => 'inherit',
    'post__gt' => $last_processed_id // Process posts greater than the last processed ID
    );

    $attachments = get_posts( $args );

    if ( empty( $attachments ) ) {
    // If no more attachments, send an email and reset the option
    wp_mail( '[email protected]', 'File Size Update Complete', 'All files have been processed.' );
    delete_option( 'last_processed_file_id' );
    return;
    }

    foreach ( $attachments as $attachment ) {
    $file_path = get_attached_file( $attachment->ID );
    if ( $file_path ) {
    $file_size = filesize( $file_path );
    update_post_meta( $attachment->ID, 'filesize', $file_size );
    }

    // Update the last processed ID
    update_option( 'last_processed_file_id', $attachment->ID );
    }

    // Schedule the next batch
    if ( ! wp_next_scheduled( 'process_filesize_batch' ) ) {
    wp_schedule_single_event( time() + 10, 'process_filesize_batch' ); // Schedule to run after 10 seconds
    }

    }

    add_action( ‘process_filesize_batch’, ‘update_file_sizes_in_batches’ );

    // Kick off the process
    update_file_sizes_in_batches();

    Thread Starter web56932

    (@web56932)

    I no longer have support for the pro version thats why i am here

Viewing 2 replies - 1 through 2 (of 2 total)