WP htaccess Control - Version 1.2

Version Description

  • Improved htaccess customization giving now much more freedom.
Download this release

Release Info

Developer andrad
Plugin Icon wp plugin WP htaccess Control
Version 1.2
Comparing to
See all releases

Code changes from version 1.1.4 to 1.2

readme.txt CHANGED
@@ -3,20 +3,20 @@ Author: andrad
3
  Author URI: http://dardna.com/
4
  Plugin URI: http://dardna.com/wp-htaccess-control
5
  Donate link:
6
- Tags: permalinks, author, htaccess
7
  Requires at least: 2.7
8
  Tested up to: 2.9.1
9
- Stable tag: 1.1.4
10
 
11
- Provides an interface to add custom htaccess rules to the htaccess file generated by Wordpress. It also includes Custom Author Permalink.
12
 
13
  == Description ==
14
 
15
- **WP htaccess Control** provides an interface to add custom htaccess rules to the htaccess file generated by Wordpress. It also includes an improved and much more stable version of **Custom Author Permalink**. (Take a look at the screenshot...)
16
 
17
  **Features:**
18
 
19
- * Adding custom redirect rules to the htaccess file generated by Wordpress;
20
  * Customizing the Author Permalink Base.
21
 
22
  == Installation ==
@@ -30,14 +30,17 @@ Provides an interface to add custom htaccess rules to the htaccess file generate
30
  == Frequently Asked Questions ==
31
 
32
  = Do you have any questions? =
33
- = Suggestions are ofcourse very welcome and please report any bugs found! =
34
 
35
  == Screenshots ==
36
 
37
- 1. Administration page (as of v.1.1)
38
 
39
  == Changelog ==
40
 
 
 
 
41
  = 1.1.4 =
42
  * Confirmed compatibility with WP 2.9.1;
43
  * Fixed "Current htaccess file as it is generated by Wordpress" which was not being printed;
@@ -64,3 +67,8 @@ Provides an interface to add custom htaccess rules to the htaccess file generate
64
 
65
  = 1.0 =
66
  * Initial release (poor interface although working).
 
 
 
 
 
3
  Author URI: http://dardna.com/
4
  Plugin URI: http://dardna.com/wp-htaccess-control
5
  Donate link:
6
+ Tags: permalinks, permalink, author, htaccess, rewrite, redirect
7
  Requires at least: 2.7
8
  Tested up to: 2.9.1
9
+ Stable tag: 1.2
10
 
11
+ Provides an interface to add custom htaccess rules to the htaccess file generated by Wordpress and customisation of the Author Permalink Base.
12
 
13
  == Description ==
14
 
15
+ **WP htaccess Control** provides an interface to add custom htaccess rules to the htaccess file generated by Wordpress and customisation of the Author Permalink Base (improved and stable version of **Custom Author Permalink**). (Take a look at the screenshot...)
16
 
17
  **Features:**
18
 
19
+ * Customizing htaccess file generated by Wordpress;
20
  * Customizing the Author Permalink Base.
21
 
22
  == Installation ==
30
  == Frequently Asked Questions ==
31
 
32
  = Do you have any questions? =
33
+ = Suggestions are of course very welcome and please report any bugs found! =
34
 
35
  == Screenshots ==
36
 
37
+ 1. Administration page (as of v.1.2)
38
 
39
  == Changelog ==
40
 
41
+ = 1.2 =
42
+ * Improved htaccess customization giving now much more freedom.
43
+
44
  = 1.1.4 =
45
  * Confirmed compatibility with WP 2.9.1;
46
  * Fixed "Current htaccess file as it is generated by Wordpress" which was not being printed;
67
 
68
  = 1.0 =
69
  * Initial release (poor interface although working).
