Quick Page/Post Redirect Plugin - Version 1.8

Version Description

  • Added a new Quick 301 Redirects Page to allow adding of additional redirects that do not have Pages or Posts created for them. Based on Scott Nelle's Simple 301 Redirects plugin.(12/28/2009)
Download this release

Release Info

Developer prophecy2040
Plugin Icon 128x128 Quick Page/Post Redirect Plugin
Version 1.8
Comparing to
See all releases

Code changes from version 1.7 to 1.8

page_post_redirect_plugin.php CHANGED
@@ -2,12 +2,13 @@
2
  /*
3
  Plugin Name: Quick Page/Post Redirect
4
  Plugin URI: http://fischercreativemedia.com/wordpress-plugins/quick-pagepost-redirct-plugin/
5
- Description: Redirect Pages or Posts to another location quickly. Adds a redirect box to the page or post edit page where you can specify the redirect Location and type. Location can be to another WordPress page/post or an external URL. UPDATE: Page or post NO LONGER needs to be published for this to work correctly - however you do need to publish it and then save it as a draft so WordPress creates the proper meta for it.
6
  Author: Don Fischer
7
  Author URI: http://www.fischercreativemedia.com/
8
- Version: 1.7
9
 
10
  Version info:
 
11
  1.7 - Small fix to correct the Meta Redirect - moved "exit" command to end of "addmetatohead_theme" function. And also fix Page redirect. (9/8/2009)
12
  1.6.1 - Small fix to correct the same problem as 1.6 for Category and Archive pages (9/1/2009)
13
  1.6 - Fix wrongful redirect when the first blog post on home page (main blog page) has a redirect set up - this was redirecting the
@@ -21,7 +22,7 @@ Version info:
21
  1.1 - Fix redirect for off site links (7/7/2009)
22
  1.0 - Plugin Release (7/1/2009)
23
 
24
- Copyright (C) 2009 Donald J. Fischer
25
 
26
  This program is free software: you can redistribute it and/or modify
27
  it under the terms of the GNU General Public License as published by
@@ -37,11 +38,130 @@ Version info:
37
  along with this program. If not, see <http://www.gnu.org/licenses/>.
38
  */
39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  // Actions
41
  //----------
42
  add_action('admin_menu', 'add_edit_box_ppr');
43
  add_action('save_post', 'ppr_save_postdata', 1, 2); // save the custom fields
44
  add_action('wp','ppr_do_redirect', 1, 2);
 
 
 
 
 
45
 
46
  // Variables
47
  //----------
@@ -107,6 +227,7 @@ Version info:
107
  endif;
108
  }
109
 
 
110
  //=======================================
111
  // Add options to post/page edit pages
112
  //=======================================
2
  /*
3
  Plugin Name: Quick Page/Post Redirect
4
  Plugin URI: http://fischercreativemedia.com/wordpress-plugins/quick-pagepost-redirct-plugin/
5
+ Description: Redirect Pages or Posts to another location quickly. Adds a redirect box to the page or post edit page where you can specify the redirect Location and type which can be to another WordPress page/post or an external URL. Additional 301 Redirects can also be added for non-existant posts or pages - helpful for sites converted to WordPress.
6
  Author: Don Fischer
7
  Author URI: http://www.fischercreativemedia.com/
8
+ Version: 1.8
9
 
10
  Version info:
11
+ 1.8 - Added a new 301 Redirect Page to allow adding of additional redirects that do not have Pages or Posts created for them. Based on Scott Nelle's Simple 301 Redirects plugin.(12/28/2009)
12
  1.7 - Small fix to correct the Meta Redirect - moved "exit" command to end of "addmetatohead_theme" function. And also fix Page redirect. (9/8/2009)
13
  1.6.1 - Small fix to correct the same problem as 1.6 for Category and Archive pages (9/1/2009)
14
  1.6 - Fix wrongful redirect when the first blog post on home page (main blog page) has a redirect set up - this was redirecting the
22
  1.1 - Fix redirect for off site links (7/7/2009)
23
  1.0 - Plugin Release (7/1/2009)
24
 
25
+ Copyright (C) 2009/2010 Donald J. Fischer
26
 
27
  This program is free software: you can redistribute it and/or modify
28
  it under the terms of the GNU General Public License as published by
38
  along with this program. If not, see <http://www.gnu.org/licenses/>.
39
  */
