diff --git a/Dockunit.json b/Dockunit.json new file mode 100644 index 000000000..155a1818f --- /dev/null +++ b/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" + } + ] +} \ No newline at end of file diff --git a/README.md b/README.md index 7af67e641..9e7d2464c 100644 --- a/README.md +++ b/README.md @@ -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" @@ -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 @@ -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 ``` @@ -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). \ No newline at end of file +[open an issue](https://github.com/tlovett1/safe-redirect-manager/issues?state=open). diff --git a/bin/install-wp-tests.sh b/bin/install-wp-tests.sh index 2e924248b..0bbeececf 100644 --- a/bin/install-wp-tests.sh +++ b/bin/install-wp-tests.sh @@ -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() { @@ -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 diff --git a/composer.json b/composer.json new file mode 100644 index 000000000..264f237d6 --- /dev/null +++ b/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" + } + ] +} diff --git a/readme.txt b/readme.txt index 04e458a4a..1b2071dc0 100644 --- a/readme.txt +++ b/readme.txt @@ -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. @@ -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) diff --git a/safe-redirect-manager.php b/safe-redirect-manager.php index aece68f9e..15b899a0c 100644 --- a/safe-redirect-manager.php +++ b/safe-redirect-manager.php @@ -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 @@ -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, @@ -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 ); ?>