diff --git a/README.md b/README.md
index a2b15f7..e9637b4 100644
--- a/README.md
+++ b/README.md
@@ -24,6 +24,9 @@ Utilities, custom post types and blocks for the Platform Cooperativism Consortiu
None yet.
## Changelog ##
+### 0.7.0 ###
+* Add fields for image and video attribution (#32): #33
+
### 0.6.0 ###
* Rename plugin: #16
* Add configuration for automatic deployment: #18
diff --git a/lib/posttypes/pcc-attachment.php b/lib/posttypes/pcc-attachment.php
new file mode 100644
index 0000000..9075826
--- /dev/null
+++ b/lib/posttypes/pcc-attachment.php
@@ -0,0 +1,83 @@
+ID, $prefix . 'creator_name', true);
+ $creator_link = get_post_meta($post->ID, $prefix . 'creator_link', true);
+ $organization_name = get_post_meta($post->ID, $prefix . 'organization_name', true);
+ $organization_link = get_post_meta($post->ID, $prefix . 'organization_link', true);
+
+ $form_fields[$prefix . 'creator_name'] = [
+ 'value' => $creator_name ?? '',
+ 'label' => __('Creator Name', 'pcc-framework'),
+ 'input' => 'text',
+ 'helps' => __('The name of the person who created this image or video.', 'pcc-framework'),
+ ];
+ $form_fields[$prefix . 'creator_link'] = [
+ 'value' => $creator_link ?? '',
+ 'label' => __('Creator Link', 'pcc-framework'),
+ 'input' => 'html',
+ 'helps' => __('A hyperlink to the website of the person who created this image or video.', 'pcc-framework'),
+ 'html' => sprintf(
+ '',
+ "attachments-$post->ID-{$prefix}creator_link",
+ "attachments[$post->ID][{$prefix}creator_link]",
+ esc_url($creator_link),
+ ),
+ ];
+ $form_fields[$prefix . 'organization_name'] = [
+ 'value' => $organization_name ?? '',
+ 'label' => __('Organization Name', 'pcc-framework'),
+ 'input' => 'text',
+ 'helps' => __('The name of the organization who created this image or video.', 'pcc-framework'),
+ ];
+ $form_fields[$prefix . 'organization_link'] = [
+ 'value' => $organization_link ?? '',
+ 'label' => __('Organization Link', 'pcc-framework'),
+ 'input' => 'html',
+ 'helps' =>
+ __('A hyperlink to the website of the organization who created this image or video.', 'pcc-framework'),
+ 'html' =>sprintf(
+ '',
+ "attachments-$post->ID-{$prefix}organization_link",
+ "attachments[$post->ID][{$prefix}organization_link]",
+ esc_url($organization_link),
+ ),
+ ];
+
+
+ return $form_fields;
+}
+
+/**
+ * Handle saving attachment data.
+ *
+ * @param int $post_id
+ */
+function save($post_id)
+{
+ $prefix = 'pcc_attachment_';
+ $fields = [
+ $prefix . 'creator_name' => 'sanitize_text_field',
+ $prefix . 'creator_link' => 'esc_url',
+ $prefix . 'organization_name' => 'sanitize_text_field',
+ $prefix . 'organization_link' => 'esc_url',
+ ];
+
+ $data = [];
+
+ foreach ($fields as $key => $cb) {
+ if (isset($_REQUEST['attachments'][$post_id][$key])) {
+ $data[ $key ] = $cb($_REQUEST['attachments'][$post_id][$key]);
+ update_post_meta($post_id, $key, $data[ $key ]);
+ }
+ }
+}
diff --git a/pcc-framework.php b/pcc-framework.php
index 86f4be6..3e8b4e7 100644
--- a/pcc-framework.php
+++ b/pcc-framework.php
@@ -33,11 +33,14 @@
}
foreach ([
+ 'attachment',
'event',
'person',
] as $posttype) {
require_once dirname(__FILE__) . "/lib/posttypes/pcc-$posttype.php";
- add_action('init', '\\PCCFramework\\PostTypes\\' . ucfirst($posttype) . '\\init');
+ if ($posttype !== 'attachment') {
+ add_action('init', '\\PCCFramework\\PostTypes\\' . ucfirst($posttype) . '\\init');
+ }
}
foreach ([
@@ -73,4 +76,6 @@
add_action('cmb2_admin_init', '\\PCCFramework\\PostTypes\\Event\\sponsors');
add_action('cmb2_admin_init', '\\PCCFramework\\PostTypes\\Person\\data');
add_action('cmb2_admin_init', '\\PCCFramework\\Settings\\page');
+ add_filter('attachment_fields_to_edit', '\\PCCFramework\\PostTypes\\Attachment\\data', 10, 2);
+ add_action('edit_attachment', '\\PCCFramework\\PostTypes\\Attachment\\save');
}
diff --git a/readme.txt b/readme.txt
index d31fd04..7b43fd4 100644
--- a/readme.txt
+++ b/readme.txt
@@ -24,6 +24,9 @@ Utilities, custom post types and blocks for the Platform Cooperativism Consortiu
None yet.
== Changelog ==
+= 0.7.0 =
+* Add fields for image and video attribution (#32): #33
+
= 0.6.0 =
* Rename plugin: #16
* Add configuration for automatic deployment: #18