Commit 208d7c1f authored by Erick Hitter's avatar Erick Hitter

v1.2

* Support for WP 4.2 and term splitting
* Fix readme line endings
parent 3c7ebf56
This diff is collapsed.
<?php
/*
Plugin Name: Taxonomy List Widget
Plugin URI: http://www.ethitter.com/plugins/taxonomy-list-widget/
Plugin URI: https://ethitter.com/plugins/taxonomy-list-widget/
Description: Creates a list of non-hierarchical taxonomies as an alternative to the term (tag) cloud. Widget provides numerous options to tailor the output to fit your site. List function can also be called directly for use outside of the widget. Formerly known as <strong><em>Tag List Widget</em></strong>.
Author: Erick Hitter
Version: 1.1.2
Author URI: http://www.ethitter.com/
Version: 1.2
Author URI: https://ethitter.com/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -55,6 +55,8 @@ class taxonomy_list_widget_plugin {
register_activation_hook( __FILE__, array( $this, 'activation_hook' ) );
register_deactivation_hook( __FILE__, array( $this, 'deactivation_hook' ) );
add_action( 'split_shared_term', array( $this, 'action_split_shared_term' ), 10, 4 );
}
/*
......@@ -105,6 +107,64 @@ class taxonomy_list_widget_plugin {
register_widget( 'taxonomy_list_widget' );
}
/**
* Update widget options when terms are split
*
* Starting in WP 4.2, terms that were previously shared will now be split into their own terms when the terms are updated.
* To ensure the widget continues to include/exclude the updated terms, we search widget options on terms split and update stored IDs.
*
* @param int $old_id ID of shared term before the split
* @param int $new_id ID of new term created after the split
* @param int $tt_id Term taxonomy ID of split term
* @param string $taxonomy Taxonomy of the term being split from its shared entry
* @action split_shared_term
* @return null
*/
public function action_split_shared_term( $old_id, $new_id, $tt_id, $taxonomy ) {
// WP provides no utility function for getting widget options, so we go straight to the source
$all_widget_options = $_all_widget_options = get_option( 'widget_taxonomy_list_widget', false );
// Loop through each widget's options and update stored term IDs if they're being split here
if ( is_array( $all_widget_options ) && ! empty( $all_widget_options ) ) {
foreach ( $all_widget_options as $key => $options ) {
// Check if widget needs updating
if ( ! is_array( $options ) ) {
continue;
}
if ( $options['taxonomy'] !== $taxonomy ) {
continue;
}
if ( empty( $options['incexc_ids'] ) ) {
continue;
}
// Account for legacy data storage option
if ( is_string( $options['incexc_ids'] ) ) {
$options['incexc_ids'] = explode( ',', $options['incexc_ids'] );
$options['incexc_ids'] = array_map( 'absint', $options['incexc_ids'] );
$options['incexc_ids'] = array_filter( $options['incexc_ids'] );
}
// Find stored term to update and do so
$key_to_update = array_search( $old_id, $options['incexc_ids'] );
if ( false === $key_to_update ) {
continue;
} else {
$all_widget_options[ $key ]['incexc_ids'][ $key_to_update ] = $new_id;
}
}
}
// If the term split was one in a widget option, update the options
// Reduces `update_option()` calls if nothing's changed
if ( $all_widget_options !== $_all_widget_options ) {
update_option( 'widget_taxonomy_list_widget', $all_widget_options );
}
}
/*
* Render list
* @param array $options
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment