Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

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 and attribute_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.

<?php
/* Plugin Name: (#82379) Empty Media options */
add_filter( 'image_size_names_choose', 'wpse82379_esc_attr' );
function wpse82379_trigger_filter( $sizes )
{
    if ( 'post' !== get_current_screen()->post )
        return $safe_text;

    add_filter( 'attribute_escape', 'wpse82379_esc_attr', 10, 2 );
    add_filter( 'esc_html', 'wpse82379_esc_attr', 10, 2 );

    return $sizes;
}
function wpse82379_esc_attr( $safe_text, $text )
{
    if ( ! in_array( absint( $text ), range( 6, 9 ) ) )
        return $safe_text;

    static $counter = 0;
    $static++;

    // 
    if ( 1 === $static )
    {
        ob_start();
        return $safe_text;
    }
    if ( in_array( $static, array( 7, 9 ) ) )
    {
        remove_filter( current_filter(), __FUNCTION__ );
        if ( 'esc_html' === current_filter() )
        {
            $html = ob_get_contents();
            ob_end_clean();
            // In case you want to alter the layout, rework $html and return it
            return '';
        }
    }

    return $safe_text;
}

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 triggers esc_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).

share|improve this answer
    
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. –  kaiser Jan 20 '13 at 15:32
    
Hey Kaiser. Thanks for your reply! Unfortunately the code doesn't work. I'm getting Parse error: syntax error, unexpected 'return' (T_RETURN)... on line 17 in the fist return of function wpse82379_esc_attr. The line return $safe_text; –  eugene.kud Jan 20 '13 at 15:42
    
@eugene.kud Yeah, a missing bracket - fixed. Btw: You should try to dig a little bit into error messages, as those are pretty clear and start being help instead of rode blockers when you got around the 5 basic or so messages. Another hint: Use a real IDE as those highlight such errors. I found it with the IDE pretty fast (without counting lines in code in here). –  kaiser Jan 20 '13 at 15:55
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.