Permalink
Browse files

Merge branch 'master' of https://github.com/tlovett1/Safe-Redirect-Ma…

…nager

Conflicts:
	safe-redirect-manager.php
  • Loading branch information...
2 parents cba5a71 + 5c455fe commit bb1164b9129ee33d1fa6ee5937d181d7414cdef2 Simon Wheatley committed Apr 4, 2013
View
@@ -0,0 +1,180 @@
+<?php
+/**
+ * wp-cli integration
+ */
+
+WP_CLI::add_command( 'safe-redirect-manager', 'Safe_Redirect_Manager_CLI' );
+
+class Safe_Redirect_Manager_CLI extends WP_CLI_Command {
+
+
+ /**
+ * List all of the currently configured redirects
+ *
+ * @subcommand list
+ */
+ public function _list() {
+ global $safe_redirect_manager;
+
+ $fields = array(
+ 'ID',
+ 'redirect_from',
+ 'redirect_to',
+ 'status_code',
+ 'enable_regex',
+ 'post_status',
+ );
+
+ $table = new \cli\Table();
+ $table->setHeaders( $fields );
+
+ $redirects = $safe_redirect_manager->get_redirects( array( 'post_status' => 'any' ) );
+ foreach( $redirects as $redirect ) {
+ $line = array();
+ foreach( $fields as $field ) {
+ if ( 'enable_regex' == $field )
+ $line[] = ( $redirect[$field] ) ? 'true' : 'false';
+ else
+ $line[] = $redirect[$field];
+ }
+ $table->addRow( $line );
+ }
+ $table->display();
+
+ WP_CLI::line( "Total of " . count( $redirects ) . " redirects" );
+ }
+
+ /**
+ * Create a redirect
+ *
+ * @subcommand create
+ * @synopsis <from> <to> [<status-code>] [<enable-regex>] [<post-status>]
+ */
+ public function create( $args ) {
+ global $safe_redirect_manager;
+
+ $defaults = array(
+ '',
+ '',
+ 302,
+ false,
+ 'publish',
+ );
+ // array_merge() doesn't work here because our keys are numeric
+ foreach( $defaults as $key => $value ) {
+ if ( ! isset( $args[$key] ) )
+ $args[$key] = $defaults[$key];
+ }
+ list( $from, $to, $status_code, $enable_regex, $post_status ) = $args;
+
+ // User might've passed as string.
+ if ( 'false' == $enable_regex )
+ $enable_regex = false;
+
+ if ( empty( $from ) || empty( $to ) )
+ WP_CLI::error( "<from> and <to> are required arguments." );
+
+ $ret = $safe_redirect_manager->create_redirect( $from, $to, $status_code, $enable_regex, $post_status );
+ if ( is_wp_error( $ret ) )
+ WP_CLI::error( $ret->get_error_message() );
+ else
+ WP_CLI::success( "Created redirect as #{$ret}" );
+ }
+
+ /**
+ * Delete a redirect
+ *
+ * @subcommand delete
+ * @synopsis <id>
+ */
+ public function delete( $args ) {
+ global $safe_redirect_manager;
+
+ $id = ( ! empty( $args[0] ) ) ? (int)$args[0] : 0;
+
+ $redirect = get_post( $id );
+ if ( ! $redirect || $safe_redirect_manager->redirect_post_type != $redirect->post_type )
+ WP_CLI::error( "{$id} isn't a valid redirect." );
+
+ wp_delete_post( $id );
+ $safe_redirect_manager->update_redirect_cache();
+ WP_CLI::success( "Redirect #{$id} has been deleted." );
+ }
+
+ /**
+ * Update the redirect cache
+ *
+ * @subcommand update-cache
+ */
+ public function update_cache() {
+ global $safe_redirect_manager;
+
+ $safe_redirect_manager->update_redirect_cache();
+ WP_CLI::success( "Redirect cache has been updated." );
+ }
+
+ /**
+ * Import .htaccess file redirects
+ *
+ * @subcommand import-htaccess
+ * @synopsis <file>
+ */
+ public function import_htaccess( $args, $assoc_args ) {
+ global $safe_redirect_manager;
+
+ list( $file ) = $args;
+
+ $contents = file_get_contents( $file );
+ if ( ! $contents )
+ WP_CLI::error( "Error retrieving .htaccess file" );
+
+ $pieces = explode( PHP_EOL, $contents );
+ $created = 0;
+ $skipped = 0;
+ foreach( $pieces as $piece ) {
+
+ // Ignore if this line isn't a redirect
+ if ( ! preg_match( '/^Redirect( permanent)?/i', $piece ) )
+ continue;
+
+ // Parse the redirect
+ $redirect = preg_replace( '/\s{2,}/', ' ', $piece );
+ $redirect = preg_replace( '/^Redirect( permanent)? (.*)$/i', '$2', trim( $redirect ) );
+ $redirect = explode( ' ', $redirect );
+
+ // if there are three parts to the redirect, we assume the first part is a status code
+ if ( 2 == count( $redirect ) ) {
+ $from = $redirect[0];
+ $to = $redirect[1];
+ $http_status = 301;
+ } elseif ( 3 == count( $redirect ) ) {
+ $http_status = $redirect[0];
+ $from = $redirect[1];
+ $to = $redirect[2];
+ } else {
+ continue;
+ }
+
+ // Validate
+ if ( ! $from || ! $to ) {
+ WP_CLI::warning( "Skipping - '{$piece}' is formatted improperly." );
+ continue;
+ }
+
+ $sanitized_redirect_from = $safe_redirect_manager->sanitize_redirect_from( $from );
+ $sanitized_redirect_to = $safe_redirect_manager->sanitize_redirect_to( $to );
+
+ $id = $safe_redirect_manager->create_redirect( $sanitized_redirect_from, $sanitized_redirect_to, $http_status );
+ if ( is_wp_error( $id ) ) {
+ WP_CLI::warning( "Error - " . $id->get_error_message() );
+ $skipped++;
+ } else {
+ WP_CLI::line( "Success - Created redirect from '{$sanitized_redirect_from}' to '{$sanitized_redirect_to}'" );
+ $created++;
+ }
+ }
+ WP_CLI::success( "All done! {$created} redirects were created, {$skipped} were skipped" );
+ }
+
+
+}
Binary file not shown.
@@ -0,0 +1,142 @@
+msgid ""
+msgstr ""
+"Project-Id-Version: \n"
+"POT-Creation-Date: \n"
+"PO-Revision-Date: \n"
+"Last-Translator: \n"
+"Language-Team: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=iso-8859-1\n"
+"Content-Transfer-Encoding: 8bit\n"
+"X-Generator: Poedit 1.5.4\n"
+
+#: safe-redirect-manager.php:367 safe-redirect-manager.php:370
+msgid "Redirect rule updated."
+msgstr "Presmerovat pravidlo aktualizovany."
+
+#: safe-redirect-manager.php:368
+msgid "Custom field updated."
+msgstr "Vlastne aktualizacie pola."
+
+#: safe-redirect-manager.php:369
+msgid "Custom field deleted."
+msgstr "Vlastne vypustaju pola."
+
+#. translators: %s: date and time of the revision
+#: safe-redirect-manager.php:372
+msgid "Redirect rule restored to revision from %s"
+msgstr "Presmerovat pravidlo obnovena reviziu z %s"
+
+#: safe-redirect-manager.php:373
+msgid "Redirect rule published."
+msgstr "Presmerovat pravidlo zverejneny."
+
+#: safe-redirect-manager.php:374
+msgid "Redirect rule saved."
+msgstr "Presmerovat pravidlo ulozeny."
+
+#: safe-redirect-manager.php:375
+msgid "Redirect rule submitted."
+msgstr "Presmerovat pravidlo predlozene."
+
+#: safe-redirect-manager.php:376
+msgid "Redirect rule scheduled for: <strong>%1$s</strong>."
+msgstr "Presmerovat pravidlo naplanovany:. <strong>%1$s</strong>."
+
+#. translators: Publish box date format, see http:php.net/date
+#: safe-redirect-manager.php:378
+msgid "M j, Y @ G:i"
+msgstr "M j, Y @ G: i"
+
+#: safe-redirect-manager.php:379
+msgid "Redirect rule draft updated."
+msgstr "Presmerovat pravidlo aktualizovany navrh."
+
+#: safe-redirect-manager.php:431
+msgid "Redirect To"
+msgstr "Presmerovat na"
+
+#: safe-redirect-manager.php:432
+msgid "HTTP Status Code"
+msgstr "HTTP Status Code"
+
+#: safe-redirect-manager.php:435
+msgid "Redirect From"
+msgstr "Presmerovanie od"
+
+#: safe-redirect-manager.php:439
+msgid "Date"
+msgstr "Datum"
+
+#: safe-redirect-manager.php:491
+msgctxt "post type general name"
+msgid "Safe Redirect Manager"
+msgstr "Safe Redirect Manager"
+
+#: safe-redirect-manager.php:492
+msgctxt "post type singular name"
+msgid "Redirect"
+msgstr "Presmerovanie"
+
+#. #-#-#-#-# plugin.pot (Safe Redirect Manager 1.4-working) #-#-#-#-#
+#. Plugin Name of the plugin/theme
+#: safe-redirect-manager.php:494 safe-redirect-manager.php:497
+#: safe-redirect-manager.php:503
+msgid "Safe Redirect Manager"
+msgstr "Safe Redirect Manager"
+
+#: safe-redirect-manager.php:495
+msgid "Edit Redirect Rule"
+msgstr "Upravit presmerovanie pravidlo"
+
+#: safe-redirect-manager.php:496
+msgid "New Redirect Rule"
+msgstr "Nova Presmerovanie pravidlo"
+
+#: safe-redirect-manager.php:498
+msgid "View Redirect Rule"
+msgstr "Zobrazit Presmerovanie pravidlo"
+
+#: safe-redirect-manager.php:499
+msgid "Search Redirects"
+msgstr "Hladat Presmerovanie"
+
+#: safe-redirect-manager.php:500
+msgid "No redirect rules found."
+msgstr "Ziadne presmerovanie najdene pravidla."
+
+#: safe-redirect-manager.php:501
+msgid "No redirect rules found in trash."
+msgstr "Ziadne presmerovanie pravidla najdene v smetiaku."
+
+#: safe-redirect-manager.php:544
+msgid "Redirect Settings"
+msgstr "Presmerovanie Nastavenie"
+
+#: safe-redirect-manager.php:565
+msgid "Redirect From:"
+msgstr "Presmerovat From:"
+
+#: safe-redirect-manager.php:571
+msgid "Redirect To:"
+msgstr "Presmerovat na:"
+
+#: safe-redirect-manager.php:577
+msgid "HTTP Status Code:"
+msgstr "HTTP Status Code:"
+
+#. #-#-#-#-# plugin.pot (Safe Redirect Manager 1.4-working) #-#-#-#-#
+#. Plugin URI of the plugin/theme
+#. #-#-#-#-# plugin.pot (Safe Redirect Manager 1.4-working) #-#-#-#-#
+#. Author URI of the plugin/theme
+#: safe-redirect-manager.php:583
+msgid "http://www.10up.com"
+msgstr "http://www.10up.com"
+
+#. Description of the plugin/theme
+msgid "Easily and safely manage HTTP redirects."
+msgstr "Lahko a bezpecne spravovat presmerovanie HTTP."
+
+#. Author of the plugin/theme
+msgid "Taylor Lovett (10up LLC), VentureBeat"
+msgstr "Taylor Lovett (10up LLC), VentureBeat"
View
@@ -2,8 +2,8 @@
Contributors: tlovett1, tollmanz, taylorde, 10up, jakemgold, danielbachhuber, VentureBeat
Tags: http redirects, redirect manager, url redirection, safe http redirection
Requires at least: 3.1
-Tested up to: 3.4.2
-Stable tag: 1.5
+Tested up to: 3.5
+Stable tag: 1.6
Safely and easily manage your website's HTTP redirects.
@@ -24,6 +24,10 @@ Extract the zip file and just drop the contents in the wp-content/plugins/ direc
== Changelog ==
+= 1.6 (Dec. 11, 2012) =
+* Bulk delete redirects from the Manage Redirects screen
+* wp-cli coverage including subcommands for creating, deleting, and listing redirects, and importing .htaccess files
+
= 1.5 (Nov. 7 2012) =
* Regular expressions allowed in redirects
* New filter 'srm_registered_redirects' allows you to conditionally unset redirects based on context, user permissions, etc. Thanks [jtsternberg](https://github.com/jtsternberg) for the pull request.
Oops, something went wrong.

0 comments on commit bb1164b

Please sign in to comment.