Is there a filter hook which changes the number of available columns in gallery settings screen. I’m talking about the :
<label class="setting">
<span><?php _e('Columns'); ?></span>
<select class="columns" name="columns"
data-setting="columns">
<?php for ( $i = 1; $i <= 9; $i++ ) : ?>
<option value="<?php echo esc_attr( $i ); ?>" <?php selected( $i, 3 ); ?>>
<?php echo esc_html( $i ); ?>
</option>
<?php endfor; ?>
</select>
</label>
in wp-includes/media-template.php
line 359-369
(WordPress v3.5)
What I basically want to do is to change $i <= 9;
to $i <= 5;
in loop exit condition.
I guess if I just do so, it will be discarded with the next WordPress update.
Thanks for your help
Eugene
Short answer
Simple as things sometimes are: No this is not possible. The whole part is hard coded.
Long answer (not recommended to do so)
You could maybe jump into the
esc_html
andattribute_escape
filters and just return empty there *), but as those are pretty generic names and would possibly also interfere with other filter results and therefore break other things.As the escape-filters are present nearly everywhere, it’s not really recommended to use them in production (like with the gettext-filters). They trigger on every escape (which are hundreds per page) and can really slow down your system.
Internals and performance
To work against this, I’ve used the filter that runs last before the HTML script output to add the callbacks as late as possible. Then I abort as often as possible to not trigger this plugins filters on any other page than the post “add new” screen. After checking the source files HTML, I can see that with version 3.5 we only have two calls for
esc_attr_e()
(which internally triggersesc_attr
and therefore our filters), but with two strings, so we can safely abort on those. When we finally reach our filters I return an empty string and then instantly remove the filter to not trigger for any later calls.This is the best you can achieve.
EDIT
After thinking about it, I used ob caching – not beautiful, but it should work (unless I counted wrong). Note: This is coded while writing and thinking, so it’s not tested. You’ll have to confirm if it works or not.
Final note: You’ll have to recheck this plugin after each following version (starting with WP v3.6) to make sure the markup hasn’t changed and it’s still working as expected.
*) This would leave you with empty strings. In other words: They would still be there but non-functional and empty (no string).
There may or may not be a filter hook, but you can restrict the number of available columns in gallery settings screen by using styles – specifically the admin CSS.
To achieve choices of 1-5 columns add this to your WordPress admin stylesheet. (You may need to create one.)
Style
Function
Tell WordPress to pull this in using
wp_enqueue_style
in your enqueue PHP file.Notes
If the
<select>
<option>
tag(s) isn’t there it cannot be chosen.* In the example above all the options starting with the 6th child are targeted. Notice this will be restricted to only the .columns class in a .gallery-settings class, so it’s pretty safe to say this probably won’t cause any problems with other admin select options.For my project I targeted only the 9th option with
nth-child(9)
. That’s because I’m using Zurb Foundation’s block-grid with choices of 1-8 columns. Choosing 9 just breaks the layout.With this sitting in a stylesheet there’s no need to worry about losing anything after an update.
*The choice will be limited but keep in mind that the user may still be able to set the column number using the text editor option.
[gallery columns="9" ids="113,107,92,57,45,44"]
But if you are smart you’ve probably turned off the text editor option for users anyway.