Make WordPress Core

Ticket #31029: 31029-allow-zero-columns-gallery.patch

File 31029-allow-zero-columns-gallery.patch, 1.9 KB (added by sachinrajcp123, 13 months ago)
Line 
1diff --git a/src/wp-includes/media-template.php b/src/wp-includes/media-template.php
2index e2d61a8..91f0e1f 100644
3--- a/src/wp-includes/media-template.php
4+++ b/src/wp-includes/media-template.php
5@@ -1175,7 +1175,10 @@ <script type="text/html" id="tmpl-gallery-settings">
6 <label class="setting">
7 <span><?php _e( 'Columns' ); ?></span>
8 <select data-setting="columns">
9- <?php for ( $i = 1; $i <= 9; $i++ ) : ?>
10- <option value="<?php echo esc_attr( $i ); ?>" <# if ( columns == <?php echo $i; ?> ) { #>selected<# } #>><?php echo esc_html( $i ); ?></option>
11- <?php endfor; ?>
12+ <option value="0" <# if ( columns == 0 ) { #>selected<# } #>><?php esc_html_e( 'None (0)' ); ?></option>
13+ <?php for ( $i = 1; $i <= 20; $i++ ) : ?>
14+ <option value="<?php echo esc_attr( $i ); ?>" <# if ( columns == <?php echo $i; ?> ) { #>selected<# } #>>
15+ <?php echo esc_html( $i ); ?>
16+ </option>
17+ <?php endfor; ?>
18 </select>
19 </label>
20diff --git a/src/wp-admin/js/gallery.js b/src/wp-admin/js/gallery.js
21index a7c6ef3..c9b1f25 100644
22--- a/src/wp-admin/js/gallery.js
23+++ b/src/wp-admin/js/gallery.js
24@@ -57,7 +57,12 @@ wp.media.galleryDefaults = {
25 link: 'none',
26 orderby: 'menu_order ID',
27 order: 'ASC',
28- columns: 3
29+ columns: 3
30 };
31+
32+// Extend validate to allow 0 columns
33+wp.media.gallery.validate = function( settings ) {
34+ if ( typeof settings.columns !== 'undefined' && settings.columns < 0 ) {
35+ settings.columns = 0;
36+ }
37+ return settings;
38+};
39diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php
40index bcc98f2..d80e3f3 100644
41--- a/src/wp-includes/media.php
42+++ b/src/wp-includes/media.php
43@@ -1970,7 +1970,13 @@ function gallery_shortcode( $attr ) {
44 $columns = intval( $columns );
45- if ( $columns < 1 )
46- $columns = 3;
47+ if ( $columns < 0 ) {
48+ $columns = 0;
49+ }
50+
51+ // Allow 0 or any positive integer.
52+ if ( $columns === 0 || $columns >= 1 ) {
53+ $selector = "gallery-{$instance}";
54+ } else {
55+ $columns = 3;
56+ }