[wp-trac] [WordPress Trac] #28693: Make gallery defaults configurable

WordPress Trac noreply at wordpress.org
Fri Jul 18 16:52:42 UTC 2014


#28693: Make gallery defaults configurable
-------------------------------------+-----------------------------
 Reporter:  michal429                |       Owner:  wonderboymusic
     Type:  enhancement              |      Status:  closed
 Priority:  normal                   |   Milestone:  4.0
Component:  Gallery                  |     Version:  trunk
 Severity:  normal                   |  Resolution:  worksforme
 Keywords:  has-patch needs-testing  |     Focuses:  javascript
-------------------------------------+-----------------------------
Changes (by adamsilverstein):

 * status:  reopened => closed
 * resolution:   => worksforme


Comment:

 I don't think my proposed filter is needed and it will not be included in
 core, sorry for any confusion this created. The resolution took a
 different approach:

 You can override the settings in JavaScript by setting
 wp.media.view.settings.galleryDefaults with what you want (in trunk after
 wonderboymusic's patch above)

 You can change the defaults from PHP by filtering shortcode_atts_gallery -
 this code sample shows how -
 https://gist.github.com/adamsilverstein/cd2675feb7233e4849b7

 Hope that makes sense and works to resolve your issue.

 Replying to [comment:9 GregLone]:
 > Hi.
 >
 > It seems it doesn't work properly. Here what I've done:
 > {{{
 > add_filter( 'media_view_settings', 'sfgv_localize_gallery_defaults', 10,
 2 );
 >
 > function sfgv_localize_gallery_defaults( $settings, $post ) {
 >       $defaults = ! empty( $settings['galleryDefaults'] ) && is_array(
 $settings['galleryDefaults'] ) ? $settings['galleryDefaults'] : array();
 >       $settings['galleryDefaults'] = array_merge( $defaults, array(
 >               'itemtag'       => 'figure',
 >               'icontag'       => 'div',
 >               'captiontag'    => 'figcaption',
 >               'columns'       => 5,
 >               'size'          => 'gallery-thumb',
 >               'link'          => 'file',
 >       ) );
 >       return $settings;
 > }
 > }}}
 >
 > Results:
 >
 > The custom values are added to the `_wpMediaViewsL10n` JS var, good.
 >
 > In the gallery creation window:
 > - The default columns value is 3,
 > - The default link value is post.
 > In short, none of my custom values are applied.
 >
 > I keep the default values as it and send the gallery to the editor:
 > - I have 5 columns,
 > - The tags are dl/dt/dd,
 > - The image size is still thumbnail.
 > In short, only the number of columns is applied.
 >
 > I click the gallery, then the edit button:
 > - Still 3 columns and "post".
 >
 > One more thing.
 > If html5 support is set for the gallery shortcode, the tags used are
 figure/div/figcaption instead of dl/dt/dd. Perhaps should we do the same
 things in the editor? But it may not be really useful though.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/28693#comment:10>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list