Skip to content

Commit

Permalink
Merge pull request #104 from 10up/feature/ep-get-sites
Browse files Browse the repository at this point in the history
Add wrapper method for wp_get_sites, added filter
  • Loading branch information
tlovett1 committed Sep 10, 2014
2 parents 2f66f3e + a2111b1 commit 9bd1fb2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
8 changes: 4 additions & 4 deletions bin/wp-cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ElasticPress_CLI_Command extends WP_CLI_Command {
public function put_mapping( $args, $assoc_args ) {

if ( ! empty( $assoc_args['network-wide'] ) ) {
$sites = wp_get_sites();
$sites = ep_get_sites();

foreach ( $sites as $site ) {
switch_to_blog( $site['blog_id'] );
Expand Down Expand Up @@ -68,7 +68,7 @@ public function put_mapping( $args, $assoc_args ) {
*/
public function delete_index( $args, $assoc_args ) {
if ( ! empty( $assoc_args['network-wide'] ) ) {
$sites = wp_get_sites();
$sites = ep_get_sites();

foreach ( $sites as $site ) {
switch_to_blog( $site['blog_id'] );
Expand Down Expand Up @@ -127,7 +127,7 @@ public function recreate_network_alias( $args, $assoc_args ) {
* @return array|bool
*/
private function _create_network_alias() {
$sites = apply_filters( 'ep_indexable_sites', wp_get_sites() );
$sites = ep_get_sites();
$indexes = array();

foreach ( $sites as $site ) {
Expand All @@ -153,7 +153,7 @@ public function index( $args, $assoc_args ) {
if ( ! empty( $assoc_args['network-wide'] ) ) {
WP_CLI::line( __( 'Indexing posts network-wide...', 'elasticpress' ) );

$sites = wp_get_sites();
$sites = ep_get_sites();

foreach ( $sites as $site ) {
switch_to_blog( $site['blog_id'] );
Expand Down
13 changes: 13 additions & 0 deletions classes/class-ep-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,15 @@ public function format_args( $args ) {

return apply_filters( 'ep_formatted_args', $formatted_args );
}

/**
* Wrapper function for wp_get_sites - allows us to have one central place for the `ep_indexable_sites` filter
*
* @return mixed|void
*/
public function get_sites() {
return apply_filters( 'ep_indexable_sites', wp_get_sites() );
}
}

EP_API::factory();
Expand Down Expand Up @@ -754,4 +763,8 @@ function ep_delete_network_alias() {

function ep_refresh_index() {
return EP_API::factory()->refresh_index();
}

function ep_get_sites() {
return EP_API::factory()->get_sites();
}
14 changes: 7 additions & 7 deletions tests/test-multisite.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function setUp() {

$this->factory->blog->create_many( 1, array( 'user_id' => $admin_id ) );

$sites = wp_get_sites();
$sites = ep_get_sites();
$indexes = array();

foreach ( $sites as $site ) {
Expand Down Expand Up @@ -69,7 +69,7 @@ public function tearDown() {

$this->fired_actions = array();

$sites = wp_get_sites();
$sites = ep_get_sites();
$indexes = array();

foreach ( $sites as $site ) {
Expand All @@ -89,7 +89,7 @@ public function tearDown() {
* @since 0.9
*/
public function testPostSync() {
$sites = wp_get_sites();
$sites = ep_get_sites();

foreach( $sites as $site ) {
switch_to_blog( $site['blog_id'] );
Expand Down Expand Up @@ -119,7 +119,7 @@ public function testPostSync() {
* @since 0.9
*/
public function testWPQuerySearchContent() {
$sites = wp_get_sites();
$sites = ep_get_sites();

foreach ( $sites as $site ) {
switch_to_blog( $site['blog_id'] );
Expand Down Expand Up @@ -186,7 +186,7 @@ public function testWPQuerySearchContent() {
* @since 0.9
*/
public function testWPQuerySearchTitle() {
$sites = wp_get_sites();
$sites = ep_get_sites();

foreach ( $sites as $site ) {
switch_to_blog( $site['blog_id'] );
Expand Down Expand Up @@ -222,7 +222,7 @@ public function testWPQuerySearchTitle() {
* @since 0.9
*/
public function testWPQuerySearchExcerpt() {
$sites = wp_get_sites();
$sites = ep_get_sites();

$i = 0;

Expand Down Expand Up @@ -265,7 +265,7 @@ public function testWPQuerySearchExcerpt() {
* @since 0.9
*/
public function testPagination() {
$sites = wp_get_sites();
$sites = ep_get_sites();

foreach ( $sites as $site ) {
switch_to_blog( $site['blog_id'] );
Expand Down

0 comments on commit 9bd1fb2

Please sign in to comment.