Taxonomy Metadata - Version 0.3

Version Description

  • Better Network Activation handling:
    • install necessary tables for each blog on Network Activate
    • if Network Activated, install necessary table when new blogs are created
Download this release

Release Info

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

Code changes from version 0.2 to 0.3

Files changed (2) hide show
  1. readme.txt +15 -10
  2. taxonomy-metadata.php +68 -28
readme.txt CHANGED
@@ -3,13 +3,13 @@ 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: taxonomy, metadata, API
8
- Requires at least: 2.9
9
- Tested up to: 3.2
10
- Stable tag: 0.2
11
 
12
- Implements metadata functionality for taxonomy terms, including for tags and categories.
13
 
14
  == Description ==
15
 
@@ -47,12 +47,17 @@ The plugin implements the following functions, from which you can build your own
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
 
 
56
 
57
  = 0.2 =
58
- * Made Multisite-compatible, thanks to Matt Wiebe!
 
 
 
3
  Author: mitcho (Michael Yoshitaka Erlewine), sirzooro
4
  Author URI: http://mitcho.com/
5
  Plugin URI: http://mitcho.com/code/
6
+ Donate link: http://tinyurl.com/donatetomitcho
7
+ Tags: infrastructure, taxonomy, metadata, API
8
+ Requires at least: 3.0
9
+ Tested up to: 3.6
10
+ Stable tag: 0.3
11
 
12
+ Infrastructure plugin which implements metadata functionality for taxonomy terms, including for tags and categories.
13
 
14
  == Description ==
15
 
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://globalshakespeares.org/).
51
 
52
  == Changelog ==
53
 
54
+ = 0.3 =
55
+ * Better Network Activation handling:
56
+ * install necessary tables for each blog on Network Activate
57
+ * if Network Activated, install necessary table when new blogs are created
58
 
59
  = 0.2 =
60
+ * Made Multisite-compatible, thanks to Matt Wiebe!
61
+
62
+ = 0.1 =
63
+ * Initial upload
taxonomy-metadata.php CHANGED
@@ -1,41 +1,81 @@
1
  <?php
2
  /*
3
  Plugin Name: Taxonomy Metadata
4
- Description: Implements metadata functionality for taxonomy terms, including for tags and categories.
5
- Version: 0.2
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
- add_action('switch_blog','taxonomy_metadata_wpdbfix');
35
- function taxonomy_metadata_wpdbfix() {
36
- global $wpdb;
37
- $wpdb->taxonomymeta = "{$wpdb->prefix}taxonomymeta";
38
  }
 
 
39
 
40
  // THE REST OF THIS CODE IS FROM http://core.trac.wordpress.org/ticket/10142
41
  // BY sirzooro
1
  <?php
2
  /*
3
  Plugin Name: Taxonomy Metadata
4
+ Description: Infrastructure plugin which implements metadata functionality for taxonomy terms, including for tags and categories.
5
+ Version: 0.3
6
  Author: mitcho (Michael Yoshitaka Erlewine), sirzooro
7
  Author URI: http://mitcho.com/
8
  */
9
 
10
+ class Taxonomy_Metadata {
11
+ function __construct() {
12
+ add_action( 'init', array($this, 'wpdbfix') );
13
+ add_action( 'switch_blog', array($this, 'wpdbfix') );
14
+
15
+ add_action('wpmu_new_blog', 'new_blog', 10, 6);
16
+ }
17
 
18
+ /*
19
+ * Quick touchup to wpdb
20
+ */
21
+ function wpdbfix() {
22
+ global $wpdb;
23
+ $wpdb->taxonomymeta = "{$wpdb->prefix}taxonomymeta";
24
+ }
25
+
26
+ /*
27
+ * TABLE MANAGEMENT
28
+ */
29
+
30
+ function activate( $network_wide = false ) {
31
+ global $wpdb;
32
+
33
+ // if activated on a particular blog, just set it up there.
34
+ if ( !$network_wide ) {
35
+ $this->setup_blog();
36
+ return;
37
+ }
38
+
39
+ $blogs = $wpdb->get_col( "SELECT blog_id FROM {$wpdb->blogs} WHERE site_id = '{$wpdb->siteid}'" );
40
+ foreach ( $blogs as $blog_id ) {
41
+ $this->setup_blog( $blog_id );
42
+ }
43
+ // I feel dirty... this line smells like perl.
44
+ do {} while ( restore_current_blog() );
45
+ }
46
+
47
+ function setup_blog( $id = false ) {
48
+ global $wpdb;
49
+
50
+ if ( $id !== false)
51
+ switch_to_blog( $id );
52
+
53
+ $charset_collate = '';
54
+ if ( ! empty($wpdb->charset) )
55
+ $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
56
+ if ( ! empty($wpdb->collate) )
57
+ $charset_collate .= " COLLATE $wpdb->collate";
58
+
59
+ $tables = $wpdb->get_results("show tables like '{$wpdb->prefix}taxonomymeta'");
60
+ if (!count($tables))
61
+ $wpdb->query("CREATE TABLE {$wpdb->prefix}taxonomymeta (
62
+ meta_id bigint(20) unsigned NOT NULL auto_increment,
63
+ taxonomy_id bigint(20) unsigned NOT NULL default '0',
64
+ meta_key varchar(255) default NULL,
65
+ meta_value longtext,
66
+ PRIMARY KEY (meta_id),
67
+ KEY taxonomy_id (taxonomy_id),
68
+ KEY meta_key (meta_key)
69
+ ) $charset_collate;");
70
+ }
71
 
72
+ function new_blog( $blog_id, $user_id, $domain, $path, $site_id, $meta ) {
73
+ if ( is_plugin_active_for_network(plugin_basename(__FILE__)) )
74
+ $this->setup_blog($blog_id);
75
+ }
 
76
  }
77
+ $taxonomy_metadata = new Taxonomy_Metadata;
78
+ register_activation_hook( __FILE__, array($taxonomy_metadata, 'activate') );
79
 
80
  // THE REST OF THIS CODE IS FROM http://core.trac.wordpress.org/ticket/10142
81
  // BY sirzooro