te the width in any [caption] shortcodes. preg_match_all( '#\[caption id="attachment_' . $this->attachment->ID . '"([^\]]+)? width="[^"]+"\]([^\[]+)size-([^" ]+)([^\[]+)\[\/caption\]#i', $content, $matches, PREG_SET_ORDER ); if ( $matches ) { foreach ( $matches as $match ) { $thumbnail = image_downsize( $this->attachment->ID, $match[3] ); if ( ! $thumbnail ) { continue; } $search[] = $match[0]; $replace[] = '[caption id="attachment_' . $this->attachment->ID . '"' . $match[1] . ' width="' . esc_attr( $thumbnail[1] ) . '"]' . $match[2] . 'size-' . $match[3] . $match[4] . '[/caption]'; } } $content = str_replace( $search, $replace, $content ); $updated_post_object = (object) array( 'ID' => $post->ID, 'post_content' => $content, ); $posts_updated[ $post->ID ] = wp_update_post( $updated_post_object, true ); } } return $posts_updated; } /** * Returns information about the current attachment for use in the REST API. * * @since 3.0.0 * * @return array|WP_Error The attachment name, fullsize URL, registered thumbnail size status, and any unregistered sizes, or WP_Error on error. */ public function get_attachment_info() { $fullsizepath = $this->get_fullsizepath(); if ( is_wp_error( $fullsizepath ) ) { $fullsizepath->add_data( array( 'attachment' => $this->attachment ) ); return $fullsizepath; } $editor = wp_get_image_editor( $fullsizepath ); if ( is_wp_error( $editor ) ) { // Display a more helpful error message. if ( 'image_no_editor' === $editor->get_error_code() ) { $editor = new WP_Error( 'image_no_editor', __( 'The current image editor cannot process this file type.', 'regenerate-thumbnails' ) ); } $editor->add_data( array( 'attachment' => $this->attachment, 'status' => 415, ) ); return $editor; } $metadata = wp_get_attachment_metadata( $this->attachment->ID ); if ( false === $metadata || ! is_array( $metadata ) ) { return new WP_Error( 'regenerate_thumbnails_regenerator_no_metadata', __( 'Unable to load the metadata for this attachment.', 'regenerate-thumbnails' ), array( 'status' => 404, 'attachment' => $this->attachment, ) ); } if ( ! isset( $metadata['sizes'] ) ) { $metadata['sizes'] = array(); } // PDFs don't have width/height set. $width = ( isset( $metadata['width'] ) ) ? $metadata['width'] : null; $height = ( isset( $metadata['height'] ) ) ? $metadata['height'] : null; require_once( ABSPATH . '/wp-admin/includes/image.php' ); $preview = false; if ( file_is_displayable_image( $fullsizepath ) ) { $preview = wp_get_attachment_url( $this->attachment->ID ); } elseif ( is_array( $metadata['sizes'] ) && is_array( $metadata['sizes']['full'] ) && ! empty( $metadata['sizes']['full']['file'] ) ) { $preview = str_replace( wp_basename( $fullsizepath ), $metadata['sizes']['full']['file'], wp_get_attachment_url( $this->attachment->ID ) ); if ( ! file_exists( $preview ) ) { $preview = false; } } $response = array( 'name' => ( $this->attachment->post_title ) ? $this->attachment->post_title : sprintf( __( 'Attachment %d', 'regenerate-thumbnails' ), $this->attachment->ID ), 'preview' => $preview, 'relative_path' => _wp_get_attachment_relative_path( $fullsizepath ) . DIRECTORY_SEPARATOR . wp_basename( $fullsizepath ), 'edit_url' => get_edit_post_link( $this->attachment->ID, 'raw' ), 'width' => $width, 'height' => $height, 'registered_sizes' => array(), 'unregistered_sizes' => array(), ); $wp_upload_dir = dirname( $fullsizepath ) . DIRECTORY_SEPARATOR; $registered_sizes = RegenerateThumbnails()->get_thumbnail_sizes(); if ( 'application/pdf' === get_post_mime_type( $this->attachment ) ) { $registered_sizes = array_intersect_key( $registered_sizes, array( 'thumbnail' => true, 'medium' => true, 'large' => true, ) ); } // Check the status of all currently registered sizes. foreach ( $registered_sizes as $size ) { // Width and height are needed to generate the thumbnail filename. if ( $width && $height ) { $thumbnail = $this->get_thumbnail( $editor, $width, $height, $size['width'], $size['height'], $size['crop'] ); if ( $thumbnail ) { $size['filename'] = wp_basename( $thumbnail['filename'] ); $size['fileexists'] = file_exists( $thumbnail['filename'] ); } else { $size['filename'] = false; $size['fileexists'] = false; } } elseif ( ! empty( $metadata['sizes'][ $size['label'] ]['file'] ) ) { $size['filename'] = wp_basename( $metadata['sizes'][ $size['label'] ]['file'] ); $size['fileexists'] = file_exists( $wp_upload_dir . $metadata['sizes'][ $size['label'] ]['file'] ); } else { $size['filename'] = false; $size['fileexists'] = false; } $response['registered_sizes'][] = $size; } if ( ! $width && ! $height && is_array( $metadata['sizes']['full'] ) ) { $response['registered_sizes'][] = array( 'label' => 'full', 'width' => $metadata['sizes']['full']['width'], 'height' => $metadata['sizes']['full']['height'], 'filename' => $metadata['sizes']['full']['file'], 'fileexists' => file_exists( $wp_upload_dir . $metadata['sizes']['full']['file'] ), ); } // Look at the attachment metadata and see if we have any extra files from sizes that are no longer registered. foreach ( $metadata['sizes'] as $label => $size ) { if ( ! file_exists( $wp_upload_dir . $size['file'] ) ) { continue; } // An unregistered size could match a registered size's dimensions. Ignore these. foreach ( $response['registered_sizes'] as $registered_size ) { if ( $size['file'] === $registered_size['filename'] ) { continue 2; } } if ( ! empty( $registered_sizes[ $label ] ) ) { /* translators: Used for listing old sizes of currently registered thumbnails */ $label = sprintf( __( '%s (old)', 'regenerate-thumbnails' ), $label ); } $response['unregistered_sizes'][] = array( 'label' => $label, 'width' => $size['width'], 'height' => $size['height'], 'filename' => $size['file'], 'fileexists' => true, ); } return $response; } } Hardware - Afinite

Need Urgent Help?
Get in touch with our Emergency Support Team:

0113 887 3999

We specialise in selecting equipment appropriate for use by our clients which they can rely upon. We supply desktop PCs, laptops, workstations, peripherals, network switches, routers, wireless access points as well as components such as RAM and SSDs to upgrade existing machines with.

We would love to assist you with hardware solutions for your business- feel free to enquire. The number one reason to choose us is that we will find something suitable for you and can back this up by experience with the equipment itself.

Latest Blog Posts

12th April 2021

Even before COVID-19 turned our lives upside down, a new generation of digital tools was opening up new possibilities for the future of work. What we didn’t expect was that…

9th March 2021

With so much of what we do day to day, especially with more of us working remotely, we’re all really reliant on being able to securely work on files and…

Get In Touch

Whether you’re having a complete system overhaul or whether it’s
something specific you’re having a problem with.
We’re here to help.

Contact Us

Or Call Us On:

0113 887 3999

Talk to us now