WordPress.org

Forums

Enable Media Replace
[resolved] Add filter hook suggestion to (3 posts)

  1. Jonas Lundman
    Member
    Posted 1 year ago #

    Hi,

    This plugin works perfectly in 3.5.1 and a lot of plugins, tested on clean install. Thanks, please keep it alive.

    In conjunction with ex Upload plus, or other plugins that cleans up the Media titles or manipulate the same, I had to add a filter hook to your upload.php file. Quite useful and works fine for a long time. Woluld like to see this as a permanent solution.

    The situation is, for readers, this plugin works directly with the database, and bypasses all hooks, exept one. Thats fine, but the title manupilation after replace and search, adds a lot of dashes and lowercases, and breaks the flow/ behaviour from other plugins and filters.

    This is my suggestion, in En M replace plugindir/upload.php

    $new_filetitle = preg_replace('/\.[^.]+$/', '', basename($new_file));
    $new_filetitle = apply_filters( 'enable_media_replace_title', $new_filetitle ); // New line at 123 in plugindir/upload.php

    In your Theme functions.php, I added a filter manipulation, similar as Rename Title after Upload plugin.

    function ua_sanitize_file_title($title){
    	$char_array = array();
    	$char_array[] = '-';
    	$char_array[] = '_';
    	$char_array[] = '~';
    	$char_array[] = '+';
    
    	$title = str_replace($char_array, ' ', $title );
    	$title = preg_replace("/\s+/", " ", $title);
    	$title = str_replace(array('.jpg', '.tiff', '.jpeg', '.tif', '.png', '.bmp', '.gif'), '', $title);
    	$title = ucfirst( strtolower( $title ) );
    	return $title;
    }
    add_filter( 'enable_media_replace_title', 'ua_sanitize_file_title');

    Another suggestion is to use the revision shortcode in the edit attachment screen.

    Thanks!

    http://wordpress.org/extend/plugins/enable-media-replace/

  2. Jonas Lundman
    Member
    Posted 1 year ago #

    This solves Another suggestion is to use the revision shortcode in the edit attachment screen. Some clients are using the EMR as doc revision handling.

    // Add Last replaced by EMR plugin in the media edit screen metabox
    function ua_admin_date_replaced_media_on_edit_media_screen() {
    	if( !function_exists( 'enable_media_replace' ) ) return;
    	global $post;
    	$id = $post->ID;
    	$shortcode = "[file_modified id=$id]";
    	?>
    	<div class="misc-pub-section curtime">
    		<span id="timestamp"><?php _e( 'Revised' ); ?>: <b><?php echo do_shortcode($shortcode); ?></b></span>
    	</div>
    	<?php
    }
    add_action( 'attachment_submitbox_misc_actions', 'ua_admin_date_replaced_media_on_edit_media_screen', 91 );

    / J

  3. Måns Jonasson
    Member
    Plugin Author

    Posted 1 year ago #

    Great ideas! I'll take a look and most likely implement these in the next update. Thank you!

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Enable Media Replace
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic