Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add wrapper method for wp_get_sites, added filter #104

Merged
merged 1 commit into from
Sep 10, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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