#35101 closed defect (bug) (worksforme)
image_default_link_type option not being respected
Reported by: | ben1390 | Owned by: | azaozz |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 4.4 |
Component: | Media | Keywords: | has-patch needs-testing close |
Focuses: | Cc: |
Description
Hi,
I have an issue on a few sites where I have set the image_default_link_type to file through /wp-admin/options.php but when using the Add Media button on the post edit window the Link To option is alway set to none. This has only happened since the upgrade to 4.4 and I have tried downgrading to 4.3.1 and this works perfectly and as this is happening across a few sites I manage I suspect that it's a core bug.
Any assistance in getting this resolved would me much appreciated.
Thanks in advance.
Attachments (2)
Change History (30)
#3
@
9 years ago
- Owner set to wonderboymusic
- Status changed from new to assigned
@liljimmi, @janhenckens, @eherman24, @wonderboymusic - This seems to have been introduced in [33729] which you all worked on, can you please take a look.
#4
follow-ups:
↓ 5
↓ 6
@
9 years ago
I just went through and did some testing against trunk, and it appears that toggling the settings on options.php is having an effect on the 'Link To' option in the Add Media window on edit.php for both pages and posts. I can set the option to file, post, none or custom and the changes seem to be occurring as expected. So, I'm not able to reproduce the issue on my end.
Maybe someone else can test and confirm?
#5
in reply to:
↑ 4
@
9 years ago
Replying to eherman24:
Maybe someone else can test and confirm?
Can't reproduce this on my end either. Test against trunk and a downloaded 4.4 , the link option in the Add Media modal changes along with what is set in options.php
#6
in reply to:
↑ 4
@
9 years ago
Replying to eherman24:
I just went through and did some testing against trunk, and it appears that toggling the settings on options.php is having an effect on the 'Link To' option in the Add Media window on edit.php for both pages and posts. I can set the option to file, post, none or custom and the changes seem to be occurring as expected. So, I'm not able to reproduce the issue on my end.
Maybe someone else can test and confirm?
I have the exact problem and can confirm. If you set the option in an edit post, it sticks to whatever you last set it to no matter what the default is set to. I have code in my custom theme to set the defaults, and they appear to be set correctly in the options.php which doesn't change. However, any new posts or edited posts have it set to whatever it was changed to in the last edit.
Here is my code from the functions.php file:
<?php /** * Set the Attachment Display Settings "Link To" default * * This function is attached to the 'after_setup_theme' action hook. */ function default_attachment_display_settings() { update_option( 'image_default_align', 'right' ); update_option( 'image_default_link_type', 'file' ); update_option( 'image_default_size', 'medium' ); } add_action( 'after_setup_theme', 'default_attachment_display_settings' );
Indeed, neither "image_default_link_type" nor "image_default_align" nor "image_default_size" are defaulting correctly, but are always set (in edit pages) to whatever it was last changed to.
#7
@
9 years ago
- Keywords has-patch needs-testing added; needs-patch removed
After some additional testing, and reading through @wetapplemedia breakdown of the issue, I was able to reproduce this issue.
It seems that after you change the value of one of the drop downs, the users settings were updated for the three respective fields, in utils.js: align
, urlbutton
and imgsize
.
Once stored in the user settings, they were being referenced on each open of the media library to reset the values back to the original state - but instead of referencing the global site options they were being referenced from the backbone model. This was happening in media-views.js.
I've attached a patch that removes referencing those three options from the Backbone model and instead references them from the defaultProps variable.
@
9 years ago
Regenerated patch from root checkout - Added fallback if no defaults are set in options.php
This ticket was mentioned in Slack in #core by jorbin. View the logs.
9 years ago
#10
follow-up:
↓ 17
@
9 years ago
- Keywords close added
There is some "history" about these options going a long way back. Before 2.6 the options were shown on the Settings => Media screen. Then getUserSetting() was added to keep the last selected value, then in 2.7 the options were removed from the settings screen.
At the time it was decided to still honor these options and override the last used value mostly as back-compat. Since then I've seen questions and confusion why some of the image insert settings keep their last used values and some do not.
Think we should keep the current behaviour to (finally) remove that confusion. For users that prefer to always reset the image insert options, they can be set with setUserSetting():
add_action( 'admin_head-post.php', '_my_reset_image_insert_settings' ); add_action( 'admin_head-post-new.php', '_my_reset_image_insert_settings' ); function _my_reset_image_insert_settings() { ?> <script> if ( typeof setUserSetting !== 'undefined' ) { setUserSetting( 'align', 'none' ); // none || left || center || right setUserSetting( 'imgsize', 'medium' ); // thumbnail || medium || large || full setUserSetting( 'urlbutton', 'none' ); // none || file || post } </script> <?php }
This ticket was mentioned in Slack in #core by azaozz. View the logs.
9 years ago
#12
follow-up:
↓ 13
@
9 years ago
The related changeset is [33729].
I agree with @azaozz. A user should be able to override a default/initial value, which in this case is provided by the image_default_*
options. That's in line with the default category or default header color/image handling.
#13
in reply to:
↑ 12
;
follow-up:
↓ 15
@
9 years ago
Replying to ocean90:
The related changeset is [33729].
I agree with @azaozz. A user should be able to override a default/initial value, which in this case is provided by the
image_default_*
options. That's in line with the default category or default header color/image handling.
I guess the question is, then... who is the user? The one who downloads, installs, and expects their website/theme installation to run as they define? Or, the visitor or editor of that website?
I vote that the webmaster is the "user" and therefore the image defaults overrides set by my default theme should override any visitor or editor's choices on initial load of edit screens.
This ticket was mentioned in Slack in #core by jorbin. View the logs.
9 years ago
#15
in reply to:
↑ 13
;
follow-ups:
↓ 16
↓ 26
@
9 years ago
- Milestone 4.4.1 deleted
- Resolution set to worksforme
- Status changed from assigned to closed
Replying to wetapplemedia:
...the image defaults overrides set by my default theme should override any visitor or editor's choices on initial load of edit screens.
This is how it works now but only until the editors select another setting. Then their choice overrides the default. If you want to force them to always use the default for all attachments that are inserted into the editor, see the above patch.
For me keeping the last selected value feels better, but I agree that always starting with the defaults is also a possibility. I'm not sure which is the better UX.
Thinking it is worth it to check how other open source software is handling similar cases, even do some user testing, and then change the way this works in core.
Going to close this ticket as it is a bug against a minor release, but feel free to open an enhancement ticket with some examples from other open source software, etc.
#16
in reply to:
↑ 15
@
9 years ago
Replying to azaozz:
Replying to wetapplemedia:
...the image defaults overrides set by my default theme should override any visitor or editor's choices on initial load of edit screens.
This is how it works now but only until the editors select another setting. Then their choice overrides the default. If you want to force them to always use the default for all attachments that are inserted into the editor, see the example in comment 10.
For me keeping the last selected value feels better, but I agree that always starting with the defaults is also a possibility. I'm not sure which is the better UX.
Thinking it is worth it to check how other open source software is handling similar cases, even do some user testing, and then change the way this works in core.
Going to close this ticket as it is a bug against a minor release, but feel free to open an enhancement ticket with some examples from other open source software, etc.
Two things:
1) I actually thought that the code I put in the theme functions.php file (see comment:6) was the override for the default behavior. So, are you saying that there is now just a new way of overriding the default behavior, using the code you outlined in comment:10?
2) In my case, the theme is designed to work with image insertions that always start on the right side, and enforcing the behavior with our editors is ...needed. ;-)
#17
in reply to:
↑ 10
@
9 years ago
Replying to azaozz:
This snippet is working perfectly, thank you!!!
#18
follow-up:
↓ 19
@
9 years ago
Hmmm... I have placed the snippet code directly after my original image_default_ settings code in my functions.php file, but for some reason it only works the same way as my original code. It doesn't seem to override the "last setting used" as default. Is there a specific spot you place it? (maybe before or after something else?)
#19
in reply to:
↑ 18
;
follow-up:
↓ 20
@
9 years ago
Replying to wetapplemedia:
Hmmm... I have placed the snippet code directly after my original image_default_ settings code in my functions.php file, but for some reason it only works the same way as my original code. It doesn't seem to override the "last setting used" as default. Is there a specific spot you place it? (maybe before or after something else?)
Why are you using original image_default_settings code? For me, that used to work but after updates it no longer does anything, from what I can tell. The last snippet posted is working for my purposes; every time the user wants to embed an image they always get the settings I've chosen. I do this mostly because some lightboxes don't work well with single images.
Just use this (make appropriate changes for your needs) and see how it works out for you.
add_action( 'admin_head-post.php', '_my_reset_image_insert_settings' ); add_action( 'admin_head-post-new.php', '_my_reset_image_insert_settings' ); function _my_reset_image_insert_settings() { ?> <script> if ( typeof setUserSetting !== 'undefined' ) { setUserSetting( 'align', 'none' ); // none || left || center || right setUserSetting( 'imgsize', 'medium' ); // thumbnail || medium || large || full setUserSetting( 'urlbutton', 'none' ); // none || file || post } </script> <?php }
#20
in reply to:
↑ 19
;
follow-up:
↓ 21
@
9 years ago
- Resolution worksforme deleted
- Status changed from closed to reopened
Replying to chrisborgman:
Replying to wetapplemedia:
Hmmm... I have placed the snippet code directly after my original image_default_ settings code in my functions.php file, but for some reason it only works the same way as my original code. It doesn't seem to override the "last setting used" as default. Is there a specific spot you place it? (maybe before or after something else?)
Why are you using original image_default_settings code? For me, that used to work but after updates it no longer does anything, from what I can tell. The last snippet posted is working for my purposes; every time the user wants to embed an image they always get the settings I've chosen. I do this mostly because some lightboxes don't work well with single images.
Just use this (make appropriate changes for your needs) and see how it works out for you.
add_action( 'admin_head-post.php', '_my_reset_image_insert_settings' ); add_action( 'admin_head-post-new.php', '_my_reset_image_insert_settings' ); function _my_reset_image_insert_settings() { ?> <script> if ( typeof setUserSetting !== 'undefined' ) { setUserSetting( 'align', 'none' ); // none || left || center || right setUserSetting( 'imgsize', 'medium' ); // thumbnail || medium || large || full setUserSetting( 'urlbutton', 'none' ); // none || file || post } </script> <?php }
I removed my old code and added the new code... and it still doesn't work. I restarted the server and cleared all caches, and can even see the new code in the source of the edit-post page.
When you say "This snippet is working perfectly, thank you!!!" what exactly do you mean? Is it defaulting to your snippet settings for every image import no matter what the last one was set to? Mine is not.
#21
in reply to:
↑ 20
;
follow-up:
↓ 22
@
9 years ago
I removed my old code and added the new code... and it still doesn't work. I restarted the server and cleared all caches, and can even see the new code in the source of the edit-post page.
When you say "This snippet is working perfectly, thank you!!!" what exactly do you mean? Is it defaulting to your snippet settings for every image import no matter what the last one was set to? Mine is not.
"Is it defaulting to your snippet settings for every image import no matter what the last one was set to?" - YES
FYI, I'm using Genesis Framework theme with Dynamik Website Builder child theme, this allows me to add functions directly in the WP admin so I don't have to alter the actual functions file. Not sure if this has anything to do with your situation, other than your theme may not like the code or where you're putting it. I can't suggest anything as this is going beyond my knowledge. All I can see it that it does work as advertised. Try contacting the theme developer...?
#22
in reply to:
↑ 21
;
follow-ups:
↓ 23
↓ 24
@
9 years ago
Replying to chrisborgman:
I removed my old code and added the new code... and it still doesn't work. I restarted the server and cleared all caches, and can even see the new code in the source of the edit-post page.
When you say "This snippet is working perfectly, thank you!!!" what exactly do you mean? Is it defaulting to your snippet settings for every image import no matter what the last one was set to? Mine is not.
"Is it defaulting to your snippet settings for every image import no matter what the last one was set to?" - YES
FYI, I'm using Genesis Framework theme with Dynamik Website Builder child theme, this allows me to add functions directly in the WP admin so I don't have to alter the actual functions file. Not sure if this has anything to do with your situation, other than your theme may not like the code or where you're putting it. I can't suggest anything as this is going beyond my knowledge. All I can see it that it does work as advertised. Try contacting the theme developer...?
I am the theme developer. ;-) My beef is that I shouldn't have to come up with a workaround for something that was working correctly for 3 years up to about two weeks ago. lol
#23
in reply to:
↑ 22
@
9 years ago
I am the theme developer. ;-)
LOL! OK then, you're a lot smarter than I am!! :-) You'll get it worked out!
https://www.dropbox.com/s/kzza74qju16hm5n/Screen%20Shot%202016-01-07%20at%201.51.46%20PM.png?dl=0
#24
in reply to:
↑ 22
@
9 years ago
Replying to wetapplemedia:
Replying to chrisborgman:
I removed my old code and added the new code... and it still doesn't work. I restarted the server and cleared all caches, and can even see the new code in the source of the edit-post page.
When you say "This snippet is working perfectly, thank you!!!" what exactly do you mean? Is it defaulting to your snippet settings for every image import no matter what the last one was set to? Mine is not.
"Is it defaulting to your snippet settings for every image import no matter what the last one was set to?" - YES
FYI, I'm using Genesis Framework theme with Dynamik Website Builder child theme, this allows me to add functions directly in the WP admin so I don't have to alter the actual functions file. Not sure if this has anything to do with your situation, other than your theme may not like the code or where you're putting it. I can't suggest anything as this is going beyond my knowledge. All I can see it that it does work as advertised. Try contacting the theme developer...?
I am the theme developer. ;-) My beef is that I shouldn't have to come up with a workaround for something that was working correctly for 3 years up to about two weeks ago. lol
Oh yeah, I 2nd your beef!
#25
@
9 years ago
- Resolution set to worksforme
- Status changed from reopened to closed
Please use the Support Forums for troubleshooting.
#26
in reply to:
↑ 15
@
9 years ago
Replying to azaozz:
For me keeping the last selected value feels better, but I agree that always starting with the defaults is also a possibility. I'm not sure which is the better UX.
I recently described my preferred UX (https://wordpress.org/support/topic/choosing-default-size-for-attachment-display-settings-no-longer-works):
"Every time I enter a post to edit it or every time I add a new post draft, I want my media modal defaults to start. I only want the settings to change once I've changed them in that editing session.
For instance, if I click Add New or Edit Post, the modal should display the selected default settings. If I change them, then they should remain that way until I go to another post. Clicking Save Draft or Update Post wouldn't change the settings back to default, only opening another post.
Anyway, that's how I would ideally like things to work, but then again, I often work with several posts open in separate tabs, so I don't know if it would be possible."
I hope this is useful to this discussion!
#27
@
9 years ago
My problem with the way this works now in WP by default (which I can no longer override) is that it makes my site more difficult to add images to posts. We always do a right-hand image first, then alternate left, right, left, etc, down the content body.
When the default settings change to match whatever was last input, it means that for us the default setting is NEVER in the correct position. We have to change it manually every time we place an image.
My code that worked for 3 years in the functions.php file no longer helps, and the snippet of code introduced to me in #comment:20 doesn't work at all in my theme for some unknown reason.
#28
@
8 years ago
Does no one else see the glaring problem with having Wordpress "remember" your last used image settings?
Let's say you like using Large
sized images. Most of your images are big so this isn't a problem. But if at any point an image too small to generate a Large
size gets added, suddenly Full Size
becomes your default, because your REAL default, the one you actually want, happened to not exist for the last image. So your preferred settings now change unexpectedly and without warning, forcing users to constantly make sure their default image size is the one they actually want.
Additionally, the snippet provided to "fix" this issue falls victim to this problem as well. The moment you have an image that doesn't support your default enter the picture, it overrides the user setting all over again causing Full Size
to be your default until you load the page again, so you also need to add a listener to $('.media-upload-form').on('click.uploader')
and change it there too just to get it working consistently.
Hi @ben1390, welcome to Trac!
Thanks for the report, appears to be introduced in [33729].