WP htaccess Control - Version 1.3

Version Description

  • Was using two fields for the custom htaccess when only one was needed, for the sake of simplicity;
  • Integrated the Custom Author Permalink with the Google XML Sitemap plugin.
Download this release

Release Info

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

Code changes from version 1.2.1 to 1.3

readme.txt CHANGED
@@ -6,19 +6,21 @@ Donate link:
6
  Tags: permalinks, permalink, author, htaccess, rewrite, redirect
7
  Requires at least: 2.7
8
  Tested up to: 2.9.2
9
- Stable tag: 1.2.1
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 ==
23
 
24
  1. Download **WP htaccess Control**;
@@ -34,14 +36,17 @@ Provides an interface to add custom htaccess rules to the htaccess file generate
34
 
35
  == Screenshots ==
36
 
37
- 1. Administration page (as of v.1.2)
38
 
39
  == Changelog ==
 
 
 
40
 
41
  = 1.2.1 =
42
  * Fixed bug on resetting all rules;
43
  * Fixed critical bug on empty htaccess custom rules;
44
- * Tested under WP 2.9.2;
45
 
46
  = 1.2 =
47
  * Improved htaccess customization giving now much more freedom.
@@ -49,32 +54,35 @@ Provides an interface to add custom htaccess rules to the htaccess file generate
49
  = 1.1.4 =
50
  * Confirmed compatibility with WP 2.9.1;
51
  * Fixed "Current htaccess file as it is generated by Wordpress" which was not being printed;
52
- * Minor gui changes;
53
 
54
  = 1.1.3 =
55
  * Fixing error on wphtc_cap's preg_replace commited on 1.1.2 (thank you mattcav for the report!);
56
- * Fixing php warning on update without htaccess rules;
57
 
58
  = 1.1.2 =
59
  * No longer creating empty option array on install or reset (globally better option array handling);
60
  * Confirmed compatibility with WP 2.8;
61
- * Still some work to do on the interface;
62
 
63
  = 1.1.1 =
64
- * Fixing screenshot mistake;
65
 
66
  = 1.1 =
67
- * Separated gui file;
68
- * Improved management and gui;
69
 
70
  = 1.0.1 =
71
- * Added GNU license;
72
 
73
  = 1.0 =
74
  * Initial release (poor interface although working).
75
 
76
  == Upgrade Notice ==
77
 
 
 
 
78
  = 1.2.1 =
79
  * Fixed critical bugs inserted on 1.2, you should update.
80
 
6
  Tags: permalinks, permalink, author, htaccess, rewrite, redirect
7
  Requires at least: 2.7
8
  Tested up to: 2.9.2