40
 
41
+ //=======================================
42
+ // Redirect Class (for non oage post redirects).
43
+ // Original Simple 301 Redirects Class created by Scott Nelle (http://www.scottnelle.com/)
44
+ //=======================================
45
+ if (!class_exists("quick_page_post_redirects")) {
46
+ class quick_page_post_redirects {
47
+
48
+ //generate the link to the options page under settings
49
+ function create_menu(){
50
+ add_options_page('Quick Redirects', 'Quick Redirects', 10, 'redirects-options', array($this,'options_page'));
51
+ }
52
+
53
+ //generate the options page in the wordpress admin
54
+ function options_page(){
55
+ ?>
56
+ <div class="wrap">
57
+ <h2>Quick 301 Redirects</h2>
58
+ <br/>This section is useful if you have links from an old site and need to have them redirect to a new location on the current site, or if you have an existing URL that you need to send some place else and you don't want to have a Page or Post created to use the other Page/Post Redirect option.
59
+ <br/>
60
+ <br/>To add additional 301 redirects, put the URL you want to redirect in the Request field and the Place you want it to redirect to, in the Destination field.
61
+ <br/>To delete a redirect, empty both fields and save the changes.
62
+ <br/>
63
+ <br/><b>PLEASE NOTE:</b> The <b>Request</b> field MUST be relative to the ROOT directory and contain the <code>/</code> at the beginning. The <b>Destination</b> field can be any valid URL or relative path (from root).<br/><br/>
64
+ <form method="post" action="options-general.php?page=redirects-options">
65
+ <table>
66
+ <tr>
67
+ <th align="left">Request</th>
68
+ <th align="left">Destination</th>
69
+ </tr>
70
+ <tr>
71
+ <td><small>example: <code>/about.htm</code> or <code>/test-directory/landing-zone/</code></small></td>
72
+ <td><small>example: <code><?php echo get_option('home'); ?>/about/</code> or <code><?php echo get_option('home'); ?>/landing/</code></small></td>
73
+ </tr>
74
+ <?php echo $this->expand_redirects(); ?>
75
+ <tr>
76
+ <td><input type="text" name="quickppr_redirects[request][]" value="" style="width:35em" />&nbsp;&raquo;&nbsp;</td>
77
+ <td><input type="text" name="quickppr_redirects[destination][]" value="" style="width:35em;" /></td>
78
+ </tr>
79
+ </table>
80
+
81
+ <p class="submit">
82
+ <input type="submit" name="submit_301" class="button-primary" value="<?php _e('Save Changes') ?>" />
83
+ </p>
84
+ </form>
85
+ </div>
86
+ <?php
87
+ } // end of function options_page
88
+
89
+ //utility function to return the current list of redirects as form fields
90
+ function expand_redirects(){
91
+ $redirects = get_option('quickppr_redirects');
92
+ $output = '';
93
+ if (!empty($redirects)) {
94
+ foreach ($redirects as $request => $destination) {
95
+ $output .= '
96
+
97
+ <tr>
98
+ <td><input type="text" name="quickppr_redirects[request][]" value="'.$request.'" style="width:35em" />&nbsp;&raquo;&nbsp;</td>
99
+ <td><input type="text" name="quickppr_redirects[destination][]" value="'.$destination.'" style="width:35em;" /></td>
100
+ </tr>
101
+
102
+ ';
103
+ }
104
+ } // end if
105
+ return $output;
106
+ }
107
+
108
+ //save the redirects from the options page to the database
109
+ function save_redirects($data){
110
+ $redirects = array();
111
+
112
+ for($i = 0; $i < sizeof($data['request']); ++$i) {
113
+ $request = trim($data['request'][$i]);
114
+ $destination = trim($data['destination'][$i]);
115
+
116
+ if ($request == '' && $destination == '') { continue; }
117
+ else { $redirects[$request] = $destination; }
118
+ }
119
+
120
+ update_option('quickppr_redirects', $redirects);
121
+ }
122
+
123
+ //Read the list of redirects and if the current page is found in the list, send the visitor on her way
124
+ function redirect(){
125
+ // this is what the user asked for
126
+ $userrequest = str_replace(get_option('home'),'',$this->getAddress());
127
+ $userrequest = rtrim($userrequest,'/');
128
+
129
+ $redirects = get_option('quickppr_redirects');
130
+ if (!empty($redirects)) {
131
+ foreach ($redirects as $storedrequest => $destination) {
132
+ // compare user request to each 301 stored in the db
133
+ if($userrequest == rtrim($storedrequest,'/')) {
134
+ header ('HTTP/1.1 301 Moved Permanently');
135
+ header ('Location: ' . $destination);
136
+ exit();
137
+ }
138
+ else { unset($redirects); }
139
+ }
140
+ }
141
+ } // end funcion redirect
142
+
143
+ //utility function to get the full address of the current request - credit: http://www.phpro.org/examples/Get-Full-URL.html
144
+ function getAddress(){
145
+ $protocol = $_SERVER['HTTPS'] == 'on' ? 'https' : 'http'; //check for https
146
+ return $protocol.'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; //return the full address
147
+ }
148
+
149
+ } // end class quick_page_post_redirects
150
+ } // end check for existance of class
151
+
152
+ // Call the 301 class (for non-existant 301 redirects)
153
+ $redirect_plugin = new quick_page_post_redirects();
154
+
155
  // Actions
