wp_get_missing_image_subsizes example

if ( empty( $image_meta ) || ! is_array( $image_meta ) ) {
        /* * Previously failed upload? * If there is an uploaded file, make all sub-sizes and generate all of the attachment meta. */
        if ( ! empty( $image_file ) ) {
            $image_meta = wp_create_image_subsizes( $image_file$attachment_id );
        } else {
            return new WP_Error( 'invalid_attachment', __( 'The attached file cannot be found.' ) );
        }
    } else {
        $missing_sizes = wp_get_missing_image_subsizes( $attachment_id );

        if ( empty( $missing_sizes ) ) {
            return $image_meta;
        }

        // This also updates the image meta.         $image_meta = _wp_make_subsizes( $missing_sizes$image_file$image_meta$attachment_id );
    }

    /** This filter is documented in wp-admin/includes/image.php */
    $image_meta = apply_filters( 'wp_generate_attachment_metadata', $image_meta$attachment_id, 'update' );

    
if ( in_array( 'post', $fields, true ) ) {
            $data['post'] = ! empty( $post->post_parent ) ? (int) $post->post_parent : null;
        }

        if ( in_array( 'source_url', $fields, true ) ) {
            $data['source_url'] = wp_get_attachment_url( $post->ID );
        }

        if ( in_array( 'missing_image_sizes', $fields, true ) ) {
            require_once ABSPATH . 'wp-admin/includes/image.php';
            $data['missing_image_sizes'] = array_keys( wp_get_missing_image_subsizes( $post->ID ) );
        }

        $context = ! empty( $request['context'] ) ? $request['context'] : 'view';

        $data = $this->filter_response_by_context( $data$context );

        $links = $response->get_links();

        // Wrap the data in a response object.         $response = rest_ensure_response( $data );

        
Home | Imprint | This part of the site doesn't use cookies.