Skip to content

Commit 148d397

Browse files
committed
Fetch used plugin and theme fields only
1 parent 3f3cb57 commit 148d397

File tree

8 files changed

+38
-12
lines changed

8 files changed

+38
-12
lines changed

assets/src/components/plugins-context-provider/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import PropTypes from 'prop-types';
88
*/
99
import { createContext, useEffect, useRef, useState } from '@wordpress/element';
1010
import apiFetch from '@wordpress/api-fetch';
11+
import { addQueryArgs } from '@wordpress/url';
1112

1213
export const Plugins = createContext();
1314

@@ -44,7 +45,9 @@ export function PluginsContextProvider( { children } ) {
4445

4546
try {
4647
const fetchedPlugins = await apiFetch( {
47-
path: '/wp/v2/plugins',
48+
path: addQueryArgs( '/wp/v2/plugins', {
49+
_fields: [ 'author', 'name', 'plugin', 'status', 'version' ],
50+
} ),
4851
} );
4952

5053
if ( hasUnmounted.current === true ) {

assets/src/components/themes-context-provider/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import PropTypes from 'prop-types';
88
*/
99
import { createContext, useEffect, useRef, useState } from '@wordpress/element';
1010
import apiFetch from '@wordpress/api-fetch';
11+
import { addQueryArgs } from '@wordpress/url';
1112

1213
export const Themes = createContext();
1314

@@ -44,7 +45,9 @@ export function ThemesContextProvider( { children } ) {
4445

4546
try {
4647
const fetchedThemes = await apiFetch( {
47-
path: '/wp/v2/themes?status=active',
48+
path: addQueryArgs( '/wp/v2/themes', {
49+
_fields: [ 'author', 'name', 'status', 'stylesheet', 'version' ],
50+
} ),
4851
} );
4952

5053
if ( hasUnmounted.current === true ) {

src/Admin/OnboardingWizardSubmenuPage.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,17 @@ protected function add_preload_rest_paths() {
301301
],
302302
'/amp/v1/scannable-urls'
303303
),
304-
'/wp/v2/plugins',
304+
add_query_arg(
305+
'_fields',
306+
[ 'author', 'name', 'plugin', 'status', 'version' ],
307+
'/wp/v2/plugins'
308+
),
305309
'/wp/v2/settings',
306-
'/wp/v2/themes?status=active',
310+
add_query_arg(
311+
'_fields',
312+
[ 'author', 'name', 'status', 'stylesheet', 'version' ],
313+
'/wp/v2/themes'
314+
),
307315
'/wp/v2/users/me',
308316
];
309317

src/Admin/OptionsMenu.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,17 @@ protected function add_preload_rest_paths() {
320320
[ 'url', 'amp_url', 'type', 'label', 'validation_errors', 'stale' ],
321321
'/amp/v1/scannable-urls'
322322
),
323-
'/wp/v2/plugins',
323+
add_query_arg(
324+
'_fields',
325+
[ 'author', 'name', 'plugin', 'status', 'version' ],
326+
'/wp/v2/plugins'
327+
),
324328
'/wp/v2/settings',
325-
'/wp/v2/themes?status=active',
329+
add_query_arg(
330+
'_fields',
331+
[ 'author', 'name', 'status', 'stylesheet', 'version' ],
332+
'/wp/v2/themes'
333+
),
326334
'/wp/v2/users/me',
327335
];
328336

src/Admin/PluginActivationSiteScan.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,11 @@ protected function add_preload_rest_paths() {
182182
],
183183
'/amp/v1/scannable-urls'
184184
),
185-
'/wp/v2/plugins',
185+
add_query_arg(
186+
'_fields',
187+
[ 'author', 'name', 'plugin', 'status', 'version' ],
188+
'/wp/v2/plugins'
189+
),
186190
'/wp/v2/users/me',
187191
];
188192

tests/php/src/Admin/OnboardingWizardSubmenuPageTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,9 @@ function ( $caps, $cap ) {
189189
'/amp/v1/options',
190190
'/amp/v1/reader-themes',
191191
'/amp/v1/scannable-urls?_fields%5B0%5D=url&_fields%5B1%5D=amp_url&_fields%5B2%5D=type&_fields%5B3%5D=label&force_standard_mode=1',
192-
'/wp/v2/plugins',
192+
'/wp/v2/plugins?_fields%5B0%5D=author&_fields%5B1%5D=name&_fields%5B2%5D=plugin&_fields%5B3%5D=status&_fields%5B4%5D=version',
193193
'/wp/v2/settings',
194-
'/wp/v2/themes',
194+
'/wp/v2/themes?_fields%5B0%5D=author&_fields%5B1%5D=name&_fields%5B2%5D=status&_fields%5B3%5D=stylesheet&_fields%5B4%5D=version',
195195
'/wp/v2/users/me',
196196
],
197197
$this->get_private_property( $rest_preloader, 'paths' )

tests/php/src/Admin/OptionsMenuTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,9 @@ function ( $caps, $cap ) {
244244
'/amp/v1/options',
245245
'/amp/v1/reader-themes',
246246
'/amp/v1/scannable-urls?_fields%5B0%5D=url&_fields%5B1%5D=amp_url&_fields%5B2%5D=type&_fields%5B3%5D=label&_fields%5B4%5D=validation_errors&_fields%5B5%5D=stale',
247-
'/wp/v2/plugins',
247+
'/wp/v2/plugins?_fields%5B0%5D=author&_fields%5B1%5D=name&_fields%5B2%5D=plugin&_fields%5B3%5D=status&_fields%5B4%5D=version',
248248
'/wp/v2/settings',
249-
'/wp/v2/themes',
249+
'/wp/v2/themes?_fields%5B0%5D=author&_fields%5B1%5D=name&_fields%5B2%5D=status&_fields%5B3%5D=stylesheet&_fields%5B4%5D=version',
250250
'/wp/v2/users/me',
251251
],
252252
$this->get_private_property( $rest_preloader, 'paths' )

tests/php/src/Admin/PluginActivationSiteScanTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ function ( $caps, $cap ) {
226226
[
227227
'/amp/v1/options',
228228
'/amp/v1/scannable-urls?_fields%5B0%5D=url&_fields%5B1%5D=amp_url&_fields%5B2%5D=type&_fields%5B3%5D=label',
229-
'/wp/v2/plugins',
229+
'/wp/v2/plugins?_fields%5B0%5D=author&_fields%5B1%5D=name&_fields%5B2%5D=plugin&_fields%5B3%5D=status&_fields%5B4%5D=version',
230230
'/wp/v2/users/me',
231231
],
232232
$this->get_private_property( $rest_preloader, 'paths' )

0 commit comments

Comments
 (0)