Simple 301 Redirects – Addon – Bulk Uploader - Version 1.0

Version Description

  • Initial

=

Download this release

Release Info

Developer ashdurham
Plugin Icon 128x128 Simple 301 Redirects – Addon – Bulk Uploader
Version 1.0
Comparing to
See all releases

Version 1.0

Files changed (3) hide show
  1. 301-example.csv +1 -0
  2. readme.txt +77 -0
  3. simple-301-bulk-uploader.php +153 -0
301-example.csv ADDED
@@ -0,0 +1 @@
 
1
+ "/EXAMPLE-old-url/","/EXAMPLE-new-url/"
readme.txt ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Simple 301 Redirects - Addon - Bulk Uploader ===
2
+ Contributors: ashdurham
3
+ Donate link: http://durham.net.au/donate/
4
+ Tags: simple 301 redirects, bulk upload, csv, 301, redirects
5
+ Requires at least: 3.0.1
6
+ Tested up to: 3.6.1
7
+ Stable tag: 1.0.1
8
+ License: GPLv2
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
+
11
+ Adds on the ability to bulk upload 301 redirects via CSV to the Simple 301 Redirects plugin
12
+
13
+ == Description ==
14
+
15
+ --
16
+
17
+ Stay up-to-date with the latest by following [@kingproplugins on Twitter](http://twitter.com/kingproplugins), [KingProPlugins on Facebook](http://facebook.com/kingproplugins) or [King Pro Plugins on Google+](https://plus.google.com/b/101488033905569308183/101488033905569308183/about)
18
+
19
+ --
20
+
21
+ This is an ADDON plugin to give further functionality to the plugin [Simple 301 Redirects](http://wordpress.org/plugins/simple-301-redirects/) plugin.
22
+
23
+ [Simple 301 Redirects - Addon - Bulk Uploader](http://kingpro.me/plugins/support-plugins/simple-301-redirects-addon-bulk-uploader/) adds an extra section to the settings tab
24
+ to upload a CSV of old and new URL's to input into the Simple 301 Redirects plugin. An example CSV is bundled in with the plugin to get you going quickly.
25
+
26
+ The plugin checks for duplicate old URLs and alerts you of these in the summary after your CSV has been processed.
27
+
28
+ --
29
+
30
+ If you have any suggestions or would like to see a feature in the plugin, please let me know in the support forum.
31
+
32
+ Any issues you are having, I'd also love to know, so again, please let me know using the support forum.
33
+
34
+ --
35
+
36
+ [Check out the King Pro Plugins range](http://kingpro.me/)
37
+
38
+
39
+ == Installation ==
40
+
41
+ 1. Download and unzip the zip file onto your computer
42
+ 2. Upload the 'simple-301-bulk-uploader' folder into the `/wp-content/plugins/` directory (alternatively, install the plugin from the plugin directory within the admin)
43
+ 3. Activate the plugin through the 'Plugins' menu in WordPress
44
+ 4. Drag the widget into your sidebar and modify the settings or insert the shortcode into a post or theme template.
45
+
46
+ --
47
+
48
+ Having Trouble? Get support either on the support forums here or at [@kingproplugins on Twitter](http://twitter.com/kingproplugins), [KingProPlugins on Facebook](http://facebook.com/kingproplugins) or [King Pro Plugins on Google+](https://plus.google.com/b/101488033905569308183/101488033905569308183/about)
49
+
50
+ --
51
+
52
+ == Frequently Asked Questions ==
53
+
54
+ = What is a CSV? =
55
+
56
+ A CSV is a Comma-Separated Values file, which put simply, is a spreadsheet saved in a particular format.
57
+
58
+ = What can I use to create a CSV? =
59
+
60
+ To easily create a CSV file, use a spreadsheet program like Excel or Open Office Spreadsheets. Simple 301 Redirects - Addon - Bulk Uploader is setup to handle a 2 column
61
+ CSV with the old URL in the first column and the new URL in the second column.
62
+
63
+ --
64
+
65
+ Have a question thats not listed? Get support either on the support forums here or at [@kingproplugins on Twitter](http://twitter.com/kingproplugins), [KingProPlugins on Facebook](http://facebook.com/kingproplugins) or [King Pro Plugins on Google+](https://plus.google.com/b/101488033905569308183/101488033905569308183/about)
66
+
67
+ --
68
+
69
+ == Changelog ==
70
+
71
+ = 1.0 =
72
+ * Initial
73
+
74
+ == Upgrade Notice ==
75
+
76
+ = 1.0 =
77
+ * Gotta start somewhere
simple-301-bulk-uploader.php ADDED
@@ -0,0 +1,153 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: Simple 301 Redirects - Addon - Bulk CSV Uploader
4
+ Plugin URI: http://kingpro.me/plugins/support-plugins/simple-301-redirects-addon-bulk-csv-uploader
5
+ Description: Adds the ability to upload a CSV to populate the Simple 301 Redirects plugin
6
+ Version: 1.0.0
7
+ Author: Ash Durham
8
+ Author URI: http://durham.net.au/
9
+ License: GPL2
10
+
11
+ Copyright 2013 Ash Durham (email : plugins@kingpro.me)
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, version 2, as
15
+ published by the Free Software Foundation.
16
+
17
+ This program is distributed in the hope that it will be useful,
18
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
+ GNU General Public License for more details.
21
+
22
+ You should have received a copy of the GNU General Public License
23
+ along with this program; if not, write to the Free Software
24
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
+ */
26
+
27
+ if (!class_exists("Bulk301Uploader")) {
28
+ class Bulk301Uploader {
29
+ /*
30
+ check if Simple 301 Redirects exists and is active
31
+ */
32
+ function check_for_parent()
33
+ {
34
+ include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
35
+ if (!is_plugin_active('simple-301-redirects/wp-simple-301-redirects.php')) {
36
+ add_action( 'admin_notices', array($this,'bulk301_admin_notice') );
37
+ return false;
38
+ }
39
+ return true;
40
+ }
41
+
42
+ function bulk301_admin_notice() {
43
+ ?>
44
+ <div class="error">
45
+ <p><?php _e( "301 Bulk Uploader requires the Simple 301 Redirects plugin to be installed and active in order to work.", 'bulk301_text' ); ?></p>
46
+ </div>
47
+ <?php
48
+ }
49
+
50
+ /*
51
+ generate the link to the options page under settings
52
+ */
53
+ function create_bulk_menu()
54
+ {
55
+ add_options_page('301 Bulk Redirects', '301 Bulk Redirects', 10, '301bulkoptions', array($this,'bulk_options_page'));
56
+ }
57
+
58
+ /*
59
+ generate the options page in the wordpress admin
60
+ */
61
+ function bulk_options_page()
62
+ {
63
+ global $report;
64
+ ?>
65
+ <div class="wrap">
66
+ <h2>Simple 301 Redirects - Bulk Upload</h2>
67
+
68
+ <a href="<?= plugins_url( '301-example.csv', __FILE__ ); ?>">Example CSV</a>
69
+
70
+ <form method="post" action="options-general.php?page=301bulkoptions" enctype="multipart/form-data">
71
+
72
+ <input type="file" name="301_bulk_redirects" />
73
+
74
+ <p class="submit">
75
+ <input type="submit" name="submit_bulk_301" class="button-primary" value="<?php _e('Upload 301s') ?>" />
76
+ </p>
77
+ </form>
78
+
79
+ <?php if (isset($report)) : echo $report; endif; ?>
80
+ </div>
81
+ <?php
82
+ } // end of function options_page
83
+
84
+ /*
85
+ save the redirects from the options page to the database
86
+ */
87
+ function save_bulk_redirects($data)
88
+ {
89
+ // Get Current Redirects
90
+ $current_redirects = get_option('301_redirects');
91
+
92
+ // Get CSV File
93
+ $allowedExts = array("csv");
94
+ $temp = explode(".", $data["name"]);
95
+ $extension = end($temp);
96
+ $report = '';
97
+
98
+ if (($data["type"] == "text/csv")
99
+ && ($data["size"] < 1000000)
100
+ && in_array($extension, $allowedExts))
101
+ {
102
+ if ($data["error"] > 0)
103
+ {
104
+ echo "Return Code: " . $data["error"] . "<br>";
105
+ }
106
+ else
107
+ {
108
+ $report .= "Upload: " . $data["name"] . "<br />";
109
+ $report .= "Size: " . ($data["size"] / 1024) . " kB<br /><br />";
110
+
111
+ $row = 1;
112
+
113
+ if (($handle = fopen($data["tmp_name"], "r")) !== FALSE) {
114
+ while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
115
+ $num = count($data);
116
+ $row++;
117
+ if (!isset($current_redirects[$data[0]]) && $data[1] !== '') {
118
+ $current_redirects[$data[0]] = $data[1];
119
+ $report .= "<strong>".$data[0]."</strong> was added to redirect to ".$data[1]."<br />";
120
+ } elseif (!isset($current_redirects[$data[0]]) && $data[1] !== '') {
121
+ $report .= "<span style='color: red'><strong>".$data[0]."</strong> is missing a corresponding URL to redirect to.</span><br />";
122
+ } else $report .= "<span style='color: red'><strong>".$data[0]."</strong> already exists and was not added.</span><br />";
123
+ }
124
+ fclose($handle);
125
+ update_option('301_redirects', $current_redirects);
126
+ }
127
+ }
128
+ }
129
+ else
130
+ {
131
+ $report .= "Invalid file";
132
+ }
133
+
134
+ return $report;
135
+ }
136
+ }
137
+ }
138
+
139
+ // instantiate
140
+ $bulk_redirect_plugin = new Bulk301Uploader();
141
+
142
+ if (isset($bulk_redirect_plugin) && $bulk_redirect_plugin->check_for_parent()) {
143
+
144
+ // create the menu
145
+ add_action('admin_menu', array($bulk_redirect_plugin,'create_bulk_menu'));
146
+
147
+ // if submitted, process the data
148
+ if (isset($_POST['submit_bulk_301'])) {
149
+ $report = $bulk_redirect_plugin->save_bulk_redirects($_FILES['301_bulk_redirects']);
150
+ }
151
+ }
152
+
153
+ ?>