public
Last active

Fix Wordpress co-authors-plus plugin taxonomy when upgrading from 2.0 to 3.0

  • Download Gist
co-authors-plus_update_taxonomy.diff
Diff
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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
commit 36419d0a0d0d6d7328877a3d9153b1aa4c76aa11
Author: Jeffrey Clark <jaclark@fnal.gov>
Date: Thu Dec 6 13:55:42 2012 -0600
 
fix co-authors-plus taxonomy bug when slug is not unique
http://core.trac.wordpress.org/ticket/5809
http://wordpress.org/support/topic/authors-names-dont-show-up-in-various-places-taxonomy-30
 
diff --git a/wp-content/plugins/co-authors-plus/co-authors-plus.php b/wp-content/plugins/co-authors-plus/co-authors-plus.php
index ec25fd0..9d8d6d9 100644
--- a/wp-content/plugins/co-authors-plus/co-authors-plus.php
+++ b/wp-content/plugins/co-authors-plus/co-authors-plus.php
@@ -56,6 +56,8 @@ class coauthors_plus {
var $having_terms = '';
+ var $_options = false;
+
/**
* __construct()
*/
@@ -188,6 +190,42 @@ class coauthors_plus {
// Apply some targeted filters
add_action( 'load-edit.php', array( $this, 'load_edit' ) );
+ // Upgrade?
+ $last_upgrade = $this->get_option( 'upgrade' );
+ if ( $last_upgrade < COAUTHORS_PLUS_VERSION ) {
+ require_once( dirname(__FILE__) . DIRECTORY_SEPARATOR . 'upgrade.php' );
+ coauthors_plus_upgrade( $last_upgrade );
+ $this->set_option( 'upgrade', COAUTHORS_PLUS_VERSION );
+ }
+ }
+
+ /**
+ * Retrieve plugin global options
+ *
+ * @since 3.0.3
+ */
+ function get_option( $key = null ) {
+ if ( ! $this->_options ) {
+ $this->_options = get_option( get_class( $this ) );
+ }
+ if ( isset( $key ) ) {
+ return isset( $this->_options[$key] ) ? $this->_options[$key] : null;
+ }
+ return $this->_options;
+ }
+
+ /**
+ * Set plugin global options
+ *
+ * @since 3.0.3
+ */
+ function set_option( $key, $value = null ) {
+ if ( is_array($key) ) {
+ $this->_options = array_merge($this->_options, $key);
+ } else {
+ $this->_options[$key] = $value;
+ }
+ update_option( get_class($this), $this->_options );
}
/**
diff --git a/wp-content/plugins/co-authors-plus/upgrade.php b/wp-content/plugins/co-authors-plus/upgrade.php
index ca73570..a1a7d45 100644
--- a/wp-content/plugins/co-authors-plus/upgrade.php
+++ b/wp-content/plugins/co-authors-plus/upgrade.php
@@ -3,6 +3,7 @@ function coauthors_plus_upgrade( $from ) {
// TODO: handle upgrade failures
if( $from < 2.0 ) coauthors_plus_upgrade_20();
+ if( $from < 3.0 ) coauthors_plus_upgrade_30();
}
/**
@@ -43,4 +44,27 @@ function coauthors_plus_upgrade_20 () {
}
}
+ $coauthors_plus->set_option( 'upgrade', '2.0' );
+}
+
+/**
+ * Upgrade to 3.0
+ * Add 'cap-' prefix to author taxonomy terms to work-around Wordpress core limitation.
+ * See: http://core.trac.wordpress.org/ticket/5809
+ */
+function coauthors_plus_upgrade_30 () {
+ global $coauthors_plus;
+ global $wpdb;
+
+ $loop_query = "SELECT term_id, name, slug FROM {$wpdb->prefix}terms WHERE term_id IN (SELECT term_id FROM {$wpdb->prefix}term_taxonomy WHERE taxonomy = '{$coauthors_plus->coauthor_taxonomy}')";
+ foreach( $wpdb->get_results($loop_query) as $term ) {
+ if ( substr( $term->slug, 0, 4 ) !== 'cap-' ) {
+ $wpdb->query(
+ $wpdb->prepare(
+ "UPDATE {$wpdb->prefix}terms SET slug = %s WHERE term_id = %d", 'cap-' . sanitize_title( $term->name ), $term->term_id
+ )
+ );
+ }
+ }
+ $coauthors_plus->set_option( 'upgrade', '3.0' );
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.