/
filetype-taxonomy.php
41 lines (30 loc) · 1.14 KB
/
filetype-taxonomy.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
/*
Plugin Name: WP Document Revisions - Filtering by Filetype
Plugin URI: https://github.com/benbalter/WP-Document-Revisions-Code-Cookbook
Description: Code sample to demonstrate how to build a filter by filetype taxonomy
Version: 1.0
Author: Benjamin J. Balter
Author URI: http://ben.balter.com
License: GPL2
*/
function wpdr_register_filetype_taxonomy() {
// better way to do this would be with WP Document Revisions Custom Taxonomy Generator
// http://wordpress.org/extend/plugins/wp-document-revisions-custom-taxonomy-and-field-generator/
register_taxonomy( 'filetype', 'document', array(
'label' => __('Filetypes'),
'show_ui' => true,
'public' => false,
));
}
add_action( 'init', 'wpdr_register_filetype_taxonomy' );
function wpdr_update_type( $postID ) {
$wpdr = Document_Revisions::$instance;
if ( !$wpdr->verify_post_type( $postID ) )
return;
$post = get_post( $postID );
$attachment = get_post( $post->post_content );
$extensions = array( $wpdr->get_extension( get_attached_file( $attachment->ID ) ) ) ;
wp_set_post_terms( $postID, $extensions, 'filetype', false );
}
add_action( 'save_post', 'wpdr_update_type', 10, 1 );