How do I add two customized fields to photographs to permit me to place in textual content for supply title instance: Shutterstock
after which hyperlink that textual content to the second customized subject URL subject instance: shutterstock.com
Some options on the market do not work or are outdated.
add_filter( ‘attachment_fields_to_edit’, ‘ac_add_image_source’, 10, 2 );
perform ac_add_image_source( $form_fields, $submit ) {
$form_fields['source_name'] = array(
'label' => __('Supply Identify'),
'enter' => 'textual content',
'worth' => get_post_meta( $post->ID, '_wp_attachment_source_name', true ),
'helps' => __('Add the title of the picture supply'),
);
$form_fields['source_url'] = array(
'label' => __('Supply URL'),
'enter' => 'textual content',
'worth' => get_post_meta( $post->ID, '_wp_attachment_source_url', true ),
'helps' => __('Add the URL the place the unique picture was posted'),
);
return $form_fields;
}
/**
* Save credit score fields
*
*/
add_filter( ‘attachment_fields_to_save’, ‘ac_save_image_source’, 10 , 2 );
perform ac_save_image_source( $submit, $attachment ) {
if ( isset( $attachment['source_name'] ) ) {
$source_name = get_post_meta( $submit['ID'], '_wp_attachment_source_name', true );
if ( $source_name != esc_attr( $attachment['source_name'] ) ) {
if ( empty( $attachment['source_name'] ) )
delete_post_meta( $submit['ID'], '_wp_attachment_source_name' );
else
update_post_meta( $submit['ID'], '_wp_attachment_source_name', esc_attr( $attachment['source_name'] ) );
}
}
if ( isset( $attachment['source_url'] ) ) {
$source_name = get_post_meta( $submit['ID'], '_wp_attachment_source_url', true );
if ( $source_name != esc_attr( $attachment['source_url'] ) ) {
if ( empty( $attachment['source_url'] ) )
delete_post_meta( $submit['ID'], '_wp_attachment_source_url' );
else
update_post_meta( $submit['ID'], '_wp_attachment_source_url', esc_attr( $attachment['source_url'] ) );
}
}
return $submit;
}