FV Top Level Categories - Version 1.3

Version Description

  • for for flushing of rewrite rules on plugin activation in WP 3.3
Download this release

Release Info

Developer FolioVision
Plugin Icon 128x128 FV Top Level Categories
Version 1.3
Comparing to
See all releases

Code changes from version 1.2 to 1.3

Files changed (2) hide show
  1. readme.txt +8 -1
  2. top-level-cats.php +28 -20
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: FolioVision
3
  Donate link: http://foliovision.com/seo-tools/wordpress/plugins/fv-top-level-categories
4
  Tags: categories, permalink
5
  Requires at least: 3.2.1
6
- Tested up to: 3.3
7
  Stable tag: trunk
8
 
9
  This is a fix of Top Level Categories plugin for Wordpress 3.1. and above.
@@ -30,6 +30,10 @@ This plugin works also if you have a permalink structure like %postname% or %cat
30
 
31
  == Frequently Asked Questions ==
32
 
 
 
 
 
33
  = How do I automatically redirect people from the old category permalink? =
34
 
35
  We recommend that you use the [Redirection](http://wordpress.org/extend/plugins/redirection/) plugin and add your old an new category links, or use a Regex redirection rule. Make sure you change Tools -> Redirection -> Options -> URL Monitoring to "Don't monitor", as there is a [bug](http://wordpress.org/support/topic/plugin-redirection-my-homepage-is-being-redirected-to-a-page-need-some-help) in that feature (also in latest current version 2.2.5) - not related to FV Top Level Categories.
@@ -45,6 +49,9 @@ Make sure your categories have unique slugs - watch out for pages with the same
45
 
46
  == Changelog ==
47
 
 
 
 
48
  = 1.2 =
49
  * fix for WP 3.3
50
  * fix for /%categor%/%post-name% permalink structure
3
  Donate link: http://foliovision.com/seo-tools/wordpress/plugins/fv-top-level-categories
4
  Tags: categories, permalink
5
  Requires at least: 3.2.1
6
+ Tested up to: 3.3.1
7
  Stable tag: trunk
8
 
9
  This is a fix of Top Level Categories plugin for Wordpress 3.1. and above.
30
 
31
  == Frequently Asked Questions ==
32
 
33
+ = I get not found/404 errors on my posts/category URLs! =
34
+
35
+ Just visit Settings --> Permalinks to refresh the rewrite rules and the issues should disappear.
36
+
37
  = How do I automatically redirect people from the old category permalink? =
38
 
39
  We recommend that you use the [Redirection](http://wordpress.org/extend/plugins/redirection/) plugin and add your old an new category links, or use a Regex redirection rule. Make sure you change Tools -> Redirection -> Options -> URL Monitoring to "Don't monitor", as there is a [bug](http://wordpress.org/support/topic/plugin-redirection-my-homepage-is-being-redirected-to-a-page-need-some-help) in that feature (also in latest current version 2.2.5) - not related to FV Top Level Categories.
49
 
50
  == Changelog ==
51
 
52
+ = 1.3 =
53
+ * for for flushing of rewrite rules on plugin activation in WP 3.3
54
+
55
  = 1.2 =
56
  * fix for WP 3.3
57
  * fix for /%categor%/%post-name% permalink structure
top-level-cats.php CHANGED
@@ -3,23 +3,25 @@
3
  Plugin Name: FV Top Level Categories
4
  Plugin URI: http://foliovision.com/seo-tools/wordpress/plugins/fv-top-level-categories
5
  Description: Removes the prefix from the URL for a category. For instance, if your old category link was <code>/category/catname</code> it will now be <code>/catname</code>
6
- Version: 1.2
7
  Author: Foliovision
8
  Author URI: http://foliovision.com/
9
  */
10
 
11
  register_activation_hook(__FILE__,'fv_top_level_categories_refresh_rules');
 
12
  add_action('created_category','fv_top_level_categories_refresh_rules');
13
  add_action('edited_category','fv_top_level_categories_refresh_rules');
14
  add_action('delete_category','fv_top_level_categories_refresh_rules');
 
15
  function fv_top_level_categories_refresh_rules() {
16
- global $wp_rewrite;
17
- $wp_rewrite->flush_rules();
18
  }
19
  register_deactivation_hook(__FILE__,'fv_top_level_categories_deactivate');
 
20
  function fv_top_level_categories_deactivate() {
21
  remove_filter('category_rewrite_rules', 'fv_top_level_categories_refresh_rules'); // We don't want to insert our custom rules again
22
- fv_top_level_categories_refresh_rules();
23
  }
24
 
25
  // Remove category base
@@ -27,20 +29,25 @@ add_action('init', 'fv_top_level_categories_permastruct');
27
  function fv_top_level_categories_permastruct() {
28
  global $wp_rewrite;
29
  $wp_rewrite->extra_permastructs['category'][0] = '%category%';
 
 
 
 
 
30
  }
31
 
32
  // Add our custom category rewrite rules
33
  add_filter('category_rewrite_rules', 'fv_top_level_categories_rewrite_rules');
34
  function fv_top_level_categories_rewrite_rules($category_rewrite) {
35
  //var_dump($category_rewrite); // For Debugging
36
-
37
- /// First we need to get full URLs of our pages
38
- $pages = get_pages( 'number=0' );
39
- $pages_urls = array();
40
- foreach( $pages AS $pages_item ) {
41
- $pages_urls[] = trim( str_replace( get_bloginfo( 'url' ), '', get_permalink( $pages_item->ID ) ), '/' );
42
- }
43
- ///
44
 
45
  $category_rewrite=array();
46
  $categories=get_categories(array('hide_empty'=>false));
@@ -49,14 +56,14 @@ function fv_top_level_categories_rewrite_rules($category_rewrite) {
49
  if ( $category->parent == $category->cat_ID ) // recursive recursion
50
  $category->parent = 0;
51
  elseif ($category->parent != 0 )
52
- $category_nicename = get_category_parents( $category->parent, false, '/', true ) . $category_nicename;
53
-
54
- /// Let's check if any of the category full URLs matches any of the pages
55
- if( in_array( $category_nicename, $pages_urls ) ) {
56
- continue;
57
- }
58
- ///
59
-
60
 
61
  $category_rewrite['('.$category_nicename.')/(?:feed/)?(feed|rdf|rss|rss2|atom)/?$'] = 'index.php?category_name=$matches[1]&feed=$matches[2]';
62
  $category_rewrite['('.$category_nicename.')/page/?([0-9]{1,})/?$'] = 'index.php?category_name=$matches[1]&paged=$matches[2]';
@@ -78,6 +85,7 @@ function fv_top_level_categories_query_vars($public_query_vars) {
78
  $public_query_vars[] = 'category_redirect';
79
  return $public_query_vars;
80
  }
 
81
  // Redirect if 'category_redirect' is set
82
  add_filter('request', 'fv_top_level_categories_request');
83
  function fv_top_level_categories_request($query_vars) {
3
  Plugin Name: FV Top Level Categories
4
  Plugin URI: http://foliovision.com/seo-tools/wordpress/plugins/fv-top-level-categories
5
  Description: Removes the prefix from the URL for a category. For instance, if your old category link was <code>/category/catname</code> it will now be <code>/catname</code>
6
+ Version: 1.3
7
  Author: Foliovision
8
  Author URI: http://foliovision.com/
9
  */
10
 
11
  register_activation_hook(__FILE__,'fv_top_level_categories_refresh_rules');
12
+
13
  add_action('created_category','fv_top_level_categories_refresh_rules');
14
  add_action('edited_category','fv_top_level_categories_refresh_rules');
15
  add_action('delete_category','fv_top_level_categories_refresh_rules');
16
+
17
  function fv_top_level_categories_refresh_rules() {
18
+ add_option('fv_top_level_categories_rewrite_rules_flush', 'true');
 
19
  }
20
  register_deactivation_hook(__FILE__,'fv_top_level_categories_deactivate');
21
+
22
  function fv_top_level_categories_deactivate() {
23
  remove_filter('category_rewrite_rules', 'fv_top_level_categories_refresh_rules'); // We don't want to insert our custom rules again
24
+ delete_option('fv_top_level_categories_rewrite_rules_flush');
25
  }
26
 
27
  // Remove category base
29
  function fv_top_level_categories_permastruct() {
30
  global $wp_rewrite;
31
  $wp_rewrite->extra_permastructs['category'][0] = '%category%';
32
+
33
+ if (get_option('fv_top_level_categories_rewrite_rules_flush') == 'true') {
34
+ flush_rewrite_rules();
35
+ delete_option('fv_top_level_categories_rewrite_rules_flush');
36
+ }
37
  }
38
 
39
  // Add our custom category rewrite rules
40
  add_filter('category_rewrite_rules', 'fv_top_level_categories_rewrite_rules');
41
  function fv_top_level_categories_rewrite_rules($category_rewrite) {
42
  //var_dump($category_rewrite); // For Debugging
43
+
44
+ /// First we need to get full URLs of our pages
45
+ $pages = get_pages( 'number=0' );
46
+ $pages_urls = array();
47
+ foreach( $pages AS $pages_item ) {
48
+ $pages_urls[] = trim( str_replace( get_bloginfo( 'url' ), '', get_permalink( $pages_item->ID ) ), '/' );
49
+ }
50
+ ///
51
 
52
  $category_rewrite=array();
53
  $categories=get_categories(array('hide_empty'=>false));
56
  if ( $category->parent == $category->cat_ID ) // recursive recursion
57
  $category->parent = 0;
58
  elseif ($category->parent != 0 )
59
+ $category_nicename = get_category_parents( $category->parent, false, '/', true ) . $category_nicename;
60
+
61
+ /// Let's check if any of the category full URLs matches any of the pages
62
+ if( in_array( $category_nicename, $pages_urls ) ) {
63
+ continue;
64
+ }
65
+ ///
66
+
67
 
68
  $category_rewrite['('.$category_nicename.')/(?:feed/)?(feed|rdf|rss|rss2|atom)/?$'] = 'index.php?category_name=$matches[1]&feed=$matches[2]';
69
  $category_rewrite['('.$category_nicename.')/page/?([0-9]{1,})/?$'] = 'index.php?category_name=$matches[1]&paged=$matches[2]';
85
  $public_query_vars[] = 'category_redirect';
86
  return $public_query_vars;
87
  }
88
+
89
  // Redirect if 'category_redirect' is set
90
  add_filter('request', 'fv_top_level_categories_request');
91
  function fv_top_level_categories_request($query_vars) {