Skip to content

Commit

Permalink
Merge branch 'master' of github.com:tlovett1/Safe-Redirect-Manager
Browse files Browse the repository at this point in the history
  • Loading branch information
tlovett1 committed Aug 11, 2015
2 parents b76cb56 + 8541d6f commit 684ff67
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 19 deletions.
13 changes: 13 additions & 0 deletions Dockunit.json
@@ -0,0 +1,13 @@
{
"containers": [
{
"prettyName": "PHP-FPM 5.5",
"image": "tlovett1/php-fpm-phpunit-wp",
"beforeScripts": [
"service mysql start",
"bash bin/install-wp-tests.sh wordpress_test root '' localhost 4.1"
],
"testCommand": "phpunit"
}
]
}
29 changes: 18 additions & 11 deletions README.md
Expand Up @@ -31,20 +31,19 @@ Each redirect contains a few fields that you can utilize:

#### "Redirect From"
This should be a path relative to the root of your WordPress installation. When someone visits your site with a path
that matches this one, a redirect will occur. If your site is located at ```http://example.com/wp/``` and you wanted to
redirect ```http://example.com/wp/about``` to ```http://example.com```, your "Redirect From" would be ```/about```.
that matches this one, a redirect will occur. If your site is located at ```http://example.com/wp/``` and you wanted to redirect `http://example.com/wp/about` to `http://example.com`, your "Redirect From" would be `/about`.

