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

Allow developers to short circuit potentially expensive is_private ch… #972

Merged
4 changes: 2 additions & 2 deletions CHANGELOG.md
@@ -1,10 +1,10 @@
# Changelog

## Upcoming
## 1.1.2

### Bugfixes

- Add a `nav_menu_item` loader to allow previous menu item IDs to work properly with WPGraphQL should they be passed to a node query (like, if the ID were persisted somewhere already)
- ([#1676](https://github.com/wp-graphql/wp-graphql/pull/1676)) Add a `nav_menu_item` loader to allow previous menu item IDs to work properly with WPGraphQL should they be passed to a node query (like, if the ID were persisted somewhere already)
- Update cases of menu item IDs to be `post:$id` instead of `nav_menu_item:$id`
- Update tests to test that both the old `nav_menu_item:$id` and `post:$id` work for nav menu item node queries to support previously issued IDs

Expand Down
2 changes: 1 addition & 1 deletion readme.txt
Expand Up @@ -4,7 +4,7 @@ Tags: GraphQL, API, Gatsby, Headless, Decoupled, React, Nextjs, Vue, Apollo, RES
Requires at least: 5.0
Tested up to: 5.6
Requires PHP: 7.1
Stable tag: 1.1.1
Stable tag: 1.1.2
License: GPL-3
License URI: https://www.gnu.org/licenses/gpl-3.0.html

Expand Down
25 changes: 24 additions & 1 deletion src/Model/Model.php
Expand Up @@ -222,9 +222,32 @@ public function get_visibility() {
*/
$protected_cap = apply_filters( 'graphql_restricted_data_cap', $this->restricted_cap, $this->get_model_name(), $this->data, $this->visibility, $this->owner, $this->current_user );

/**
* Filter to short circuit default is_private check for the model. This is expensive in some cases so
* this filter lets you prevent this from running by returning a true or false value.
*
* @param string $model_name Name of the model the filter is currently being executed in
* @param mixed $data The un-modeled incoming data
* @param string|null $visibility The visibility that has currently been set for the data at this point
* @param null|int $owner The user ID for the owner of this piece of data
* @param WP_User $current_user The current user for the session
*
* @return bool|null
*/
$pre_is_private = apply_filters( 'graphql_pre_model_data_is_private', null, $this->get_model_name(), $this->data, $this->visibility, $this->owner, $this->current_user );

// If 3rd party code has not filtered this, use the Models default logic to determine
// whether the model should be considered private
if ( null !== $pre_is_private ) {
$is_private = $pre_is_private;
} else {
$is_private = $this->is_private();
}

/**
* Filter to determine if the data should be considered private or not
*
* @param boolean $is_private Whether the model is private
* @param string $model_name Name of the model the filter is currently being executed in
* @param mixed $data The un-modeled incoming data
* @param string|null $visibility The visibility that has currently been set for the data at this point
Expand All @@ -233,7 +256,7 @@ public function get_visibility() {
*
* @return bool
*/
$is_private = apply_filters( 'graphql_data_is_private', $this->is_private(), $this->get_model_name(), $this->data, $this->visibility, $this->owner, $this->current_user );
$is_private = apply_filters( 'graphql_data_is_private', $is_private, $this->get_model_name(), $this->data, $this->visibility, $this->owner, $this->current_user );

if ( true === $is_private ) {
$this->visibility = 'private';
Expand Down
6 changes: 3 additions & 3 deletions wp-graphql.php
Expand Up @@ -6,7 +6,7 @@
* Description: GraphQL API for WordPress
* Author: WPGraphQL
* Author URI: http://www.wpgraphql.com
* Version: 1.1.1
* Version: 1.1.2
* Text Domain: wp-graphql
* Domain Path: /languages/
* Requires at least: 5.0
Expand All @@ -18,7 +18,7 @@
* @package WPGraphQL
* @category Core
* @author WPGraphQL
* @version 1.1.1
* @version 1.1.2
*/

// Exit if accessed directly.
Expand Down Expand Up @@ -186,7 +186,7 @@ private function setup_constants() {

// Plugin version.
if ( ! defined( 'WPGRAPHQL_VERSION' ) ) {
define( 'WPGRAPHQL_VERSION', '1.1.1' );
define( 'WPGRAPHQL_VERSION', '1.1.2' );
}

// Plugin Folder Path.
Expand Down