Skip to content

Instantly share code, notes, and snippets.

@xavier-lc
Last active September 5, 2025 11:17
Show Gist options
  • Save xavier-lc/005cf2cf3e37197e28b6514e1865f551 to your computer and use it in GitHub Desktop.
Save xavier-lc/005cf2cf3e37197e28b6514e1865f551 to your computer and use it in GitHub Desktop.
diff --git a/packages/core-data/src/tryit.ts b/packages/core-data/src/tryit.ts
new file mode 100644
index 0000000000..38c0721690
--- /dev/null
+++ b/packages/core-data/src/tryit.ts
@@ -0,0 +1,43 @@
+/**
+ * WordPress dependencies
+ */
+import { privateApis } from '@wordpress/core-data';
+import type {
+ Theme,
+ WithPermissions,
+ useEntityRecords,
+} from '@wordpress/core-data';
+import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis';
+
+export const { lock, unlock } =
+ __dangerousOptInToUnstableAPIsOnlyForCoreModules(
+ 'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.',
+ '@wordpress/core-data'
+ );
+
+interface EntityRecordsWithPermissionsResolution< RecordType >
+ extends Omit<
+ ReturnType< typeof useEntityRecords< RecordType > >,
+ 'records'
+ > {
+ /** The requested entity records with permissions */
+ records: WithPermissions< RecordType >[] | null;
+}
+
+type UseEntityRecordsWithPermissionsType = < RecordType >(
+ ...args: Parameters< typeof useEntityRecords< RecordType > >
+) => EntityRecordsWithPermissionsResolution< RecordType >;
+
+const { useEntityRecordsWithPermissions } = unlock< {
+ useEntityRecordsWithPermissions: UseEntityRecordsWithPermissionsType;
+} >( privateApis );
+
+const useThemes = () => {
+ const { records: allThemes, isResolving } =
+ useEntityRecordsWithPermissions< Theme >( 'root', 'theme', {
+ context: 'view',
+ per_page: -1,
+ } );
+
+ return { allThemes, isResolving };
+};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment