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

Additional steps for glueing toghether #7

Open
wants to merge 7 commits into
base: gluing-together
from

caputure current REST API request using rest_pre_serve_request filter

  • Loading branch information...
Shelob9 committed May 28, 2018
commit 1bfce073049db26486503bcd2f1e392e32be7f6e
@@ -21,6 +21,13 @@ class FilterWPQuery implements FiltersPreWPQuery
*/
protected static $contentGetter;
/**
* Current REST request
*
* @var \WP_REST_Request
*/
protected static $request;
/**
* Priority for filter
*
@@ -84,13 +91,15 @@ private static function doingREST(): bool
/** @inheritdoc */
public static function addFilter(): bool
{
add_filter( 'rest_pre_serve_request', [FilterWPQuery::class, 'captureRequest' ] );
return add_filter('posts_pre_query', [FilterWPQuery::class, 'filterPreQuery'], static::$filterPriority, 2);
}
/** @inheritdoc */
public static function removeFilter(): bool
{
return remove_filter('posts_pre_query', [FilterWPQuery::class, 'filterPreQuery'], static::$filterPriority);
remove_filter( 'rest_pre_serve_request', [FilterWPQuery::class, 'captureRequest' ] );
return remove_filter('posts_pre_query', [FilterWPQuery::class, 'filterPreQuery'], static::$filterPriority);
}
/** @inheritdoc */
@@ -99,9 +108,17 @@ public static function getFilterPriority(): int
return static::$filterPriority;
}
public static function captureRequest( $return, $result, $request )
{
static::$request = $request;
return $return;
}
/** @inheritdoc */
public static function getPosts(WP_Query $query): array
{
return static::$contentGetter->getContent($query);
$request = is_object( static::$request ) ? static::$request ? new \WP_REST_Request();
return static::$contentGetter->getContent($query,$request);
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.