70
+
71
+ == Upgrade Notice ==
72
+
73
+ = 1.2 =
74
+ * You should try the new htaccess customization possibilities.
screenshot-1.jpg ADDED
Binary file
screenshot-1.png → screenshot-v1.1.png RENAMED
File without changes
wp-htaccess-control-gui.php CHANGED
@@ -5,61 +5,10 @@ $plugin_url = WP_CONTENT_URL.'/plugins/'.plugin_basename(dirname(__FILE__));
5
 
6
  $q=explode('&',$_SERVER['QUERY_STRING']);
7
  $purl='http'.((!empty($_SERVER['HTTPS'])) ? 's' : '').'://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?'.$q[0];
8
- $action=$_POST['action']?$_POST['action']:$_GET['action'];
9
- if(isset($action)){
10
- $WPhtc_data=get_option('WPhtc_data');
11
- switch($action){
12
- # if reseting everything just delete the option array
13
- case 'reset_rules':
14
- delete_option('WPhtc_data');
15
- $echo.="All rules (Custom Author Permalink + htaccess Custom Rewrite Pairs) reset.";
16
- break;
17
- # if updating, save new rules in database and flush rewrite rules as if regenerating permalink structure
18
- case 'update':
19
- for($i=0;$i<$_POST['WPhtc_num'];$i++){
20
- if(!empty($_POST['WPhtc_pat'.$i]) && !empty($_POST['WPhtc_sub'.$i])){
21
- $WPhtc_data['pats'][$i]=$_POST['WPhtc_pat'.$i];
22
- $WPhtc_data['subs'][$i]=$_POST['WPhtc_sub'.$i];
23
- }
24
- }
25
- if(count($WPhtc_data['pats'])>1 && $WPhtc_data['pats'][0]==''){
26
- unset($WPhtc_data['pats'][0],$WPhtc_data['subs'][0]);
27
- }
28
- if(is_array($WPhtc_data['pats'])&&is_array($WPhtc_data['subs'])){
29
- $WPhtc_data['pats']=array_values($WPhtc_data['pats']);
30
- $WPhtc_data['subs']=array_values($WPhtc_data['subs']);
31
- }
32
- $WPhtc_data['cap']=$_POST['WPhtc_cap'];
33
- update_option('WPhtc_data',$WPhtc_data);
34
- global $wp_rewrite;
35
- $wp_rewrite->flush_rules();
36
- $echo.="Author permalink structure and htaccess rules updated.";
37
- break;
38
- # add_rule deprecated by jQuery use below but still present just in case
39
- case 'add_rule':
40
- $add_rule=true;
41
- $echo='New pair available!';
42
- break;
43
- # deleting individual rewrite pair
44
- case 'delete_pair':
45
- if(isset($_GET['pair'])){
46
- # if it's the last pair
47
- if($_GET['pair']==0 && !isset($WPhtc_data['pats'][1])){
48
- unset($WPhtc_data['pats'], $WPhtc_data['subs']);
49
- update_option('WPhtc_data',$WPhtc_data);
50
- $echo.="htaccess rules reset.";
51
- break;
52
- }
53
- unset($WPhtc_data['pats'][$_GET['pair']],$WPhtc_data['subs'][$_GET['pair']]);
54
- $WPhtc_data['pats']=array_values($WPhtc_data['pats']);
55
- $WPhtc_data['subs']=array_values($WPhtc_data['subs']);
56
- update_option('WPhtc_data',$WPhtc_data);
57
- $echo.='Pair deleted!';
58
- }
59
- break;
60
- }
61
- }
62
- $WPhtc_data=get_option('WPhtc_data');?>
63
  <script>