156
  //----------
157
  add_action('admin_menu', 'add_edit_box_ppr');
158
  add_action('save_post', 'ppr_save_postdata', 1, 2); // save the custom fields
159
  add_action('wp','ppr_do_redirect', 1, 2);
160
+ if (isset($redirect_plugin)) {
161
+ add_action('init', array($redirect_plugin,'redirect'), 1); // add the redirect action, high priority
162
+ add_action('admin_menu', array($redirect_plugin,'create_menu')); // create the menu
163
+ if (isset($_POST['submit_301'])) {$redirect_plugin->save_redirects($_POST['quickppr_redirects']);} //if submitted, process the data
164
+ }
165
 
166
  // Variables
167
  //----------
227
  endif;
228
  }
229
 
230
+
231
  //=======================================
232
  // Add options to post/page edit pages
233
  //=======================================
readme.txt CHANGED
@@ -4,15 +4,16 @@ Donate link: http://fischercreativemedia.com/
4
  Tags: redirect, 301, 302, meta, post, plugin, page, forward, re-direct, wpmu, WordPress MU
5
  Requires at least: 2.5
6
  Tested up to: 2.9.1
7
- Stable tag: 1.7
8
 
9
  Redirect Pages/Posts to another page/post or external URL. Adds edit box to admin edit so user can specify the redirect Location and type.
10
 
11
  == Description ==
12
-
13
  Quick Page/Post Redirect Plugin redirects WordPress Pages or Posts to another location quickly.
14
  It adds an option box to the edit section where you can specify the redirect location and type of redirect that you want, temporary, permanent, or meta.
15
 
 
 
16
  The redirect Location can be to another WordPress page/post or any other website with an external URL. It allows the use of a full URL path, the post or page ID, permalink or page-name.
17
 
18
  PLEASE NOTE: At this time, the a new page or post needs to be Published in order for the redirect to happen. It WILL work on a DRAFT Status Post/Page ONLY, and I mean ONLY, if the Post/Page has FIRST been Published and the re-saved as a Draft - WordPress does not set up the post meta for the permalink until after first publish for some reason - will hopefully fix this in the future.
@@ -25,19 +26,30 @@ TROUBLESHOOTING:
25
  If your page or post is not redirecting, this is most likely because something else like the theme functions file or another plugin is outputting the header BEFORE the plugin can perform the redirect. This can be tested by turning off all plugins except the Quick Page/Post Redirect Plugin and testing if the redirect works. 9 out of 10 times, a plugin or bad code is the culprit.