Clicking the "Enable Regex" checkbox allows you to use regular expressions in your path. There are many
[great tutorials](http://www.regular-expressions.info) on regular expressions.

You can also use wildcards in your "Redirect From" paths. By adding an ```*``` at the end of a URL, your redirect will
You can also use wildcards in your "Redirect From" paths. By adding an `*` at the end of a URL, your redirect will
match any request that starts with your "Redirect From". Wildcards support replacements. This means if you have a
wildcard in your from path that matches a string, you can have that string replace a wildcard character in your
"Redirect To" path. For example, if your "Redirect From" is ```/test/*```, your "Redirect To" is
```http://google.com/*```, and the requested path is ```/test/string```, the user would be redirect to ```http://google.com/string```.
"Redirect To" path. For example, if your "Redirect From" is `/test/*`, your "Redirect To" is
`http://google.com/*`, and the requested path is `/test/string`, the user would be redirect to `http://google.com/string`.

#### "Redirect To"
This should be a path i.e. ```/test``` or a URL i.e. ```http://example.com/wp/test```. If a requested path matches
This should be a path i.e. `/test` or a URL i.e. `http://example.com/wp/test`. If a requested path matches
"Redirect From", they will be redirected here. "Redirect To" supports wildcard and regular expression replacements.

#### "HTTP Status Code"
Expand All @@ -57,9 +56,17 @@ temporarily moved, or 301, permanently moved.
* Redirects are cached using the Transients API. Cache busts occur when redirects are added, updated, and deleted
so you shouldn't be serving stale redirects.
* By default the plugin only allows at most 150 redirects to prevent performance issues. There is a filter
```srm_max_redirects``` that you can utilize to up this number.
`srm_max_redirects` that you can utilize to up this number.
* "Redirect From" and requested paths are case insensitive by default.

## Redirect loops

By default redirect loop detection is disabled. To prevent redirect loops you can filter `srm_check_for_possible_redirect_loops`.

```php
add_filter( 'my_srm_redirect_loop_filter', '__return_true' );
```

## Development

#### Setup
Expand All @@ -76,12 +83,12 @@ Within the terminal change directories to the plugin folder. Initialize your uni
following command:

For VVV users:
```
```bash
bash bin/install-wp-tests.sh wordpress_test root root localhost latest
```

For VIP Quickstart users:
```
```bash
bash bin/install-wp-tests.sh wordpress_test root '' localhost latest
```

Expand All @@ -94,10 +101,10 @@ where:
* latest is the WordPress version; could also be 3.7, 3.6.2 etc.

Run the plugin tests:
```
```bash
phpunit
```

#### Issues
If you identify any errors or have an idea for improving the plugin, please
[open an issue](https://github.com/tlovett1/safe-redirect-manager/issues?state=open).
[open an issue](https://github.com/tlovett1/safe-redirect-manager/issues?state=open).
10 changes: 5 additions & 5 deletions bin/install-wp-tests.sh
Expand Up @@ -19,16 +19,16 @@ set -ex
install_wp() {
mkdir -p $WP_CORE_DIR

if [ $WP_VERSION == 'latest' ]; then
if [ $WP_VERSION == 'latest' ]; then
local ARCHIVE_NAME='latest'
else
local ARCHIVE_NAME="wordpress-$WP_VERSION"
fi

wget -nv -O /tmp/wordpress.tar.gz http://wordpress.org/${ARCHIVE_NAME}.tar.gz
wget -nv -O /tmp/wordpress.tar.gz https://wordpress.org/${ARCHIVE_NAME}.tar.gz --no-check-certificate
tar --strip-components=1 -zxmf /tmp/wordpress.tar.gz -C $WP_CORE_DIR

wget -nv -O $WP_CORE_DIR/wp-content/db.php https://raw.github.com/markoheijnen/wp-mysqli/master/db.php
wget -nv -O $WP_CORE_DIR/wp-content/db.php https://raw.github.com/markoheijnen/wp-mysqli/master/db.php --no-check-certificate
}

install_test_suite() {
Expand All @@ -42,9 +42,9 @@ install_test_suite() {
# set up testing suite
mkdir -p $WP_TESTS_DIR
cd $WP_TESTS_DIR
svn co --quiet http://develop.svn.wordpress.org/trunk/tests/phpunit/includes/
svn co --quiet https://develop.svn.wordpress.org/trunk/tests/phpunit/includes/

wget -nv -O wp-tests-config.php http://develop.svn.wordpress.org/trunk/wp-tests-config-sample.php
wget -nv -O wp-tests-config.php https://develop.svn.wordpress.org/trunk/wp-tests-config-sample.php --no-check-certificate
sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR':" wp-tests-config.php
sed $ioption "s/youremptytestdbnamehere/$DB_NAME/" wp-tests-config.php
sed $ioption "s/yourusernamehere/$DB_USER/" wp-tests-config.php
Expand Down
11 changes: 11 additions & 0 deletions composer.json
@@ -0,0 +1,11 @@
{
"name": "tlovett1/safe-redirect-manager",
"type": "wordpress-plugin",
"description": "Easily and safely manage HTTP redirects.",
"authors": [
{
"name": "Taylor Lovett",
"email": "taylorl@10up.com"
}
]
}
7 changes: 6 additions & 1 deletion readme.txt
Expand Up @@ -3,7 +3,7 @@ Contributors: tlovett1, tollmanz, taylorde, 10up, jakemgold, danielbachhuber, Ve
Tags: http redirects, redirect manager, url redirection, safe http redirection, multisite redirects
Requires at least: 3.1
Tested up to: 4.2
Stable tag: 1.7.6
Stable tag: 1.7.7

Safely and easily manage your website's HTTP redirects.

Expand All @@ -24,6 +24,11 @@ Extract the zip file and just drop the contents in the wp-content/plugins/ direc

== Changelog ==

= 1.7.7 (Jun. 18, 2015) =
* Make default redirect status filterable
* Add composer.json
* Fix delete capability on redirect post type

= 1.7.6 (Feb. 13, 2015) =
* Use home_url() instead of site_url(). Props [swalkinshaw](https://github.com/swalkinshaw)
* Don't redirect if redirect to location is invalid. Props [vaurdan](https://github.com/vaurdan)
Expand Down
5 changes: 3 additions & 2 deletions safe-redirect-manager.php
Expand Up @@ -4,7 +4,7 @@
Plugin URI: http://www.10up.com
Description: Easily and safely manage HTTP redirects.
Author: Taylor Lovett (10up)
Version: 1.7.6
Version: 1.7.7
Author URI: http://www.10up.com
GNU General Public License, Free Software Foundation <http://creativecommons.org/licenses/GPL/2.0/>
Expand Down Expand Up @@ -583,6 +583,7 @@ public function action_register_post_types() {
'edit_post' => $redirect_capability,
'read_post' => $redirect_capability,
'delete_post' => $redirect_capability,
'delete_posts' => $redirect_capability,
'edit_posts' => $redirect_capability,
'edit_others_posts' => $redirect_capability,
'publish_posts' => $redirect_capability,
Expand Down Expand Up @@ -635,7 +636,7 @@ public function redirect_rule_metabox( $post ) {
$status_code = get_post_meta( $post->ID, $this->meta_key_redirect_status_code, true );
$enable_regex = get_post_meta( $post->ID, $this->meta_key_enable_redirect_from_regex, true );
if ( empty( $status_code ) )
$status_code = 302;
$status_code = apply_filters( 'srm_default_direct_status', 302 );
?>
<p>
<label for="srm<?php echo $this->meta_key_redirect_from; ?>"><?php _e( 'Redirect From:', 'safe-redirect-manager' ); ?></label><br />
Expand Down

0 comments on commit 684ff67

Please sign in to comment.