-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #164 from PRX/fix-image-credit
Add ACF Credit Field and display credits on images
- Loading branch information
Showing
8 changed files
with
186 additions
and
220 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 0 additions & 63 deletions
63
wp-content/plugins/pri-external-attachment/acf-json/group_62b485f48c100.json
This file was deleted.
Oops, something went wrong.
44 changes: 0 additions & 44 deletions
44
wp-content/plugins/pri-external-attachment/acf-json/group_62d671b9ba699.json
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
/** | ||
* Plugin Name: TW Image Credit | ||
* Plugin URI: https://www.dinkuminteractive.com/ | ||
* Description: Add image credit and credit field. | ||
* Version: 1.0.0 | ||
*/ | ||
|
||
/** | ||
* Adds the images media credit to rendered `core/image` blocks. | ||
* | ||
* @param string $block_content The block content about to be appended. | ||
* @param mixed[] $block The full block, including name and attributes. | ||
* | ||
* @return string | ||
* | ||
* @phpstan-param BlockMetaData $block | ||
*/ | ||
function tw_add_media_credit_to_image_blocks( $block_content, array $block ) { | ||
|
||
// We only target standard images, and only when the credits are not displayed after the post content. | ||
if ( 'core/image' !== $block['blockName'] || ! isset( $block['attrs']['id'] ) || stripos( $block_content, 'class="media-credit"' ) ) { | ||
return $block_content; | ||
} | ||
|
||
// Get attachment credit using the block id. | ||
$attachment_credit = get_post_meta( $block['attrs']['id'], '_media_credit', true ); | ||
if ( empty( $attachment_credit ) ) { | ||
// Not a valid attachment, let's bail. | ||
return $block_content; | ||
} | ||
|
||
// Filter if needed. | ||
$block_content = apply_filters( 'tw_add_media_credit_to_image_blocks', $block_content, $attachment_credit ); | ||
|
||
return $block_content; | ||
} | ||
add_filter( 'render_block', 'tw_add_media_credit_to_image_blocks', 10, 2 ); | ||
|
||
/** | ||
* Injects the credit into the caption markup of a `core/image` block. | ||
* | ||
* @param string $block_content The block content. | ||
* @param string $credit The credit markup. | ||
* | ||
* @return string | ||
*/ | ||
function tw_inject_credit_into_caption( $block_content, $credit ) { | ||
|
||
// If we have a credit, inject it into the caption markup. | ||
if ( $credit ) { | ||
|
||
// Replacement parts. | ||
$pattern = '</figcaption>'; | ||
$open = '<span class="media-credit">'; | ||
$credit = trim( $credit ); | ||
$close = '</span>'; | ||
|
||
// Inject the credit into the caption markup. | ||
$block_content = str_replace( $pattern, "{$open}{$credit}{$close}{$pattern}", $block_content ); | ||
} | ||
|
||
// Return the modified block content. | ||
return $block_content; | ||
} | ||
add_filter( 'tw_add_media_credit_to_image_blocks', 'tw_inject_credit_into_caption', 10, 2 ); |
44 changes: 0 additions & 44 deletions
44
wp-content/themes/the-world/acf-json/group_622a629eb83b7.json
This file was deleted.
Oops, something went wrong.
132 changes: 68 additions & 64 deletions
132
wp-content/themes/the-world/acf-json/group_62b485f48c100.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,69 @@ | ||
{ | ||
"key": "group_62b485f48c100", | ||
"title": "File Meta - Migration", | ||
"fields": [ | ||
{ | ||
"key": "field_62b4862efaff1", | ||
"label": "Original URI", | ||
"name": "original_uri", | ||
"aria-label": "", | ||
"type": "text", | ||
"instructions": "", | ||
"required": 0, | ||
"conditional_logic": 0, | ||
"wrapper": { | ||
"width": "", | ||
"class": "", | ||
"id": "" | ||
}, | ||
"default_value": "", | ||
"placeholder": "", | ||
"prepend": "", | ||
"append": "", | ||
"maxlength": "" | ||
}, | ||
{ | ||
"key": "field_62b48652faff2", | ||
"label": "Drupal ID", | ||
"name": "fid", | ||
"aria-label": "", | ||
"type": "text", | ||
"instructions": "", | ||
"required": 0, | ||
"conditional_logic": 0, | ||
"wrapper": { | ||
"width": "", | ||
"class": "", | ||
"id": "" | ||
}, | ||
"default_value": "", | ||
"placeholder": "", | ||
"prepend": "", | ||
"append": "", | ||
"maxlength": "" | ||
} | ||
], | ||
"location": [ | ||
[ | ||
{ | ||
"param": "attachment", | ||
"operator": "==", | ||
"value": "all" | ||
} | ||
] | ||
], | ||
"menu_order": 999, | ||
"position": "normal", | ||
"style": "default", | ||
"label_placement": "top", | ||
"instruction_placement": "label", | ||
"hide_on_screen": "", | ||
"active": true, | ||
"description": "", | ||
"show_in_rest": 0, | ||
"modified": 1684260351 | ||
} | ||
"key": "group_62b485f48c100", | ||
"title": "File Meta - Migration", | ||
"fields": [ | ||
{ | ||
"key": "field_62b4862efaff1", | ||
"label": "Original URI", | ||
"name": "original_uri", | ||
"aria-label": "", | ||
"type": "text", | ||
"instructions": "", | ||
"required": 0, | ||
"conditional_logic": 0, | ||
"wrapper": { | ||
"width": "", | ||
"class": "", | ||
"id": "" | ||
}, | ||
"default_value": "", | ||
"placeholder": "", | ||
"prepend": "", | ||
"append": "", | ||
"maxlength": "" | ||
}, | ||
{ | ||
"key": "field_62b48652faff2", | ||
"label": "Drupal ID", | ||
"name": "fid", | ||
"aria-label": "", | ||
"type": "text", | ||
"instructions": "", | ||
"required": 0, | ||
"conditional_logic": 0, | ||
"wrapper": { | ||
"width": "", | ||
"class": "", | ||
"id": "" | ||
}, | ||
"default_value": "", | ||
"placeholder": "", | ||
"prepend": "", | ||
"append": "", | ||
"maxlength": "" | ||
} | ||
], | ||
"location": [ | ||
[ | ||
{ | ||
"param": "attachment", | ||
"operator": "==", | ||
"value": "all" | ||
} | ||
] | ||
], | ||
"menu_order": 10, | ||
"position": "normal", | ||
"style": "seamless", | ||
"label_placement": "top", | ||
"instruction_placement": "label", | ||
"hide_on_screen": "", | ||
"active": true, | ||
"description": "", | ||
"show_in_rest": 0, | ||
"show_in_graphql": 0, | ||
"graphql_field_name": "fileMeta", | ||
"map_graphql_types_from_location_rules": 0, | ||
"graphql_types": "", | ||
"modified": 1709041316 | ||
} |
Oops, something went wrong.