1) Aggiungere un tab
//Assegnare un nome al tab
function upload_test_media_menu($tabs) {
$tabs['test_upload']='Test Upload';
return $tabs;
}
//Needed script to make sure wordpresses media upload scripts are inplace
wp_enqueue_script('media-upload');
//Adds your tab to the media upload button
add_filter('media_upload_tabs', 'upload_test_media_menu');
2) Aggiungere un field
function my_add_attachment_location_field( $form_fields, $post ) {
$field_value = get_post_meta( $post->ID, 'location', true );
$form_fields['location'] = array(
'value' => $field_value ? $field_value : '',
'label' => __( 'Location' ),
'helps' => __( 'Set a location for this attachment' )
);
return $form_fields;
}
add_filter( 'attachment_fields_to_edit', 'my_add_attachment_location_field', 10, 2 );
function my_save_attachment_location( $attachment_id ) {
if ( isset( $_REQUEST['attachments'][$attachment_id]['location'] ) ) {
$location = $_REQUEST['attachments'][$attachment_id]['location'];
update_post_meta( $attachment_id, 'location', $location );
}
}
add_action( 'edit_attachment', 'my_save_attachment_location' );
Nessun commento:
Posta un commento