From 6904619d0e6cbe2b845d2bde1a1a7d6851a16d54 Mon Sep 17 00:00:00 2001 From: Rick Peterman Date: Tue, 30 Apr 2024 14:30:52 -0500 Subject: [PATCH 1/2] feat(twimagecredit): add image credit link - add image credit url field - update image field groups to display in block editor dialogs - add field descriptions to image fields --- .../tw-image-credit/tw-image-credit.php | 24 +-- .../acf-json/group_62b485f48c100.json | 146 ++++++++++-------- .../acf-json/group_62d671b9ba699.json | 35 ++++- 3 files changed, 121 insertions(+), 84 deletions(-) diff --git a/wp-content/plugins/tw-image-credit/tw-image-credit.php b/wp-content/plugins/tw-image-credit/tw-image-credit.php index fbcb952f0..76af4ca9d 100644 --- a/wp-content/plugins/tw-image-credit/tw-image-credit.php +++ b/wp-content/plugins/tw-image-credit/tw-image-credit.php @@ -4,6 +4,8 @@ * Plugin URI: https://www.dinkuminteractive.com/ * Description: Add image credit and credit field. * Version: 1.0.0 + * + * @package tw-image-credit */ /** @@ -24,14 +26,15 @@ function tw_add_media_credit_to_image_blocks( $block_content, array $block ) { } // Get attachment credit using the block id. - $attachment_credit = get_post_meta( $block['attrs']['id'], '_media_credit', true ); + $attachment_credit = get_post_meta( $block['attrs']['id'], '_media_credit', true ); + $attachment_credit_url = get_post_meta( $block['attrs']['id'], '_media_credit_url', 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 ); + $block_content = apply_filters( 'tw_add_media_credit_to_image_blocks', $block_content, $attachment_credit, $attachment_credit_url ); return $block_content; } @@ -42,25 +45,28 @@ function tw_add_media_credit_to_image_blocks( $block_content, array $block ) { * * @param string $block_content The block content. * @param string $credit The credit markup. + * @param string $url The credit url. * * @return string */ -function tw_inject_credit_into_caption( $block_content, $credit ) { +function tw_inject_credit_into_caption( $block_content, $credit, $url ) { // If we have a credit, inject it into the caption markup. if ( $credit ) { // Replacement parts. - $pattern = ''; - $open = ''; - $credit = trim( $credit ); - $close = ''; + $pattern = ''; + $open = ''; + $credit = trim( $credit ); + $link = "{$credit}"; + $content = $url ? $link : $credit; + $close = ''; // Inject the credit into the caption markup. - $block_content = str_replace( $pattern, "{$open}{$credit}{$close}{$pattern}", $block_content ); + $block_content = str_replace( $pattern, "{$open}{$content}{$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 ); +add_filter( 'tw_add_media_credit_to_image_blocks', 'tw_inject_credit_into_caption', 10, 3 ); diff --git a/wp-content/themes/the-world/acf-json/group_62b485f48c100.json b/wp-content/themes/the-world/acf-json/group_62b485f48c100.json index 58610cb6f..9cf74f175 100644 --- a/wp-content/themes/the-world/acf-json/group_62b485f48c100.json +++ b/wp-content/themes/the-world/acf-json/group_62b485f48c100.json @@ -1,69 +1,81 @@ { - "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 + "key": "group_62b485f48c100", + "title": "File Meta", + "fields": [ + { + "key": "field_62b4862efaff1", + "label": "Original URI", + "name": "original_uri", + "aria-label": "", + "type": "text", + "instructions": "Holds URL to remote file, usually in S3.", + "required": 0, + "conditional_logic": 0, + "wrapper": { + "width": "", + "class": "", + "id": "" + }, + "show_in_graphql": 0, + "default_value": "", + "maxlength": "", + "placeholder": "", + "prepend": "", + "append": "" + }, + { + "key": "field_62b48652faff2", + "label": "Drupal ID", + "name": "fid", + "aria-label": "", + "type": "text", + "instructions": "File ID from Drupal prior to migration.", + "required": 0, + "conditional_logic": 0, + "wrapper": { + "width": "", + "class": "", + "id": "" + }, + "show_in_graphql": 0, + "default_value": "", + "maxlength": "", + "placeholder": "", + "prepend": "", + "append": "" + } + ], + "location": [ + [ + { + "param": "attachment", + "operator": "==", + "value": "all" + }, + { + "param": "current_user_role", + "operator": "==", + "value": "administrator" + }, + { + "param": "user_role", + "operator": "==", + "value": "administrator" + } + ] + ], + "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": 1714496454 } diff --git a/wp-content/themes/the-world/acf-json/group_62d671b9ba699.json b/wp-content/themes/the-world/acf-json/group_62d671b9ba699.json index 8846c7e28..70e28bf40 100644 --- a/wp-content/themes/the-world/acf-json/group_62d671b9ba699.json +++ b/wp-content/themes/the-world/acf-json/group_62d671b9ba699.json @@ -8,7 +8,7 @@ "name": "image_title", "aria-label": "", "type": "text", - "instructions": "", + "instructions": "Provide a human readable title to be used in title attribute of image element. Will show up as a tooltip in most browsers and read by screen readers. Should be short and descriptive, but not as descriptive as the alt text.", "required": 0, "conditional_logic": 0, "wrapper": { @@ -16,11 +16,12 @@ "class": "", "id": "" }, + "show_in_graphql": 1, "default_value": "", - "placeholder": "", + "maxlength": "", + "placeholder": "Example: \"Luke Skywalker Training With Yoda\"", "prepend": "", - "append": "", - "maxlength": "" + "append": "" }, { "key": "field_622a6312b1b5d", @@ -48,7 +49,7 @@ "name": "_media_credit", "aria-label": "", "type": "text", - "instructions": "", + "instructions": "Give credit when credit is due. See image usage agreement for required credit text format.", "required": 0, "conditional_logic": 0, "wrapper": { @@ -62,6 +63,24 @@ "placeholder": "", "prepend": "", "append": "" + }, + { + "key": "field_66311e6ccd8b9", + "label": "Image Credit URL", + "name": "_media_credit_url", + "aria-label": "", + "type": "url", + "instructions": "Provide link back to source as required by image usage agreement.", + "required": 0, + "conditional_logic": 0, + "wrapper": { + "width": "", + "class": "", + "id": "" + }, + "show_in_graphql": 1, + "default_value": "", + "placeholder": "" } ], "location": [ @@ -74,10 +93,10 @@ ] ], "menu_order": 5, - "position": "normal", + "position": "side", "style": "default", "label_placement": "top", - "instruction_placement": "label", + "instruction_placement": "field", "hide_on_screen": "", "active": true, "description": "", @@ -86,5 +105,5 @@ "graphql_field_name": "imageFields", "map_graphql_types_from_location_rules": 0, "graphql_types": "", - "modified": 1709042362 + "modified": 1714499083 } From 44c37a80857318c10fca02a14d06f8b839989b22 Mon Sep 17 00:00:00 2001 From: Rick Peterman Date: Tue, 30 Apr 2024 15:45:12 -0500 Subject: [PATCH 2/2] fix(theme): update selector to hide unused preview menu buttons --- wp-content/themes/the-world/functions.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/wp-content/themes/the-world/functions.php b/wp-content/themes/the-world/functions.php index 71c9bf5ad..462111d6f 100644 --- a/wp-content/themes/the-world/functions.php +++ b/wp-content/themes/the-world/functions.php @@ -65,14 +65,14 @@ function tw_allowed_redirect_hosts( $hosts ) { function tw_admin_styles() { // Fixes layout heights of some accordion containers after WP 6.3 update. echo ''; // Hides device options from preview menu dropdown. They are basically useless and confusing. echo ''; } endif;