FV Top Level Categories - Version 1.7

Version Description

Download this release

Release Info

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

Code changes from version 1.6 to 1.7

languages/fv_tlc-pl_PL.mo ADDED
Binary file
languages/fv_tlc-pl_PL.po ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: FV-topl-level-categories\n"
4
+ "POT-Creation-Date: 2015-05-01 00:15+0100\n"
5
+ "PO-Revision-Date: 2015-05-01 00:30+0100\n"
6
+ "Last-Translator: Maciej Gryniuk <maciejka45@gmail.com>\n"
7
+ "Language-Team: Maciej Gryniuk <maciejka45@gmail.com>\n"
8
+ "Language: pl_PL\n"
9
+ "MIME-Version: 1.0\n"
10
+ "Content-Type: text/plain; charset=UTF-8\n"
11
+ "Content-Transfer-Encoding: 8bit\n"
12
+ "X-Generator: Poedit 1.8beta1\n"
13
+ "X-Poedit-Basepath: .\n"
14
+ "Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 "
15
+ "|| n%100>=20) ? 1 : 2);\n"
16
+ "X-Poedit-KeywordsList: __;_e;_n\n"
17
+ "X-Poedit-SearchPath-0: ..\n"
18
+
19
+ #: top-level-cats.php:3
20
+ msgid "FV Top Level Categories"
21
+ msgstr "FV Kategorie najwyższego poziomu"
22
+
23
+ #: top-level-cats.php:5
24
+ msgid ""
25
+ "Removes the prefix from the URL for a category. For instance, if your old "
26
+ "category link was <code>/category/catname</code> it will now be <code>/"
27
+ "catname</code>"
28
+ msgstr ""
29
+ "Usuwa prefiks kategorii z adresu URL. Przykładowo, jeżeli Twój stary link do "
30
+ "kategorii wyglądał tak: <code>/category/nazwakategorii</code>, teraz będzie "
31
+ "taki: <code>/nazwakategorii</code>"
32
+
33
+ #: top-level-cats.php:380
34
+ msgid "Adjust categories in your post URLs"
35
+ msgstr "Dostosuj kategorie w adresach URL wpisów"
36
+
37
+ #: top-level-cats.php:388
38
+ msgid "Only use top-level categories in URLs."
39
+ msgstr "Używaj w adresach URL tylko kategorii najwyższego poziomu."
40
+
41
+ #: top-level-cats.php:396
42
+ msgid "Only allow following categories in URLs:"
43
+ msgstr "Dozwól jedynie następujące kategorie w adresach URL:"
44
+
45
+ #: top-level-cats.php:403
46
+ msgid "Save Changes"
47
+ msgstr "Zapisz zmiany"
48
+
49
+ #: top-level-cats.php:407
50
+ msgid ""
51
+ "Are you having any problems or questions? Use our <a target=\"_blank\" href="
52
+ "\"http://foliovision.com/support/fv-top-level-categories/\">support forums</"
53
+ "a>."
54
+ msgstr ""
55
+ "Doświadczasz jakiś problemów lub masz pytania? Skorzytaj z naszego <a target="
56
+ "\"_blank\" href=\"http://foliovision.com/support/fv-top-level-categories/"
57
+ "\">forum wsparcia</a>."
58
+
59
+ #: top-level-cats.php:412
60
+ msgid ""
61
+ "Since you are not using %category% in your post permalinks, there is nothing "
62
+ "to adjust."
63
+ msgstr ""
64
+ "Ponieważ nie używasz %category% w bezpośrednich odnośnikach wpisów, nie "
65
+ "musisz nic dostosowywać."
languages/fv_tlc-pt_PT.mo ADDED
Binary file
languages/fv_tlc-pt_PT.po ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: FV-topl-level-categories\n"
4
+ "POT-Creation-Date: 2015-05-11 09:35-0000\n"
5
+ "PO-Revision-Date: 2015-05-11 09:44-0000\n"
6
+ "Last-Translator: Pedro Mendonça <ped.gaspar@gmail.com>\n"
7
+ "Language-Team: \n"
8
+ "Language: pt_PT\n"
9
+ "MIME-Version: 1.0\n"
10
+ "Content-Type: text/plain; charset=UTF-8\n"
11
+ "Content-Transfer-Encoding: 8bit\n"
12
+ "X-Generator: Poedit 1.7.6\n"
13
+ "X-Poedit-Basepath: ..\n"
14
+ "Plural-Forms: nplurals=2; plural=(n != 1);\n"
15
+ "X-Poedit-KeywordsList: __;_e;__ngettext:1,2;_n:1,2;__ngettext_noop:1,2;_n_noop:1,2;_c,_nc:4c,1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;_nx_noop:4c,1,2;esc_attr__;esc_attr_e;esc_attr_x:1,2c;esc_html__;esc_html_e;esc_html_x:1,2c\n"
16
+ "X-Poedit-SourceCharset: UTF-8\n"
17
+ "X-Poedit-SearchPath-0: .\n"
18
+
19
+ #: ../top-level-cats.php:270 ../top-level-cats.php:368
20
+ msgid "FV Top Level Categories"
21
+ msgstr "FV Top Level Categories"
22
+
23
+ #: ../top-level-cats.php:380
24
+ msgid "Adjust categories in your post URLs"
25
+ msgstr "Ajustar categorias nos URL dos seus artigos"
26
+
27
+ #: ../top-level-cats.php:388
28
+ msgid "Only use top-level categories in URLs."
29
+ msgstr "Utilizar apenas as categorias de topo nos URLs."
30
+
31
+ #: ../top-level-cats.php:396
32
+ msgid "Only allow following categories in URLs:"
33
+ msgstr "Apenas permitir as seguintes categorias nos URLs:"
34
+
35
+ #: ../top-level-cats.php:403
36
+ msgid "Save Changes"
37
+ msgstr "Guardar alterações"
38
+
39
+ #: ../top-level-cats.php:407
40
+ msgid "Are you having any problems or questions? Use our <a target=\"_blank\" href=\"http://foliovision.com/support/fv-top-level-categories/\">support forums</a>."
41
+ msgstr "Tem algum problema ou alguma dúvida? Utilize os nossos <a target=\"_blank\" href=\"http://foliovision.com/support/fv-top-level-categories/\">fóruns de suporte</a>."
42
+
43
+ #: ../top-level-cats.php:412
44
+ msgid "Since you are not using %category% in your post permalinks, there is nothing to adjust."
45
+ msgstr "Como não está a utilizar %category% nas ligações permanentes dos seus artigos, não há nada para ser ajustado."
46
+
47
+ #: ../top-level-cats.php:428
48
+ msgid "Settings"
49
+ msgstr "Definições"
languages/fv_tlc-sk_SK.po CHANGED
@@ -1,50 +1,50 @@
1
- msgid ""
2
- msgstr ""
3
- "Project-Id-Version: FV-topl-level-categories\n"
4
- "POT-Creation-Date: 2014-09-19 11:37+0100\n"
5
- "PO-Revision-Date: 2014-09-19 11:49+0100\n"
6
- "Last-Translator: \n"
7
- "Language-Team: \n"
8
- "Language: sk_SK\n"
9
- "MIME-Version: 1.0\n"
10
- "Content-Type: text/plain; charset=UTF-8\n"
11
- "Content-Transfer-Encoding: 8bit\n"
12
- "X-Generator: Poedit 1.6.9\n"
13
- "X-Poedit-Basepath: .\n"
14
- "Plural-Forms: nplurals=3; plural=(n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2;\n"
15
- "X-Poedit-KeywordsList: __;_e;_n\n"
16
- "X-Poedit-SearchPath-0: ..\n"
17
-
18
- #: ../top-level-cats.php:374
19
- msgid "Adjust categories in your post URLs"
20
- msgstr "Nastavenie kategórií v URL adresách postov"
21
-
22
- #: ../top-level-cats.php:382
23
- msgid "Only use top-level catogories in URLs."
24
- msgstr "Použiť iba hlavné kategórie v adresách URL."
25
-
26
- #: ../top-level-cats.php:390
27
- msgid "Only allow following categories in URLs:"
28
- msgstr "V URL adresách povoliť iba nasledujúce kategórie:"
29
-
30
- #: ../top-level-cats.php:397
31
- msgid "Save Changes"
32
- msgstr "Uložiť zmeny"
33
-
34
- #: ../top-level-cats.php:401
35
- msgid ""
36
- "Are you having any problems or questions? Use our <a target=\"_blank\" href="
37
- "\"http://foliovision.com/support/fv-top-level-categories/\">support forums</"
38
- "a>."
39
- msgstr ""
40
- "Máte nejaké problémy alebo otázky? Použite naše <a target=\"_blank\" href="
41
- "\"http://foliovision.com/support/fv-top-level-categories/\">forúm podpory</"
42
- "a>."
43
-
44
- #: ../top-level-cats.php:406
45
- msgid ""
46
- "Since you are not using %category% in your post permalinks, there is nothing "
47
- "to adjust."
48
- msgstr ""
49
- "Keďže vo svojích post permalinkoch nepoužívate %category% nie je tu nič čo "
50
- "by ste mohli nastaviť."
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: FV-topl-level-categories\n"
4
+ "POT-Creation-Date: 2014-09-19 11:37+0100\n"
5
+ "PO-Revision-Date: 2014-09-19 11:49+0100\n"
6
+ "Last-Translator: \n"
7
+ "Language-Team: \n"
8
+ "Language: sk_SK\n"
9
+ "MIME-Version: 1.0\n"
10
+ "Content-Type: text/plain; charset=UTF-8\n"
11
+ "Content-Transfer-Encoding: 8bit\n"
12
+ "X-Generator: Poedit 1.6.9\n"
13
+ "X-Poedit-Basepath: .\n"
14
+ "Plural-Forms: nplurals=3; plural=(n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2;\n"
15
+ "X-Poedit-KeywordsList: __;_e;_n\n"
16
+ "X-Poedit-SearchPath-0: ..\n"
17
+
18
+ #: ../top-level-cats.php:374
19
+ msgid "Adjust categories in your post URLs"
20
+ msgstr "Nastavenie kategórií v URL adresách postov"
21
+
22
+ #: ../top-level-cats.php:382
23
+ msgid "Only use top-level categories in URLs."
24
+ msgstr "Použiť iba hlavné kategórie v adresách URL."
25
+
26
+ #: ../top-level-cats.php:390
27
+ msgid "Only allow following categories in URLs:"
28
+ msgstr "V URL adresách povoliť iba nasledujúce kategórie:"
29
+
30
+ #: ../top-level-cats.php:397
31
+ msgid "Save Changes"
32
+ msgstr "Uložiť zmeny"
33
+
34
+ #: ../top-level-cats.php:401
35
+ msgid ""
36
+ "Are you having any problems or questions? Use our <a target=\"_blank\" href="
37
+ "\"http://foliovision.com/support/fv-top-level-categories/\">support forums</"
38
+ "a>."
39
+ msgstr ""
40
+ "Máte nejaké problémy alebo otázky? Použite naše <a target=\"_blank\" href="
41
+ "\"http://foliovision.com/support/fv-top-level-categories/\">forúm podpory</"
42
+ "a>."
43
+
44
+ #: ../top-level-cats.php:406
45
+ msgid ""
46
+ "Since you are not using %category% in your post permalinks, there is nothing "
47
+ "to adjust."
48
+ msgstr ""
49
+ "Keďže vo svojích post permalinkoch nepoužívate %category% nie je tu nič čo "
50
+ "by ste mohli nastaviť."
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: 4.1
7
  Stable tag: trunk
8
 
9
  This is a fix of Top Level Categories plugin for Wordpress 3.1. and above.
@@ -45,6 +45,11 @@ Make sure your categories have unique slugs - watch out for pages with the same
45
 
46
  == Changelog ==
47
 
 
 
 
 
 
48
  = Version 1.6 - September 19th, 2014 =
49
  * Adding support for translations ( Slovak language added )
50
 
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: 4.2.1
7
  Stable tag: trunk
8
 
9
  This is a fix of Top Level Categories plugin for Wordpress 3.1. and above.
45
 
46
  == Changelog ==
47
 
48
+ = Version 1.7- May 12th, 2014 =
49
+
50
+ * Added Polish translation - thanks to maciejka45@gmail.com
51
+ * Added Portuguese translation - thanks to Pedro Mendonça
52
+
53
  = Version 1.6 - September 19th, 2014 =
54
  * Adding support for translations ( Slovak language added )
55
 
top-level-cats.php CHANGED
@@ -1,422 +1,434 @@
1
- <?php
2
- /*
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.6
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
28
- add_action('init', 'fv_top_level_categories_permastruct');
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));
54
- foreach($categories as $category) {
55
- $category_nicename = $category->slug;
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]';
70
- $category_rewrite['('.$category_nicename.')/?$'] = 'index.php?category_name=$matches[1]';
71
- }
72
- // Redirect support from Old Category Base
73
- global $wp_rewrite;
74
- $old_category_base = get_option('category_base') ? get_option('category_base') : 'category';
75
- $old_category_base = trim($old_category_base, '/');
76
- $category_rewrite[$old_category_base.'/(.*)$'] = 'index.php?category_redirect=$matches[1]';
77
-
78
- //var_dump($category_rewrite); // For Debugging
79
- return $category_rewrite;
80
- }
81
-
82
- //Redirect to TL parent categ, if "Only use top-level catogories in URLs." is on
83
- add_filter('template_redirect', 'fv_top_level_categories_tlc_redirect', 999, 2);
84
- function fv_top_level_categories_tlc_redirect( $link ) {
85
- if( FV_Top_Level_Cats::is_top_level_only() && is_single() ) {
86
- global $wp_query;
87
- $requested_url = is_ssl() ? 'https://' : 'http://';
88
- $requested_url .= $_SERVER['HTTP_HOST'];
89
- $requested_url .= $_SERVER['REQUEST_URI'];
90
-
91
- $real_permalink = get_permalink($wp_query->queried_object_id);
92
-
93
- if( FALSE === stripos($requested_url, $real_permalink) ) {
94
-
95
- $bMached = preg_match('~/([^/:]+/?)$~',$real_permalink, $end_of_permalink);
96
- if( $bMached && preg_match('~'.$end_of_permalink[1].'(.+)$~', $requested_url, $end_of_url) )
97
- wp_redirect( $real_permalink . $end_of_url[1], 301 );
98
- else
99
- wp_redirect( $real_permalink, 301 );
100
- die();
101
- }
102
- }
103
-
104
- return $link;
105
- }
106
-
107
- // Add 'category_redirect' query variable
108
- add_filter('query_vars', 'fv_top_level_categories_query_vars');
109
- function fv_top_level_categories_query_vars($public_query_vars) {
110
- $public_query_vars[] = 'category_redirect';
111
- return $public_query_vars;
112
- }
113
-
114
- // Redirect if 'category_redirect' is set
115
- add_filter('request', 'fv_top_level_categories_request');
116
- function fv_top_level_categories_request($query_vars) {
117
- //print_r($query_vars); // For Debugging
118
- if(isset($query_vars['category_redirect'])) {
119
- $catlink = trailingslashit(get_option( 'home' )) . user_trailingslashit( $query_vars['category_redirect'], 'category' );
120
- status_header(301);
121
- header("Location: $catlink");
122
- exit();
123
- }
124
- return $query_vars;
125
- }
126
-
127
- add_filter('category_link', 'top_level_cats_remove_cat_base');
128
- function top_level_cats_remove_cat_base($link) {
129
- $category_base = get_option('category_base');
130
-
131
- // WP uses "category/" as the default
132
- if ($category_base == '')
133
- $category_base = 'category';
134
-
135
- // Remove initial slash, if there is one (we remove the trailing slash in the regex replacement and don't want to end up short a slash)
136
- if (substr($category_base, 0, 1) == '/')
137
- $category_base = substr($category_base, 1);
138
-
139
- $category_base .= '/';
140
-
141
- return preg_replace('|' . $category_base . '|', '', $link, 1);
142
- }
143
-
144
-
145
-
146
-
147
- function fv_top_level_cats_post_link_category_top_level_only( $cat ) {
148
- if( !FV_Top_Level_Cats::is_category_permalinks() ) {
149
- return $cat;
150
- }
151
-
152
- while( FV_Top_Level_Cats::is_top_level_only() && $cat->parent != 0 ) {
153
- $cat = get_term_by( 'id', $cat->parent, 'category' );
154
- }
155
-
156
- return $cat;
157
- }
158
- add_filter( 'post_link_category', 'fv_top_level_cats_post_link_category_top_level_only', 201, 3 );
159
-
160
-
161
-
162
-
163
- function fv_top_level_cats_post_link_category_restrict( $cat ) {
164
- if( !FV_Top_Level_Cats::is_category_permalinks() || !FV_Top_Level_Cats::is_category_restriction() ) {
165
- return $cat;
166
- }
167
-
168
- $aArgs = func_get_args();
169
-
170
- $aAllowedCats = FV_Top_Level_Cats::get_allowed_cats();
171
- if( !count($aAllowedCats) ) {
172
- return $cat;
173
- }
174
-
175
- // check if the main category is allowed
176
- if( in_array( $cat->term_id, $aAllowedCats ) ) {
177
- return $cat;
178
- }
179
-
180
- // check if any of the other categories is allowed!
181
- $isOk = false;
182
- foreach( $aArgs[1] AS $objCat ) {
183
- if( in_array( $objCat->term_id, $aAllowedCats ) ) {
184
- $isOk = true;
185
- $cat = $objCat;
186
- }
187
- }
188
-
189
- // check if any of the parent categories is allowed
190
- if( !$isOk ) {
191
- foreach( $aArgs[1] AS $objCat ) {
192
- while( $objCat->parent != 0 ) {
193
- $objCat = get_term_by( 'id', $objCat->parent, 'category' );
194
- }
195
- if( in_array( $objCat->term_id, $aAllowedCats ) ) {
196
- $isOk = true;
197
- $cat = $objCat;
198
- }
199
- }
200
- }
201
-
202
- return $cat;
203
- }
204
- add_filter( 'post_link_category', 'fv_top_level_cats_post_link_category_restrict', 200, 3 );
205
-
206
-
207
-
208
-
209
- function fv_top_level_category_filter( $aCategories ) {
210
- if( class_exists('FV_Top_Level_Cats') && method_exists('FV_Top_Level_Cats','get_allowed_cats') ) {
211
-
212
- $aAllowedCats = FV_Top_Level_Cats::get_allowed_cats();
213
- if( !count($aAllowedCats) ) {
214
- return $aCategories;
215
- }
216
-
217
- // check if the main category is allowed
218
- foreach( $aCategories AS $objCat ) {
219
- if( in_array( $objCat->term_id, $aAllowedCats ) ) {
220
- return array($objCat);
221
- }
222
- }
223
-
224
- foreach( $aCategories AS $objCat ) {
225
- while( $objCat->parent != 0 ) {
226
- $objCat = get_term_by( 'id', $objCat->parent, 'category' );
227
- }
228
- if( in_array( $objCat->term_id, $aAllowedCats ) ) {
229
- return array($objCat);
230
- }
231
- }
232
- }
233
- return $aCategories;
234
- }
235
-
236
-
237
-
238
-
239
-
240
- function fv_top_level_category( $separator = '', $parents = '', $post_id = false ) {
241
- add_filter( 'get_the_categories', 'fv_top_level_category_filter' );
242
- the_category( $separator, $parents, $post_id );
243
- remove_filter( 'get_the_categories', 'fv_top_level_category_filter' );
244
- }
245
- add_action( 'fv_top_level_category', 'fv_top_level_category', 10, 3 );
246
-
247
-
248
-
249
-
250
- class FV_Top_Level_Cats {
251
-
252
- var $enabled;
253
- var $default_form_code;
254
- var $default_form_css;
255
-
256
-
257
-
258
-
259
- public function __construct() {
260
- add_action( 'admin_menu', array($this, 'admin_menu') );
261
- add_action('init',array($this,'load_languages'));
262
- }
263
-
264
-
265
-
266
-
267
- function admin_menu() {
268
- add_options_page( 'FV Top Level Categories', 'FV Top Level Categories', 'manage_options', 'fv_top_level_cats', array($this, 'options_panel') );
269
- }
270
-
271
-
272
-
273
-
274
- public static function get_allowed_cats() {
275
- $options = get_option( 'fv_top_level_cats' );
276
- if( isset($options['category-allow']) ) {
277
- return $options['category-allow'];
278
- } else {
279
- return false;
280
- }
281
- }
282
-
283
-
284
-
285
-
286
- public static function is_category_permalinks() {
287
- $sPermalinks = get_option( 'permalink_structure' );
288
- if( stripos($sPermalinks, '%category%/') !== false ) {
289
- return true;
290
- } else {
291
- return false;
292
- }
293
- }
294
-
295
-
296
-
297
-
298
- function load_languages(){
299
- // Localization
300
- load_plugin_textdomain('fv_tlc', false, dirname(plugin_basename(__FILE__)) . "/languages");
301
- }
302
-
303
-
304
-
305
-
306
- public static function is_top_level_only() {
307
- $options = get_option( 'fv_top_level_cats' );
308
- if( isset($options['top-level-only']) && $options['top-level-only'] ) {
309
- return true;
310
- } else {
311
- return false;
312
- }
313
- }
314
-
315
-
316
-
317
-
318
- public static function is_category_restriction() {
319
- $options = get_option( 'fv_top_level_cats' );
320
- if( isset($options['category-allow-enabled']) && $options['category-allow-enabled'] ) {
321
- return true;
322
- } else {
323
- return false;
324
- }
325
- }
326
-
327
-
328
-
329
-
330
- function options_panel() {
331
-
332
- if (!empty($_POST)) :
333
-
334
- check_admin_referer('fv_top_level_cats');
335
-
336
- if( isset($_POST['fv_top_level_cats_submit'] ) ) :
337
- $options = get_option( 'fv_top_level_cats', array() );
338
-
339
- $options['category-allow'] = $_POST['post_category'];
340
- $options['top-level-only'] = ( $_POST['top-level-only'] ) ? true : false;
341
- $options['category-allow-enabled'] = ( $_POST['category-allow-enabled'] ) ? true : false;
342
-
343
- update_option( 'fv_top_level_cats', $options );
344
- ?>
345
- <div id="message" class="updated fade">
346
- <p>
347
- <strong>
348
- Settings saved
349
- </strong>
350
- </p>
351
- </div>
352
- <?php
353
- endif; // fv_top_level_cats_submit
354
-
355
- endif;
356
-
357
- $options = get_option( 'fv_top_level_cats' );
358
- ?>
359
-
360
- <div class="wrap">
361
- <div style="position: absolute; right: 20px; margin-top: 5px">
362
- <a href="http://foliovision.com/wordpress/plugins/fv-top-level-categories" target="_blank" title="Documentation"><img alt="visit foliovision" src="http://foliovision.com/shared/fv-logo.png" /></a>
363
- </div>
364
- <div>
365
- <div id="icon-options-general" class="icon32"><br /></div>
366
- <h2>FV Top Level Categories</h2>
367
- </div>
368
-
369
- <?php if( $this->is_category_permalinks() ) : ?>
370
- <style>
371
- #category-allow ul.children { margin-left: 20px; }
372
- </style>
373
- <form method="post" action="">
374
- <?php wp_nonce_field('fv_top_level_cats') ?>
375
- <div id="poststuff" class="ui-sortable">
376
- <div class="postbox">
377
- <h3>
378
- <?php _e('Adjust categories in your post URLs','fv_tlc') ?>
379
- </h3>
380
- <div class="inside">
381
- <table class="form-table">
382
- <tr>
383
- <td>
384
- <label for="top-level-only">
385
- <input type="checkbox" name="top-level-only" id="top-level-only" value="1" <?php if( $options['top-level-only'] ) echo 'checked="checked"'; ?> />
386
- <?php _e('Only use top-level catogories in URLs.','fv_tlc') ; ?>
387
- </label>
388
- </td>
389
- </tr>
390
- <tr>
391
- <td>
392
- <label for="category-allow-enabled">
393
- <input type="checkbox" name="category-allow-enabled" id="category-allow-enabled" value="1" <?php if( $options['category-allow-enabled'] ) echo 'checked="checked"'; ?> />
394
- <?php _e('Only allow following categories in URLs:','fv_tlc' );?>
395
- </label>
396
- <blockquote><ul id="category-allow"><?php wp_category_checklist( 0, 0, $options['category-allow'], false, null, false ); ?></ul></blockquote>
397
- </td>
398
- </tr>
399
- </table>
400
- <p>
401
- <input type="submit" name="fv_top_level_cats_submit" class="button-primary" value="<?php _e('Save Changes','fv_tlc'); ?>" />
402
- </p>
403
- </div>
404
- </div>
405
- <p><?php echo __('Are you having any problems or questions? Use our <a target="_blank" href="http://foliovision.com/support/fv-top-level-categories/">support forums</a>.','fv_tlc'); ?></p>
406
- </div>
407
-
408
- </form>
409
- <?php else : ?>
410
- <p><?php _e('Since you are not using %category% in your post permalinks, there is nothing to adjust.','fv_tlc'); ?></p>
411
- <?php endif; ?>
412
-
413
- </div>
414
-
415
-
416
- <?php
417
- }
418
-
419
-
420
- }
421
-
422
- $FV_Top_Level_Cats = new FV_Top_Level_Cats;
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
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.7
7
+ Author: Foliovision
8
+ Author URI: http://foliovision.com/
9
+ Text Domain: fv_tlc
10
+ Domain Path: /languages/
11
+ */
12
+
13
+ register_activation_hook(__FILE__,'fv_top_level_categories_refresh_rules');
14
+
15
+ add_action('created_category','fv_top_level_categories_refresh_rules');
16
+ add_action('edited_category','fv_top_level_categories_refresh_rules');
17
+ add_action('delete_category','fv_top_level_categories_refresh_rules');
18
+
19
+ function fv_top_level_categories_refresh_rules() {
20
+ add_option('fv_top_level_categories_rewrite_rules_flush', 'true');
21
+ }
22
+ register_deactivation_hook(__FILE__,'fv_top_level_categories_deactivate');
23
+
24
+ function fv_top_level_categories_deactivate() {
25
+ remove_filter('category_rewrite_rules', 'fv_top_level_categories_refresh_rules'); // We don't want to insert our custom rules again
26
+ delete_option('fv_top_level_categories_rewrite_rules_flush');
27
+ }
28
+
29
+ // Remove category base
30
+ add_action('init', 'fv_top_level_categories_permastruct');
31
+ function fv_top_level_categories_permastruct() {
32
+ global $wp_rewrite;
33
+ $wp_rewrite->extra_permastructs['category'][0] = '%category%';
34
+
35
+ if (get_option('fv_top_level_categories_rewrite_rules_flush') == 'true') {
36
+ flush_rewrite_rules();
37
+ delete_option('fv_top_level_categories_rewrite_rules_flush');
38
+ }
39
+ }
40
+
41
+ // Add our custom category rewrite rules
42
+ add_filter('category_rewrite_rules', 'fv_top_level_categories_rewrite_rules');
43
+ function fv_top_level_categories_rewrite_rules($category_rewrite) {
44
+ //var_dump($category_rewrite); // For Debugging
45
+
46
+ /// First we need to get full URLs of our pages
47
+ $pages = get_pages( 'number=0' );
48
+ $pages_urls = array();
49
+ foreach( $pages AS $pages_item ) {
50
+ $pages_urls[] = trim( str_replace( get_bloginfo( 'url' ), '', get_permalink( $pages_item->ID ) ), '/' );
51
+ }
52
+ ///
53
+
54
+ $category_rewrite=array();
55
+ $categories=get_categories(array('hide_empty'=>false));
56
+ foreach($categories as $category) {
57
+ $category_nicename = $category->slug;
58
+ if ( $category->parent == $category->cat_ID ) // recursive recursion
59
+ $category->parent = 0;
60
+ elseif ($category->parent != 0 )
61
+ $category_nicename = get_category_parents( $category->parent, false, '/', true ) . $category_nicename;
62
+
63
+ /// Let's check if any of the category full URLs matches any of the pages
64
+ if( in_array( $category_nicename, $pages_urls ) ) {
65
+ continue;
66
+ }
67
+ ///
68
+
69
+
70
+ $category_rewrite['('.$category_nicename.')/(?:feed/)?(feed|rdf|rss|rss2|atom)/?$'] = 'index.php?category_name=$matches[1]&feed=$matches[2]';
71
+ $category_rewrite['('.$category_nicename.')/page/?([0-9]{1,})/?$'] = 'index.php?category_name=$matches[1]&paged=$matches[2]';
72
+ $category_rewrite['('.$category_nicename.')/?$'] = 'index.php?category_name=$matches[1]';
73
+ }
74
+ // Redirect support from Old Category Base
75
+ global $wp_rewrite;
76
+ $old_category_base = get_option('category_base') ? get_option('category_base') : 'category';
77
+ $old_category_base = trim($old_category_base, '/');
78
+ $category_rewrite[$old_category_base.'/(.*)$'] = 'index.php?category_redirect=$matches[1]';
79
+
80
+ //var_dump($category_rewrite); // For Debugging
81
+ return $category_rewrite;
82
+ }
83
+
84
+ //Redirect to TL parent categ, if "Only use top-level categories in URLs." is on
85
+ add_filter('template_redirect', 'fv_top_level_categories_tlc_redirect', 999, 2);
86
+ function fv_top_level_categories_tlc_redirect( $link ) {
87
+ if( FV_Top_Level_Cats::is_top_level_only() && is_single() ) {
88
+ global $wp_query;
89
+ $requested_url = is_ssl() ? 'https://' : 'http://';
90
+ $requested_url .= $_SERVER['HTTP_HOST'];
91
+ $requested_url .= $_SERVER['REQUEST_URI'];
92
+
93
+ $real_permalink = get_permalink($wp_query->queried_object_id);
94
+
95
+ if( FALSE === stripos($requested_url, $real_permalink) ) {
96
+
97
+ $bMached = preg_match('~/([^/:]+/?)$~',$real_permalink, $end_of_permalink);
98
+ if( $bMached && preg_match('~'.$end_of_permalink[1].'(.+)$~', $requested_url, $end_of_url) )
99
+ wp_redirect( $real_permalink . $end_of_url[1], 301 );
100
+ else
101
+ wp_redirect( $real_permalink, 301 );
102
+ die();
103
+ }
104
+ }
105
+
106
+ return $link;
107
+ }
108
+
109
+ // Add 'category_redirect' query variable
110
+ add_filter('query_vars', 'fv_top_level_categories_query_vars');
111
+ function fv_top_level_categories_query_vars($public_query_vars) {
112
+ $public_query_vars[] = 'category_redirect';
113
+ return $public_query_vars;
114
+ }
115
+
116
+ // Redirect if 'category_redirect' is set
117
+ add_filter('request', 'fv_top_level_categories_request');
118
+ function fv_top_level_categories_request($query_vars) {
119
+ //print_r($query_vars); // For Debugging
120
+ if(isset($query_vars['category_redirect'])) {
121
+ $catlink = trailingslashit(get_option( 'home' )) . user_trailingslashit( $query_vars['category_redirect'], 'category' );
122
+ status_header(301);
123
+ header("Location: $catlink");
124
+ exit();
125
+ }
126
+ return $query_vars;
127
+ }
128
+
129
+ add_filter('category_link', 'top_level_cats_remove_cat_base');
130
+ function top_level_cats_remove_cat_base($link) {
131
+ $category_base = get_option('category_base');
132
+
133
+ // WP uses "category/" as the default
134
+ if ($category_base == '')
135
+ $category_base = 'category';
136
+
137
+ // Remove initial slash, if there is one (we remove the trailing slash in the regex replacement and don't want to end up short a slash)
138
+ if (substr($category_base, 0, 1) == '/')
139
+ $category_base = substr($category_base, 1);
140
+
141
+ $category_base .= '/';
142
+
143
+ return preg_replace('|' . $category_base . '|', '', $link, 1);
144
+ }
145
+
146
+
147
+
148
+
149
+ function fv_top_level_cats_post_link_category_top_level_only( $cat ) {
150
+ if( !FV_Top_Level_Cats::is_category_permalinks() ) {
151
+ return $cat;
152
+ }
153
+
154
+ while( FV_Top_Level_Cats::is_top_level_only() && $cat->parent != 0 ) {
155
+ $cat = get_term_by( 'id', $cat->parent, 'category' );
156
+ }
157
+
158
+ return $cat;
159
+ }
160
+ add_filter( 'post_link_category', 'fv_top_level_cats_post_link_category_top_level_only', 201, 3 );
161
+
162
+
163
+
164
+
165
+ function fv_top_level_cats_post_link_category_restrict( $cat ) {
166
+ if( !FV_Top_Level_Cats::is_category_permalinks() || !FV_Top_Level_Cats::is_category_restriction() ) {
167
+ return $cat;
168
+ }
169
+
170
+ $aArgs = func_get_args();
171
+
172
+ $aAllowedCats = FV_Top_Level_Cats::get_allowed_cats();
173
+ if( !count($aAllowedCats) ) {
174
+ return $cat;
175
+ }
176
+
177
+ // check if the main category is allowed
178
+ if( in_array( $cat->term_id, $aAllowedCats ) ) {
179
+ return $cat;
180
+ }
181
+
182
+ // check if any of the other categories is allowed!
183
+ $isOk = false;
184
+ foreach( $aArgs[1] AS $objCat ) {
185
+ if( in_array( $objCat->term_id, $aAllowedCats ) ) {
186
+ $isOk = true;
187
+ $cat = $objCat;
188
+ }
189
+ }
190
+
191
+ // check if any of the parent categories is allowed
192
+ if( !$isOk ) {
193
+ foreach( $aArgs[1] AS $objCat ) {
194
+ while( $objCat->parent != 0 ) {
195
+ $objCat = get_term_by( 'id', $objCat->parent, 'category' );
196
+ }
197
+ if( in_array( $objCat->term_id, $aAllowedCats ) ) {
198
+ $isOk = true;
199
+ $cat = $objCat;
200
+ }
201
+ }
202
+ }
203
+
204
+ return $cat;
205
+ }
206
+ add_filter( 'post_link_category', 'fv_top_level_cats_post_link_category_restrict', 200, 3 );
207
+
208
+
209
+
210
+
211
+ function fv_top_level_category_filter( $aCategories ) {
212
+ if( class_exists('FV_Top_Level_Cats') && method_exists('FV_Top_Level_Cats','get_allowed_cats') ) {
213
+
214
+ $aAllowedCats = FV_Top_Level_Cats::get_allowed_cats();
215
+ if( !count($aAllowedCats) ) {
216
+ return $aCategories;
217
+ }
218
+
219
+ // check if the main category is allowed
220
+ foreach( $aCategories AS $objCat ) {
221
+ if( in_array( $objCat->term_id, $aAllowedCats ) ) {
222
+ return array($objCat);
223
+ }
224
+ }
225
+
226
+ foreach( $aCategories AS $objCat ) {
227
+ while( $objCat->parent != 0 ) {
228
+ $objCat = get_term_by( 'id', $objCat->parent, 'category' );
229
+ }
230
+ if( in_array( $objCat->term_id, $aAllowedCats ) ) {
231
+ return array($objCat);
232
+ }
233
+ }
234
+ }
235
+ return $aCategories;
236
+ }
237
+
238
+
239
+
240
+
241
+
242
+ function fv_top_level_category( $separator = '', $parents = '', $post_id = false ) {
243
+ add_filter( 'get_the_categories', 'fv_top_level_category_filter' );
244
+ the_category( $separator, $parents, $post_id );
245
+ remove_filter( 'get_the_categories', 'fv_top_level_category_filter' );
246
+ }
247
+ add_action( 'fv_top_level_category', 'fv_top_level_category', 10, 3 );
248
+
249
+
250
+
251
+
252
+ class FV_Top_Level_Cats {
253
+
254
+ var $enabled;
255
+ var $default_form_code;
256
+ var $default_form_css;
257
+
258
+
259
+
260
+
261
+ public function __construct() {
262
+ add_action( 'admin_menu', array($this, 'admin_menu') );
263
+ add_action('init',array($this,'load_languages'));
264
+ }
265
+
266
+
267
+
268
+
269
+ function admin_menu() {
270
+ add_options_page( __('FV Top Level Categories','fv_tlc'), __('FV Top Level Categories','fv_tlc'), 'manage_options', 'fv_top_level_cats', array($this, 'options_panel') );
271
+ }
272
+
273
+
274
+
275
+
276
+ public static function get_allowed_cats() {
277
+ $options = get_option( 'fv_top_level_cats' );
278
+ if( isset($options['category-allow']) ) {
279
+ return $options['category-allow'];
280
+ } else {
281
+ return false;
282
+ }
283
+ }
284
+
285
+
286
+
287
+
288
+ public static function is_category_permalinks() {
289
+ $sPermalinks = get_option( 'permalink_structure' );
290
+ if( stripos($sPermalinks, '%category%/') !== false ) {
291
+ return true;
292
+ } else {
293
+ return false;
294
+ }
295
+ }
296
+
297
+
298
+
299
+
300
+ function load_languages(){
301
+ // Localization
302
+ load_plugin_textdomain('fv_tlc', false, dirname(plugin_basename(__FILE__)) . "/languages");
303
+ }
304
+
305
+
306
+
307
+
308
+ public static function is_top_level_only() {
309
+ $options = get_option( 'fv_top_level_cats' );
310
+ if( isset($options['top-level-only']) && $options['top-level-only'] ) {
311
+ return true;
312
+ } else {
313
+ return false;
314
+ }
315
+ }
316
+
317
+
318
+
319
+
320
+ public static function is_category_restriction() {
321
+ $options = get_option( 'fv_top_level_cats' );
322
+ if( isset($options['category-allow-enabled']) && $options['category-allow-enabled'] ) {
323
+ return true;
324
+ } else {
325
+ return false;
326
+ }
327
+ }
328
+
329
+
330
+
331
+
332
+ function options_panel() {
333
+
334
+ if (!empty($_POST)) :
335
+
336
+ check_admin_referer('fv_top_level_cats');
337
+
338
+ if( isset($_POST['fv_top_level_cats_submit'] ) ) :
339
+ $options = get_option( 'fv_top_level_cats', array() );
340
+
341
+ $options['category-allow'] = $_POST['post_category'];
342
+ $options['top-level-only'] = ( $_POST['top-level-only'] ) ? true : false;
343
+ $options['category-allow-enabled'] = ( $_POST['category-allow-enabled'] ) ? true : false;
344
+
345
+ update_option( 'fv_top_level_cats', $options );
346
+ ?>
347
+ <div id="message" class="updated fade">
348
+ <p>
349
+ <strong>
350
+ Settings saved
351
+ </strong>
352
+ </p>
353
+ </div>
354
+ <?php
355
+ endif; // fv_top_level_cats_submit
356
+
357
+ endif;
358
+
359
+ $options = get_option( 'fv_top_level_cats' );
360
+ ?>
361
+
362
+ <div class="wrap">
363
+ <div style="position: absolute; right: 20px; margin-top: 5px">
364
+ <a href="http://foliovision.com/wordpress/plugins/fv-top-level-categories" target="_blank" title="Documentation"><img alt="visit foliovision" src="http://foliovision.com/shared/fv-logo.png" /></a>
365
+ </div>
366
+ <div>
367
+ <div id="icon-options-general" class="icon32"><br /></div>
368
+ <h2><?php _e('FV Top Level Categories','fv_tlc'); ?></h2>
369
+ </div>
370
+
371
+ <?php if( $this->is_category_permalinks() ) : ?>
372
+ <style>
373
+ #category-allow ul.children { margin-left: 20px; }
374
+ </style>
375
+ <form method="post" action="">
376
+ <?php wp_nonce_field('fv_top_level_cats') ?>
377
+ <div id="poststuff" class="ui-sortable">
378
+ <div class="postbox">
379
+ <h3>
380
+ <?php _e('Adjust categories in your post URLs','fv_tlc') ?>
381
+ </h3>
382
+ <div class="inside">
383
+ <table class="form-table">
384
+ <tr>
385
+ <td>
386
+ <label for="top-level-only">
387
+ <input type="checkbox" name="top-level-only" id="top-level-only" value="1" <?php if( $options['top-level-only'] ) echo 'checked="checked"'; ?> />
388
+ <?php _e('Only use top-level categories in URLs.','fv_tlc') ; ?>
389
+ </label>
390
+ </td>
391
+ </tr>
392
+ <tr>
393
+ <td>
394
+ <label for="category-allow-enabled">
395
+ <input type="checkbox" name="category-allow-enabled" id="category-allow-enabled" value="1" <?php if( $options['category-allow-enabled'] ) echo 'checked="checked"'; ?> />
396
+ <?php _e('Only allow following categories in URLs:','fv_tlc' );?>
397
+ </label>
398
+ <blockquote><ul id="category-allow"><?php wp_category_checklist( 0, 0, $options['category-allow'], false, null, false ); ?></ul></blockquote>
399
+ </td>
400
+ </tr>
401
+ </table>
402
+ <p>
403
+ <input type="submit" name="fv_top_level_cats_submit" class="button-primary" value="<?php _e('Save Changes','fv_tlc'); ?>" />
404
+ </p>
405
+ </div>
406
+ </div>
407
+ <p><?php _e('Are you having any problems or questions? Use our <a target="_blank" href="http://foliovision.com/support/fv-top-level-categories/">support forums</a>.','fv_tlc'); ?></p>
408
+ </div>
409
+
410
+ </form>
411
+ <?php else : ?>
412
+ <p><?php _e('Since you are not using %category% in your post permalinks, there is nothing to adjust.','fv_tlc'); ?></p>
413
+ <?php endif; ?>
414
+
415
+ </div>
416
+
417
+
418
+ <?php
419
+ }
420
+
421
+
422
+ }
423
+
424
+ $FV_Top_Level_Cats = new FV_Top_Level_Cats;
425
+
426
+ // Add settings link on plugin page
427
+ function fv_top_level_categories_settings_link($links) {
428
+ $settings_link = '<a href="options-general.php?page=fv_top_level_cats.php">' . __('Settings','fv_tlc') . '</a>';
429
+ array_unshift($links, $settings_link);
430
+ return $links;
431
+ }
432
+
433
+ $plugin = plugin_basename(__FILE__);
434
+ add_filter("plugin_action_links_$plugin", 'fv_top_level_categories_settings_link' );