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

Pass title attribute when uploading an image #8955

Merged
merged 1 commit into from Aug 21, 2018

Conversation

Projects
None yet
3 participants
@WPprodigy
Contributor

WPprodigy commented Aug 14, 2018

Description

Fixes #8902 by passing along an image title during the upload.

How has this been tested?

Steps to test:

  1. Upload a new image to the GB image block called image name.png.
  2. Notice the title is now image-name.
  3. Apply patch and upload a new image called another image.png.
  4. Notice the title is now correctly another image.

Screenshots

Before: http://cld.wthms.co/QJgKc8
After: http://cld.wthms.co/N2IhcF

Types of changes

The title will be the file's name (ex file name.jpg) if it exists, except with the extension and period removed. If the file name does not exist (an edge case shown in the line above), then it will pass image/png for example, except a period substituted for the slash as done on line 161.

The regex for removing the extension is the same used in WP core https://github.com/WordPress/WordPress/blob/aab929b8d619bde14495a97cdc1eb7bdf1f1d487/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php#L143 and https://github.com/WordPress/WordPress/blob/acd3f4cb10675c35b7532f123bc4ddb871d35ff1/wp-admin/includes/media.php#L436

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
@jorgefilipecosta

This PR seems to work correctly in my tests. The title now matches the one used when uploading the file using the media library. I think this can be merged after the release.
Thank you for your contributions @WPprodigy!

@danielbachhuber danielbachhuber added this to the 3.7 milestone Aug 17, 2018

@jorgefilipecosta jorgefilipecosta merged commit e2f3120 into WordPress:master Aug 21, 2018

2 checks passed

codecov/project 50.59% (-0.01%) compared to acef68f
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment