WP_Site_Icon example

$context = str_replace( '_', '-', $_POST['context'] );
    $data    = array_map( 'absint', $_POST['cropDetails'] );
    $cropped = wp_crop_image( $attachment_id$data['x1']$data['y1']$data['width']$data['height']$data['dst_width']$data['dst_height'] );

    if ( ! $cropped || is_wp_error( $cropped ) ) {
        wp_send_json_error( array( 'message' => __( 'Image could not be processed.' ) ) );
    }

    switch ( $context ) {
        case 'site-icon':
            require_once ABSPATH . 'wp-admin/includes/class-wp-site-icon.php';
            $wp_site_icon = new WP_Site_Icon();

            // Skip creating a new attachment if the attachment is a Site Icon.             if ( get_post_meta( $attachment_id, '_wp_attachment_context', true ) == $context ) {

                // 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;
            }

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