| 1 |
<?php |
| 2 |
/** |
| 3 |
* Redirection |
| 4 |
* |
| 5 |
* @package Redirection |
| 6 |
* @author John Godley |
| 7 |
* @copyright Copyright (C) John Godley |
| 8 |
**/ |
| 9 |
|
| 10 |
/* |
| 11 |
============================================================================================================ |
| 12 |
This software is provided "as is" and any express or implied warranties, including, but not limited to, the |
| 13 |
implied warranties of merchantibility and fitness for a particular purpose are disclaimed. In no event shall |
| 14 |
the copyright owner or contributors be liable for any direct, indirect, incidental, special, exemplary, or |
| 15 |
consequential damages (including, but not limited to, procurement of substitute goods or services; loss of |
| 16 |
use, data, or profits; or business interruption) however caused and on any theory of liability, whether in |
| 17 |
contract, strict liability, or tort (including negligence or otherwise) arising in any way out of the use of |
| 18 |
this software, even if advised of the possibility of such damage. |
| 19 |
|
| 20 |
For full license details see license.txt |
| 21 |
============================================================================================================ */ |
| 22 |
|
| 23 |
class Random_Action extends Red_Action |
| 24 |
{ |
| 25 |
function can_change_code () { return true; } |
| 26 |
function can_perform_action () { return false; } |
| 27 |
|
| 28 |
function action_codes () |
| 29 |
{ |
| 30 |
return array |
| 31 |
( |
| 32 |
301 => get_status_header_desc (301), |
| 33 |
302 => get_status_header_desc (302), |
| 34 |
307 => get_status_header_desc (307) |
| 35 |
); |
| 36 |
} |
| 37 |
|
| 38 |
function process_before ($code, $target) |
| 39 |
{ |
| 40 |
// Pick a random WordPress page |
| 41 |
global $wpdb; |
| 42 |
$id = $wpdb->get_var ("SELECT ID FROM {$wpdb->prefix}posts WHERE post_status='publish' AND post_password='' AND post_type='post' ORDER BY RAND() LIMIT 0,1"); |
| 43 |
|
| 44 |
$target = str_replace (get_bloginfo ('url'), '', get_permalink ($id)); |
| 45 |
|
| 46 |
wp_redirect ($target, $code); |
| 47 |
exit (); |
| 48 |
} |
| 49 |
} |
| 50 |
|