64
  jQuery(document).ready(function(){
65
  init();
@@ -106,7 +55,7 @@ jQuery(document).ready(function(){
106
  <div class="updated fade" id="message" style="background-color: rgb(255, 251, 204);"><p><?php echo $echo;?></p></div>
107
  <?php }?>
108
  <form method="post" action="<?php echo $purl?>">
109
- <h3>Custom Author Permalink</h3>
110
  <table class="form-table">
111
  <tr valign="top">
112
  <th scope="row"><label for="blogdescription">Author Base</label></th>
@@ -119,10 +68,35 @@ jQuery(document).ready(function(){
119
  </td>
120
  </tr>
121
  </table>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
  <h3>Rewrite Pairs</h3>
123
  <ul class="wphtc-menu">
124
  <li><a class="add" href="<?php echo $purl?>&action=add_rule" title="Add new htaccess redirection pair"><img src="<?php echo $plugin_url?>/gfx/image_new.gif"> Add rule</a></li>
125
  </ul>
 
126
  <table id="htaccess-rules" class="form-table">
127
  <?php
128
  $num=count($WPhtc_data['pats'])?count($WPhtc_data['pats']):1;
@@ -141,6 +115,9 @@ jQuery(document).ready(function(){
141
  <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
142
  </p>
143
  </form>
144
- <?php if(isset($WPhtc_data['cur_hta'],$WPhtc_data['pats'][0])){echo'<h3>Current htaccess file as it is generated by Wordpress</h3><p><code>'.$WPhtc_data['cur_hta'].'</code></p>';}?>
 
 
 
145
  </div>
146
  <p class="setting-description alignright"><small><a href="http://dardna.com/wp-htaccess-control" title="Visit WP htaccess Control page at dardna.com">WP htaccess Control</a> by <a href="http://dardna.com" title="Visit dardna.com">dardna</a>, thanks to <a href="http://www.famfamfam.com/lab/icons/mini/" title="Visit 'Mini iconset' page at FamFamFam.com">FamFamFam</a> for the icons.</small></p>
5
 
6
  $q=explode('&',$_SERVER['QUERY_STRING']);
7
  $purl='http'.((!empty($_SERVER['HTTPS'])) ? 's' : '').'://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?'.$q[0];
8
+ WPhtc::wphtc_page_action();
9
+ global $echo;
10
+ $WPhtc_data=get_option('WPhtc_data');
11
+ ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  <script>
13
  jQuery(document).ready(function(){
14
  init();
55
  <div class="updated fade" id="message" style="background-color: rgb(255, 251, 204);"><p><?php echo $echo;?></p></div>
56
  <?php }?>
57
  <form method="post" action="<?php echo $purl?>">
58
+ <h3>Custom Author Permalink</h3>
59
  <table class="form-table">
60
  <tr valign="top">
61
  <th scope="row"><label for="blogdescription">Author Base</label></th>
68
  </td>
69
  </tr>
70
  </table>
71
+ <h3>Custom htaccess</h3>
72
+ <table id="" class="form-table">
73
+ <tr>
74
+ <td>
75
+ <textarea name="WPhtc_hta" cols="70" rows="5"><?php echo $WPhtc_data['hta']; ?></textarea>
76
+ <p class="description">This rules will be printed before "RewriteEngine On".</p>
77
+ <p class="description">Please double check them before saving as a mistake could make your site unaccessable.</p>
78
+ <p class="description">In any case you can always edit your .htaccess file manually.</p>
79
+ <p class="description">In case of doubt as where this rules will be kept save a comment line (like #test1) and check the end of this page.</p>
80
+ </td>
81
+ </tr>
82
+ </table>
83
+ <h3>Custom mod_rewrite</h3>
84
+ <table id="" class="form-table">
85
+ <tr>
86
+ <td>
87
+ <textarea name="WPhtc_hta_mr" cols="70" rows="5"><?php echo $WPhtc_data['hta_mr']; ?></textarea>
88
+ <p class="description">This rules will be printed right after "RewriteEngine On".</p>
89
+ <p class="description">Please double check them before saving as a mistake could make your site unaccessable.</p>
90
+ <p class="description">In any case you can always edit your .htaccess file manually.</p>
91
+ <p class="description">In case of doubt as where this rules will be kept save a comment line (like #test2) and check the end of this page.</p>
92
+ </td>
93
+ </tr>
94
+ </table>
95
  <h3>Rewrite Pairs</h3>
96
  <ul class="wphtc-menu">
97
  <li><a class="add" href="<?php echo $purl?>&action=add_rule" title="Add new htaccess redirection pair"><img src="<?php echo $plugin_url?>/gfx/image_new.gif"> Add rule</a></li>
98
  </ul>
99
+ <p class="description">These are rewrite pairs(RewriteRule) which Wordpress can add to its rules.</p>
100
  <table id="htaccess-rules" class="form-table">
101
  <?php
102
  $num=count($WPhtc_data['pats'])?count($WPhtc_data['pats']):1;
115
  <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
116
  </p>
117
  </form>
118
+ <h3>Current htaccess file as it is generated by Wordpress</h3>
119
+ <p>
120
+ <code><?php echo str_replace(array("&lt;br /&gt;","&lt;br/&gt;"),"<br/>",htmlspecialchars($WPhtc_data['cur_hta']));?></code>
121
+ </p>
122
  </div>
123
  <p class="setting-description alignright"><small><a href="http://dardna.com/wp-htaccess-control" title="Visit WP htaccess Control page at dardna.com">WP htaccess Control</a> by <a href="http://dardna.com" title="Visit dardna.com">dardna</a>, thanks to <a href="http://www.famfamfam.com/lab/icons/mini/" title="Visit 'Mini iconset' page at FamFamFam.com">FamFamFam</a> for the icons.</small></p>
wp-htaccess-control.php CHANGED
@@ -2,8 +2,8 @@
2
  /*
3
  Plugin Name: WP htaccess Control
4
  Plugin URI: http://dardna.com/wp-htaccess-control
5
- Description: Provides an interface to add custom htaccess rules to the htaccess file generated by wordpress. Also includes an improved and much more stable version of Custom Author Permalink
6
- Version: 1.1.4
7
  Author: dardna
8
  Author URI: http://dardna.com
9
  */
@@ -56,9 +56,8 @@ Author URI: http://dardna.com
56
  if (!class_exists("WPhtc")) {
57
  class WPhtc {
58
  function WPhtc() {
59
- }
60
-
61
- # Replacing the Wordpress Author Permalink by rewriting it's rules if we have a Custom Author Permalink, everytime the rules are flush
62
  function wphtc_cap($rules){
63
  $WPhtc_data=get_option('WPhtc_data');
64
  if(isset($WPhtc_data['cap']) && $WPhtc_data['cap']!=''){
@@ -66,28 +65,99 @@ if (!class_exists("WPhtc")) {
66
  }
67
  return $rules;
68
  }
69
-
70
  # Adding our rule pairs to the .htaccess generated by Wordpress, everytime the rules are flush
71
- function wphtc_rules($wp_rewrite){
72
  $WPhtc_data=get_option('WPhtc_data');
73
  for($i=0;$i<count($WPhtc_data['pats']);$i++){
74
  if($WPhtc_data['pats'][$i]!=''&&$WPhtc_data['subs'][$i]!=''){
75
- # adding each custom rewrite pair to $wp_rewrite->non_wp_rules['pattern']='substitution'
76
  $wp_rewrite->non_wp_rules[$WPhtc_data['pats'][$i]]=$WPhtc_data['subs'][$i];
77
  }
78
  }
79
- # keeping a copy of the generated htaccess in our option array for later reviewing
80
  $WPhtc_data['cur_hta']='# BEGIN Wordpress<br/>'.nl2br($wp_rewrite->mod_rewrite_rules()).'# END Wordpress';
81
  update_option('WPhtc_data',$WPhtc_data);
82
  return $wp_rewrite;
83
  }
84
-
 
 
 
 
 
 
 
 
 
 
 
 
85
  # WP-htaccess Control options page
86
  function wphtc_page(){
87
  include (dirname (__FILE__).'/wp-htaccess-control-gui.php');
88
  }
89
-
90
- # Adding our optons page to the admin menu
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91
  function ConfigureMenu(){
92
  add_submenu_page("options-general.php","WP htaccess Control", "WP htaControl", 6, __FILE__, array('WPhtc','wphtc_page'));
93
  }
@@ -97,7 +167,8 @@ if (class_exists("WPhtc")) {
97
  $WPhtc = new WPhtc();
98
  }
99
  if (isset($WPhtc)) {
100
- add_filter('generate_rewrite_rules', array($WPhtc,'wphtc_rules'));
 
101
  add_filter('rewrite_rules_array',array($WPhtc,'wphtc_cap'));
102
  add_action('admin_menu', array($WPhtc,'ConfigureMenu'));
103
  }
2
  /*
3
  Plugin Name: WP htaccess Control
4
  Plugin URI: http://dardna.com/wp-htaccess-control
5
+ Description: Provides an interface to add custom htaccess rules to the htaccess file generated by wordpress. Also provides customisation of the Author Permalink Base.
6
+ Version: 1.2
7
  Author: dardna
8
  Author URI: http://dardna.com
9
  */
56
  if (!class_exists("WPhtc")) {
57
  class WPhtc {
58
  function WPhtc() {
59
+ }
60
+ # Replacing the Wordpress Author Permalink by rewriting its rules if we have a Custom Author Permalink, everytime the rules are flush
 
61
  function wphtc_cap($rules){
62
  $WPhtc_data=get_option('WPhtc_data');
63
  if(isset($WPhtc_data['cap']) && $WPhtc_data['cap']!=''){
65
  }
66
  return $rules;
67
  }
 
68
  # Adding our rule pairs to the .htaccess generated by Wordpress, everytime the rules are flush
69
+ function wphtc_wp_rewrite_rules($wp_rewrite){
70
  $WPhtc_data=get_option('WPhtc_data');
71
  for($i=0;$i<count($WPhtc_data['pats']);$i++){
72
  if($WPhtc_data['pats'][$i]!=''&&$WPhtc_data['subs'][$i]!=''){
73
+ # Adding each custom rewrite pair to $wp_rewrite->non_wp_rules['pattern']='substitution'
74
  $wp_rewrite->non_wp_rules[$WPhtc_data['pats'][$i]]=$WPhtc_data['subs'][$i];
75
  }
76
  }
77
+ # Keeping a copy of the generated htaccess in our option array for later reviewing
78
  $WPhtc_data['cur_hta']='# BEGIN Wordpress<br/>'.nl2br($wp_rewrite->mod_rewrite_rules()).'# END Wordpress';
79
  update_option('WPhtc_data',$WPhtc_data);
80
  return $wp_rewrite;
81
  }
82
+ function wphtc_hta_rules($rules){
83
+ $WPhtc_data=get_option('WPhtc_data');
84
+ if($WPhtc_data['hta']!=''){
85
+ $new_rules.="\n# Begin Custom htaccess from WP htaccess Control\n";
86
+ $new_rules.=$WPhtc_data['hta']."\n";
87
+ $new_rules.="# End Custom htaccess from WP htaccess Control\n\n";
88
+ }
89
+ if($WPhtc_data['hta_mr']!=''){
90
+ $insert="\n\n# Begin Custom htaccess from WP htaccess Control\n".$WPhtc_data['hta_mr']."\n# End Custom htaccess from WP htaccess Control\n";
91
+ $new_rules.=str_replace("RewriteEngine On","RewriteEngine On".$insert,$rules);
92
+ }
93
+ return $new_rules;
94
+ }
95
  # WP-htaccess Control options page
96
  function wphtc_page(){
97
  include (dirname (__FILE__).'/wp-htaccess-control-gui.php');
98
  }
99
+ function wphtc_page_action(){
100
+ $action=$_POST['action']?$_POST['action']:$_GET['action'];
101
+ global $echo;
102
+ if(isset($action)){
103
+ $WPhtc_data=get_option('WPhtc_data');
104
+ switch($action){
105
+ # if reseting everything just delete the option array
106
+ case 'reset_rules':
107
+ delete_option('WPhtc_data');
108
+ $echo.="All rules (Custom Author Permalink + htaccess Custom Rules) reset.";
109
+ break;
110
+ # if updating, save new rules in database and flush rewrite rules as if regenerating permalink structure
111
+ case 'update':
112
+ for($i=0;$i<$_POST['WPhtc_num'];$i++){
113
+ if(!empty($_POST['WPhtc_pat'.$i]) && !empty($_POST['WPhtc_sub'.$i])){
114
+ $WPhtc_data['pats'][$i]=$_POST['WPhtc_pat'.$i];
115
+ $WPhtc_data['subs'][$i]=$_POST['WPhtc_sub'.$i];
116
+ }
117
+ }
118
+ if(count($WPhtc_data['pats'])>1 && $WPhtc_data['pats'][0]==''){
119
+ unset($WPhtc_data['pats'][0],$WPhtc_data['subs'][0]);
120
+ }
121
+ if(is_array($WPhtc_data['pats'])&&is_array($WPhtc_data['subs'])){
122
+ $WPhtc_data['pats']=array_values($WPhtc_data['pats']);
123
+ $WPhtc_data['subs']=array_values($WPhtc_data['subs']);
124
+ }
125
+ $WPhtc_data['hta']=$_POST['WPhtc_hta'];
126
+ $WPhtc_data['hta_mr']=$_POST['WPhtc_hta_mr'];
127
+ $WPhtc_data['cap']=$_POST['WPhtc_cap'];
128
+ update_option('WPhtc_data',$WPhtc_data);
129
+ global $wp_rewrite;
130
+ $wp_rewrite->flush_rules();
131
+ $echo.="Author permalink structure and htaccess Rules updated.";
132
+ break;
133
+ # add_rule substituted by jQuery use below but still present just in case
134
+ case 'add_rule':
135
+ $add_rule=true;
136
+ $echo='New pair available!';
137
+ break;
138
+ # deleting individual rewrite pair
139
+ case 'delete_pair':
140
+ if(isset($_GET['pair'])){
141
+ # if it's the last pair
142
+ if($_GET['pair']==0 && !isset($WPhtc_data['pats'][1])){
143
+ unset($WPhtc_data['pats'], $WPhtc_data['subs']);
144
+ $echo.="Wordpress Rewrite pairs reset.";
145
+ }
146
+ else{
147
+ unset($WPhtc_data['pats'][$_GET['pair']],$WPhtc_data['subs'][$_GET['pair']]);
148
+ $WPhtc_data['pats']=array_values($WPhtc_data['pats']);
149
+ $WPhtc_data['subs']=array_values($WPhtc_data['subs']);
150
+ $echo.='Wordpress Rewrite pair deleted!';
151
+ }
152
+ update_option('WPhtc_data',$WPhtc_data);
153
+ global $wp_rewrite;
154
+ $wp_rewrite->flush_rules();
155
+ }
156
+ break;
157
+ }
158
+ }
159
+ }
160
+ # Adding our options page to the admin menu
161
  function ConfigureMenu(){
162
  add_submenu_page("options-general.php","WP htaccess Control", "WP htaControl", 6, __FILE__, array('WPhtc','wphtc_page'));
163
  }
167
  $WPhtc = new WPhtc();
168
  }
169
  if (isset($WPhtc)) {
170
+ add_filter('mod_rewrite_rules', array($WPhtc,'wphtc_hta_rules'));
171
+ add_filter('generate_rewrite_rules', array($WPhtc,'wphtc_wp_rewrite_rules'));
172
  add_filter('rewrite_rules_array',array($WPhtc,'wphtc_cap'));
173
  add_action('admin_menu', array($WPhtc,'ConfigureMenu'));
174
  }