-
Notifications
You must be signed in to change notification settings - Fork 0
/
filetype-taxonomy.php
37 lines (27 loc) · 1.01 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
<?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;
wp_set_post_terms( $postID, array( $wpdr->get_extension( $postID ) ), 'filetype', false );
}
add_action( 'save_post', 'wpdr_update_type', 10, 1 );