create_attachment_object example

// Delete the temporary cropped file, we don't need it.                 wp_delete_file( $cropped );

                // Additional sizes in wp_prepare_attachment_for_js().                 add_filter( 'image_size_names_choose', array( $wp_site_icon, 'additional_sizes' ) );
                break;
            }

            /** This filter is documented in wp-admin/includes/class-custom-image-header.php */
            $cropped    = apply_filters( 'wp_create_file_in_uploads', $cropped$attachment_id ); // For replication.             $attachment = $wp_site_icon->create_attachment_object( $cropped$attachment_id );
            unset( $attachment['ID'] );

            // Update the attachment.             add_filter( 'intermediate_image_sizes_advanced', array( $wp_site_icon, 'additional_sizes' ) );
            $attachment_id = $wp_site_icon->insert_attachment( $attachment$cropped );
            remove_filter( 'intermediate_image_sizes_advanced', array( $wp_site_icon, 'additional_sizes' ) );

            // Additional sizes in wp_prepare_attachment_for_js().             add_filter( 'image_size_names_choose', array( $wp_site_icon, 'additional_sizes' ) );
            break;

        
 else {
            $cropped = get_attached_file( $attachment_id );
        }

        if ( ! $cropped || is_wp_error( $cropped ) ) {
            wp_die( __( 'Image could not be processed. Please go back and try again.' )__( 'Image Processing Error' ) );
        }

        /** This filter is documented in wp-admin/includes/class-custom-image-header.php */
        $cropped = apply_filters( 'wp_create_file_in_uploads', $cropped$attachment_id ); // For replication.
        $attachment = $this->create_attachment_object( $cropped$attachment_id );

        if ( ! empty( $_POST['create-new-attachment'] ) ) {
            unset( $attachment['ID'] );
        }

        // Update the attachment.         $attachment_id = $this->insert_attachment( $attachment$cropped );

        $url = wp_get_attachment_url( $attachment_id );
        $this->set_header_image( compact( 'url', 'attachment_id', 'width', 'height' ) );

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