Remove Category URL - Version 1.1.2

Version Description

  • Update
Download this release

Release Info

Developer valeriosza
Plugin Icon 128x128 Remove Category URL
Version 1.1.2
Comparing to
See all releases

Code changes from version 1.1 to 1.1.2

Files changed (4) hide show
  1. index.php +3 -3
  2. readme.txt +96 -87
  3. remove-category-url.php +129 -127
  4. uninstall.php +19 -19
index.php CHANGED
@@ -1,4 +1,4 @@
1
- <?php
2
- // Nothing to see here
3
- header("HTTP/1.1 403 Forbidden");
4
  ?>
1
+ <?php
2
+ // Nothing to see here
3
+ header("HTTP/1.1 403 Forbidden");
4
  ?>
readme.txt CHANGED
@@ -1,87 +1,96 @@
1
- === Remove Category URL ===
2
- Contributors: valeriosza, wordlab
3
- Tags: categories, category base, category, permalinks, URL structure, links, seo, cms, wpml, URL
4
- Requires at least: 3.1
5
- Tested up to: 4.3.2
6
- Stable tag: 1.1
7
- License: GPLv2
8
- Donate link: http://wordlab.com.br/donate/
9
-
10
- This plugin removes '/category' from your category permalinks. (e.g. `/category/my-category/` to `/my-category/`)
11
-
12
- == Description ==
13
-
14
- This plugin will completely remove the '/category/' from your permalinks ( e.g. `mydomain.com/category/my-category/` to `mydomain.com/my-category/` ).
15
-
16
- No configuration is required
17
-
18
- = Features =
19
-
20
- 1. Better and logical permalinks like `mydomain.com/my-category/` and `mydomain.com/my-category/my-post/`.
21
- 2. Simple plugin - No configuration is required.
22
- 3. No need to modify wordpress files.
23
- 4. Doesn't require other plugins to work.
24
- 5. Compatible with sitemap plugins.
25
- 6. Compatible with WPML.
26
- 7. Works with multiple sub-categories.
27
- 8. Works with WordPress Multisite.
28
- 9. Redirects old category permalinks to the new ones (301 redirect, good for SEO).
29
-
30
- = Heads up: =
31
-
32
- Read the [FAQ](https://wordpress.org/plugins/remove-category-url/faq/) before use.
33
-
34
- Want to help? Use the [support](https://wordpress.org/support/plugin/remove-category-url)
35
-
36
- == Installation ==
37
-
38
- 1. Upload `remove-category-url.zip` to the `/wp-content/plugins/` directory.
39
- 2. Activate the plugin through the 'Plugins' menu in WordPress.
40
- 3. That's it! You sould now be able to access your categories via http://mydomain.com/my-category/
41
-
42
- == Frequently Asked Questions ==
43
-
44
- = Why should I use this plugin? =
45
-
46
- 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" blank in the Permalink settings. So your category links look like `mydomain.com/category/my-category/`. With this plugin your category links will look like `mydomain.com/my-category/` (or `mydomain.com/my-category/sub-category/` in case of sub categories).
47
-
48
- = Will it break any other plugins? =
49
-
50
- As far as I can tell, no. I have been using this on several blogs for a while and it doesn't break anything.
51
-
52
- = Won't this conflict with pages? =
53
-
54
- 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 `mydomain.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.
55
-
56
- = The plugin has been uninstalled, but the slug /category/ did not reappear why? =
57
-
58
- A particular installation does not allow the rewrite feature in disabling the plugin. Try after disabling the plugin, save permanent links again.
59
-
60
- == Screenshots ==
61
-
62
- 1. No Category URL
63
-
64
- == Changelog ==
65
-
66
- = 1.1 =
67
- * Fix Erros
68
-
69
- = 1.0.2 =
70
- * Update Compatible with WPML.
71
-
72
- = 0.1.1 =
73
- * Add uninstall.
74
-
75
- = 0.1.0 =
76
- * Initial release.
77
-
78
- == Upgrade Notice ==
79
-
80
- = 1.0.2 =
81
- * Update Compatible with WPML.
82
-
83
- = 0.1.1 =
84
- * Add uninstall.
85
-
86
- = 0.1.0 =
87
- * Initial release.
 
 
 
 
 
 
 
 
 
1
+ === Remove Category URL ===
2
+ Contributors: valeriosza
3
+ Tags: categories, category base, category, permalinks, URL structure, links, seo, cms, wpml, URL
4
+ Requires at least: 3.1
5
+ Tested up to: 4.8.3
6
+ Stable tag: 1.1.2
7
+ License: GPLv2
8
+ Donate link:
9
+
10
+ This plugin removes '/category' from your category permalinks. (e.g. `/category/my-category/` to `/my-category/`)
11
+
12
+ == Description ==
13
+
14
+ This plugin will completely remove the '/category/' from your permalinks ( e.g. `mydomain.com/category/my-category/` to `mydomain.com/my-category/` ).
15
+
16
+ No configuration is required
17
+
18
+ = Features =
19
+
20
+ 1. Better and logical permalinks like `mydomain.com/my-category/` and `mydomain.com/my-category/my-post/`.
21
+ 2. Simple plugin - No configuration is required.
22
+ 3. No need to modify wordpress files.
23
+ 4. Doesn't require other plugins to work.
24
+ 5. Compatible with sitemap plugins.
25
+ 6. Compatible with WPML.
26
+ 7. Works with multiple sub-categories.
27
+ 8. Works with WordPress Multisite.
28
+ 9. Redirects old category permalinks to the new ones (301 redirect, good for SEO).
29
+
30
+ = Heads up: =
31
+
32
+ Read the [FAQ](https://wordpress.org/plugins/remove-category-url/faq/) before use.
33
+
34
+ Want to help? Use the [support](https://wordpress.org/support/plugin/remove-category-url)
35
+
36
+ == Installation ==
37
+
38
+ 1. Upload `remove-category-url.zip` to the `/wp-content/plugins/` directory.
39
+ 2. Activate the plugin through the 'Plugins' menu in WordPress.
40
+ 3. That's it! You sould now be able to access your categories via http://mydomain.com/my-category/
41
+
42
+ == Frequently Asked Questions ==
43
+
44
+ = Why should I use this plugin? =
45
+
46
+ 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" blank in the Permalink settings. So your category links look like `mydomain.com/category/my-category/`. With this plugin your category links will look like `mydomain.com/my-category/` (or `mydomain.com/my-category/sub-category/` in case of sub categories).
47
+
48
+ = Will it break any other plugins? =
49
+
50
+ As far as I can tell, no. I have been using this on several blogs for a while and it doesn't break anything.
51
+
52
+ = Won't this conflict with pages? =
53
+
54
+ 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 `mydomain.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.
55
+
56
+ = The plugin has been uninstalled, but the slug /category/ did not reappear why? =
57
+
58
+ A particular installation does not allow the rewrite feature in disabling the plugin. Try after disabling the plugin, save permanent links again.
59
+
60
+ == Screenshots ==
61
+
62
+ 1. No Category URL
63
+
64
+ == Changelog ==
65
+
66
+ = 1.1.2 =
67
+ * Update
68
+
69
+ = 1.1.1 =
70
+ * Compatible with translate.wordpress.org
71
+
72
+ = 1.1 =
73
+ * Fix Erros
74
+
75
+ = 1.0.2 =
76
+ * Update Compatible with WPML.
77
+
78
+ = 0.1.1 =
79
+ * Add uninstall.
80
+
81
+ = 0.1.0 =
82
+ * Initial release.
83
+
84
+ == Upgrade Notice ==
85
+
86
+ = 1.1.1 =
87
+ * Compatible with translate.wordpress.org
88
+
89
+ = 1.0.2 =
90
+ * Update Compatible with WPML.
91
+
92
+ = 0.1.1 =
93
+ * Add uninstall.
94
+
95
+ = 0.1.0 =
96
+ * Initial release.
remove-category-url.php CHANGED
@@ -1,128 +1,130 @@
1
- <?php
2
- /**
3
- * Plugin Name: Remove Category URL
4
- * Plugin URI: http://valeriosouza.com.br/portfolio/remove-category-url/
5
- * Description: This plugin removes '/category' from your category permalinks. (e.g. `/category/my-category/` to `/my-category/`)
6
- * Version: 1.1
7
- * Author: Valerio Souza, WordLab Academy
8
- * Author URI: http://valeriosouza.com.br/
9
- */
10
-
11
- /* hooks */
12
- register_activation_hook( __FILE__, 'remove_category_url_refresh_rules' );
13
- register_deactivation_hook( __FILE__, 'remove_category_url_deactivate' );
14
-
15
- /* actions */
16
- add_action( 'created_category', 'remove_category_url_refresh_rules' );
17
- add_action( 'delete_category', 'remove_category_url_refresh_rules' );
18
- add_action( 'edited_category', 'remove_category_url_refresh_rules' );
19
- add_action( 'init', 'remove_category_url_permastruct' );
20
-
21
- /* filters */
22
- add_filter( 'category_rewrite_rules', 'remove_category_url_rewrite_rules' );
23
- add_filter( 'query_vars', 'remove_category_url_query_vars' ); // Adds 'category_redirect' query variable
24
- add_filter( 'request', 'remove_category_url_request' ); // Redirects if 'category_redirect' is set
25
- add_filter( 'plugin_row_meta', 'remove_category_url_plugin_row_meta', 10, 4 );
26
-
27
- function remove_category_url_refresh_rules() {
28
- global $wp_rewrite;
29
- $wp_rewrite->flush_rules();
30
- }
31
-
32
- function remove_category_url_deactivate() {
33
- remove_filter( 'category_rewrite_rules', 'remove_category_url_rewrite_rules' ); // We don't want to insert our custom rules again
34
- remove_category_url_refresh_rules();
35
- }
36
-
37
- /**
38
- * Removes category base.
39
- *
40
- * @return void
41
- */
42
- function remove_category_url_permastruct() {
43
- global $wp_rewrite, $wp_version;
44
-
45
- if ( 3.4 <= $wp_version ) {
46
- $wp_rewrite->extra_permastructs['category']['struct'] = '%category%';
47
- } else {
48
- $wp_rewrite->extra_permastructs['category'][0] = '%category%';
49
- }
50
- }
51
-
52
- /**
53
- * Adds our custom category rewrite rules.
54
- *
55
- * @param array $category_rewrite Category rewrite rules.
56
- *
57
- * @return array
58
- */
59
- function remove_category_url_rewrite_rules( $category_rewrite ) {
60
- global $wp_rewrite;
61
-
62
- $category_rewrite = array();
63
-
64
- /* WPML is present: temporary disable terms_clauses filter to get all categories for rewrite */
65
- if ( class_exists( 'Sitepress' ) ) {
66
- global $sitepress;
67
-
68
- remove_filter( 'terms_clauses', array( $sitepress, 'terms_clauses' ) );
69
- $categories = get_categories( array( 'hide_empty' => false, '_icl_show_all_langs' => true ) );
70
- add_filter( 'terms_clauses', array( $sitepress, 'terms_clauses' ) );
71
- } else {
72
- $categories = get_categories( array( 'hide_empty' => false ) );
73
- }
74
-
75
- foreach ( $categories as $category ) {
76
- $category_nicename = $category->slug;
77
- if ( $category->parent == $category->cat_ID ) {
78
- $category->parent = 0;
79
- } elseif ( 0 != $category->parent ) {
80
- $category_nicename = get_category_parents( $category->parent, false, '/', true ) . $category_nicename;
81
- }
82
- $category_rewrite[ '(' . $category_nicename . ')/(?:feed/)?(feed|rdf|rss|rss2|atom)/?$' ] = 'index.php?category_name=$matches[1]&feed=$matches[2]';
83
- $category_rewrite[ '(' . $category_nicename . ')/page/?([0-9]{1,})/?$' ] = 'index.php?category_name=$matches[1]&paged=$matches[2]';
84
- $category_rewrite[ '(' . $category_nicename . ')/?$' ] = 'index.php?category_name=$matches[1]';
85
- }
86
-
87
- // Redirect support from Old Category Base
88
- $old_category_base = get_option( 'category_base' ) ? get_option( 'category_base' ) : 'category';
89
- $old_category_base = trim( $old_category_base, '/' );
90
- $category_rewrite[ $old_category_base . '/(.*)$' ] = 'index.php?category_redirect=$matches[1]';
91
-
92
- return $category_rewrite;
93
- }
94
-
95
- function remove_category_url_query_vars( $public_query_vars ) {
96
- $public_query_vars[] = 'category_redirect';
97
-
98
- return $public_query_vars;
99
- }
100
-
101
- /**
102
- * Handles category redirects.
103
- *
104
- * @param $query_vars Current query vars.
105
- *
106
- * @return array $query_vars, or void if category_redirect is present.
107
- */
108
- function remove_category_url_request( $query_vars ) {
109
- if ( isset( $query_vars['category_redirect'] ) ) {
110
- $catlink = trailingslashit( get_option( 'home' ) ) . user_trailingslashit( $query_vars['category_redirect'], 'category' );
111
- status_header( 301 );
112
- header( "Location: $catlink" );
113
- exit;
114
- }
115
-
116
- return $query_vars;
117
- }
118
-
119
- function remove_category_url_plugin_row_meta( $links, $file ) {
120
- if( plugin_basename( __FILE__ ) === $file ) {
121
- $links[] = sprintf(
122
- '<a target="_blank" href="%s">%s</a>',
123
- esc_url('http://wordlab.com.br/donate/'),
124
- __( 'Donate', 'remove_category_url' )
125
- );
126
- }
127
- return $links;
 
 
128
  }
1
+ <?php
2
+ /**
3
+ * Plugin Name: Remove Category URL
4
+ * Plugin URI: http://valeriosouza.com.br/portfolio/remove-category-url/
5
+ * Description: This plugin removes '/category' from your category permalinks. (e.g. `/category/my-category/` to `/my-category/`)
6
+ * Version: 1.1.2
7
+ * Author: Valerio Souza
8
+ * Author URI: http://valeriosouza.com.br/
9
+ * Text Domain: remove-category-url
10
+ * Domain Path: /languages
11
+ */
12
+
13
+ /* hooks */
14
+ register_activation_hook( __FILE__, 'remove_category_url_refresh_rules' );
15
+ register_deactivation_hook( __FILE__, 'remove_category_url_deactivate' );
16
+
17
+ /* actions */
18
+ add_action( 'created_category', 'remove_category_url_refresh_rules' );
19
+ add_action( 'delete_category', 'remove_category_url_refresh_rules' );
20
+ add_action( 'edited_category', 'remove_category_url_refresh_rules' );
21
+ add_action( 'init', 'remove_category_url_permastruct' );
22
+
23
+ /* filters */
24
+ add_filter( 'category_rewrite_rules', 'remove_category_url_rewrite_rules' );
25
+ add_filter( 'query_vars', 'remove_category_url_query_vars' ); // Adds 'category_redirect' query variable
26
+ add_filter( 'request', 'remove_category_url_request' ); // Redirects if 'category_redirect' is set
27
+ add_filter( 'plugin_row_meta', 'remove_category_url_plugin_row_meta', 10, 4 );
28
+
29
+ function remove_category_url_refresh_rules() {
30
+ global $wp_rewrite;
31
+ $wp_rewrite->flush_rules();
32
+ }
33
+
34
+ function remove_category_url_deactivate() {
35
+ remove_filter( 'category_rewrite_rules', 'remove_category_url_rewrite_rules' ); // We don't want to insert our custom rules again
36
+ remove_category_url_refresh_rules();
37
+ }
38
+
39
+ /**
40
+ * Removes category base.
41
+ *
42
+ * @return void
43
+ */
44
+ function remove_category_url_permastruct() {
45
+ global $wp_rewrite, $wp_version;
46
+
47
+ if ( 3.4 <= $wp_version ) {
48
+ $wp_rewrite->extra_permastructs['category']['struct'] = '%category%';
49
+ } else {
50
+ $wp_rewrite->extra_permastructs['category'][0] = '%category%';
51
+ }
52
+ }
53
+
54
+ /**
55
+ * Adds our custom category rewrite rules.
56
+ *
57
+ * @param array $category_rewrite Category rewrite rules.
58
+ *
59
+ * @return array
60
+ */
61
+ function remove_category_url_rewrite_rules( $category_rewrite ) {
62
+ global $wp_rewrite;
63
+
64
+ $category_rewrite = array();
65
+
66
+ /* WPML is present: temporary disable terms_clauses filter to get all categories for rewrite */
67
+ if ( class_exists( 'Sitepress' ) ) {
68
+ global $sitepress;
69
+
70
+ remove_filter( 'terms_clauses', array( $sitepress, 'terms_clauses' ) );
71
+ $categories = get_categories( array( 'hide_empty' => false, '_icl_show_all_langs' => true ) );
72
+ add_filter( 'terms_clauses', array( $sitepress, 'terms_clauses' ) );
73
+ } else {
74
+ $categories = get_categories( array( 'hide_empty' => false ) );
75
+ }
76
+
77
+ foreach ( $categories as $category ) {
78
+ $category_nicename = $category->slug;
79
+ if ( $category->parent == $category->cat_ID ) {
80
+ $category->parent = 0;
81
+ } elseif ( 0 != $category->parent ) {
82
+ $category_nicename = get_category_parents( $category->parent, false, '/', true ) . $category_nicename;
83
+ }
84
+ $category_rewrite[ '(' . $category_nicename . ')/(?:feed/)?(feed|rdf|rss|rss2|atom)/?$' ] = 'index.php?category_name=$matches[1]&feed=$matches[2]';
85
+ $category_rewrite[ '(' . $category_nicename . ')/page/?([0-9]{1,})/?$' ] = 'index.php?category_name=$matches[1]&paged=$matches[2]';
86
+ $category_rewrite[ '(' . $category_nicename . ')/?$' ] = 'index.php?category_name=$matches[1]';
87
+ }
88
+
89
+ // Redirect support from Old Category Base
90
+ $old_category_base = get_option( 'category_base' ) ? get_option( 'category_base' ) : 'category';
91
+ $old_category_base = trim( $old_category_base, '/' );
92
+ $category_rewrite[ $old_category_base . '/(.*)$' ] = 'index.php?category_redirect=$matches[1]';
93
+
94
+ return $category_rewrite;
95
+ }
96
+
97
+ function remove_category_url_query_vars( $public_query_vars ) {
98
+ $public_query_vars[] = 'category_redirect';
99
+
100
+ return $public_query_vars;
101
+ }
102
+
103
+ /**
104
+ * Handles category redirects.
105
+ *
106
+ * @param $query_vars Current query vars.
107
+ *
108
+ * @return array $query_vars, or void if category_redirect is present.
109
+ */
110
+ function remove_category_url_request( $query_vars ) {
111
+ if ( isset( $query_vars['category_redirect'] ) ) {
112
+ $catlink = trailingslashit( get_option( 'home' ) ) . user_trailingslashit( $query_vars['category_redirect'], 'category' );
113
+ status_header( 301 );
114
+ header( "Location: $catlink" );
115
+ exit;
116
+ }
117
+
118
+ return $query_vars;
119
+ }
120
+
121
+ function remove_category_url_plugin_row_meta( $links, $file ) {
122
+ if( plugin_basename( __FILE__ ) === $file ) {
123
+ $links[] = sprintf(
124
+ '<a target="_blank" href="%s">%s</a>',
125
+ esc_url('http://wordlab.com.br/donate/'),
126
+ __( 'Donate', 'remove_category_url' )
127
+ );
128
+ }
129
+ return $links;
130
  }
uninstall.php CHANGED
@@ -1,19 +1,19 @@
1
- <?php
2
- /**
3
- * Fired when the plugin is uninstalled.
4
- *
5
- * @package Remove_Category_URL
6
- * @author Valerio Souza <eu@valeriosouza.com.br>
7
- * @license GPL-2.0+
8
- * @link http://wordpress.org/plugins/remove-category-url
9
- * @copyright 2013 CodeHost
10
- */
11
-
12
- // If uninstall not called from WordPress, then exit
13
- if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
14
- exit;
15
- }
16
-
17
- remove_filter('category_rewrite_rules', 'remove_category_url_rewrite_rules');
18
- global $wp_rewrite;
19
- $wp_rewrite->flush_rules();
1
+ <?php
2
+ /**
3
+ * Fired when the plugin is uninstalled.
4
+ *
5
+ * @package Remove_Category_URL
6
+ * @author Valerio Souza <eu@valeriosouza.com.br>
7
+ * @license GPL-2.0+
8
+ * @link http://wordpress.org/plugins/remove-category-url
9
+ * @copyright 2013 CodeHost
10
+ */
11
+
12
+ // If uninstall not called from WordPress, then exit
13
+ if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
14
+ exit;
15
+ }
16
+
17
+ remove_filter('category_rewrite_rules', 'remove_category_url_rewrite_rules');
18
+ global $wp_rewrite;
19
+ $wp_rewrite->flush_rules();