Taxonomy Metadata - Version 0.1

Version Description

  • Initial upload
Download this release

Release Info

Developer mitchoyoshitaka
Plugin Icon wp plugin Taxonomy Metadata
Version 0.1
Comparing to
See all releases

Version 0.1

Files changed (2) hide show
  1. readme.txt +55 -0
  2. taxonomy-metadata.php +104 -0
readme.txt ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Taxonomy Metadata ===
2
+ Contributors: mitchoyoshitaka, sirzooro
3
+ Author: mitcho (Michael Yoshitaka Erlewine), sirzooro
4
+ Author URI: http://mitcho.com/
5
+ Plugin URI: http://mitcho.com/code/
6
+ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=66G4DATK4999L&item_name=mitcho%2ecom%2fcode%3a%20donate%20to%20Michael%20Yoshitaka%20Erlewine&no_shipping=0&no_note=1&tax=0&currency_code=USD&lc=US&charset=UTF%2d8
7
+ Tags: uploads, latex, tex, file
8
+ Requires at least: 2.9
9
+ Tested up to: 3.0
10
+ Stable tag: 0.1
11
+
12
+ Implements metadata functionality for taxonomy terms, including for tags and categories.
13
+
14
+ == Description ==
15
+
16
+ This plugin implements the metadata infrastructure for taxonomy terms, so you can add custom metadata (by key) to tags, categories, and other taxonomies. The majority of the code is from [sirzooro's submission](http://core.trac.wordpress.org/ticket/10142) to the WordPress Core Trac. The rest of the plugin is simply some hacky glue to make this work without modifying the Core. It *does not* implement any UI for taxonomy term metadata.
17
+
18
+ The plugin implements the following functions, from which you can build your own custom UI and display code:
19
+
20
+ `add_term_meta($term_id, $meta_key, $meta_value, $unique)`: Add meta data field to a term.
21
+
22
+ * @param int $term_id Post ID.
23
+ * @param string $key Metadata name.
24
+ * @param mixed $value Metadata value.
25
+ * @param bool $unique Optional, default is false. Whether the same key should not be added.
26
+ * @return bool False for failure. True for success.
27
+
28
+ `delete_term_meta($term_id, $meta_key, $meta_value)`: Remove metadata matching criteria from a term. You can match based on the key, or key and value. Removing based on key and value, will keep from removing duplicate metadata with the same key. It also allows removing all metadata matching key, if needed.
29
+
30
+ * @param int $term_id term ID
31
+ * @param string $meta_key Metadata name.
32
+ * @param mixed $meta_value Optional. Metadata value.
33
+ * @return bool False for failure. True for success.
34
+
35
+ `get_term_meta($term_id, $key, $single)`: Retrieve term meta field for a term.
36
+
37
+ * @param int $term_id Term ID.
38
+ * @param string $key The meta key to retrieve.
39
+ * @param bool $single Whether to return a single value.
40
+ * @return mixed Will be an array if $single is false. Will be value of meta data field if $single is true.
41
+
42
+ `update_term_meta($term_id, $meta_key, $meta_value, $prev_value)`: Update term meta field based on term ID. Use the $prev_value parameter to differentiate between meta fields with the same key and term ID. If the meta field for the term does not exist, it will be added.
43
+
44
+ * @param int $term_id Term ID.
45
+ * @param string $key Metadata key.
46
+ * @param mixed $value Metadata value.
47
+ * @param mixed $prev_value Optional. Previous value to check before removing.
48
+ * @return bool False on failure, true if success.
49
+
50
+ Development of this plugin was supported by the [Massachusetts Institute of Technology Shakespeare Project](http://web.mit.edu/shakespeare/).
51
+
52
+ == Changelog ==
53
+
54
+ = 0.1 =
55
+ * Initial upload
taxonomy-metadata.php ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: Taxonomy Metadata
4
+ Description: Implements metadata functionality for taxonomy terms, including for tags and categories.
5
+ Version: 0.1
6
+ Author: mitcho (Michael Yoshitaka Erlewine), sirzooro
7
+ Author URI: http://mitcho.com/
8
+ */
9
+
10
+ register_activation_hook(__FILE__,'taxonomy_metadata_setup');
11
+ function taxonomy_metadata_setup() {
12
+ global $wpdb;
13
+
14
+ $charset_collate = '';
15
+ if ( ! empty($wpdb->charset) )
16
+ $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
17
+ if ( ! empty($wpdb->collate) )
18
+ $charset_collate .= " COLLATE $wpdb->collate";
19
+
20
+ $tables = $wpdb->get_results("show tables like '{$wpdb->prefix}taxonomymeta'");
21
+ if (!count($tables))
22
+ $wpdb->query("CREATE TABLE {$wpdb->prefix}taxonomymeta (
23
+ meta_id bigint(20) unsigned NOT NULL auto_increment,
24
+ taxonomy_id bigint(20) unsigned NOT NULL default '0',
25
+ meta_key varchar(255) default NULL,
26
+ meta_value longtext,
27
+ PRIMARY KEY (meta_id),
28
+ KEY taxonomy_id (taxonomy_id),
29
+ KEY meta_key (meta_key)
30
+ ) $charset_collate;");
31
+ }
32
+
33
+ add_action('init','taxonomy_metadata_wpdbfix');
34
+ function taxonomy_metadata_wpdbfix() {
35
+ global $wpdb;
36
+ $wpdb->taxonomymeta = "{$wpdb->prefix}taxonomymeta";
37
+ }
38
+
39
+ // THE REST OF THIS CODE IS FROM http://core.trac.wordpress.org/ticket/10142
40
+ // BY sirzooro
41
+
42
+ //
43
+ // Taxonomy meta functions
44
+ //
45
+
46
+ /**
47
+ * Add meta data field to a term.
48
+ *
49
+ * @param int $term_id Post ID.
50
+ * @param string $key Metadata name.
51
+ * @param mixed $value Metadata value.
52
+ * @param bool $unique Optional, default is false. Whether the same key should not be added.
53
+ * @return bool False for failure. True for success.
54
+ */
55
+ function add_term_meta($term_id, $meta_key, $meta_value, $unique = false) {
56
+ return add_metadata('taxonomy', $term_id, $meta_key, $meta_value, $unique);
57
+ }
58
+
59
+ /**
60
+ * Remove metadata matching criteria from a term.
61
+ *
62
+ * You can match based on the key, or key and value. Removing based on key and
63
+ * value, will keep from removing duplicate metadata with the same key. It also
64
+ * allows removing all metadata matching key, if needed.
65
+ *
66
+ * @param int $term_id term ID
67
+ * @param string $meta_key Metadata name.
68
+ * @param mixed $meta_value Optional. Metadata value.
69
+ * @return bool False for failure. True for success.
70
+ */
71
+ function delete_term_meta($term_id, $meta_key, $meta_value = '') {
72
+ return delete_metadata('taxonomy', $term_id, $meta_key, $meta_value);
73
+ }
74
+
75
+ /**
76
+ * Retrieve term meta field for a term.
77
+ *
78
+ * @param int $term_id Term ID.
79
+ * @param string $key The meta key to retrieve.
80
+ * @param bool $single Whether to return a single value.
81
+ * @return mixed Will be an array if $single is false. Will be value of meta data field if $single
82
+ * is true.
83
+ */
84
+ function get_term_meta($term_id, $key, $single = false) {
85
+ return get_metadata('taxonomy', $term_id, $key, $single);
86
+ }
87
+
88
+ /**
89
+ * Update term meta field based on term ID.
90
+ *
91
+ * Use the $prev_value parameter to differentiate between meta fields with the
92
+ * same key and term ID.
93
+ *
94
+ * If the meta field for the term does not exist, it will be added.
95
+ *
96
+ * @param int $term_id Term ID.
97
+ * @param string $key Metadata key.
98
+ * @param mixed $value Metadata value.
99
+ * @param mixed $prev_value Optional. Previous value to check before removing.
100
+ * @return bool False on failure, true if success.
101
+ */
102
+ function update_term_meta($term_id, $meta_key, $meta_value, $prev_value = '') {
103
+ return update_metadata('taxonomy', $term_id, $meta_key, $meta_value, $prev_value);
104
+ }