Skip to content

Commit

Permalink
add remove rarely used terms featured, release 2.1.1
Browse files Browse the repository at this point in the history
git-svn-id: http://plugins.svn.wordpress.org/simple-tags/trunk@423973 b8457f37-d9ea-0310-8a92-e5e31aec5664
  • Loading branch information
momo360modena committed Aug 15, 2011
1 parent 1ad2c02 commit 1836593
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 16 deletions.
70 changes: 70 additions & 0 deletions inc/class.admin.manage.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ function pageManageTags() {
$newtag = (isset($_POST['addterm_new'])) ? $_POST['addterm_new'] : '';
$this->addMatchTerms( $this->taxonomy, $matchtag, $newtag );

} elseif ( $_POST['term_action'] == 'remove-rarelyterms' ) {

$this->removeRarelyUsed( $this->taxonomy, (int) $_POST['number-rarely'] );

} /* elseif ( $_POST['term_action'] == 'editslug' ) {
$matchtag = (isset($_POST['tagname_match'])) ? $_POST['tagname_match'] : '';
Expand Down Expand Up @@ -217,6 +221,36 @@ function pageManageTags() {
</td>
</tr>

<tr valign="top">
<th scope="row"><strong><?php _e('Remove rarely used terms', 'simpletags'); ?></strong></th>
<td>
<p><?php _e('This feature allows you to remove rarely used terms.', 'simpletags'); ?></p>
<p><?php _e('You can specify the number below which will be removed terms. If you put 5, all terms with a counter inferior to 5 will be deleted. The terms with a counter equal to 5 is keep.', 'simpletags'); ?></p>

<fieldset>
<form action="" method="post">
<input type="hidden" name="taxo" value="<?php echo esc_attr($this->taxonomy); ?>" />
<input type="hidden" name="cpt" value="<?php echo esc_attr($this->post_type); ?>" />

<input type="hidden" name="term_action" value="remove-rarelyterms" />
<input type="hidden" name="term_nonce" value="<?php echo wp_create_nonce('simpletags_admin'); ?>" />

<p>
<label for="number-delete"><?php _e('Numbers minimum:', 'simpletags'); ?></label>
<br />
<select name="number-rarely" id="number-delete">
<?php for( $i = 1; $i <= 100; $i++ ) : ?>
<option value="<?php echo $i; ?>"><?php echo $i; ?></option>
<?php endfor; ?>
</select>
</p>

<input class="button-primary" type="submit" name="Delete" value="<?php _e('Delete rarely used', 'simpletags'); ?>" />
</form>
</fieldset>
</td>
</tr>

<?php /*
<tr valign="top">
<th scope="row"><strong><?php _e('Edit Term Slug', 'simpletags'); ?></strong></th>
Expand Down Expand Up @@ -517,6 +551,42 @@ function addMatchTerms( $taxonomy = 'post_tag', $match, $new ) {
return true;
}

/**
* Delete terms when counter if inferior to a specific number
*
* @param string $taxonomy
* @param integer $number
* @return boolean
* @author Amaury Balmer
*/
function removeRarelyUsed( $taxonomy = 'post_tag', $number = 0 ) {
global $wpdb;

if ( (int) $number > 100 )
wp_die( 'Tcheater ?' );

// Get terms with counter inferior to...
$terms_id = $wpdb->get_col( $wpdb->prepare("SELECT term_id FROM $wpdb->term_taxonomy WHERE taxonomy = %s AND count < %d", $taxonomy, $number) );

// Delete terms
$counter = 0;
foreach ( (array) $terms_id as $term_id ) {
if ( $term_id != 0 ) {
wp_delete_term( $term_id, $taxonomy );
clean_term_cache( $term_id, $taxonomy );
$counter++;
}
}

if ( $counter == 0 ) {
$this->message = __('No term deleted.', 'simpletags');
} else {
$this->message = sprintf(__('%1s term(s) deleted.', 'simpletags'), $counter);
}

return true;
}

