Skip to content

Commit

Permalink
A new method for getting a set of redirects, optionally limited by so…
Browse files Browse the repository at this point in the history
…me criteria
  • Loading branch information
danielbachhuber committed Dec 10, 2012
1 parent 6ac98b8 commit adcfe94
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions safe-redirect-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,46 @@ public function filter_allowed_redirect_hosts( $content ) {
return $content;
}

/**
* Get redirects from the database
*
* @since 1.6
* @param array $args Any arguments to filter by
* @return array $redirects An array of redirects
*/
public function get_redirects( $args = array() ) {

$defaults = array(
'posts_per_page' => 1000,
'post_status' => 'publish',
);

$query_args = array_merge( $defaults, $args );

// Some arguments that don't need to be configurable
$query_args['post_type'] = $this->redirect_post_type;
$query_args['no_found_rows'] = false;
$query_args['update_term_cache'] = false;

$redirect_query = new WP_Query( $query_args );

if ( empty( $redirect_query->posts ) )
return array();

$redirects = array();
foreach( $redirect_query->posts as $redirect ) {
$redirects[] = array(
'ID' => $redirect->ID,
'post_status' => $redirect->post_status,
'redirect_from' => get_post_meta( $redirect->ID, $this->meta_key_redirect_from, true ),
'redirect_to' => get_post_meta( $redirect->ID, $this->meta_key_redirect_to, true ),
'status_code' => (int)get_post_meta( $redirect->ID, $this->meta_key_redirect_status_code, true ),
'enable_regex' => (bool)get_post_meta( $redirect->ID, $this->meta_key_enable_redirect_from_regex, true ),
);
}
return $redirects;
}

/**
* Force update on the redirect cache and return cache
*
Expand Down

0 comments on commit adcfe94

Please sign in to comment.