WP htaccess Control - Version 1.1.2

Version Description

  • No longer creating empty option array on install or reset (globally better option array handling);
  • Confirmed compatibility with WP 2.8
  • Still some work to do on the interface;
Download this release

Release Info

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

Code changes from version 1.1.1 to 1.1.2

Files changed (3) hide show
  1. readme.txt +29 -3
  2. wp-htaccess-control-gui.php +36 -29
  3. wp-htaccess-control.php +14 -11
readme.txt CHANGED
@@ -5,14 +5,19 @@ 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.7.1
9
- Stable tag: 1.1.1
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 screenshots...
 
 
 
 
 
16
 
17
  == Installation ==
18
 
@@ -25,7 +30,28 @@ Provides an interface to add custom htaccess rules to the htaccess file generate
25
  == Frequently Asked Questions ==
26
 
27
  = Do you have any questions? =
 
28
 
29
  == Screenshots ==
30
 
31
  1. Administration page (as of v.1.1)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  Donate link:
6
  Tags: permalinks, author, htaccess
7
  Requires at least: 2.7
8
+ Tested up to: 2.8
9
+ Stable tag: 1.1.2
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 ==
23
 
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.2 =
42
+ * No longer creating empty option array on install or reset (globally better option array handling);
43
+ * Confirmed compatibility with WP 2.8
44
+ * Still some work to do on the interface;
45
+
46
+ = 1.1.1 =
47
+ * Fixing screenshot mistake;
48
+
49
+ = 1.1 =
50
+ * Separated gui file;
51
+ * Improved management and gui;
52
+
53
+ = 1.0.1 =
54
+ * Added GNU license;
55
+
56
+ = 1.0 =
57
+ * Initial release (poor interface although working).
wp-htaccess-control-gui.php CHANGED
@@ -5,10 +5,16 @@ $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
- $WPhtc_data=get_option('WPhtc_data');
9
  $action=$_POST['action']?$_POST['action']:$_GET['action'];
