diff options
Diffstat (limited to 'plugins/jetpack/modules/theme-tools/random-redirect.php')
-rw-r--r-- | plugins/jetpack/modules/theme-tools/random-redirect.php | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/plugins/jetpack/modules/theme-tools/random-redirect.php b/plugins/jetpack/modules/theme-tools/random-redirect.php index 78c8f349..d866d336 100644 --- a/plugins/jetpack/modules/theme-tools/random-redirect.php +++ b/plugins/jetpack/modules/theme-tools/random-redirect.php @@ -12,8 +12,10 @@ function jetpack_matt_random_redirect() { // Verify that the Random Redirect plugin this code is from is not active // See http://plugins.trac.wordpress.org/ticket/1898 if ( ! ( defined( 'IS_WPCOM' ) && IS_WPCOM ) ) { - require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); - if ( is_plugin_active( 'random-redirect/random-redirect.php' ) ) return; + require_once ABSPATH . 'wp-admin/includes/plugin.php'; + if ( is_plugin_active( 'random-redirect/random-redirect.php' ) ) { + return; + } } // Set default post type. @@ -29,31 +31,36 @@ function jetpack_matt_random_redirect() { // Set author name if we're on an author archive. if ( is_author() ) { - $random_author_name = get_the_author_meta( 'user_login' ); + $random_author_name = get_the_author_meta( 'user_login' ); $random_author_query = 'AND user_login = "' . $random_author_name . '"'; } else { $random_author_query = ''; } // Acceptable URL formats: /[...]/?random=[post type], /?random, /&random, /&random=1 - if ( ! isset( $_GET['random'] ) && ! in_array( strtolower( $_SERVER['REQUEST_URI'] ), array( '/&random', '/&random=1' ) ) ) + if ( ! isset( $_GET['random'] ) && ! in_array( strtolower( $_SERVER['REQUEST_URI'] ), array( '/&random', '/&random=1' ) ) ) { return; + } // Ignore POST requests. - if ( ! empty( $_POST ) ) + if ( ! empty( $_POST ) ) { return; + } // Persistent AppEngine abuse. ORDER BY RAND is expensive. - if ( strstr( $_SERVER['HTTP_USER_AGENT'], 'AppEngine-Google' ) ) + if ( strstr( $_SERVER['HTTP_USER_AGENT'], 'AppEngine-Google' ) ) { wp_die( 'Please <a href="http://en.support.wordpress.com/contact/" rel="noopener noreferrer" target="_blank">contact support</a>' ); + } // Set the category ID if the parameter is set. - if ( isset( $_GET['random_cat_id'] ) ) + if ( isset( $_GET['random_cat_id'] ) ) { $random_cat_id = (int) $_GET['random_cat_id']; + } // Change the post type if the parameter is set. - if ( isset( $_GET['random_post_type'] ) && post_type_exists( $_GET['random_post_type'] ) ) + if ( isset( $_GET['random_post_type'] ) && post_type_exists( $_GET['random_post_type'] ) ) { $post_type = $_GET['random_post_type']; + } // Don't show a random page if 'page' isn't specified as the post type specifically. if ( 'page' === $post_type && is_front_page() && ! isset( $_GET['random_post_type'] ) ) { |