Skip to content

Commit 9680559

Browse files
committed
Exclude ChartJS from REST
This will exclue ChartJS from Rest route. Fixes #532 (comment)
1 parent e7fff71 commit 9680559

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

classes/Visualizer/Gutenberg/Block.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ private function __construct() {
6060
add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_gutenberg_scripts' ) );
6161
add_action( 'init', array( $this, 'register_block_type' ) );
6262
add_action( 'rest_api_init', array( $this, 'register_rest_endpoints' ) );
63+
add_filter( 'rest_visualizer_query', array( $this, 'add_rest_query_vars' ), 9, 2 );
6364
}
6465

6566
/**
@@ -413,4 +414,15 @@ public function get_permission_data( $data ) {
413414
return $options;
414415
}
415416

417+
/**
418+
* Filter Rest Query
419+
*/
420+
public function add_rest_query_vars( $args, \WP_REST_Request $request ) {
421+
if( isset( $request[ 'meta_key' ] ) && isset( $request['meta_value'] ) ) {
422+
$args['meta_key'] = $request->get_param('meta_key');
423+
$args['meta_value'] = $request->get_param('meta_value');
424+
$args['meta_compare'] = '!=';
425+
}
426+
return $args;
427+
}
416428
}

classes/Visualizer/Gutenberg/build/block.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

classes/Visualizer/Gutenberg/src/Components/Charts.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class Charts extends Component {
4646
async componentDidMount() {
4747

4848
// Fetch review again if block loaded after saving.
49-
let result = await apiFetch({ path: 'wp/v2/visualizer/?per_page=6' });
49+
let result = await apiFetch({ path: 'wp/v2/visualizer/?per_page=6&meta_key=visualizer-chart-library&meta_value=ChartJS' });
5050
this.setState({ charts: result });
5151
}
5252

@@ -56,7 +56,7 @@ class Charts extends Component {
5656

5757
this.setState({ isBusy: true });
5858

59-
let result = await apiFetch({ path: `wp/v2/visualizer/?per_page=6&offset=${ offset }` });
59+
let result = await apiFetch({ path: `wp/v2/visualizer/?per_page=6&meta_key=visualizer-chart-library&meta_value=ChartJS&offset=${ offset }` });
6060

6161
if ( 6 > result.length ) {
6262
chartsLoaded = true;

0 commit comments

Comments
 (0)