10
  if(isset($action)){
 
11
  switch($action){
 
 
 
 
 
 
12
  case 'update':
13
  for($i=0;$i<$_POST['WPhtc_num'];$i++){
14
  if(!empty($_POST['WPhtc_pat'.$i]) && !empty($_POST['WPhtc_sub'.$i])){
@@ -27,23 +33,17 @@ if(isset($action)){
27
  $wp_rewrite->flush_rules();
28
  $echo.="Author permalink structure and htaccess rules updated.";
29
  break;
30
- case 'reset_rules':
31
- $WPhtc_data=array(
32
- 'pats'=>array(0=>''),
33
- 'subs'=>array(0=>''),
34
- );
35
- update_option('WPhtc_data',$WPhtc_data);
36
- $echo.="All rules reset.";
37
- break;
38
  case 'add_rule':
39
  $add_rule=true;
40
  $echo='New pair available!';
41
  break;
 
42
  case 'delete_pair':
43
  if(isset($_GET['pair'])){
 
44
  if($_GET['pair']==0 && !isset($WPhtc_data['pats'][1])){
45
- $WPhtc_data['pats']=array(0=>'');
46
- $WPhtc_data['subs']=array(0=>'');
47
  update_option('WPhtc_data',$WPhtc_data);
48
  $echo.="htaccess rules reset.";
49
  break;
@@ -52,11 +52,12 @@ if(isset($action)){
52
  $WPhtc_data['pats']=array_values($WPhtc_data['pats']);
53
  $WPhtc_data['subs']=array_values($WPhtc_data['subs']);
54
  update_option('WPhtc_data',$WPhtc_data);
55
- $echo='Pair deleted!';
56
  }
57
  break;
58
  }
59
- }?>
 
60
  <script>
61
  jQuery(document).ready(function(){
62
  init();
@@ -70,39 +71,45 @@ jQuery(document).ready(function(){
70
  num=parseInt(jQuery("#WPhtc_num").val());
71
  if(!jQuery('.wphtc-menu .add').hasClass('doing')){
72
  jQuery('.wphtc-menu .add').addClass('doing');
73
- lrule=jQuery("#htaccess-rules tr:last").attr('id').split('-');
74
- nrule=parseInt(lrule[1])+1;
75
- jQuery("#htaccess-rules tr:last").clone().attr('id','rule-'+nrule).hide().insertAfter("#htaccess-rules tr:last").fadeIn('slow',function(){jQuery('.wphtc-menu .add').removeClass('doing');}).css({display: ""});
76
- jQuery("#rule-"+nrule+" input:first").val('').attr('name','WPhtc_pat'+nrule);
77
- jQuery("#rule-"+nrule+" input:last").val('').attr('name','WPhtc_sub'+nrule);
78
- jQuery("#rule-"+nrule+" td:last").empty();
79
  jQuery("#WPhtc_num").val(num+1);
80
  }
81
  }
82
  });
83
  </script>
84
  <style>
 
 
85
  .wphtc-menu li{display:inline;margin-right:20px;}
86
  .wphtc-menu img{position:relative;top:2px;}
 
87
  #htaccess-rules img{position:relative;top:4px;}
88
  #htaccess-rules a, .wphtc-menu a{text-decoration:none;}
89
  p.alignright{padding-right:20px;}
 
90
  </style>
91
  <div class="wrap">
92
  <h2>Wp htaccess Control</h2>
 
 
 
93
  <?php if($echo!=''){?>
94
  <div class="updated fade" id="message" style="background-color: rgb(255, 251, 204);"><p><?php echo $echo;?></p></div>
95
  <?php }?>
96
- <ul class="wphtc-menu">
97
- <li><a href="<?php echo $purl?>&action=reset_rules"><img src="<?php echo $plugin_url?>/gfx/icon_alert.gif"> Reset all rules</a></li>
98
- </ul>
99
  <form method="post" action="<?php echo $purl?>">
100
- <h3>Custom Author Permalink</h3>
101
- <p class="setting-description">If you do not want to use a custom Author Permalink base just leave the field empty. Otherwise, if set, the base will be used as shown next to the form field.</p>
102
  <table class="form-table">
103
- <tr valign="top">
104
- <th><input type="text" style="width:100%" name="WPhtc_cap" value="<?php echo $WPhtc_data['cap']; ?>" /></th>
105
- <td><p><code><?php bloginfo('home')?>/<em>(your-base)</em>/admin</code></p></td>
 
 
 
 
106
  </tr>
107
  </table>
108
  <h3>Rewrite Pairs</h3>
@@ -111,7 +118,7 @@ jQuery(document).ready(function(){
111
  </ul>
112
  <table id="htaccess-rules" class="form-table">
113
  <?php
114
- $num=count($WPhtc_data['pats']);
115
  if($add_rule){$num++;};
116
  for($i=0;$i<$num;$i++){?>
117
  <tr id="rule-<?php echo $i;?>" valign="top">
@@ -127,6 +134,6 @@ jQuery(document).ready(function(){
127
  <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
128
  </p>
129
  </form>
130
- <?php if(isset($WPhtc_data['cur_hta'])){echo'<h3>Current htaccess file as it is generated by Wordpress</h3><p><code>'.$WPhtc_data['cur_hta'].'</code></p>';}?>
131
  </div>
132
  <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
  $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])){
33
  $wp_rewrite->flush_rules();
34
  $echo.="Author permalink structure and htaccess rules updated.";
35
  break;
36
+ # add_rule deprecated by jQuery use below but still present just in case
 
 
 
 
 
 
 
37
  case 'add_rule':
38
  $add_rule=true;
39
  $echo='New pair available!';
40
  break;
41
+ # deleting individual rewrite pair
42
  case 'delete_pair':
43
  if(isset($_GET['pair'])){
44
+ # if it's the last pair
45
  if($_GET['pair']==0 && !isset($WPhtc_data['pats'][1])){
46
+ unset($WPhtc_data['pats'], $WPhtc_data['subs']);
 
47
  update_option('WPhtc_data',$WPhtc_data);
48
  $echo.="htaccess rules reset.";
49
  break;
52
  $WPhtc_data['pats']=array_values($WPhtc_data['pats']);
53
  $WPhtc_data['subs']=array_values($WPhtc_data['subs']);
54
  update_option('WPhtc_data',$WPhtc_data);
55
+ $echo.='Pair deleted!';
56
  }
57
  break;
58
  }
59
+ }
60
+ $WPhtc_data=get_option('WPhtc_data');?>
61
  <script>
62
  jQuery(document).ready(function(){
63
  init();
71
  num=parseInt(jQuery("#WPhtc_num").val());
72
  if(!jQuery('.wphtc-menu .add').hasClass('doing')){
73
  jQuery('.wphtc-menu .add').addClass('doing');
74
+ lastrule=jQuery("#htaccess-rules tr:last").attr('id').split('-');
75
+ newrule=parseInt(lastrule[1])+1;
76
+ jQuery("#htaccess-rules tr:last").clone().attr('id','rule-'+newrule).hide().insertAfter("#htaccess-rules tr:last").fadeIn('slow',function(){jQuery('.wphtc-menu .add').removeClass('doing');}).css({display: ""});
77
+ jQuery("#rule-"+newrule+" input:first").val('').attr('name','WPhtc_pat'+newrule);
78
+ jQuery("#rule-"+newrule+" input:last").val('').attr('name','WPhtc_sub'+newrule);
79
+ jQuery("#rule-"+newrule+" td:last").empty();
80
  jQuery("#WPhtc_num").val(num+1);
81
  }
82
  }
83
  });
84
  </script>
85
  <style>
86
+ h2,h3,.wphtc-menu {float:left;}
87
+ .wphtc-menu {margin:1em;}
88
  .wphtc-menu li{display:inline;margin-right:20px;}
89
  .wphtc-menu img{position:relative;top:2px;}
90
+ #wphtc-menu{margin-top:2em;}
91
  #htaccess-rules img{position:relative;top:4px;}
92
  #htaccess-rules a, .wphtc-menu a{text-decoration:none;}
93
  p.alignright{padding-right:20px;}
94
+ p,.updated{clear:both;}
95
  </style>
96
  <div class="wrap">
97
  <h2>Wp htaccess Control</h2>
98
+ <ul id="wphtc-menu" class="wphtc-menu">
99
+ <li><a href="<?php echo $purl?>&action=reset_rules"><img src="<?php echo $plugin_url?>/gfx/icon_alert.gif"> Reset all rules</a></li>
100
+ </ul>
101
  <?php if($echo!=''){?>
102
  <div class="updated fade" id="message" style="background-color: rgb(255, 251, 204);"><p><?php echo $echo;?></p></div>
103
  <?php }?>
 
 
 
104
  <form method="post" action="<?php echo $purl?>">
 
 
105
  <table class="form-table">
106
+ <tr valign="top">
107
+ <th scope="row"><label for="blogdescription">Custom Author Permalink</label></th>
108
+ <td>
109
+ <input type="text" name="WPhtc_cap" value="<?php echo $WPhtc_data['cap']; ?>" /> <code><?php bloginfo('home')?>/<em>(your-base)</em>/admin</code><br/>
110
+ <span class="description">If you do not want to use a custom Author Permalink base just leave the field empty. Otherwise, if set, the base will be used as shown next to the form field.</span>
111
+ <p></p>
112
+ </td>
113
  </tr>
114
  </table>
115
  <h3>Rewrite Pairs</h3>
118
  </ul>
119
  <table id="htaccess-rules" class="form-table">
120
  <?php
121
+ $num=count($WPhtc_data['pats'])?count($WPhtc_data['pats']):1;
122
  if($add_rule){$num++;};
123
  for($i=0;$i<$num;$i++){?>
124
  <tr id="rule-<?php echo $i;?>" valign="top">
134
  <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
135
  </p>
136
  </form>
137
+ <?php if(isset($WPhtc_data['cur_hta'],$WPhtc_data['pats1'])){echo'<h3>Current htaccess file as it is generated by Wordpress</h3><p><code>'.$WPhtc_data['cur_hta'].'</code></p>';}?>
138
  </div>
139
  <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
@@ -3,12 +3,12 @@
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.1
7
  Author: dardna
8
  Author URI: http://dardna.com
9
  */
10
 
11
- /* Copyright 2008 Ant�nio Andrade (email : dardna@dardna.com)
12
 
13
  This program is free software; you can redistribute it and/or modify
14
  it under the terms of the GNU General Public License as published by
@@ -26,6 +26,7 @@ Author URI: http://dardna.com
26
  */
27
  /*
28
 
 
29
  1.1.1 - fixing screenshot mistake;
30
  1.1 - separated gui, improved management and gui;
31
  1.0.1 - added GNU license;
@@ -36,27 +37,37 @@ if (!class_exists("WPhtc")) {
36
  class WPhtc {
37
  function WPhtc() {
38
  }
 
 
39
  function wphtc_cap($rules){
40
  $WPhtc_data=get_option('WPhtc_data');
41
  if(isset($WPhtc_data['cap']) && $WPhtc_data['cap']!=''){
42
- $rules=unserialize(preg_replace('!s:(\d+):"(.*?)";!se', "'s:'.strlen('$2').':\"$2\";'",str_replace('author/',$WPhtc_data['cap'].'/',serialize($rules))));
43
  }
44
  return $rules;
45
  }
 
 
46
  function wphtc_rules($wp_rewrite){
47
  $WPhtc_data=get_option('WPhtc_data');
48
  for($i=0;$i<count($WPhtc_data['pats']);$i++){
49
  if($WPhtc_data['pats'][$i]!=''&&$WPhtc_data['subs'][$i]!=''){
 
50
  $wp_rewrite->non_wp_rules[$WPhtc_data['pats'][$i]]=$WPhtc_data['subs'][$i];
51
  }
52
  }
 
53
  $WPhtc_data['cur_hta']='# BEGIN Wordpress<br/>'.nl2br($wp_rewrite->mod_rewrite_rules()).'# END Wordpress';
54
  update_option('WPhtc_data',$WPhtc_data);
55
  return $wp_rewrite;
56
  }
 
 
57
  function wphtc_page(){
58
  include (dirname (__FILE__).'/wp-htaccess-control-gui.php');
59
  }
 
 
60
  function ConfigureMenu(){
61
  add_submenu_page("options-general.php","WP htaccess Control", "WP htaControl", 6, __FILE__, array('WPhtc','wphtc_page'));
62
  }
@@ -70,12 +81,4 @@ if (isset($WPhtc)) {
70
  add_filter('rewrite_rules_array',array($WPhtc,'wphtc_cap'));
71
  add_action('admin_menu', array($WPhtc,'ConfigureMenu'));
72
  }
73
- register_activation_hook(__FILE__,'WPhtc_install');
74
- function WPhtc_install() {
75
- $WPhtc_data=array(
76
- 'pats'=>array(0=>''),
77
- 'subs'=>array(0=>''),
78
- );
79
- update_option('WPhtc_data',$WPhtc_data);
80
- }
81
  ?>
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.2
7
  Author: dardna
8
  Author URI: http://dardna.com
9
  */
10
 
11
+ /* Copyright 2008 António Andrade (email : dardna@dardna.com)
12
 
13
  This program is free software; you can redistribute it and/or modify
14
  it under the terms of the GNU General Public License as published by
26
  */
27
  /*
28
 
29
+ 1.1.2 - no longer creating empty option array on install or reset (globally better option array handling), confirmed compatibility with WP 2.8, some work on the gui to-do;
30
  1.1.1 - fixing screenshot mistake;
31
  1.1 - separated gui, improved management and gui;
32
  1.0.1 - added GNU license;
37
  class WPhtc {
38
  function WPhtc() {
39
  }
40
+
41
+ # Replacing the Wordpress Author Permalink by rewriting it's rules if we have a Custom Author Permalink, everytime the rules are flush
42
  function wphtc_cap($rules){
43
  $WPhtc_data=get_option('WPhtc_data');
44
  if(isset($WPhtc_data['cap']) && $WPhtc_data['cap']!=''){
45
+ $rules=unserialize(preg_replace('!s:(\d+):"(.*?)";!se', '"s:".strlen("$2").":\"$2\";"',str_replace('author/',$WPhtc_data['cap'].'/',serialize($rules))));
46
  }
47
  return $rules;
48
  }
49
+
50
+ # Adding our rule pairs to the .htaccess generated by Wordpress, everytime the rules are flush
51
  function wphtc_rules($wp_rewrite){
52
  $WPhtc_data=get_option('WPhtc_data');
53
  for($i=0;$i<count($WPhtc_data['pats']);$i++){
54
  if($WPhtc_data['pats'][$i]!=''&&$WPhtc_data['subs'][$i]!=''){
55
+ # adding each custom rewrite pair to $wp_rewrite->non_wp_rules['pattern']='substitution'
56
  $wp_rewrite->non_wp_rules[$WPhtc_data['pats'][$i]]=$WPhtc_data['subs'][$i];
57
  }
58
  }
59
+ # keeping a copy of the generated htaccess in our option array for later reviewing
60
  $WPhtc_data['cur_hta']='# BEGIN Wordpress<br/>'.nl2br($wp_rewrite->mod_rewrite_rules()).'# END Wordpress';
61
  update_option('WPhtc_data',$WPhtc_data);
62
  return $wp_rewrite;
63
  }
64
+
65
+ # WP-htaccess Control options page
66
  function wphtc_page(){
67
  include (dirname (__FILE__).'/wp-htaccess-control-gui.php');
68
  }
69
+
70
+ # Adding our optons page to the admin menu
71
  function ConfigureMenu(){
72
  add_submenu_page("options-general.php","WP htaccess Control", "WP htaControl", 6, __FILE__, array('WPhtc','wphtc_page'));
73
  }
81
  add_filter('rewrite_rules_array',array($WPhtc,'wphtc_cap'));
82
  add_action('admin_menu', array($WPhtc,'ConfigureMenu'));
83
  }
 
 
 
 
 
 
 
 
84
  ?>