# redirection/2.6.3/actions/random.php

Redirection, version 2.6.3. 33 lines.

- Page: https://pluginprobe.com/plugins/redirection/2.6.3/code/actions/random.php
- Raw: https://pluginprobe.com/plugins/redirection/2.6.3/raw/actions/random.php
- Modified: 2017-05-31T05:34:34+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/redirection/2.6.3/code/actions/random.php#L10-L20`.

```php
<?php

class Random_Action extends Red_Action {
	function can_change_code() {
		return true;
	}

	function can_perform_action() {
		return false;
	}

	function action_codes() {
		return array(
			301 => get_status_header_desc( 301 ),
			302 => get_status_header_desc( 302 ),
			307 => get_status_header_desc( 307 ),
            308 => get_status_header_desc( 308 ),
		);
	}

	function process_before( $code, $target ) {
		// Pick a random WordPress page
		global $wpdb;

		$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" );

		$target = str_replace( get_bloginfo( 'url' ), '', get_permalink( $id ) );

		wp_redirect( $target, $code );
		exit();
	}
}

```
