tonytable
Forum Replies Created
Viewing 1 replies (of 1 total)
-
Forum: Plugins
In reply to: [Phoenix Media Rename] Edit filename in attachement details?Yes, specifically using this snippet of code in a plugin that appends functions.php I can add an entry to the attachment details page:
//function to add custom media field function custom_media_add_media_custom_field( $form_fields, $post ) { $field_value = get_post_meta( $post->ID, 'edit_filename', true ); $form_fields['edit_filename'] = array( 'value' => $field_value ? $field_value : '', 'label' => __( 'Filename' ), 'helps' => __( 'Enter new filename' ), 'input' => 'input' ); return $form_fields; } //add metadata field to attachment page add_filter( 'attachment_fields_to_edit', 'custom_media_add_media_custom_field', null, 2 );
What I had tried then after that was to run your code when the edit attachment action runs:
//save your custom media field function custom_media_save_attachment( $attachment_id ) { if ( isset( $_REQUEST['attachments'][ $attachment_id ]['edit_filename'] ) ) { //Get value stored in attachment details form $edit_filename = $_REQUEST['attachments'][ $attachment_id ]['edit_filename']; //Save filename to metadata update_post_meta( $attachment_id, 'edit_filename', $edit_filename ); //Run rename using phoenix plugin Phoenix_Media_Rename::do_rename($attachment_id, $edit_filename); } } add_action( 'edit_attachment', 'custom_media_save_attachment' );
But doing this essentially crashes the server for a while (my database kept crashing because it was saying it was receiving too many calls, so I had to wait about 30-45 minutes for that to fix itself.)
I did find out though, that in your add_filename_field function, if I remove the stipulations of it being a post and attachment, the filename field does show up on the attachment details page.
/** * Add the "Filename" field to the Media form * * @param [type] $form_fields * @param [type] $post * @return array form fields */ function add_filename_field($form_fields, $post) { //if (isset($GLOBALS['post']) && $GLOBALS['post']->post_type=='attachment') { $file_parts=$this->get_file_parts($GLOBALS['post']->ID); $form_fields['mr_filename']=array( 'label' => __('Filename', 'phoenix-media-rename'), 'input' => 'html', 'html' => $this->get_filename_field($GLOBALS['post']->ID, $file_parts['filename'], $file_parts['extension']) ); //} return $form_fields; }
That is about all I found out before I decided to reach out to you.
- This reply was modified 3 years, 10 months ago by tonytable.
Viewing 1 replies (of 1 total)