9
+ Stable tag: 1.3
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. (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
+ * If Google XML Sitemap is found installed, you'll be able to use your Custom Author Permalink on the sitemap generated.
23
+
24
  == Installation ==
25
 
26
  1. Download **WP htaccess Control**;
36
 
37
  == Screenshots ==
38
 
39
+ 1. Administration page (as of v.1.3)
40
 
41
  == Changelog ==
42
+ = 1.3 =
43
+ * Was using two fields for the custom htaccess when only one was needed, for the sake of simplicity;
44
+ * Integrated the Custom Author Permalink with the Google XML Sitemap plugin.
45
 
46
  = 1.2.1 =
47
  * Fixed bug on resetting all rules;
48
  * Fixed critical bug on empty htaccess custom rules;
49
+ * Tested under WP 2.9.2.
50
 
51
  = 1.2 =
52
  * Improved htaccess customization giving now much more freedom.
54
  = 1.1.4 =
55
  * Confirmed compatibility with WP 2.9.1;
56
  * Fixed "Current htaccess file as it is generated by Wordpress" which was not being printed;
57
+ * Minor ui changes.
58
 
59
  = 1.1.3 =
60
  * Fixing error on wphtc_cap's preg_replace commited on 1.1.2 (thank you mattcav for the report!);
61
+ * Fixing php warning on update without htaccess rules.
62
 
63
  = 1.1.2 =
64
  * No longer creating empty option array on install or reset (globally better option array handling);
65
  * Confirmed compatibility with WP 2.8;
66
+ * Still some work to do on the interface.
67
 
68
  = 1.1.1 =
69
+ * Fixing screenshot mistake.
70
 
71
  = 1.1 =
72
+ * Separated ui file;
73
+ * Improved management and ui.
74
 
75
  = 1.0.1 =
76
+ * Added GNU license.
77
 
78
  = 1.0 =
79
  * Initial release (poor interface although working).
80
 
81
  == Upgrade Notice ==
82
 
83
+ = 1.3 =
84
+ * Integrated the Custom Author Permalink with the Google XML Sitemap plugin.
85
+
86
  = 1.2.1 =
87
  * Fixed critical bugs inserted on 1.2, you should update.
88
 
screenshot-1.jpg CHANGED
Binary file
screenshot-v1.1.png DELETED
Binary file
wp-htaccess-control-gui.php → wp-htaccess-control-ui.php RENAMED
@@ -1,15 +1,13 @@
1
  <?php
2
-
3
  $plugin_path = WP_CONTENT_DIR.'/plugins/'.plugin_basename(dirname(__FILE__));
4
  $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::wphtc_page_action();
9
  global $echo;
10
  $WPhtc_data=get_option('WPhtc_data');
11
  ?>
12
- <script>
13
  jQuery(document).ready(function(){
14
  init();
15
  function init(){
@@ -33,7 +31,7 @@ jQuery(document).ready(function(){
33
  }
34
  });
35
  </script>
36
- <style>
37
  h2,h3,.wphtc-menu {float:left;}
38
  h3{clear:left;}
39
  span.description{display:block}
@@ -64,31 +62,32 @@ jQuery(document).ready(function(){
64
  <span class="description">Permalink settings must be set and not Default (/?p=123).</span>
65
  <span class="description">If set, the author base will be used as shown next to the form field.</span>
66
  <span class="description">If you do not want to use a custom Author Permalink base just leave the field empty.</span>
67
- <p></p>
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>
1
  <?php
 
2
  $plugin_path = WP_CONTENT_DIR.'/plugins/'.plugin_basename(dirname(__FILE__));
3
  $plugin_url = WP_CONTENT_URL.'/plugins/'.plugin_basename(dirname(__FILE__));
 
4
  $q=explode('&',$_SERVER['QUERY_STRING']);
5
  $purl='http'.((!empty($_SERVER['HTTPS'])) ? 's' : '').'://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?'.$q[0];
6
  WPhtc::wphtc_page_action();
7
  global $echo;
8
  $WPhtc_data=get_option('WPhtc_data');
9
  ?>
10
+ <script type="text/javascript">
11
  jQuery(document).ready(function(){
12
  init();
13
  function init(){
31
  }
32
  });
33
  </script>
34
+ <style type="text/css">
35
  h2,h3,.wphtc-menu {float:left;}
36
  h3{clear:left;}
37
  span.description{display:block}
62
  <span class="description">Permalink settings must be set and not Default (/?p=123).</span>
63
  <span class="description">If set, the author base will be used as shown next to the form field.</span>
64
  <span class="description">If you do not want to use a custom Author Permalink base just leave the field empty.</span>
 
65
  </td>
66
  </tr>
67
+ <?php if(class_exists('GoogleSitemapGeneratorLoader')){?>
68
+ <tr>
69
+ <th>Google XML Sitemap</th>
70
+ <td>
71
+ <input type="checkbox" name="WPhtc_sm_enabled" value="1" <?php if($WPhtc_data['sm_enabled']==1){ echo "checked";}?>/> Apply Custom Author Permalink on Generated Sitemap
72
+ <span class="description">Leave "Include author pages" unchecked on Google XML Sitemap options page if using this.</span>
73
+ <span class="description">However, if you want to adjust the "Priority" or "Change frequency" you should do so on the <a href="options-general.php?page=google-sitemap-generator/sitemap.php">Google XML Sitemap options page</a>.</span>
74
+ </td>
75
+ </tr>
76
+ <?php } ?>
77
  </table>
78
  <h3>Custom htaccess</h3>
79
  <table id="" class="form-table">
80
  <tr>
81
  <td>
82
+ <textarea name="WPhtc_hta" cols="70" rows="5"><?php
83
+ echo $WPhtc_data['hta'];
84
+ if($WPhtc_data['hta_mr']!=""){
85
+ echo "\n<IfModule mod_rewrite.c>\nRewriteEngine On\n".$WPhtc_data['hta_mr']."\n</IfModule>";
86
+ }?></textarea>
87
+ <p class="description">This rules will be printed before any Wordpress rules.</p>
 
 
 
 
 
 
 
 
88
  <p class="description">Please double check them before saving as a mistake could make your site unaccessable.</p>
89
  <p class="description">In any case you can always edit your .htaccess file manually.</p>
90
+ <p class="description">In case of doubt as where this rules will be kept save a comment line (like #test) and check the end of this page.</p>
91
  </td>
92
  </tr>
93
  </table>
wp-htaccess-control.php CHANGED
@@ -3,12 +3,11 @@
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.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
@@ -36,7 +35,41 @@ if (!class_exists("WPhtc")) {
36
  }
37
  return $rules;
38
  }
39
- # Adding our rule pairs to the .htaccess generated by Wordpress, everytime the rules are flush
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  function wphtc_wp_rewrite_rules($wp_rewrite){
41
  $WPhtc_data=get_option('WPhtc_data');
42
  for($i=0;$i<count($WPhtc_data['pats']);$i++){
@@ -50,6 +83,7 @@ if (!class_exists("WPhtc")) {
50
  update_option('WPhtc_data',$WPhtc_data);
51
  return $wp_rewrite;
52
  }
 
53
  function wphtc_hta_rules($rules){
54
  $WPhtc_data=get_option('WPhtc_data');
55
  if($WPhtc_data['hta']!=''){
@@ -57,19 +91,25 @@ if (!class_exists("WPhtc")) {
57
  $new_rules.=$WPhtc_data['hta']."\n";
58
  $new_rules.="# End Custom htaccess from WP htaccess Control\n\n";
59
  }
60
- if($WPhtc_data['hta_mr']!=''){
61
- $insert="\n\n# Begin Custom htaccess from WP htaccess Control\n".$WPhtc_data['hta_mr']."\n# End Custom htaccess from WP htaccess Control\n";
62
- $new_rules.=str_replace("RewriteEngine On","RewriteEngine On".$insert,$rules);
63
- }
 
64
  else{
65
  $new_rules.=$rules;
66
  }
67
  return $new_rules;
68
  }
69
- # WP-htaccess Control options page
70
  function wphtc_page(){
71
- include (dirname (__FILE__).'/wp-htaccess-control-gui.php');
72
  }
 
 
 
 
 
73
  function wphtc_page_action(){
74
  $action=$_POST['action']?$_POST['action']:$_GET['action'];
75
  global $echo;
@@ -83,7 +123,7 @@ if (!class_exists("WPhtc")) {
83
  global $wp_rewrite;
84
  $wp_rewrite->flush_rules();
85
  break;
86
- # if updating, save new rules in database and flush rewrite rules as if regenerating permalink structure
87
  case 'update':
88
  for($i=0;$i<$_POST['WPhtc_num'];$i++){
89
  if(!empty($_POST['WPhtc_pat'.$i]) && !empty($_POST['WPhtc_sub'.$i])){
@@ -99,14 +139,30 @@ if (!class_exists("WPhtc")) {
99
  $WPhtc_data['subs']=array_values($WPhtc_data['subs']);
100
  }
101
  $WPhtc_data['hta']=$_POST['WPhtc_hta'];
102
- $WPhtc_data['hta_mr']=$_POST['WPhtc_hta_mr'];
 
 
103
  $WPhtc_data['cap']=$_POST['WPhtc_cap'];
 
 
 
 
 
 
 
 
 
 
 
 
 
104
  update_option('WPhtc_data',$WPhtc_data);
 
105
  global $wp_rewrite;
106
  $wp_rewrite->flush_rules();
107
  $echo.="Author permalink structure and htaccess Rules updated.";
108
  break;
109
- # add_rule substituted by jQuery use below but still present just in case
110
  case 'add_rule':
111
  $add_rule=true;
112
  $echo='New pair available!';
@@ -133,10 +189,6 @@ if (!class_exists("WPhtc")) {
133
  }
134
  }
135
  }
136
- # Adding our options page to the admin menu
137
- function ConfigureMenu(){
138
- add_submenu_page("options-general.php","WP htaccess Control", "WP htaControl", 6, __FILE__, array('WPhtc','wphtc_page'));
139
- }
140
  }
141
  }
142
  if (class_exists("WPhtc")) {
@@ -146,6 +198,7 @@ if (isset($WPhtc)) {
146
  add_filter('mod_rewrite_rules', array($WPhtc,'wphtc_hta_rules'));
147
  add_filter('generate_rewrite_rules', array($WPhtc,'wphtc_wp_rewrite_rules'));
148
  add_filter('rewrite_rules_array',array($WPhtc,'wphtc_cap'));
149
- add_action('admin_menu', array($WPhtc,'ConfigureMenu'));
 
150
  }
151
  ?>
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.3
7
  Author: dardna
8
  Author URI: http://dardna.com
9
  */
10
+ /* Copyright 2010 António Andrade (email : dardna@dardna.com)
 
11
 
12
  This program is free software; you can redistribute it and/or modify
13
  it under the terms of the GNU General Public License as published by
35
  }
36
  return $rules;
37
  }
38
+ # Adding our Custom Author Base to the sitemap generated by Google XML Sitemaps
39
+ # Adapted from sitemap-core.php line 2036
40
+ function set_sm(){
41
+ $WPhtc_data=get_option('WPhtc_data');
42
+ if(class_exists('GoogleSitemapGenerator')&&$WPhtc_data['cap']!=''){
43
+ $generatorObject = &GoogleSitemapGenerator::GetInstance();
44
+ if ($generatorObject != null){
45
+ global $wpdb;
46
+ $sql = "SELECT DISTINCT
47
+ p.ID,
48
+ u.user_nicename,
49
+ MAX(p.post_modified_gmt) AS last_post
50
+ FROM
51
+ {$wpdb->users} u,
52
+ {$wpdb->posts} p
53
+ WHERE
54
+ p.post_author = u.ID
55
+ AND p.post_status = 'publish'
56
+ AND p.post_type = 'post'
57
+ AND p.post_password = ''
58
+ " . (floatval($wp_version) < 2.1?"AND p.post_date_gmt <= '" . gmdate('Y-m-d H:i:59') . "'":"") . "
59
+ GROUP BY
60
+ u.ID,
61
+ u.user_nicename";
62
+ $authors = $wpdb->get_results($sql);
63
+ if($authors && is_array($authors)) {
64
+ foreach($authors as $author) {
65
+ $url=get_bloginfo('home')."/".$WPhtc_data['cap']."/".$author->user_nicename."/";
66
+ $generatorObject->AddUrl($url,$generatorObject->GetTimestampFromMySql($author->last_post),$generatorObject->GetOption("cf_auth"),$generatorObject->GetOption("pr_auth"));
67
+ }
68
+ }
69
+ }
70
+ }
71
+ }
72
+ # Adding rewrite pairs to the .htaccess generated by Wordpress, everytime the rules are flush
73
  function wphtc_wp_rewrite_rules($wp_rewrite){
74
  $WPhtc_data=get_option('WPhtc_data');
75
  for($i=0;$i<count($WPhtc_data['pats']);$i++){
83
  update_option('WPhtc_data',$WPhtc_data);
84
  return $wp_rewrite;
85
  }
86
+ # Adding Custom Rules to htaccess file generated by Wordpress, everytime the rules are flush
87
  function wphtc_hta_rules($rules){
88
  $WPhtc_data=get_option('WPhtc_data');
89
  if($WPhtc_data['hta']!=''){
91
  $new_rules.=$WPhtc_data['hta']."\n";
92
  $new_rules.="# End Custom htaccess from WP htaccess Control\n\n";
93
  }
94
+ // DEPRECATE LATER
95
+ if($WPhtc_data['hta_mr']!=''){
96
+ $insert="\n\n# Begin Custom htaccess from WP htaccess Control\n".$WPhtc_data['hta_mr']."\n# End Custom htaccess from WP htaccess Control\n";
97
+ $new_rules.=str_replace("RewriteEngine On","RewriteEngine On".$insert,$rules);
98
+ }
99
  else{
100
  $new_rules.=$rules;
101
  }
102
  return $new_rules;
103
  }
104
+ # WP-htaccess Control options page interface
105
  function wphtc_page(){
106
+ include (dirname (__FILE__).'/wp-htaccess-control-ui.php');
107
  }
108
+ # Adding our options page to the admin menu
109
+ function configure_menu(){
110
+ add_submenu_page("options-general.php","WP htaccess Control", "WP htaControl", 6, __FILE__, array('WPhtc','wphtc_page'));
111
+ }
112
+ # Options Page Actions
113
  function wphtc_page_action(){
114
  $action=$_POST['action']?$_POST['action']:$_GET['action'];
115
  global $echo;
123
  global $wp_rewrite;
124
  $wp_rewrite->flush_rules();
125
  break;
126
+ # if updating, save new rules in database and flush rewrite rules
127
  case 'update':
128
  for($i=0;$i<$_POST['WPhtc_num'];$i++){
129
  if(!empty($_POST['WPhtc_pat'.$i]) && !empty($_POST['WPhtc_sub'.$i])){
139
  $WPhtc_data['subs']=array_values($WPhtc_data['subs']);
140
  }
141
  $WPhtc_data['hta']=$_POST['WPhtc_hta'];
142
+ // DEPRECATING
143
+ //$WPhtc_data['hta_mr']=$_POST['WPhtc_hta_mr'];
144
+ unset($WPhtc_data['hta_mr']);
145
  $WPhtc_data['cap']=$_POST['WPhtc_cap'];
146
+ # Unsetting inclusion of Author pages on Google XML Sitemap options, we'll add those links to the sitemap later with our Custom Author Permalink
147
+ $WPhtc_data['sm_enabled']=($_POST['WPhtc_sm_enabled']==1&&$WPhtc_data['cap']!='')?1:0;
148
+ if($WPhtc_data['sm_enabled']==1){
149
+ $SMoptions=get_option("sm_options");
150
+ if($SMoptions&&is_array($SMoptions)){
151
+ $SMoptions=get_option("sm_options");
152
+ $SMoptions['sm_in_auth']=0;
153
+ update_option('sm_options',$SMoptions);
154
+ # Try to rebuild Sitemap
155
+ do_action("sm_rebuild");
156
+ }
157
+ }
158
+ # Update WP htaccess Control options
159
  update_option('WPhtc_data',$WPhtc_data);
160
+ # Flush Rewrite Rules
161
  global $wp_rewrite;
162
  $wp_rewrite->flush_rules();
163
  $echo.="Author permalink structure and htaccess Rules updated.";
164
  break;
165
+ # add_rule substituted by jQuery use below but still present just in case (this should be Deprecated really)
166
  case 'add_rule':
167
  $add_rule=true;
168
  $echo='New pair available!';
189
  }
190
  }
191
  }
 
 
 
 
192
  }
193
  }
194
  if (class_exists("WPhtc")) {
198
  add_filter('mod_rewrite_rules', array($WPhtc,'wphtc_hta_rules'));
199
  add_filter('generate_rewrite_rules', array($WPhtc,'wphtc_wp_rewrite_rules'));
200
  add_filter('rewrite_rules_array',array($WPhtc,'wphtc_cap'));
201
+ add_action('admin_menu', array($WPhtc,'configure_menu'));
202
+ add_action('sm_buildmap',array($WPhtc,'set_sm'));
203
  }
204
  ?>