Permalink
Browse files

A new method for getting a set of redirects, optionally limited by so…

…me criteria
  • Loading branch information...
1 parent 6ac98b8 commit adcfe944d6adb174ca03396bac290c5c65506cd6 @danielbachhuber danielbachhuber committed Dec 10, 2012
Showing with 40 additions and 0 deletions.
  1. +40 −0 safe-redirect-manager.php
View
@@ -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
*

0 comments on commit adcfe94

Please sign in to comment.