-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Try to figure out which is the right LinkDestination value for an image #17401
Conversation
After rebasing my changes on the latest commits I did a mistake while resolving conflicts. I need more time to test again my changes. |
Any progress? |
I'm sorry @vdrover, but I've been very busy. I'll try to fix the errors next week. |
Hi @jesusangel, when do you think you'll be able to fix the errors ? I'm very interested in this PR. |
@jesusangel is the only thing stopping this from being reviewed the CI errors, or is there something else left over from the old PR that needs fixed in the code? |
when the user has changed its default value. I change the LinkDestination value so it matches the innerHTML: <img ... /> => none <a href="source_url"><img ... /></a> => media <a href="attachment_url"><img ... /></a> => attachment <a href="another_url"><img ... /> => custom
4a7a537
to
773d6ec
Compare
Why I always got "Parse error: syntax error, unexpected ',', expecting variable (T_VARIABLE)" when added your code to function.php? |
It's not PHP code, you have to put it inside a JavaScript (.js) file. |
Somewhat related to this is #10173 which is that the image and gallery blocks should respect the |
excuse me, where do I have to put this code? |
This seems to be resolved by #25578. The default setting can now be changed by editing the
|
I want to always link the images in my posts to its source url. This way, users can click on the thumbnail and see the image full size. In Gutenberg's image block, the default setting is not to link the images, so I have to manually change the LinkDestination select for each image I insert in the posts.
Users can change the default value of LinkDestination with a plugin and some JavaScript like this:
The actual code of the Gutenberg's image block doesn't work well when it finds old posts with no LinkDestination attribute, as no attribute means default value, but the new default value isn't the same as the old one.
Description
I've added code to the componentDidMount method of the image block to figure out which is the right value for the LinkDestination attribute based on the innerHTML. This work is based on @SeanDS pull request #13797 and closes issue #13749.
How has this been tested?
I used the latest development release of Gutenberg (cloned at 313974f), and WordPress 5.1, using docker images. I used the plugin showed above to change the default link target to media. I added several images with different LinkDestination values and I edited again after disabling the plugin.
This change doesn't affect other areas of the code.
Types of changes
Bug fix (non-breaking change which fixes an issue)
Checklist:
[ X] My code is tested.
[ X] My code follows the WordPress code style.
[ X] My code follows the accessibility standards.
[ X] My code has proper inline documentation.
[ X] I've included developer documentation if appropriate.