26
  We have tested the plugin in dozens of themes and alongside a whole lot more plugins. In our experience, (with exception to a few bugs) most of the time another plugin is the problem. If you do notice a problem, please let us know at plugins@fischercreativemedia.com - along with the WP version, theme you are using and plugins you have installed - and we will try to troubleshoot the problem.
27
 
 
28
  == Installation ==
29
 
30
  = If you downloaded this plugin: =
31
  * Upload `quick_page_post_redirect` folder to the `/wp-content/plugins/` directory
32
  * Activate the plugin through the 'Plugins' menu in WordPress
33
  * Once Activated, you can add a redirect by entering the correct information in the `Quick Page/Post Redirect` box in the edit section of a page or post
 
34
 
35
  = If you install this plugin through WordPress 2.8+ plugin search interface: =
36
  * Click Install `Quick Page/Post Redirect Plugin`
37
  * Activate the plugin through the 'Plugins' menu in WordPress
38
  * Once Activated, you can add a redirect by entering the correct information in the `Quick Page/Post Redirect` box in the edit section of a page or post
 
39
 
40
  == Frequently Asked Questions ==
 
 
 
 
 
 
 
 
41
 
42
  = Why is my Page/Post not redirecting? =
43
  If your page or post is not redirecting, this is most likely because something else like the theme functions file or another plugin is outputting the header BEFORE the plugin can perform the redirect. This can be tested by turning off all plugins except the Quick Page/Post Redirect Plugin and testing if the redirect works. 9 out of 10 times, a plugin or bad code is the culprit.
@@ -48,11 +60,9 @@ We have tested the plugin in dozens of themes and a whole lot more plugins. In o
48
  YES... and NO... The redirect will always work on a Published Post/Page. For it to work correctly on a Post/Page in DRAFT status, you need to fist publish the page, then re-save it as a draft. If you don't follow that step, you will get a 404 error.
49
 
50
  = Can I do a permanent 301 Redirect? =
51
-
52
  Yes. You can perform a 301 Permanent Redirect. Additionally, you can select a 302 Temporary or a 307 Temporary redirect or a Meta redirect.
53
 
54
  = What the heck is a 301 or 302 redirect anyway? =
55
-
56
  Good question! THe number corresponds with the header code that is returned to the browser when the page is first accessed. A good page, meaning something was found, returns a 200 status code and that tells the browser to go ahead and keep loading the content for the page. If nothing is found a 404 error is returned (and we have ALL seen these - usually it is a bad link or a page was moved). There are many other types of codes, but those ore the most common.
57
 
58
  The 300+ range of codes in the header, tells the browser (and search engine spider) that the original page has moved to a new location - this can be just a new file name a new folder or a completely different site.
@@ -62,22 +72,23 @@ A 301 code means that you want to tell the browser (or Google, bing, etc.) that
62
  A 302 or 307 code tell the browser that the file was there but TEMPORARILY it can be found at a new location. This will tell the search engines to KEEP the old link in place becasue SOME day it will be back at the same old link. There is only a slight difference between a 302 and a 307 status. Truth is, 302 is more widely used, so unless you know why you need a 307, stick with a 302.
63
 
64
  = So, which one do I use? =
65
-
66
  Easiest way to decide is this: If you want the page to permanetnly change to a new spot, use 301. If you are editing the page or post and only want it to be down for a few hours, minutes, days or weeks and plan on putting it back with the same link as before, then us 302. If you want to hide the reponse code from the spiders, use the `no code` option, and if you are having trouble with the redirects, use a `meta` redirect. The meta redirect actuall starts to load the page as a 200 good status, then redirects using a meta redirect tag.
67
 
68
  Still not sure? Try 302 for now - at least until you have a little time to read up on the subject.
69
 
70
  = Should I use a full URL with http:// or https:// ? =
71
-
72
  Yes, you can, but you do not always need to. If you are redirecting to an external URL, then yes. If you are just redirecting to another page or post on your site, then no, it is not needed. When in doubt, use the entire URL.
73
 
74
 
75
  == Screenshots ==
