post_type == 'attachment' && $GLOBALS['pagenow'] == 'post.php';
$is_media_listing_page = $GLOBALS['pagenow'] == 'upload.php';
$this->is_media_rename_page = $is_media_edit_page || $is_media_listing_page;
}
// Adds the "Filename" column at the media posts listing page
function add_filename_column($columns) {
$columns['filename'] = 'Filename';
return $columns;
}
// Adds the "Filename" column content at the media posts listing page
function add_filename_column_content($column_name, $post_id) {
if ($column_name == 'filename') {
$file_parts = $this->get_file_parts($post_id);
echo $this->get_filename_field($post_id, $file_parts['filename'], $file_parts['extension']);
}
}
// Add the "Filename" field to the Media form
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'),
'input' => 'html',
'html' => $this->get_filename_field($GLOBALS['post']->ID, $file_parts['filename'], $file_parts['extension'])
);
}
return $form_fields;
}
// Makes sure that the success message will be shown on bulk rename
function handle_bulk_rename_form_submit() {
if ( array_search('rename', $_REQUEST) !== FALSE || array_search('rename_retitle', $_REQUEST) !== FALSE ) {
wp_redirect( add_query_arg( array('renamed' => 1), wp_get_referer() ) );
exit;
}
}
// Shows bulk rename success notice
function show_bulk_rename_success_notice() {
if( isset($_REQUEST['renamed']) ) {
echo '
Medias successfully renamed!
';
}
}
// Print the JS code only on media.php and media-upload.php pages
function print_js() {
if ($this->is_media_rename_page) {
wp_enqueue_script('media-rename', plugins_url('js/scripts.js', __FILE__), array('jquery'));
?>
is_media_rename_page) {
wp_enqueue_style('media-rename', plugins_url('css/style.css', __FILE__));
}
}
// Prints the "Filename" textfield
function get_filename_field($post_id, $filename, $extension) {
if (!isset($this->nonce_printed)) $this->nonce_printed=0;
ob_start(); ?>