/**
* Method for edit one or more terms slug
*
Expand Down
23 changes: 11 additions & 12 deletions inc/class.admin.suggest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,8 @@ function SimpleTags_Admin_Suggest() {
// Ajax action, JS Helper and admin action
add_action('wp_ajax_'.'simpletags', array(&$this, 'ajaxCheck'));

// Box for post
add_action('admin_menu', array(&$this, 'helperSuggestTags_Post'), 1);

// Box for Page
if ( is_page_have_tags() ) {
add_action('admin_menu', array(&$this, 'helperSuggestTags_Page'), 1);
}
// Box for post/page
add_action('admin_menu', array(&$this, 'helperSuggestTags'), 1);

wp_register_script('st-helper-suggested-tags', STAGS_URL.'/inc/js/helper-suggested-tags.min.js', array('jquery', 'st-helper-add-tags'), STAGS_VERSION);
wp_localize_script('st-helper-suggested-tags', 'stHelperSuggestedTagsL10n', array( 'title_bloc' => $this->getSuggestTagsTitle(), 'content_bloc' => __('Choose a provider to get suggested tags (local, yahoo or tag the net).', 'simpletags') ) );
Expand Down Expand Up @@ -46,12 +41,16 @@ function getSuggestTagsTitle() {
return $title;
}

function helperSuggestTags_Post() {
/**
* Register metabox for suggest tags, for post, and optionnaly page.
*
* @return void
* @author Amaury Balmer
*/
function helperSuggestTags() {
add_meta_box('suggestedtags', __('Suggested tags', 'simpletags'), array(&$this, 'boxSuggestTags'), 'post', 'advanced', 'core');
}

function helperSuggestTags_Page() {
add_meta_box('suggestedtags', __('Suggested tags', 'simpletags'), array(&$this, 'boxSuggestTags'), 'page', 'advanced', 'core');
if ( is_page_have_tags() )
add_meta_box('suggestedtags', __('Suggested tags', 'simpletags'), array(&$this, 'boxSuggestTags'), 'page', 'advanced', 'core');
}

/**
Expand Down
5 changes: 4 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Donate link: http://beapi.fr/donate/
Tags: tag, posts, tags, admin, administration, tagging, navigation, terms, taxonomy
Requires at least: 3.0
Tested up to: 3.2.1
Stable tag: 2.1
Stable tag: 2.1.1

Add some tools for taxonomies : Terms suggestion, Mass Edit Terms, Auto link Terms, Ajax Autocompletion, Click Terms, Auto terms, Advanced manage terms, Advanced Post Terms, Related Posts by Terms, etc.

Expand Down Expand Up @@ -70,6 +70,9 @@ The Simple Tags can be installed in 3 easy steps:

== Changelog ==

* Version 2.1.1 :
* Add a feature that allow deleting rarely used terms. (based on counter term)
* Fix bug for allow Suggested Tags for page CPT.
* Version 2.1 :
* Add compatibility with WP 3.2
* Fix bug with autocompletion. (jQuery want now a strict content type text/plain)
Expand Down
6 changes: 3 additions & 3 deletions simple-tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: Simple Tags
Plugin URI: http://redmine.beapi.fr/projects/show/simple-tags
Description: Extended Tagging for WordPress 3.1 : Suggested Tags, Mass edit tags, Auto-tags, Autocompletion, Related Posts etc. NOW Compatible custom post type and custom taxonomy !
Version: 2.1
Version: 2.1.1
Author: Amaury BALMER
Author URI: http://www.herewithme.fr
Text Domain: simpletags
Expand Down Expand Up @@ -42,10 +42,10 @@
}

//Spit out die messages
wp_die(sprintf(__('Your PHP version is too old, please upgrade to a newer version. Your version is %s, Simple Tags requires %s', 'simpletags'), phpversion(), '5.0.0'));
wp_die(sprintf(__('Your PHP version is too old, please upgrade to a newer version. Your version is %s, Simple Tags requires %s. Remove the plugin from WordPress plugins directory with FTP client.', 'simpletags'), phpversion(), '5.0.0'));
}

define( 'STAGS_VERSION', '2.1' );
define( 'STAGS_VERSION', '2.1.1' );
define( 'STAGS_OPTIONS_NAME', 'simpletags' ); // Option name for save settings
define( 'STAGS_OPTIONS_NAME_AUTO', 'simpletags-auto' ); // Option name for save settings auto terms
define( 'STAGS_FOLDER', 'simple-tags' );
Expand Down

0 comments on commit 1836593

Please sign in to comment.