76
 
77
  1. Sample admin Post/Page edit box screenshot.
78
-
 
79
 
80
  == Changelog ==
 
 
81
  = 1.7 =
82
  * fix to correct meta redirect - moved "exit" commant to "addtoheader_theme" function. Also fixed the problem woth some pages not redirecting. Made the plugin WordPress MU compatible. (9/8/2009)
83
  = 1.6.1 =
4
  Tags: redirect, 301, 302, meta, post, plugin, page, forward, re-direct, wpmu, WordPress MU
5
  Requires at least: 2.5
6
  Tested up to: 2.9.1
7
+ Stable tag: 1.8
8
 
9
  Redirect Pages/Posts to another page/post or external URL. Adds edit box to admin edit so user can specify the redirect Location and type.
10
 
11
  == Description ==
 
12
  Quick Page/Post Redirect Plugin redirects WordPress Pages or Posts to another location quickly.
13
  It adds an option box to the edit section where you can specify the redirect location and type of redirect that you want, temporary, permanent, or meta.
14
 
15
+ *NEW* - Version 1.8 adds a new feature to allow you to add redirects without needing to create a Page or Post to do so. This is very useful for sites that were converted to WordPress and have old links that create 404 errors (see FAQs for more information).
16
+
17
  The redirect Location can be to another WordPress page/post or any other website with an external URL. It allows the use of a full URL path, the post or page ID, permalink or page-name.
18
 
19
  PLEASE NOTE: At this time, the a new page or post needs to be Published in order for the redirect to happen. It WILL work on a DRAFT Status Post/Page ONLY, and I mean ONLY, if the Post/Page has FIRST been Published and the re-saved as a Draft - WordPress does not set up the post meta for the permalink until after first publish for some reason - will hopefully fix this in the future.
26
  If your page or post is not redirecting, this is most likely because something else like the theme functions file or another plugin is outputting the header BEFORE the plugin can perform the redirect. This can be tested by turning off all plugins except the Quick Page/Post Redirect Plugin and testing if the redirect works. 9 out of 10 times, a plugin or bad code is the culprit.
27
  We have tested the plugin in dozens of themes and alongside a whole lot more plugins. In our experience, (with exception to a few bugs) most of the time another plugin is the problem. If you do notice a problem, please let us know at plugins@fischercreativemedia.com - along with the WP version, theme you are using and plugins you have installed - and we will try to troubleshoot the problem.
28
 
