-
Notifications
You must be signed in to change notification settings - Fork 2
/
wp-disable-generated-image-sizes.php
74 lines (63 loc) · 2.48 KB
/
wp-disable-generated-image-sizes.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
/**
* Plugin Name: Wp Disable Generated image sizes
* Plugin URI: https://github.com/andriilive/wp-disable-image-sizes
* Description: Disable Wordpress & plugins image sizes. No need for configuration, activate and go
* Version: 0.1.0
* Author: DigitalAndy
* Author URI: https://github.com/andriilive
* License: Apache License 2.0
*
* @package Wp_Disable_Image_Sizes
*/
global $_wp_additional_image_sizes;
// Disable all image sizes
add_filter('intermediate_image_sizes', '__return_empty_array', 999);
// disable scaled image size
add_filter('big_image_size_threshold', '__return_false');
add_filter('wp_image_maybe_exif_rotate', '__return_false');
function remove_default_image_sizes( $sizes) {
unset( $sizes['large']); // Added to remove 1024
unset( $sizes['thumbnail']);
unset( $sizes['medium']);
unset( $sizes['medium_large']);
unset( $sizes['1536x1536']);
unset( $sizes['2048x2048']);
return $sizes;
}
add_filter('intermediate_image_sizes_advanced', 'remove_default_image_sizes');
remove_image_size('1536x1536');
remove_image_size('2048x2048');
update_option( 'thumbnail_size_h', 0 );
update_option( 'thumbnail_size_w', 0 );
update_option( 'medium_size_h', 0 );
update_option( 'medium_size_w', 0 );
update_option( 'medium_large_size_w', 0 );
update_option( 'medium_large_size_h', 0 );
update_option( 'large_size_h', 0 );
update_option( 'large_size_w', 0 );
add_action( 'init', function () {
remove_image_size( '1536x1536' ); // 2 x Medium Large (1536 x 1536)
remove_image_size( '2048x2048' ); // 2 x Large (2048 x 2048)
} );
// Update the WP Media Options Settings
function wp_media_options_update() {
if (get_option('_wp_media_options_updated') != 1) {
// Set image sizes to 0 x 0
update_option('thumbnail_size_w', 0);
update_option('thumbnail_size_h', 0);
update_option('medium_size_w', 0);
update_option('medium_size_h', 0);
update_option('large_size_w', 0);
update_option('large_size_h', 0);
update_option('medium_large_size_w', 0);
update_option('medium_large_size_h', 0);
// Disable cropping
update_option('thumbnail_crop', null);
update_option('uploads_use_yearmonth_folders', 1);
// update_option('image_default_size', null);
// Set _wp_media_options_updated to yes
update_option('_wp_media_options_updated', 1);
}
}
add_action('after_setup_theme', 'wp_media_options_update');