|
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' ); |
|
} |