Skip to content
This repository has been archived by the owner on Oct 12, 2021. It is now read-only.

feat: add settings page, and show placeholder if no credit #9

Merged
merged 10 commits into from
Aug 25, 2021

Conversation

dkoo
Copy link
Contributor

@dkoo dkoo commented Aug 23, 2021

Adds a new settings page for Image Credits options under the WP Admin > Settings > Media menu (placed there because this plugin has no dependencies on other Newspack products). New options available:

  • Image Credit Class Name: Lets you set the CSS class name given to the span that wraps image credit strings. This defaults to image-credit, which was previously hard-coded, so it shouldn't change behavior for sites that are already using the plugin.
  • Image Credit Label: Lets you change the label printed before image credits. This defaults to Credit: , which was previously hard-coded, so it shouldn't change behavior for sites that are already using the plugin.
  • Placeholder Image: Lets you choose an image from the media library to be displayed in place of any image that lacks a credit. This should help publishers avoid legal trouble in the event of messy migrations that fail to bring over all credit data. Will work for featured images, core/image blocks, and jetpack/slideshow blocks.

Screen Shot 2021-08-23 at 2 05 44 PM

Note: The options have been moved to the Media settings page instead of living in their own standalone page.

To test:

  1. The first two options (class name and label) are straightforward: test with the default options, then with updated options, and then with empty options. Verify that the settings are respected on the front-end for all three contexts (featured image, core image block, Jetpack slideshow block).
  2. For the placeholder image, first verify that without choosing any image, behavior is unchanged. Images are rendered as usual with or without a credit.
  3. Choose a placeholder image from the Media Library, then save.
  4. Now verify that any images that lack a credit are replaced by the chosen placeholder image (just the image, not the caption or anything else having to do with the image) in all contexts.
  5. Add a credit to images that are missing them and verify that after a refresh, the images render instead of the placeholder.
  6. Remove the placeholder in settings, save, and verify that all images behave as usual.

@dkoo dkoo added the enhancement New feature or request label Aug 23, 2021
@dkoo dkoo requested a review from a team August 23, 2021 20:20
@dkoo dkoo self-assigned this Aug 23, 2021
@dkoo dkoo linked an issue Aug 23, 2021 that may be closed by this pull request
@dkoo
Copy link
Contributor Author

dkoo commented Aug 23, 2021

Also adds a newspack_image_credits_media_credit filter on the credits data output, as suggested by @benlk.

Copy link
Member

@miguelpeixe miguelpeixe left a comment

Choose a reason for hiding this comment

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

It's working great! Crazy to see all my images being replaced for a placeholder 😅

I've left some comments for small adjustments and there's also a tiny but very annoying UX detail: when I write the credit name to the image, I then press tab to start writing the next field. This action fires a save action and after it succeeds the field I'm writing loses focus and I start triggering keyboard shortcuts 😆 . I don't know why this happens only to the image credits fields.

[
'description' => __( 'A label to prefix all image credits. Leave blank to display no prefix.', 'newspack-image-credits' ),
'key' => 'newspack_image_credits_prefix_label',
'label' => __( 'Image Credit Label', 'newpack-listings' ),
Copy link
Member

Choose a reason for hiding this comment

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

Need to change the domain from newspack-listing to newspack-image-credits

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Whoops! Updated in fcc3699

[
'description' => __( 'A placeholder image to be displayed in place of images without credits. If none is chosen, the image will be displayed normally whether or not it has a credit.', 'newspack-image-credits' ),
'key' => 'newspack_image_credits_placeholder',
'label' => __( 'Placeholder Image', 'newpack-listings' ),
Copy link
Member

Choose a reason for hiding this comment

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

Need to change the domain from newspack-listing to newspack-image-credits

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Whoops! Updated in fcc3699

*/
public static function add_media_credit( $fields, $post ) {
$credit_info = self::get_media_credit( $post->ID );
$fields['media_credit'] = [
Copy link
Member

Choose a reason for hiding this comment

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

Update indentation from space to tabs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated in fcc3699

package.json Outdated
"prettier": "https://github.com/Automattic/wp-prettier/releases/download/wp-1.16.4/wp-prettier-1.16.4.tgz",
"stylelint": "^13.12.0",
"stylelint-config-prettier": "^8.0.1",
"stylelint-config-wordpress": "^17.0.0",
Copy link
Member

@miguelpeixe miguelpeixe Aug 24, 2021

Choose a reason for hiding this comment

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

Non-blocking: stylelint-config-wordpress has been deprecated in favor of @wordpress/stylelint-config. Should we start using the maintained package?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated in 1fcfcbe

@dkoo dkoo requested a review from miguelpeixe August 24, 2021 22:40
@dkoo
Copy link
Contributor Author

dkoo commented Aug 24, 2021

when I write the credit name to the image, I then press tab to start writing the next field. This action fires a save action and after it succeeds the field I'm writing loses focus and I start triggering keyboard shortcuts 😆 . I don't know why this happens only to the image credits fields.

@miguelpeixe I'm also not sure why this is, but the fields are added using the attachment_fields_to_edit and attachment_fields_to_save filter hooks. I don't see any options available here to change focus/blur behavior.

Copy link
Member

@miguelpeixe miguelpeixe left a comment

Choose a reason for hiding this comment

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

It's probably a core issue. Thank you for the updates! 💯

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Show placeholder image if no credit
2 participants