29
+ If you are using the new Quick 301 Redirects method to do your redirects, be sure that your Request URL starts with a / and is releative to the root (i.e., http://mysite.com/test/ would have /test/ in the request field).
30
  == Installation ==
31
 
32
  = If you downloaded this plugin: =
33
  * Upload `quick_page_post_redirect` folder to the `/wp-content/plugins/` directory
34
  * Activate the plugin through the 'Plugins' menu in WordPress
35
  * Once Activated, you can add a redirect by entering the correct information in the `Quick Page/Post Redirect` box in the edit section of a page or post
36
+ * Additionally, with 1.8, you can create a redirect with the 'Redirects' option located in the Admin Settings menu.
37
 
38
  = If you install this plugin through WordPress 2.8+ plugin search interface: =
39
  * Click Install `Quick Page/Post Redirect Plugin`
40
  * Activate the plugin through the 'Plugins' menu in WordPress
41
  * Once Activated, you can add a redirect by entering the correct information in the `Quick Page/Post Redirect` box in the edit section of a page or post
42
+ * Additionally, with 1.8, you can create a redirect with the 'Redirects' option located in the Admin Settings menu.
43
 
44
  == Frequently Asked Questions ==
45
+ = Do I need to have a Page or Post Created to redirect? =
46
+ Not any more! With 1.8, a new feature was added that allows you to create a redirect for any URL on your site. This is VERY helpful when you move an old site to WordPress and have old links that need to go some place new. For example,
47
+ If you had a link on a site that went to http://yoursite.com/aboutme.html you can now redirect that to http://yoursite.com/about/ without needing to edit the htaccess file. You simply add the old URL (/aboutme.html) and tell it you want to go to the new one (/about/). Simple as that.
48
+
49
+ The new fuctionality is located in the Admin under Settings/Quick Redirects. The olde URL goes in the Request field and the to new URL goes in the Destination field. Simple and Quick!
50
+
51
+ = I have Business Cards/Postcards/Ads that say my website is http://something.com/my-name/ or http://something.com/my-product/, can I set that up with this? =
52
+ YES! Just set up a redirect (see above) and set the Request field to /my-name/ or /my-product/ and the Destination field to the place you want it to go. The destination doesn't even need to be on the same site - it can go anywhere you want it to go!
53
 
54
  = Why is my Page/Post not redirecting? =
55
  If your page or post is not redirecting, this is most likely because something else like the theme functions file or another plugin is outputting the header BEFORE the plugin can perform the redirect. This can be tested by turning off all plugins except the Quick Page/Post Redirect Plugin and testing if the redirect works. 9 out of 10 times, a plugin or bad code is the culprit.
60
  YES... and NO... The redirect will always work on a Published Post/Page. For it to work correctly on a Post/Page in DRAFT status, you need to fist publish the page, then re-save it as a draft. If you don't follow that step, you will get a 404 error.
61
 
62
  = Can I do a permanent 301 Redirect? =
 
63
  Yes. You can perform a 301 Permanent Redirect. Additionally, you can select a 302 Temporary or a 307 Temporary redirect or a Meta redirect.
64
 
65
  = What the heck is a 301 or 302 redirect anyway? =
 
66
  Good question! THe number corresponds with the header code that is returned to the browser when the page is first accessed. A good page, meaning something was found, returns a 200 status code and that tells the browser to go ahead and keep loading the content for the page. If nothing is found a 404 error is returned (and we have ALL seen these - usually it is a bad link or a page was moved). There are many other types of codes, but those ore the most common.
67
 
68
  The 300+ range of codes in the header, tells the browser (and search engine spider) that the original page has moved to a new location - this can be just a new file name a new folder or a completely different site.
72
  A 302 or 307 code tell the browser that the file was there but TEMPORARILY it can be found at a new location. This will tell the search engines to KEEP the old link in place becasue SOME day it will be back at the same old link. There is only a slight difference between a 302 and a 307 status. Truth is, 302 is more widely used, so unless you know why you need a 307, stick with a 302.
73
 
74
  = So, which one do I use? =
 
75
  Easiest way to decide is this: If you want the page to permanetnly change to a new spot, use 301. If you are editing the page or post and only want it to be down for a few hours, minutes, days or weeks and plan on putting it back with the same link as before, then us 302. If you want to hide the reponse code from the spiders, use the `no code` option, and if you are having trouble with the redirects, use a `meta` redirect. The meta redirect actuall starts to load the page as a 200 good status, then redirects using a meta redirect tag.
76
 
77
  Still not sure? Try 302 for now - at least until you have a little time to read up on the subject.
78
 
79
  = Should I use a full URL with http:// or https:// ? =
 
80
  Yes, you can, but you do not always need to. If you are redirecting to an external URL, then yes. If you are just redirecting to another page or post on your site, then no, it is not needed. When in doubt, use the entire URL.
81
 
82
 
83
  == Screenshots ==
84
 
85
  1. Sample admin Post/Page edit box screenshot.
86
+ 2. New Quick 301 Redirects Page.
87
+ 3. Menu for the Quick 301 Redirects page - located in the settings menu.
88
 
89
  == Changelog ==
90
+ = 1.8 =
91
+ * Added a new Quick 301 Redirects Page to allow adding of additional redirects that do not have Pages or Posts created for them. Based on Scott Nelle's Simple 301 Redirects plugin.(12/28/2009)
92
  = 1.7 =
93
  * fix to correct meta redirect - moved "exit" commant to "addtoheader_theme" function. Also fixed the problem woth some pages not redirecting. Made the plugin WordPress MU compatible. (9/8/2009)
94
  = 1.6.1 =
screenshot-2.jpg ADDED
Binary file
screenshot-3.jpg ADDED
Binary file