renames > specify wich by post types
-
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 );
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘renames > specify wich by post types’ is closed to new replies.