33Plugin Name: WP Document Revisions - Filtering by Filetype
44Plugin URI: https://github.com/wp-document-revisions/WP-Document-Revisions-Code-Cookbook
55Description: Code sample to demonstrate how to build a filter by filetype taxonomy
6- Version: 1 .0
6+ Version: 2 .0
77Author: Benjamin J. Balter
88Author URI: http://ben.balter.com
99License: GPL2
@@ -33,7 +33,7 @@ function wpdr_register_filetype_taxonomy() {
3333 }
3434}
3535
36- add_action ( 'init ' , 'wpdr_register_filetype_taxonomy ' );
36+ add_action ( 'init ' , 'wpdr_register_filetype_taxonomy ' , 99 );
3737
3838/**
3939 * Saves the filetype terms from the post.
@@ -54,14 +54,15 @@ function wpdr_update_type( $post_ID ) {
5454
5555 $ post = get_post ( $ post_ID );
5656 // is there an attachment (new post).
57- if ( empty ( $ post ->post_content ) || ! is_numeric ( $ post ->post_content ) ) {
57+ $ attach = $ wpdr ->extract_document_id ( $ post ->post_content );
58+ if ( ! $ attach ) {
5859 return ;
5960 }
6061
61- $ attachment = get_post ( $ post -> post_content );
62- $ extensions = array ( $ wpdr ->get_extension ( get_attached_file ( $ attachment -> ID ) ) );
62+ // find the attachment filetype.
63+ $ extensions = array ( $ wpdr ->get_extension ( get_attached_file ( $ attach ) ) );
6364
6465 wp_set_post_terms ( $ post_ID , $ extensions , 'filetype ' , false );
6566}
6667
67- add_action ( 'save_post ' , 'wpdr_update_type ' , 10 , 1 );
68+ add_action ( 'save_post_document ' , 'wpdr_update_type ' , 10 , 1 );
0 commit comments