Skip to content
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

Allow to fetch custom meta fields for uploaded images. #22

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from

Conversation

Nube2021
Copy link

@Nube2021 Nube2021 commented Mar 3, 2017

Some Wordpress plugins allow the user in the backend to add some extra
meta information to an image. For instance, the plugin „WP Gallery
Custom Links“ allows to add a custom url, a css class and other
information to an image. This commit adds a function to the Image Field
class with which it is possible to fetch these custom meta fields. The
function is called „fetchCustomMetaValues“ and receives as input a comma
separated list or an array with the meta keys names that should be
fetched.

Testing was included with the function „testImageCustomMetadataValues“
in ContentFieldsTest.php. The database was updated and includes now
images with some extra meta fields. Here are the results of the tests:

$ ./vendor/bin/phpunit --filter
{ContentFieldsTest::testImageCustomMetadataValues}
PHPUnit 4.2.2 by Sebastian Bergmann.

Configuration read from ……/phpunit.xml

.

Time: 167 ms, Memory: 6.00MB

OK (1 test, 6 assertions)

Nube2021 and others added 7 commits March 3, 2017 11:31
Some Wordpress plugins allow the user in the backend to add some extra
meta information to an image. For instance, the plugin „WP Gallery
Custom Links“ allows to add a custom url, a css class and other
information to an image. This commit adds a function to the Image Field
class with which it is possible to fetch these custom meta fields. The
function is called „fetchCustomMetaValues“ and receives as input a comma
separated list or an array with the meta keys names that should be
fetched.

Testing was included with the function „testImageCustomMetadataValues“
in ContentFieldsTest.php. The database was updated and includes now
images with some extra meta fields. Here are the results of the tests:

$ ./vendor/bin/phpunit --filter
{ContentFieldsTest::testImageCustomMetadataValues}
PHPUnit 4.2.2 by Sebastian Bergmann.

Configuration read from ……/phpunit.xml

.

Time: 167 ms, Memory: 6.00MB

OK (1 test, 6 assertions)
$customMetaValues = [];

foreach ($metaKeys as $metaKey) {
$customMetaValues[] = $this->attachment->meta->{trim($metaKey)};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you check how many queries are you doing here?

*
* @return string|array string if only one meta key was received as input, otherwise an array with the values of all meta keys received as input
*/
public function fetchCustomMetadataValues($metaKeys)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it would be better to create a metadata method passing or just 1 string or an array of metadata fields to be returned.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this metadata method should be another method, and then refactor fetchCustomMetadataValues() one to accept both parameters.

@@ -116,6 +122,10 @@ protected function fillThumbnailFields(array $data)
$size->height = $data['height'];
$size->mime_type = $data['mime-type'];

$imgDir = substr($this->url, 0, strrpos($this->url, '/'));
$size->url = $imgDir.'/'.$data['file'];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not being tested. If you can please write a test. I guess no fields are being tested, so if you can please test all of them.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two lines weren't intended to be included. I included them by mistake. I have already removed them.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants