WP htaccess Control - Version 2.6

Version Description

(23/08/2011) = * Feature: added option to remove author base.

Download this release

Release Info

Developer dardna
Plugin Icon wp plugin WP htaccess Control
Version 2.6
Comparing to
See all releases

Code changes from version 2.5.8 to 2.6

readme.txt CHANGED
@@ -6,7 +6,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=s4man
6
  Tags: permalinks, permalink, author, htaccess, rewrite, redirect, admin, maintenance, pagination, category, category base, archive, archives
7
  Requires at least: 2.7
8
  Tested up to: 3.2.1
9
- Stable tag: 2.5.8
10
 
11
  Interface to customize the permalinks (author, category, archives and pagination) and htaccess file generated by Wordpress.
12
 
@@ -18,7 +18,8 @@ Despite the name, many of the options now present on this plugin do not use the
18
  **Features:**
19
 
20
  * Customizing the htaccess file generated by Wordpress;
21
- * Removing the category base;
 
22
  * Customizing the Author Permalink Base;
23
  * Customizing Paginated Permalinks (translate the "page" word on permalinks to your own language);
24
  * Customization (and canonization) of the Search Permalink Base;
@@ -72,8 +73,11 @@ Search redirection is based on Mark Jaquith's **Nice Search** but extended so th
72
 
73
  == Changelog ==
74
 
 
 
 
75
  = 2.5.8 (23/08/2011) =
76
- * *Fix:* fixed file encoding from 2.5.7 (which should always by UTF-8 without BOM).
77
 
78
  = 2.5.7 (22/08/2011) =
79
  * *Fix:* fixed daily archives on categories, authors and tags (thank you AlZuwaga).
6
  Tags: permalinks, permalink, author, htaccess, rewrite, redirect, admin, maintenance, pagination, category, category base, archive, archives
7
  Requires at least: 2.7
8
  Tested up to: 3.2.1
9
+ Stable tag: 2.6
10
 
11
  Interface to customize the permalinks (author, category, archives and pagination) and htaccess file generated by Wordpress.
12
 
18
  **Features:**
19
 
20
  * Customizing the htaccess file generated by Wordpress;
21
+ * Removing the category base from permalinks;
22
+ * Removing the author base from permalinks;
23
  * Customizing the Author Permalink Base;
24
  * Customizing Paginated Permalinks (translate the "page" word on permalinks to your own language);
25
  * Customization (and canonization) of the Search Permalink Base;
73
 
74
  == Changelog ==
75
 
76
+ = 2.6 (23/08/2011) =
77
+ * *Feature:* added option to remove author base.
78
+
79
  = 2.5.8 (23/08/2011) =
80
+ * *Fix:* fixed file encoding introduced on 2.5.7 (which should always by UTF-8 without BOM).
81
 
82
  = 2.5.7 (22/08/2011) =
83
  * *Fix:* fixed daily archives on categories, authors and tags (thank you AlZuwaga).
wp-htaccess-control-ui.php CHANGED
@@ -156,6 +156,28 @@ $WPhtc_data=get_option('WPhtc_data');
156
  <td valign="middle">
157
  <p class="description"><?php _e('If active, the category base will be removed from permalinks:'); ?></p>
158
  <p class="description"><code><?php bloginfo('home')?>/<?php _e('your-category', 'wp-htaccess-control'); ?></code></p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
159
  </td>
160
  </tr>
161
  </table>
156
  <td valign="middle">
157
  <p class="description"><?php _e('If active, the category base will be removed from permalinks:'); ?></p>
158
  <p class="description"><code><?php bloginfo('home')?>/<?php _e('your-category', 'wp-htaccess-control'); ?></code></p>
159
+ <p class="description"><strong><?php _e('Beware:'); ?></strong> <?php _e('This could conflict with the removal of the author base on a situation where a category slug is the same as a user nicename.'); ?></p>
160
+ </td>
161
+ </tr>
162
+ </table>
163
+ </div>
164
+ <!-- Remove Author Base -->
165
+ <div class="wphtc-section">
166
+ <div class="wphtc-section-title stuffbox">
167
+ <div title="Click to toggle" class="handlediv" style="background:url('<?php bloginfo("wpurl")?>/wp-admin/images/menu-bits.gif') no-repeat scroll left -111px transparent"><br></div>
168
+ <h3><?php _e('Remove Author Base', 'wp-htaccess-control');?></h3>
169
+ </div>
170
+ <table class="form-table wphtc-inputs">
171
+ <tr valign="top">
172
+ <th scope="row" style="width:18%;"><?php _e('Remove Author Base', 'wp-htaccess-control'); ?></th>
173
+ <td >
174
+ <input type="checkbox" name="WPhtc_remove_author_base" <?php if($WPhtc_data['remove_author_base']){echo "checked=checked";} ?> />
175
+ </td>
176
+ <td valign="middle">
177
+ <p class="description"><?php _e('If active, the author base will be removed from permalinks:'); ?></p>
178
+ <p class="description"><code><?php bloginfo('home')?>/<?php _e('the-author', 'wp-htaccess-control'); ?></code></p>
179
+ <p class="description"><strong><?php _e('Beware:'); ?></strong> <?php _e('This could conflict with the removal of the category base on a situation where a category slug is the same as a user nicename.'); ?></p>
180
+ <p class="description"><strong><?php _e('Beware:'); ?></strong> <?php _e('I have not evaluated the impact on performance when using this with dozens of users. Please tell me how it goes.'); ?></p>
181
  </td>
182
  </tr>
183
  </table>
wp-htaccess-control.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: WP htaccess Control
4
  Plugin URI: http://dardna.com/wp-htaccess-control
5
  Description: Interface to customize the permalinks (author, category, archives and pagination) and htaccess file generated by Wordpress.
6
- Version: 2.5.8
7
  Author: António Andrade
8
  Author URI: http://dardna.com
9
  */
@@ -129,7 +129,10 @@ if (!class_exists("WPhtc")) {
129
  # Filter link generated by get_author_posts_url() to use the Custom Author Permalink
130
  function wphtc_filter_author_link($link){
131
  $WPhtc_data=get_option('WPhtc_data');
132
- if(isset($WPhtc_data['cap']) && $WPhtc_data['cap']!=''){
 
 
 
133
  $link=str_replace("author",urlencode($WPhtc_data['cap']),$link);
134
  }
135
  return $link;
@@ -193,7 +196,24 @@ if (!class_exists("WPhtc")) {
193
  }
194
  }
195
  # Author Archives
196
- if(isset($WPhtc_data['author_archives'])){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
197
  $author_base = ($WPhtc_data['cap']!='')?$WPhtc_data['cap']:'author';
198
  $new_rules = array(
199
  $author_base.'/([^/]+)/([0-9]{4})/?$' => 'index.php?author_name=$matches[1]&year=$matches[2]',
@@ -480,6 +500,20 @@ if (!class_exists("WPhtc")) {
480
  }
481
  return $category_rewrite;
482
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
483
  # WP-htaccess Control options page interface
484
  function wphtc_page(){
485
  include (dirname (__FILE__).'/wp-htaccess-control-ui.php');
@@ -564,6 +598,8 @@ if (!class_exists("WPhtc")) {
564
  }
565
  # Remove Category Base
566
  $WPhtc_data['remove_category_base']=$_POST['WPhtc_remove_category_base'];
 
 
567
  # Advanced Archives
568
  $WPhtc_data['category_archives']=$_POST['WPhtc_category_archives'];
569
  $WPhtc_data['author_archives']=$_POST['WPhtc_author_archives'];
@@ -634,6 +670,7 @@ if (isset($WPhtc)) {
634
  add_action('init', array($WPhtc,'wphtc_init'));
635
  add_action('template_redirect', array($WPhtc,'wphtc_template_redirect') );
636
  add_filter('category_rewrite_rules', array($WPhtc,'remove_category_base_from_rewrite_rules'));
 
637
  add_filter('category_link', array($WPhtc,'filter_category_link'),1000,2);
638
  add_action('created_category',array($WPhtc,'refresh_rewrite_rules'));
639
  add_action('edited_category',array($WPhtc,'refresh_rewrite_rules'));
3
  Plugin Name: WP htaccess Control
4
  Plugin URI: http://dardna.com/wp-htaccess-control
5
  Description: Interface to customize the permalinks (author, category, archives and pagination) and htaccess file generated by Wordpress.
6
+ Version: 2.6
7
  Author: António Andrade
8
  Author URI: http://dardna.com
9
  */
129
  # Filter link generated by get_author_posts_url() to use the Custom Author Permalink
130
  function wphtc_filter_author_link($link){
131
  $WPhtc_data=get_option('WPhtc_data');
132
+ if($WPhtc_data['remove_author_base']){
133
+ $link=str_replace("author/","",$link);
134
+ }
135
+ else if(isset($WPhtc_data['cap']) && $WPhtc_data['cap']!=''){
136
  $link=str_replace("author",urlencode($WPhtc_data['cap']),$link);
137
  }
138
  return $link;
196
  }
197
  }
198
  # Author Archives
199
+ if($WPhtc_data['remove_author_base']){
200
+ $blogusers = get_users('who=authors');
201
+ foreach ($blogusers as $user) {
202
+
203
+ $new_rules = array(
204
+ '('.$user->user_nicename.')/([^/]+)/([0-9]{4})/?$' => 'index.php?author_name=$matches[1]&year=$matches[2]',
205
+ '('.$user->user_nicename.')/([^/]+)/([0-9]{4})/'.$page_base.'/?([0-9]{1,})/?$' => 'index.php?author_name=$matches[1]&year=$matches[2]&paged=$matches[3]',
206
+
207
+ '('.$user->user_nicename.')/([^/]+)/([0-9]{4})/([0-9]{2})/?$' => 'index.php?author_name=$matches[1]&year=$matches[2]&monthnum=$matches[3]',
208
+ '('.$user->user_nicename.')/([^/]+)/([0-9]{4})/([0-9]{2})/'.$page_base.'/?([0-9]{1,})/?$' => 'index.php?author_name=$matches[1]&year=$matches[2]&monthnum=$matches[3]&paged=$matches[4]',
209
+
210
+ '('.$user->user_nicename.')/([^/]+)/([0-9]{4})/([0-9]{2})/([0-9]{2})/?$' => 'index.php?author_name=$matches[1]&year=$matches[2]&monthnum=$matches[3]&day=$matches[4]',
211
+ '('.$user->user_nicename.')/([^/]+)/([0-9]{4})/([0-9]{2})/([0-9]{2})/'.$page_base.'/?([0-9]{1,})/?$' => 'index.php?author_name=$matches[1]&year=$matches[2]&monthnum=$matches[3]&day=$matches[4]&paged=$matches[5]');
212
+
213
+ $rewrite_rules = $new_rules + $rewrite_rules;
214
+ }
215
+ }
216
+ else if(isset($WPhtc_data['author_archives'])){
217
  $author_base = ($WPhtc_data['cap']!='')?$WPhtc_data['cap']:'author';
218
  $new_rules = array(
219
  $author_base.'/([^/]+)/([0-9]{4})/?$' => 'index.php?author_name=$matches[1]&year=$matches[2]',
500
  }
501
  return $category_rewrite;
502
  }
503
+ # Filter Author Rewrite Rules
504
+ function remove_author_base_from_rewrite_rules($author_rewrite) {
505
+ $WPhtc_data=get_option('WPhtc_data');
506
+ if($WPhtc_data['remove_author_base']){
507
+ $author_rewrite=array();
508
+ $blogusers = get_users('who=authors');
509
+ foreach($blogusers as $user) {
510
+ $author_rewrite['('.$user->user_nicename.')/(?:feed/)?(feed|rdf|rss|rss2|atom)/?$'] = 'index.php?author_name=$matches[1]&feed=$matches[2]';
511
+ $author_rewrite['('.$user->user_nicename.')/page/?([0-9]{1,})/?$'] = 'index.php?author_name=$matches[1]&paged=$matches[2]';
512
+ $author_rewrite['('.$user->user_nicename.')/?$'] = 'index.php?author_name=$matches[1]';
513
+ }
514
+ }
515
+ return $author_rewrite;
516
+ }
517
  # WP-htaccess Control options page interface
518
  function wphtc_page(){
519
  include (dirname (__FILE__).'/wp-htaccess-control-ui.php');
598
  }
599
  # Remove Category Base
600
  $WPhtc_data['remove_category_base']=$_POST['WPhtc_remove_category_base'];
601
+ # Remove Author Base
602
+ $WPhtc_data['remove_author_base']=$_POST['WPhtc_remove_author_base'];
603
  # Advanced Archives
604
  $WPhtc_data['category_archives']=$_POST['WPhtc_category_archives'];
605
  $WPhtc_data['author_archives']=$_POST['WPhtc_author_archives'];
670
  add_action('init', array($WPhtc,'wphtc_init'));
671
  add_action('template_redirect', array($WPhtc,'wphtc_template_redirect') );
672
  add_filter('category_rewrite_rules', array($WPhtc,'remove_category_base_from_rewrite_rules'));
673
+ add_filter('author_rewrite_rules', array($WPhtc,'remove_author_base_from_rewrite_rules'));
674
  add_filter('category_link', array($WPhtc,'filter_category_link'),1000,2);
675
  add_action('created_category',array($WPhtc,'refresh_rewrite_rules'));
676
  add_action('edited_category',array($WPhtc,'refresh_rewrite_rules'));