|
11 | 11 | class GoogleSheetsIntegration {
|
12 | 12 | public static function init(): void {
|
13 | 13 | add_action( 'init', [ __CLASS__, 'register_blocks' ], 10, 0 );
|
| 14 | + add_filter( 'remote_data_blocks_request_details', [ __CLASS__, 'enhance_request_details' ], 10, 3 ); |
14 | 15 | }
|
15 | 16 |
|
16 | 17 | public static function register_blocks(): void {
|
@@ -186,4 +187,28 @@ public static function get_block_registration_snippets( array $data_source_confi
|
186 | 187 |
|
187 | 188 | return $snippets;
|
188 | 189 | }
|
| 190 | + |
| 191 | + /** |
| 192 | + * Due to the fact that we are using the same query for both the get and list queries, and |
| 193 | + * only filtering out the results based on the input variables, the in-memory cache will not |
| 194 | + * work as expected. This enhances the request details to include the input variables, so that |
| 195 | + * the in-memory cache will be able to differenciate each request. |
| 196 | + * |
| 197 | + * @param array<string, mixed> $request_details The request details. |
| 198 | + * @param string $_query The query being executed. |
| 199 | + * @param array<string, mixed> $input_variables The input variables for the current request. |
| 200 | + * @return array<string, array{ |
| 201 | + * method: string, |
| 202 | + * options: array<string, mixed>, |
| 203 | + * origin: string, |
| 204 | + * uri: string, |
| 205 | + * }> |
| 206 | + */ |
| 207 | + public static function enhance_request_details( array $request_details, string $_query, array $input_variables ): array { |
| 208 | + if ( isset( $request_details['origin'] ) && 'https://sheets.googleapis.com' === $request_details['origin'] && ! empty( $input_variables ) ) { |
| 209 | + $request_details['input_variables'] = $input_variables; |
| 210 | + } |
| 211 | + |
| 212 | + return $request_details; |
| 213 | + } |
189 | 214 | }
|
0 commit comments