From c9dde3fdad20330038f2e9f681dcac8e11102ed5 Mon Sep 17 00:00:00 2001 From: Memo Date: Thu, 22 Feb 2024 19:26:21 -0300 Subject: [PATCH 1/3] Add ACF Credit Field and display credits on images --- .../configs/global/global-plugins.php | 1 + .../tw-image-credit/tw-image-credit.php | 69 +++++++++++++++++++ .../acf-json/group_65cdf8ec2d27d.json | 50 ++++++++++++++ 3 files changed, 120 insertions(+) create mode 100644 wp-content/plugins/tw-image-credit/tw-image-credit.php create mode 100644 wp-content/themes/the-world/acf-json/group_65cdf8ec2d27d.json diff --git a/wp-content/mu-plugins/the-world-site-config/configs/global/global-plugins.php b/wp-content/mu-plugins/the-world-site-config/configs/global/global-plugins.php index 01f64a29d..6a124444a 100644 --- a/wp-content/mu-plugins/the-world-site-config/configs/global/global-plugins.php +++ b/wp-content/mu-plugins/the-world-site-config/configs/global/global-plugins.php @@ -27,6 +27,7 @@ 'tw-episode-importer/tw-episode-importer.php', 'tw-episodes/tw-episodes.php', 'tw-graphql/tw-graphql.php', + 'tw-image-credit/tw-image-credit.php', 'tw-import-post-types/tw-import-post-types.php', // This is the plugin that creates the custom post types for the import. Can be removed after the import is complete. 'tw-media/tw-media.php', 'tw-menus/tw-menus.php', diff --git a/wp-content/plugins/tw-image-credit/tw-image-credit.php b/wp-content/plugins/tw-image-credit/tw-image-credit.php new file mode 100644 index 000000000..83fea3195 --- /dev/null +++ b/wp-content/plugins/tw-image-credit/tw-image-credit.php @@ -0,0 +1,69 @@ +ID, '_media_credit', true ); + + // 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 = ''; + $open = ''; + $credit = trim( $credit ); + $close = ''; + + // Inject the credit into the caption markup. + $block_content = str_replace( $pattern, "{$pattern}{$open}{$credit}{$close}", $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 ); diff --git a/wp-content/themes/the-world/acf-json/group_65cdf8ec2d27d.json b/wp-content/themes/the-world/acf-json/group_65cdf8ec2d27d.json new file mode 100644 index 000000000..9ca25b0a7 --- /dev/null +++ b/wp-content/themes/the-world/acf-json/group_65cdf8ec2d27d.json @@ -0,0 +1,50 @@ +{ + "key": "group_65cdf8ec2d27d", + "title": "Image Credit", + "fields": [ + { + "key": "field_65cdf8ee238b7", + "label": "Image Credit", + "name": "_media_credit", + "aria-label": "", + "type": "text", + "instructions": "", + "required": 0, + "conditional_logic": 0, + "wrapper": { + "width": "", + "class": "", + "id": "" + }, + "show_in_graphql": 1, + "default_value": "", + "maxlength": "", + "placeholder": "", + "prepend": "", + "append": "" + } + ], + "location": [ + [ + { + "param": "attachment", + "operator": "==", + "value": "all" + } + ] + ], + "menu_order": 0, + "position": "normal", + "style": "default", + "label_placement": "top", + "instruction_placement": "label", + "hide_on_screen": "", + "active": true, + "description": "", + "show_in_rest": 0, + "show_in_graphql": 0, + "graphql_field_name": "imageCredit", + "map_graphql_types_from_location_rules": 0, + "graphql_types": "", + "modified": 1707997512 +} From bd2ac0491e89146ac1ecd275284162a0d975c907 Mon Sep 17 00:00:00 2001 From: Memo Date: Thu, 22 Feb 2024 20:13:01 -0300 Subject: [PATCH 2/3] Add media-credit class to the credits span tag --- wp-content/plugins/tw-image-credit/tw-image-credit.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 83fea3195..cf72c341f 100644 --- a/wp-content/plugins/tw-image-credit/tw-image-credit.php +++ b/wp-content/plugins/tw-image-credit/tw-image-credit.php @@ -55,7 +55,7 @@ function tw_inject_credit_into_caption( $block_content, $credit ) { // Replacement parts. $pattern = ''; - $open = ''; + $open = ''; $credit = trim( $credit ); $close = ''; From e4238f7b58bbbfc622629f575fe8fcd5853a32c4 Mon Sep 17 00:00:00 2001 From: Memo Date: Thu, 29 Feb 2024 11:57:51 -0300 Subject: [PATCH 3/3] Improve image credit feature and organize ACF fields --- .../acf-json/group_62b485f48c100.json | 63 --------- .../acf-json/group_62d671b9ba699.json | 44 ------ .../admin/includes/acf-fix-helper.php | 1 + .../tw-image-credit/tw-image-credit.php | 13 +- .../acf-json/group_622a629eb83b7.json | 44 ------ .../acf-json/group_62b485f48c100.json | 132 +++++++++--------- .../acf-json/group_62d671b9ba699.json | 55 +++++++- .../acf-json/group_65cdf8ec2d27d.json | 50 ------- 8 files changed, 124 insertions(+), 278 deletions(-) delete mode 100644 wp-content/plugins/pri-external-attachment/acf-json/group_62b485f48c100.json delete mode 100644 wp-content/plugins/pri-external-attachment/acf-json/group_62d671b9ba699.json delete mode 100644 wp-content/themes/the-world/acf-json/group_622a629eb83b7.json delete mode 100644 wp-content/themes/the-world/acf-json/group_65cdf8ec2d27d.json diff --git a/wp-content/plugins/pri-external-attachment/acf-json/group_62b485f48c100.json b/wp-content/plugins/pri-external-attachment/acf-json/group_62b485f48c100.json deleted file mode 100644 index e46f0cbba..000000000 --- a/wp-content/plugins/pri-external-attachment/acf-json/group_62b485f48c100.json +++ /dev/null @@ -1,63 +0,0 @@ -{ - "key": "group_62b485f48c100", - "title": "File Meta", - "fields": [ - { - "key": "field_62b4862efaff1", - "label": "Original URI", - "name": "original_uri", - "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", - "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": 0, - "position": "normal", - "style": "default", - "label_placement": "top", - "instruction_placement": "label", - "hide_on_screen": "", - "active": true, - "description": "", - "show_in_rest": 0, - "modified": 1658220935 -} \ No newline at end of file diff --git a/wp-content/plugins/pri-external-attachment/acf-json/group_62d671b9ba699.json b/wp-content/plugins/pri-external-attachment/acf-json/group_62d671b9ba699.json deleted file mode 100644 index 8695c03fc..000000000 --- a/wp-content/plugins/pri-external-attachment/acf-json/group_62d671b9ba699.json +++ /dev/null @@ -1,44 +0,0 @@ -{ - "key": "group_62d671b9ba699", - "title": "File Image Meta", - "fields": [ - { - "key": "field_62d671c653456", - "label": "Image Title", - "name": "image_title", - "type": "text", - "instructions": "", - "required": 0, - "conditional_logic": 0, - "wrapper": { - "width": "", - "class": "", - "id": "" - }, - "default_value": "", - "placeholder": "", - "prepend": "", - "append": "", - "maxlength": "" - } - ], - "location": [ - [ - { - "param": "attachment", - "operator": "==", - "value": "image" - } - ] - ], - "menu_order": 0, - "position": "normal", - "style": "default", - "label_placement": "top", - "instruction_placement": "label", - "hide_on_screen": "", - "active": true, - "description": "", - "show_in_rest": 0, - "modified": 1658221035 -} \ No newline at end of file diff --git a/wp-content/plugins/pri-migration-helper/admin/includes/acf-fix-helper.php b/wp-content/plugins/pri-migration-helper/admin/includes/acf-fix-helper.php index 59ce4fc6b..73f5d33cb 100644 --- a/wp-content/plugins/pri-migration-helper/admin/includes/acf-fix-helper.php +++ b/wp-content/plugins/pri-migration-helper/admin/includes/acf-fix-helper.php @@ -78,6 +78,7 @@ function pri_get_post_meta_keys_and_values( $type = null, $field = null ) { '_fid' => 'field_62b48652faff2', '_image_title' => 'field_62d671c653456', '_hide_image' => 'field_622a6312b1b5d', + '__media_credit' => 'field_65cdf8ee238b7', ), 'audio' => array( '_original_uri' => 'field_62b4862efaff1', 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 cf72c341f..fbcb952f0 100644 --- a/wp-content/plugins/tw-image-credit/tw-image-credit.php +++ b/wp-content/plugins/tw-image-credit/tw-image-credit.php @@ -19,20 +19,17 @@ 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'] ) ) { + if ( 'core/image' !== $block['blockName'] || ! isset( $block['attrs']['id'] ) || stripos( $block_content, 'class="media-credit"' ) ) { return $block_content; } - // Retrieve image. - $attachment = get_post( $block['attrs']['id'] ); - if ( empty( $attachment ) ) { + // 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; } - // Get attachment credit. - $attachment_credit = get_post_meta( $attachment->ID, '_media_credit', true ); - // Filter if needed. $block_content = apply_filters( 'tw_add_media_credit_to_image_blocks', $block_content, $attachment_credit ); @@ -60,7 +57,7 @@ function tw_inject_credit_into_caption( $block_content, $credit ) { $close = ''; // Inject the credit into the caption markup. - $block_content = str_replace( $pattern, "{$pattern}{$open}{$credit}{$close}", $block_content ); + $block_content = str_replace( $pattern, "{$open}{$credit}{$close}{$pattern}", $block_content ); } // Return the modified block content. diff --git a/wp-content/themes/the-world/acf-json/group_622a629eb83b7.json b/wp-content/themes/the-world/acf-json/group_622a629eb83b7.json deleted file mode 100644 index 8c1642120..000000000 --- a/wp-content/themes/the-world/acf-json/group_622a629eb83b7.json +++ /dev/null @@ -1,44 +0,0 @@ -{ - "key": "group_622a629eb83b7", - "title": "Image Fields", - "fields": [ - { - "key": "field_622a6312b1b5d", - "label": "Hide Image", - "name": "hide_image", - "type": "true_false", - "instructions": "Hide image when we are not sure we have the rights to use it. Once usage rights have been determined or acquired, deselect this option.", - "required": 0, - "conditional_logic": 0, - "wrapper": { - "width": "", - "class": "", - "id": "" - }, - "message": "", - "default_value": 0, - "ui": 0, - "ui_on_text": "", - "ui_off_text": "" - } - ], - "location": [ - [ - { - "param": "attachment", - "operator": "==", - "value": "image" - } - ] - ], - "menu_order": 0, - "position": "normal", - "style": "seamless", - "label_placement": "left", - "instruction_placement": "label", - "hide_on_screen": "", - "active": true, - "description": "", - "show_in_rest": 1, - "modified": 1648154104 -} \ No newline at end of file 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 c4b74fd15..58610cb6f 100644 --- a/wp-content/themes/the-world/acf-json/group_62b485f48c100.json +++ b/wp-content/themes/the-world/acf-json/group_62b485f48c100.json @@ -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 -} \ No newline at end of file + "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 +} 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 9140901b6..8846c7e28 100644 --- a/wp-content/themes/the-world/acf-json/group_62d671b9ba699.json +++ b/wp-content/themes/the-world/acf-json/group_62d671b9ba699.json @@ -1,6 +1,6 @@ { "key": "group_62d671b9ba699", - "title": "File Image Meta", + "title": "Image Fields", "fields": [ { "key": "field_62d671c653456", @@ -21,6 +21,47 @@ "prepend": "", "append": "", "maxlength": "" + }, + { + "key": "field_622a6312b1b5d", + "label": "Hide Image", + "name": "hide_image", + "aria-label": "", + "type": "true_false", + "instructions": "Hide image when we are not sure we have the rights to use it. Once usage rights have been determined or acquired, deselect this option.", + "required": 0, + "conditional_logic": 0, + "wrapper": { + "width": "", + "class": "", + "id": "" + }, + "message": "", + "default_value": 0, + "ui": 0, + "ui_on_text": "", + "ui_off_text": "" + }, + { + "key": "field_65cdf8ee238b7", + "label": "Image Credit", + "name": "_media_credit", + "aria-label": "", + "type": "text", + "instructions": "", + "required": 0, + "conditional_logic": 0, + "wrapper": { + "width": "", + "class": "", + "id": "" + }, + "show_in_graphql": 1, + "default_value": "", + "maxlength": "", + "placeholder": "", + "prepend": "", + "append": "" } ], "location": [ @@ -32,7 +73,7 @@ } ] ], - "menu_order": 0, + "menu_order": 5, "position": "normal", "style": "default", "label_placement": "top", @@ -40,6 +81,10 @@ "hide_on_screen": "", "active": true, "description": "", - "show_in_rest": 1, - "modified": 1684260287 -} \ No newline at end of file + "show_in_rest": 0, + "show_in_graphql": 1, + "graphql_field_name": "imageFields", + "map_graphql_types_from_location_rules": 0, + "graphql_types": "", + "modified": 1709042362 +} diff --git a/wp-content/themes/the-world/acf-json/group_65cdf8ec2d27d.json b/wp-content/themes/the-world/acf-json/group_65cdf8ec2d27d.json deleted file mode 100644 index 9ca25b0a7..000000000 --- a/wp-content/themes/the-world/acf-json/group_65cdf8ec2d27d.json +++ /dev/null @@ -1,50 +0,0 @@ -{ - "key": "group_65cdf8ec2d27d", - "title": "Image Credit", - "fields": [ - { - "key": "field_65cdf8ee238b7", - "label": "Image Credit", - "name": "_media_credit", - "aria-label": "", - "type": "text", - "instructions": "", - "required": 0, - "conditional_logic": 0, - "wrapper": { - "width": "", - "class": "", - "id": "" - }, - "show_in_graphql": 1, - "default_value": "", - "maxlength": "", - "placeholder": "", - "prepend": "", - "append": "" - } - ], - "location": [ - [ - { - "param": "attachment", - "operator": "==", - "value": "all" - } - ] - ], - "menu_order": 0, - "position": "normal", - "style": "default", - "label_placement": "top", - "instruction_placement": "label", - "hide_on_screen": "", - "active": true, - "description": "", - "show_in_rest": 0, - "show_in_graphql": 0, - "graphql_field_name": "imageCredit", - "map_graphql_types_from_location_rules": 0, - "graphql_types": "", - "modified": 1707997512 -}