/var/www/html/wp-content/plugins/imsanity/

OS : Linux

PHP Version : 7.4.33

Software : Apache/2.4.6 (CentOS) PHP/7.4.33

Information System : Linux apprendre2 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64

Disable Function : * : do not prompt, just resize everything * * ## EXAMPLES * * wp-cli imsanity resize --noprompt * * @synopsis [--noprompt] * * @param array $args A numbered array of arguments provided via WP-CLI without option names. * @param array $assoc_args An array of named arguments provided via WP-CLI. */ public function resize( $args, $assoc_args ) { // let's get started, shall we? // imsanity_init();. $maxw = imsanity_get_option( 'imsanity_max_width', IMSANITY_DEFAULT_MAX_WIDTH ); $maxh = imsanity_get_option( 'imsanity_max_height', IMSANITY_DEFAULT_MAX_HEIGHT ); if ( empty( $assoc_args['noprompt'] ) ) { WP_CLI::warning( __( 'Bulk Resize will alter your original images and cannot be undone!', 'imsanity' ) . "\n" . __( 'It is HIGHLY recommended that you backup your wp-content/uploads folder before proceeding. You will be prompted before resizing each image.', 'imsanity' ) . "\n" . __( 'It is also recommended that you initially resize only 1 or 2 images and verify that everything is working properly before processing your entire library.', 'imsanity' ) ); } /* translators: 1: width in pixels, 2: height in pixels */ WP_CLI::line( sprintf( __( 'Resizing images to %1$d x %2$d', 'imsanity' ), $maxw, $maxh ) ); global $wpdb; $attachments = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE (post_type = 'attachment' OR post_type = 'ims_image') AND post_mime_type LIKE '%%image%%' ORDER BY ID DESC" ); $image_count = count( $attachments ); if ( ! $image_count ) { WP_CLI::success( __( 'There are no images to resize.', 'imsanity' ) ); return; } elseif ( empty( $assoc_args['noprompt'] ) ) { WP_CLI::confirm( /* translators: %d: number of images */ sprintf( __( 'There are %d images to check.', 'imsanity' ), $image_count ) . ' ' . __( 'Continue?', 'imsanity' ) ); } else { /* translators: %d: number of images */ WP_CLI::line( sprintf( __( 'There are %d images to check.', 'imsanity' ), $image_count ) ); } $images_finished = 0; foreach ( $attachments as $id ) { $imagew = false; $imageh = false; ++$images_finished; $path = get_attached_file( $id ); if ( $path ) { list( $imagew, $imageh ) = getimagesize( $path ); } if ( empty( $imagew ) || empty( $imageh ) ) { continue; } if ( $imagew <= $maxw && $imageh <= $maxh ) { /* translators: %s: File-name of the image */ WP_CLI::line( sprintf( esc_html__( 'SKIPPED: %s (Resize not required)', 'imsanity' ), $path ) . " -- $imagew x $imageh" ); continue; } $confirm = ''; if ( empty( $assoc_args['noprompt'] ) ) { $confirm = \cli\prompt( $path . ': ' . $imagew . 'x' . $imageh . "\n" . __( 'Resize (Y/n)?', 'imsanity' ) ); } if ( 'n' === $confirm ) { continue; } $result = imsanity_resize_from_id( $id ); if ( $result['success'] ) { WP_CLI::line( $result['message'] . " $images_finished / $image_count" ); } else { WP_CLI::warning( $result['message'] . " $images_finished / $image_count" ); } } // and let the user know we are done. WP_CLI::success( __( 'Finished Resizing!', 'imsanity' ) ); } } WP_CLI::add_command( 'imsanity', 'Imsanity_CLI' );