#28693 closed enhancement (fixed)
Make gallery defaults configurable
Reported by: | michal429 | Owned by: | wonderboymusic |
---|---|---|---|
Milestone: | 4.0 | Priority: | normal |
Severity: | normal | Version: | 4.0 |
Component: | Gallery | Keywords: | has-patch |
Focuses: | javascript | Cc: |
Description
Please make the "new gallery" default options configurable. Right now there are hard-coded defaults of 3 columns and link to post. All galleries on my sites are 5-column wide and link to files with colorbox slideshow. Right now I have to override the whole gallery drawing just for that and tell users to ignore the settings when creating a gallery.
Attachments (2)
Change History (22)
#1
@
10 years ago
- Component changed from Administration to Gallery
- Milestone Awaiting Review deleted
- Resolution set to duplicate
- Status changed from new to closed
#2
@
10 years ago
- Keywords has-patch dev-feedback added
michal429 -
Seems like what you need here is a way to filter the default values - which are currently hard-coded into the media-editor.js JavaScript. I can certainly see the use case for this!
I am attempting this in 28693.diff, moved default values over to wp.media.view.settings.galleryDefaults which you can adjust using the existing media_view_settings filter. For example, to set the default value gallery columns you would do something like this:
function my_set_gallery_default_five_columns( $settings ) { $settings['galleryDefaults']['columns'] = '5'; return $settings; } add_filter( 'media_view_settings', 'my_set_gallery_default_five_columns', 10 );
#4
@
10 years ago
Hi.
I agree. Not being able to change these default settings is very annoying.
I think there's more things to change:
wp-admin/js/gallery.js L215
if ( I('linkto-file').checked ) { s += ' link="file"'; setUserSetting('galfile', '1'); } if ( I('order-desc').checked ) { s += ' order="DESC"'; setUserSetting('galdesc', '1'); } if ( I('columns').value !== 3 ) { s += ' columns="' + I('columns').value + '"'; setUserSetting('galcols', I('columns').value); }
wp-includes/js/mce-views.js L316:
options = { attachments: attachments, columns: attrs.columns ? parseInt( attrs.columns, 10 ) : 3 };
EDIT: oh, and there's even more later in wp-admin/js/gallery.js.
#5
@
10 years ago
- Focuses javascript added
- Keywords dev-feedback removed
- Milestone set to 4.0
28693.2.diff does this without us having to localize
#6
follow-up:
↓ 8
@
10 years ago
- Owner set to wonderboymusic
- Resolution set to fixed
- Status changed from reopened to closed
In 28990:
#9
follow-up:
↓ 10
@
10 years ago
- Keywords needs-testing added
- Resolution fixed deleted
- Status changed from closed to reopened
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.
#10
in reply to:
↑ 9
;
follow-up:
↓ 11
@
10 years ago
- Resolution set to worksforme
- Status changed from reopened to closed
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 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.
#11
in reply to:
↑ 10
;
follow-up:
↓ 12
@
10 years ago
- Resolution worksforme deleted
- Status changed from closed to reopened
Replying to adamsilverstein:
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)
Indeed, and that's what I'm doing with the filter: $settings['galleryDefaults']
will populate the JS variable _wpMediaViewsL10n
, and then will set wp.media.view.settings.galleryDefaults
. So, my custom values are in wp.media.view.settings.galleryDefaults
. The problem is that values alone do (almost) nothing.
You can change the defaults from PHP by filtering shortcode_atts_gallery - this code sample shows how - https://gist.github.com/adamsilverstein/cd2675feb7233e4849b7
Yep, I know.
Hope that makes sense and works to resolve your issue.
#12
in reply to:
↑ 11
;
follow-up:
↓ 13
@
10 years ago
Why are you re-opening the ticket, do you still have an issue?
Replying to GregLone:
Replying to adamsilverstein:
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)
Indeed, and that's what I'm doing with the filter:
$settings['galleryDefaults']
will populate the JS variable_wpMediaViewsL10n
, and then will setwp.media.view.settings.galleryDefaults
. So, my custom values are inwp.media.view.settings.galleryDefaults
. The problem is that values alone do (almost) nothing.
You can change the defaults from PHP by filtering shortcode_atts_gallery - this code sample shows how - https://gist.github.com/adamsilverstein/cd2675feb7233e4849b7
Yep, I know.
Hope that makes sense and works to resolve your issue.
#13
in reply to:
↑ 12
;
follow-up:
↓ 14
@
10 years ago
Replying to adamsilverstein:
Why are you re-opening the ticket, do you still have an issue?
Unless something changed since my latest post, yes, it won't work. Have you tried to have custom parameters in the editor and the media modal?
#14
in reply to:
↑ 13
@
10 years ago
Replying to GregLone:
Replying to adamsilverstein:
Why are you re-opening the ticket, do you still have an issue?
Unless something changed since my latest post, yes, it won't work. Have you tried to have custom parameters in the editor and the media modal?
i will give it a try to see why its not working.
#15
follow-up:
↓ 19
@
10 years ago
Sorry for butting in here but I'm curious. Will this change allow some customization from the Media Gallery modal itself? Ideally, I'd like to be able to add some filters or something to my functions file and then the user is displayed with some options during Gallery creation. Instead of just the "Link to" and "Column sizes" that are currently available, I'd like to also see a dropdown for "image size", which you could even go further to add the custom sizes from your functions in there. This would also help theme developers out. Thank you!
#18
@
10 years ago
- Keywords needs-testing removed
- Resolution set to fixed
- Status changed from reopened to closed
Changing the markup in the MCE view for HTML5 will be super gnarly in the Underscore template. I fixed the main issues you pointed out.
#19
in reply to:
↑ 15
@
10 years ago
lilqhgal,
I don't think this ticket will help you - its just about overriding the defaults for the existing values. There may already be action on this in another ticket or a good approach to use now; Otherwise, consider opening a new ticket to request this feature.
Replying to lilqhgal:
Sorry for butting in here but I'm curious. Will this change allow some customization from the Media Gallery modal itself? Ideally, I'd like to be able to add some filters or something to my functions file and then the user is displayed with some options during Gallery creation. Instead of just the "Link to" and "Column sizes" that are currently available, I'd like to also see a dropdown for "image size", which you could even go further to add the custom sizes from your functions in there. This would also help theme developers out. Thank you!
#20
@
10 years ago
Great.
It seems to work fine so far: when I want to create a new gallery, the number of columns and the link are preset with the custom values.
Unfortunately I couldn't see if these custom values are used when Editing an existing gallery: the "Edit" and "Remove" buttons in the editor don't work anymore (related?).
A bit further: to be able to also have a different image size in the galleries, should I open a new ticket for this enhancement?
Thanks.
Duplicate of #22773.