• Resolved neosan

    (@nreljed)


    Hello,
    I just discovered your plugin
    I have already tried to create a snippet to rename my uploads on a custom post type in my case it ‘property’

    can you add this possibility in your plugin?

    in the meantime here is my code but I can not make it work it is obvious that I missed something. if you can help me make it work that would be nice. until you add the ability to specify which post type we use renames.

    /*Renaming attachment files to the post title*/
    function rename_attacment($post_ID){
        
       if ( get_post_type( $_REQUEST['post_id'] ) === 'property') {
    
        $info = pathinfo( $filename );
        $ext  = empty( $info['extension'] ) ? '' : '.' . $info['extension'];
        $name = basename( $filename, $ext );
    
         if( $post_id = array_key_exists("post_id", $_POST) ? $_POST["post_id"] : null) {
                if($post = get_post($post_id)) {
                    return $post->post_title . $ext;
                }
            }
    
        $my_image_title = $post;
       
    
        $file['name'] = $my_image_title  . - uniqid() . $ext; // uniqid method
        // $file['name'] = md5($name) . $ext; // md5 method
        // $file['name'] = base64_encode($name) . $ext; // base64 method
    
        return $filename;
    
      } 
    }
    
    add_filter( 'sanitize_file_name', 'file_renamer', 10, 1 );
    • This topic was modified 4 years ago by neosan.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Pablo Pacheco

    (@karzin)

    Hello @nreljed,

    I’ll try to add a new option for it on the next version of the Pro ??
    Meanwhile, I believe this chunk of code would work for the free version:

    
    // Allows renaming only for 'property' post type
    add_filter( 'frou_filename_allowed', function ( $validation ) {
    	if (
    		empty( $allowed_cpts = array( 'property' ) )
    		|| empty( $post_id = \FROU\WordPress\Post::get_parent_post_id() )
    		|| in_array( get_post_type( $post_id ), $allowed_cpts )
    	) {
    		return $validation;
    	}
    	$validation = false;
    	return $validation;
    } );

    Hello @karzin, I just bought the plugin again and thanks for the code. I’ll try to edit it for “posts” only — yes, I’m another customer who would like to select which post type I want to rename automatically. For me it’s “posts” type, all other types I need to keep untouched. Please mention me here once the plugin is updated. Thanks!

    Plugin Author Pablo Pacheco

    (@karzin)

    Hello @viktorhanacek ,

    I just updated the pro plugin and it’s now possible to select which post type will be renamed ??

    I’m closing the ticket.
    Let me know if you need help

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘renames > specify wich by post types’ is closed to new replies.