| 1 |
<?php |
| 2 |
|
| 3 |
class Random_Action extends Red_Action { |
| 4 |
function can_change_code() { |
| 5 |
return true; |
| 6 |
} |
| 7 |
|
| 8 |
function can_perform_action() { |
| 9 |
return false; |
| 10 |
} |
| 11 |
|
| 12 |
function action_codes() { |
| 13 |
return array( |
| 14 |
301 => get_status_header_desc( 301 ), |
| 15 |
302 => get_status_header_desc( 302 ), |
| 16 |
307 => get_status_header_desc( 307 ), |
| 17 |
308 => get_status_header_desc( 308 ), |
| 18 |
); |
| 19 |
} |
| 20 |
|
| 21 |
function process_before( $code, $target ) { |
| 22 |
// Pick a random WordPress page |
| 23 |
global $wpdb; |
| 24 |
|
| 25 |
$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" ); |
| 26 |
|
| 27 |
$target = str_replace( get_bloginfo( 'url' ), '', get_permalink( $id ) ); |
| 28 |
|
| 29 |
wp_redirect( $target, $code ); |
| 30 |
exit(); |
| 31 |
} |
| 32 |
} |
| 33 |
|