No Category Base (WPML) - Version 1.1.0

Version Description

Fixed compatibility for WordPress 3.4

Download this release

Release Info

Developer mines.io
Plugin Icon 128x128 No Category Base (WPML)
Version 1.1.0
Comparing to
See all releases

Version 1.1.0

Files changed (4) hide show
  1. index.php +4 -0
  2. no-category-base-wpml.php +136 -0
  3. readme.txt +67 -0
  4. screenshot-1.png +0 -0
index.php ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ <?php
2
+ // Nothing to see here
3
+ header("HTTP/1.1 403 Forbidden");
4
+ ?>
no-category-base-wpml.php ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: WP No Category Base - WPML compatible
4
+ Plugin URI: http://github.com/mines/no-category-base-wpml
5
+ Description: Removes '/category' from your category permalinks. WPML compatible.
6
+ Version: 1.1.0
7
+ Author: Mines
8
+ Author URI: http://mines.io/
9
+ */
10
+
11
+ /*
12
+ Based on the work by Saurabh Gupta (email : saurabh0@gmail.com)
13
+
14
+ Copyright 2008 Saurabh Gupta (email : saurabh0@gmail.com)
15
+ Copyright 2011 Mines (email: hi@mines.io)
16
+
17
+ This program is free software; you can redistribute it and/or modify
18
+ it under the terms of the GNU General Public License as published by
19
+ the Free Software Foundation; either version 2 of the License, or
20
+ (at your option) any later version.
21
+
22
+ This program is distributed in the hope that it will be useful,
23
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
24
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25
+ GNU General Public License for more details.
26
+
27
+ You should have received a copy of the GNU General Public License
28
+ along with this program; if not, write to the Free Software
29
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30
+ */
31
+
32
+ /* hooks */
33
+ register_activation_hook(__FILE__, 'no_category_base_refresh_rules');
34
+ register_deactivation_hook(__FILE__, 'no_category_base_deactivate');
35
+
36
+ /* actions */
37
+ add_action('created_category', 'no_category_base_refresh_rules');
38
+ add_action('delete_category', 'no_category_base_refresh_rules');
39
+ add_action('edited_category', 'no_category_base_refresh_rules');
40
+ add_action('init', 'no_category_base_permastruct');
41
+
42
+ /* filters */
43
+ add_filter('category_rewrite_rules', 'no_category_base_rewrite_rules');
44
+ add_filter('query_vars', 'no_category_base_query_vars'); // Adds 'category_redirect' query variable
45
+ add_filter('request', 'no_category_base_request'); // Redirects if 'category_redirect' is set
46
+
47
+ function no_category_base_refresh_rules()
48
+ {
49
+ global $wp_rewrite;
50
+ $wp_rewrite->flush_rules();
51
+ }
52
+
53
+ function no_category_base_deactivate()
54
+ {
55
+ remove_filter('category_rewrite_rules', 'no_category_base_rewrite_rules'); // We don't want to insert our custom rules again
56
+ no_category_base_refresh_rules();
57
+ }
58
+
59
+ /**
60
+ * Removes category base.
61
+ *
62
+ * @return void
63
+ */
64
+ function no_category_base_permastruct()
65
+ {
66
+ global $wp_rewrite;
67
+ global $wp_version;
68
+ if ($wp_version >= 3.4) {
69
+ $wp_rewrite->extra_permastructs['category']['struct'] = '%category%';
70
+ } else {
71
+ $wp_rewrite->extra_permastructs['category'][0] = '%category%';
72
+ }
73
+ }
74
+
75
+ /**
76
+ * Adds our custom category rewrite rules.
77
+ *
78
+ * @param array $category_rewrite Category rewrite rules.
79
+ *
80
+ * @return array
81
+ */
82
+ function no_category_base_rewrite_rules($category_rewrite)
83
+ {
84
+ $category_rewrite=array();
85
+ /* WPML is present: temporary disable terms_clauses filter to get all categories for rewrite */
86
+ if (class_exists('Sitepress')) {
87
+ global $sitepress;
88
+ remove_filter('terms_clauses', array($sitepress, 'terms_clauses'));
89
+ $categories = get_categories(array('hide_empty' => false));
90
+ add_filter('terms_clauses', array($sitepress, 'terms_clauses'));
91
+ } else {
92
+ $categories = get_categories(array('hide_empty' => false));
93
+ }
94
+
95
+ foreach($categories as $category) {
96
+ $category_nicename = $category->slug;
97
+ if ( $category->parent == $category->cat_ID ) {
98
+ $category->parent = 0;
99
+ } elseif ($category->parent != 0 ) {
100
+ $category_nicename = get_category_parents( $category->parent, false, '/', true ) . $category_nicename;
101
+ }
102
+ $category_rewrite['('.$category_nicename.')/(?:feed/)?(feed|rdf|rss|rss2|atom)/?$'] = 'index.php?category_name=$matches[1]&feed=$matches[2]';
103
+ $category_rewrite['('.$category_nicename.')/page/?([0-9]{1,})/?$'] = 'index.php?category_name=$matches[1]&paged=$matches[2]';
104
+ $category_rewrite['('.$category_nicename.')/?$'] = 'index.php?category_name=$matches[1]';
105
+ }
106
+ // Redirect support from Old Category Base
107
+ global $wp_rewrite;
108
+ $old_category_base = get_option('category_base') ? get_option('category_base') : 'category';
109
+ $old_category_base = trim($old_category_base, '/');
110
+ $category_rewrite[$old_category_base.'/(.*)$'] = 'index.php?category_redirect=$matches[1]';
111
+ return $category_rewrite;
112
+ }
113
+
114
+ function no_category_base_query_vars($public_query_vars)
115
+ {
116
+ $public_query_vars[] = 'category_redirect';
117
+ return $public_query_vars;
118
+ }
119
+
120
+ /**
121
+ * Handles category redirects.
122
+ *
123
+ * @param $query_vars Current query vars.
124
+ *
125
+ * @return array $query_vars, or void if category_redirect is present.
126
+ */
127
+ function no_category_base_request($query_vars)
128
+ {
129
+ if(isset($query_vars['category_redirect'])) {
130
+ $catlink = trailingslashit(get_option( 'home' )) . user_trailingslashit( $query_vars['category_redirect'], 'category' );
131
+ status_header(301);
132
+ header("Location: $catlink");
133
+ exit();
134
+ }
135
+ return $query_vars;
136
+ }
readme.txt ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === WP No Category Base - WPML compatible ===
2
+ Contributors: mines.io
3
+ Tags: categories, category base, category, permalinks, permastruct, links, seo, cms, wpml
4
+ Requires at least: 3.1
5
+ Tested up to: 3.4
6
+ Stable tag: 1.1.0
7
+
8
+ This plugin removes the mandatory 'Category Base' from your category permalinks. It is compatible with WPML.
9
+
10
+ == Description ==
11
+
12
+ As the name suggests this plugin will completely remove the mandatory 'Category Base' from your category permalinks ( e.g. `myblog.com/category/my-category/` to `myblog.com/my-category/` ).
13
+
14
+ The plugin requires no setup or modifying core wordpress files and will not break any links. It will also take care of redirecting your old category links to the new ones.
15
+
16
+ = Features =
17
+
18
+ 1. Better and logical permalinks like `myblog.com/my-category/` and `myblog.com/my-category/my-post/`.
19
+ 2. Simple plugin - barely adds any overhead.
20
+ 3. Works out of the box - no setup needed.
21
+ 4. No need to modify wordpress files.
22
+ 5. Doesn't require other plugins to work.
23
+ 6. Compatible with sitemap plugins.
24
+ 7. Compatible with WPML.
25
+ 8. Works with multiple sub-categories.
26
+ 9. Works with WordPress Multisite.
27
+ 10. Redirects old category permalinks to the new ones (301 redirect, good for SEO).
28
+
29
+ == Installation ==
30
+
31
+ 1. Upload `no-category-base-wpml.php` to the `/wp-content/plugins/` directory
32
+ 2. Activate the plugin through the 'Plugins' menu in WordPress
33
+ 3. That's it! You sould now be able to access your categories via http://myblog.com/my-category/
34
+
35
+ Note: If you have Wordpress 2.7 or above you can simply go to 'Plugins' &gt; 'Add New' in the Wordpress admin and search for "No Category Base" and install it from there.
36
+
37
+ == Frequently Asked Questions ==
38
+
39
+ = Why should I use this plugin? =
40
+
41
+ Use this plugin if you want to get rid of Wordpress' "Category base" completely. The normal behaviour of Wordpress is to add '/category' to your category permalinks if you leave "Category base" blank in the Permalink settings. So your category links look like `myblog.com/category/my-category/`. With this plugin your category links will look like `myblog.com/my-category/` (or `myblog.com/my-category/sub-category/` in case of sub categories).
42
+
43
+ = Will it break any other plugins? =
44
+
45
+ As far as I can tell, no. I have been using this on several blogs for a while and it doesn't break anything.
46
+
47
+ = Won't this conflict with pages? =
48
+
49
+ Simply don't have a page and category with the same slug. Even if they do have the same slug it won't break anything, just the category will get priority (Say if a category and page are both 'xyz' then `myblog.com/xyz/` will give you the category). This can have an useful side-effect. Suppose you have a category 'news', you can add a page 'news' which will show up in the page navigation but will show the 'news' category.
50
+
51
+ = Can you add a feature X? =
52
+
53
+ Depends, if its useful enough and I have time for it.
54
+
55
+
56
+ == Screenshots ==
57
+
58
+ 1. Look Ma, No Category Base!
59
+
60
+ == Changelog ==
61
+
62
+ = 1.1.0 =
63
+
64
+ Fixed compatibility for WordPress 3.4
65
+
66
+ = 1.0.0 =
67
+ * Initial release.
screenshot-1.png ADDED
Binary file