WordPress.org

Plugin Directory

Changeset 569845


Ignore:
Timestamp:
07/10/12 06:49:35 (22 months ago)
Author:
wet
Message:

wet_smartslug 1.6: Employ 'wp_unique_post_slug' filter; do not modify numerical slug parts.

Location:
smart-slug/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • smart-slug/trunk/readme.txt

    r563394 r569845  
    11=== Smart Slug === 
    22Contributors: wet 
    3 Tags: admin, slug, plugin, Post, posts, administration, seo, permalink, url, tag, category, page, hindi 
    4 Requires at least: 2.6 
     3Tags: admin, slug, plugin, Post, posts, administration, seo, permalink, url, hindi 
     4Requires at least: 3.3 
    55Tested up to: 3.5-alpha 
    66Stable tag: trunk 
    77 
    8 Smartify your post, page, tag and category slugs by removing too short or insignificant stopwords automatically. 
     8Smartify your post and page slugs by removing too short or insignificant stopwords automatically. 
    99 
    1010== Description == 
    1111 
    12 Smartify your post, page, tag and category slugs and let them convey the very essence of your content's titles by removing too short or insignificant stopwords - automatically, that is. **Smart Slug** comes preloaded with an easily expandable and configurable set of German, Dutch, Russian, Portuguese and English stopwords. Please visit my [Smart WordPress Slug Plugin](http://talkpress.de/blip/wet-smartslug-wordpress-plugin) article to review additional screenshots, grasp implementation details and contribute to a related discussion on how search engines evaluate words in URL fragments. 
     12Smartify your post and page slugs and let them convey the very essence of your content's titles by removing too short or insignificant stopwords - automatically, that is. **Smart Slug** comes preloaded with an easily expandable and configurable set of German, Dutch, Russian, Portuguese and English stopwords. 
     13 
     14Please visit my [Smart WordPress Slug Plugin](http://talkpress.de/blip/wet-smartslug-wordpress-plugin) article to review additional screenshots, grasp implementation details and contribute to a related discussion on how search engines evaluate words in URL fragments. 
    1315 
    1416= Credits = 
     
    2123- Hindi translation by [Outshine Solutions](http://outshinesolutions.com/) 
    2224 
     25= Limitations = 
     26 
     27- Smart Slug overrides all manual slug modifications which would violate its rule set, even if you are making them deliberately. 
     28- WordPress appends a unique number to ambigous slugs (e.g. hello-word, hello-world-2 et cetera). Smart Slug may not notice this behaviour when an article is saved for the first time. If this happens you may simply re-save the post to attach a smart slug. 
     29 
    2330== Installation == 
    2431 
     
    2734 
    2835== Changelog == 
     36 
     37= 1.6 = 
     38 
     391. Use `wp_unique_post_slug` filter instead of `editable_slug`. Requires WP 3.3. 
     401. Keep numerical slug parts unaltered. 
    2941 
    3042= 1.5 = 
  • smart-slug/trunk/wet_smartslug.php

    r563394 r569845  
    33Plugin Name: wet_smartslug 
    44Plugin URI: http://talkpress.de/blip/wet-smartslug-wordpress-plugin 
    5 Description: Smartify your post, page, tag and category slugs by removing too short or insignificant stopwords automatically. 
     5Description: Smartify your post and page slugs by removing too short or insignificant stopwords automatically. 
    66Author: Robert Wetzlmayr 
    7 Version: 1.5 
     7Version: 1.6 
    88Author URI: http://wetzlmayr.com/ 
    99*/ 
     
    2222            $this->get_options(); 
    2323            load_plugin_textdomain('wet_smartslug', false, dirname(plugin_basename(__FILE__))); 
    24             add_filter('editable_slug', array($this, 'smart_slug'), 100); 
     24            add_filter('wp_unique_post_slug', array($this, 'smart_slug'), 100, 6); 
    2525            add_action('admin_menu', array($this, 'admin_menu')); 
    2626            $this->strlen = (function_exists('mb_strlen')) ? 'mb_strlen' : 'strlen'; 
     
    2828    } 
    2929 
    30     function smart_slug($title) { 
    31         /* 
    32         // restrict smart slug functions to pages and posts. 
    33         // TODO: detect "save draft" 
    34         if (!in_array($_POST['action'], array('sample-permalink', 'editpost', 'post'))) 
    35             return $title; 
    36          */ 
     30    function smart_slug($slug, $post_ID, $post_status, $post_type, $post_parent, $original_slug='' /* @since WP3.5 */) { 
     31        if ($slug === '') return ''; 
    3732 
    38         if ($title === '') return ''; 
    39  
    40         $old_title = $title; 
     33        $old_slug = $slug; 
    4134        // strip out too short parts and members of the stoplist array 
    42         $title = explode('-', $title); 
     35        $slug = explode('-', $slug); 
    4336        $f = $this->strlen; 
    44         foreach ($title as $t) { 
    45             if (($f($t) >= $this->min_chars) && !(in_array($t, $this->stopwords))) { 
     37        foreach ($slug as $t) { 
     38            $t_ = urldecode($t); 
     39            if (($f($t_) >= $this->min_chars) && !(in_array($t_, $this->stopwords)) || is_numeric($t_)) { 
    4640                $out[] = $t; 
    4741            } 
     
    4943        // are we acting overzealous? 
    5044        if (empty($out)) { 
    51             $title = $old_title; 
     45            $slug = $old_slug; 
    5246        } else { 
    53             $title = join('-', $out); 
     47            $slug = join('-', $out); 
    5448        } 
    55         return $title; 
     49        return $slug; 
    5650    } 
    5751 
Note: See TracChangeset for help on using the changeset viewer.