From 339db9c13aea9a7d0052be83fffab954f0925a23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Ka=CC=88gy?= Date: Fri, 26 Jan 2024 10:53:56 +0100 Subject: [PATCH 01/14] change rest api priviliges of /templates endpoint to allow anyone with `edit_posts` capability to view templates --- ...utenberg-rest-templates-controller-6-4.php | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/lib/compat/wordpress-6.4/class-gutenberg-rest-templates-controller-6-4.php b/lib/compat/wordpress-6.4/class-gutenberg-rest-templates-controller-6-4.php index ec969519f9ac4f..09a4fff4109698 100644 --- a/lib/compat/wordpress-6.4/class-gutenberg-rest-templates-controller-6-4.php +++ b/lib/compat/wordpress-6.4/class-gutenberg-rest-templates-controller-6-4.php @@ -72,4 +72,29 @@ protected function prepare_revision_links( $template ) { return $links; } + + /** + * Checks if a given request has access to read templates. + * + * @since 6.5 + * + * @param WP_REST_Request $request Full details about the request. + * @return true|WP_Error True if the request has read access, WP_Error object otherwise. + */ + public function get_items_permissions_check( $request ) { + /* + * Allow access to anyone who can edit posts. + */ + if ( ! current_user_can( 'edit_posts' ) ) { + return new WP_Error( + 'rest_cannot_manage_templates', + __( 'Sorry, you are not allowed to access the templates on this site.' ), + array( + 'status' => rest_authorization_required_code(), + ) + ); + } + + return true; + } } From 1da75492992abfe5dc47b4963a5c3d696b4d531b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Ka=CC=88gy?= Date: Fri, 26 Jan 2024 10:54:54 +0100 Subject: [PATCH 02/14] fix pass current template into edit post ExperimentalEditorProvider when user can view template --- packages/edit-post/src/editor.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/edit-post/src/editor.js b/packages/edit-post/src/editor.js index fd44d3dae4ca4a..41043954454f26 100644 --- a/packages/edit-post/src/editor.js +++ b/packages/edit-post/src/editor.js @@ -55,12 +55,12 @@ function Editor( { getEditorSettings().supportsTemplateMode; const isViewable = getPostType( currentPost.postType )?.viewable ?? false; - const canEditTemplate = canUser( 'create', 'templates' ); + const canViewTemplate = canUser( 'read', 'templates' ); return { template: supportsTemplateMode && isViewable && - canEditTemplate && + canViewTemplate && currentPost.postType !== 'wp_template' ? getEditedPostTemplate() : null, From 52fad8247c179546cdf14910570177fc09230df5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Ka=CC=88gy?= Date: Fri, 26 Jan 2024 10:55:27 +0100 Subject: [PATCH 03/14] fix only show Edit & Create template buttons if user can create templates --- .../components/post-template/block-theme.js | 55 +++++++++++-------- 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/packages/editor/src/components/post-template/block-theme.js b/packages/editor/src/components/post-template/block-theme.js index 3ad4966a44ecce..8f2d94ebb7fa4d 100644 --- a/packages/editor/src/components/post-template/block-theme.js +++ b/packages/editor/src/components/post-template/block-theme.js @@ -5,7 +5,7 @@ import { useSelect, useDispatch } from '@wordpress/data'; import { decodeEntities } from '@wordpress/html-entities'; import { DropdownMenu, MenuGroup, MenuItem } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; -import { useEntityRecord } from '@wordpress/core-data'; +import { useEntityRecord, store as coreStore } from '@wordpress/core-data'; import { check } from '@wordpress/icons'; import { store as noticesStore } from '@wordpress/notices'; @@ -48,6 +48,12 @@ export default function BlockThemeControl( { id } ) { 'wp_template', id ); + + const canCreateTemplate = useSelect( + ( select ) => + select( coreStore ).canUser( 'create', 'templates' ) ?? false + ); + const { createSuccessNotice } = useDispatch( noticesStore ); const { setRenderingMode } = useDispatch( editorStore ); @@ -81,30 +87,33 @@ export default function BlockThemeControl( { id } ) { { ( { onClose } ) => ( <> - { - onNavigateToEntityRecord( { - postId: template.id, - postType: 'wp_template', - } ); - onClose(); - createSuccessNotice( - __( - 'Editing template. Changes made here affect all posts and pages that use the template.' - ), - { - type: 'snackbar', - actions: notificationAction, - } - ); - } } - > - { __( 'Edit template' ) } - - + { canCreateTemplate && ( + { + onNavigateToEntityRecord( { + postId: template.id, + postType: 'wp_template', + } ); + onClose(); + createSuccessNotice( + __( + 'Editing template. Changes made here affect all posts and pages that use the template.' + ), + { + type: 'snackbar', + actions: notificationAction, + } + ); + } } + > + { __( 'Edit template' ) } + + ) } - + { canCreateTemplate && ( + + ) } Date: Fri, 26 Jan 2024 12:04:36 +0100 Subject: [PATCH 04/14] =?UTF-8?q?don=E2=80=99t=20show=20notice=20to=20dire?= =?UTF-8?q?ct=20user=20to=20template=20editor=20when=20they=20aren?= =?UTF-8?q?=E2=80=99t=20allowed=20to=20do=20so?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../edit-template-blocks-notification.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/packages/editor/src/components/editor-canvas/edit-template-blocks-notification.js b/packages/editor/src/components/editor-canvas/edit-template-blocks-notification.js index 2000ae5727190c..3581a49608c734 100644 --- a/packages/editor/src/components/editor-canvas/edit-template-blocks-notification.js +++ b/packages/editor/src/components/editor-canvas/edit-template-blocks-notification.js @@ -2,6 +2,7 @@ * WordPress dependencies */ import { useSelect, useDispatch } from '@wordpress/data'; +import { store as coreStore } from '@wordpress/core-data'; import { useEffect, useState, useRef } from '@wordpress/element'; import { store as noticesStore } from '@wordpress/notices'; import { __ } from '@wordpress/i18n'; @@ -42,12 +43,20 @@ export default function EditTemplateBlocksNotification( { contentRef } ) { const { createInfoNotice, removeNotice } = useDispatch( noticesStore ); + const canEditTemplate = useSelect( + ( select ) => + select( coreStore ).canUser( 'create', 'templates' ) ?? false + ); + const [ isDialogOpen, setIsDialogOpen ] = useState( false ); const lastNoticeId = useRef( 0 ); useEffect( () => { const handleClick = async ( event ) => { + if ( ! canEditTemplate ) { + return; + } if ( ! event.target.classList.contains( 'is-root-container' ) ) { return; } @@ -104,8 +113,13 @@ export default function EditTemplateBlocksNotification( { contentRef } ) { onNavigateToEntityRecord, templateId, removeNotice, + canEditTemplate, ] ); + if ( ! canEditTemplate ) { + return null; + } + return ( Date: Fri, 26 Jan 2024 13:23:34 +0100 Subject: [PATCH 05/14] fix also allow viewing individual templates & template parts as a regular editor --- ...utenberg-rest-templates-controller-6-4.php | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/lib/compat/wordpress-6.4/class-gutenberg-rest-templates-controller-6-4.php b/lib/compat/wordpress-6.4/class-gutenberg-rest-templates-controller-6-4.php index 09a4fff4109698..b98f3341acbb33 100644 --- a/lib/compat/wordpress-6.4/class-gutenberg-rest-templates-controller-6-4.php +++ b/lib/compat/wordpress-6.4/class-gutenberg-rest-templates-controller-6-4.php @@ -97,4 +97,29 @@ public function get_items_permissions_check( $request ) { return true; } + + /** + * Checks if a given request has access to read templates. + * + * @since 6.5 + * + * @param WP_REST_Request $request Full details about the request. + * @return true|WP_Error True if the request has read access, WP_Error object otherwise. + */ + public function get_item_permissions_check( $request ) { + /* + * Allow access to anyone who can edit posts. + */ + if ( ! current_user_can( 'edit_posts' ) ) { + return new WP_Error( + 'rest_cannot_manage_templates', + __( 'Sorry, you are not allowed to access the templates on this site.' ), + array( + 'status' => rest_authorization_required_code(), + ) + ); + } + + return true; + } } From df29500ea408c94bfcabe847cf73e19378593cbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Ka=CC=88gy?= Date: Fri, 26 Jan 2024 13:23:58 +0100 Subject: [PATCH 06/14] add the ability to pass the rest context to the useEntityBlockEditor hook --- packages/core-data/src/entity-provider.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/core-data/src/entity-provider.js b/packages/core-data/src/entity-provider.js index 51830f622a026d..3c7012d2dccb44 100644 --- a/packages/core-data/src/entity-provider.js +++ b/packages/core-data/src/entity-provider.js @@ -145,14 +145,19 @@ const parsedBlocksCache = new WeakMap(); * `BlockEditorProvider` and are intended to be used with it, * or similar components or hooks. * - * @param {string} kind The entity kind. - * @param {string} name The entity name. + * @param {string} kind The entity kind. + * @param {string} name The entity name. * @param {Object} options - * @param {string} [options.id] An entity ID to use instead of the context-provided one. + * @param {string} [options.id] An entity ID to use instead of the context-provided one. + * @param {string} [options.context] The context param to be passed to the REST API. * * @return {[WPBlock[], Function, Function]} The block array and setters. */ -export function useEntityBlockEditor( kind, name, { id: _id } = {} ) { +export function useEntityBlockEditor( + kind, + name, + { id: _id, context = 'edit' } = {} +) { const providerId = useEntityId( kind, name ); const id = _id ?? providerId; const { getEntityRecord, getEntityRecordEdits } = useSelect( STORE_NAME ); @@ -162,7 +167,9 @@ export function useEntityBlockEditor( kind, name, { id: _id } = {} ) { return {}; } const { getEditedEntityRecord } = select( STORE_NAME ); - const editedRecord = getEditedEntityRecord( kind, name, id ); + const editedRecord = getEditedEntityRecord( kind, name, id, { + context, + } ); return { editedBlocks: editedRecord.blocks, content: editedRecord.content, From 98e7bee2062fe6bf0fe53143e7ba87f876fae952 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Ka=CC=88gy?= Date: Fri, 26 Jan 2024 13:24:23 +0100 Subject: [PATCH 07/14] add a method to only preview a template part for users that can only view but not edit them --- .../src/template-part/edit/index.js | 62 ++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/packages/block-library/src/template-part/edit/index.js b/packages/block-library/src/template-part/edit/index.js index 34a60e2659bf0d..1df90b080f4b69 100644 --- a/packages/block-library/src/template-part/edit/index.js +++ b/packages/block-library/src/template-part/edit/index.js @@ -7,6 +7,8 @@ import { useBlockProps, Warning, store as blockEditorStore, + useInnerBlocksProps, + useSettings, RecursionProvider, useHasRecursion, InspectorControls, @@ -15,7 +17,7 @@ import { import { PanelBody, Spinner, Modal, MenuItem } from '@wordpress/components'; import { useAsyncList } from '@wordpress/compose'; import { __, sprintf } from '@wordpress/i18n'; -import { store as coreStore } from '@wordpress/core-data'; +import { store as coreStore, useEntityBlockEditor } from '@wordpress/core-data'; import { useState } from '@wordpress/element'; import { store as noticesStore } from '@wordpress/notices'; @@ -88,12 +90,53 @@ function TemplatesList( { availableTemplates, onSelect } ) { ); } +function NonEditableTemplatePartPreview( { + postId: id, + layout, + tagName: TagName, + blockProps, +} ) { + const themeSupportsLayout = useSelect( ( select ) => { + const { getSettings } = select( blockEditorStore ); + return getSettings()?.supportsLayout; + }, [] ); + const [ defaultLayout ] = useSettings( 'layout' ); + const usedLayout = layout?.inherit ? defaultLayout || {} : layout; + + const [ blocks ] = useEntityBlockEditor( 'postType', 'wp_template_part', { + id, + context: 'view', + } ); + + const innerBlocksProps = useInnerBlocksProps( blockProps, { + value: blocks, + onChange: () => {}, + onInput: () => {}, + renderAppender: undefined, + layout: themeSupportsLayout ? usedLayout : undefined, + } ); + + return ; +} + export default function TemplatePartEdit( { attributes, setAttributes, clientId, } ) { const { createSuccessNotice } = useDispatch( noticesStore ); + const { canEditTemplatePart, canViewTemplatePart } = useSelect( + ( select ) => ( { + canEditTemplatePart: + select( coreStore ).canUser( 'create', 'template-parts' ) ?? + false, + canViewTemplatePart: + select( coreStore ).canUser( 'read', 'template-parts' ) ?? + false, + } ), + [] + ); + const currentTheme = useSelect( ( select ) => select( coreStore ).getCurrentTheme()?.stylesheet, [] @@ -161,6 +204,23 @@ export default function TemplatePartEdit( { setAttributes ); + if ( ! canEditTemplatePart && canViewTemplatePart ) { + return ( + + + + ); + } + // We don't want to render a missing state if we have any inner blocks. // A new template part is automatically created if we have any inner blocks but no entity. if ( From 06c0ae7b88b668c95ad00cd21d8935285338585c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Ka=CC=88gy?= Date: Mon, 5 Feb 2024 17:24:51 +0100 Subject: [PATCH 08/14] fix whitespace error --- .../class-gutenberg-rest-templates-controller-6-4.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/compat/wordpress-6.4/class-gutenberg-rest-templates-controller-6-4.php b/lib/compat/wordpress-6.4/class-gutenberg-rest-templates-controller-6-4.php index b98f3341acbb33..2276185f409d16 100644 --- a/lib/compat/wordpress-6.4/class-gutenberg-rest-templates-controller-6-4.php +++ b/lib/compat/wordpress-6.4/class-gutenberg-rest-templates-controller-6-4.php @@ -97,7 +97,7 @@ public function get_items_permissions_check( $request ) { return true; } - + /** * Checks if a given request has access to read templates. * From b9bbe961d04256a5879de63fbf8e4813caeabd98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Ka=CC=88gy?= Date: Mon, 5 Feb 2024 17:43:19 +0100 Subject: [PATCH 09/14] fix php cs issues --- .../class-gutenberg-rest-templates-controller-6-4.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/compat/wordpress-6.4/class-gutenberg-rest-templates-controller-6-4.php b/lib/compat/wordpress-6.4/class-gutenberg-rest-templates-controller-6-4.php index 2276185f409d16..380ab47fe20e03 100644 --- a/lib/compat/wordpress-6.4/class-gutenberg-rest-templates-controller-6-4.php +++ b/lib/compat/wordpress-6.4/class-gutenberg-rest-templates-controller-6-4.php @@ -78,17 +78,16 @@ protected function prepare_revision_links( $template ) { * * @since 6.5 * - * @param WP_REST_Request $request Full details about the request. * @return true|WP_Error True if the request has read access, WP_Error object otherwise. */ - public function get_items_permissions_check( $request ) { + public function get_items_permissions_check() { /* * Allow access to anyone who can edit posts. */ if ( ! current_user_can( 'edit_posts' ) ) { return new WP_Error( 'rest_cannot_manage_templates', - __( 'Sorry, you are not allowed to access the templates on this site.' ), + __( 'Sorry, you are not allowed to access the templates on this site.', 'default' ), array( 'status' => rest_authorization_required_code(), ) @@ -103,17 +102,16 @@ public function get_items_permissions_check( $request ) { * * @since 6.5 * - * @param WP_REST_Request $request Full details about the request. * @return true|WP_Error True if the request has read access, WP_Error object otherwise. */ - public function get_item_permissions_check( $request ) { + public function get_item_permissions_check() { /* * Allow access to anyone who can edit posts. */ if ( ! current_user_can( 'edit_posts' ) ) { return new WP_Error( 'rest_cannot_manage_templates', - __( 'Sorry, you are not allowed to access the templates on this site.' ), + __( 'Sorry, you are not allowed to access the templates on this site.', 'default' ), array( 'status' => rest_authorization_required_code(), ) From a6871eb408d1173cdd2a3519834854092d58cc47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Ka=CC=88gy?= Date: Wed, 14 Feb 2024 19:07:20 +0100 Subject: [PATCH 10/14] fix update rest controler to match shape of core function --- .../class-gutenberg-rest-templates-controller-6-4.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/compat/wordpress-6.4/class-gutenberg-rest-templates-controller-6-4.php b/lib/compat/wordpress-6.4/class-gutenberg-rest-templates-controller-6-4.php index 380ab47fe20e03..3b8de9dfb74f22 100644 --- a/lib/compat/wordpress-6.4/class-gutenberg-rest-templates-controller-6-4.php +++ b/lib/compat/wordpress-6.4/class-gutenberg-rest-templates-controller-6-4.php @@ -74,13 +74,14 @@ protected function prepare_revision_links( $template ) { } /** - * Checks if a given request has access to read templates. + * Checks if the user has permissions to make the request. * * @since 6.5 * + * @param WP_REST_Request $request Full details about the request. * @return true|WP_Error True if the request has read access, WP_Error object otherwise. */ - public function get_items_permissions_check() { + protected function permissions_check( $request ) { /* * Allow access to anyone who can edit posts. */ @@ -102,9 +103,10 @@ public function get_items_permissions_check() { * * @since 6.5 * + * @param WP_REST_Request $request Full details about the request. * @return true|WP_Error True if the request has read access, WP_Error object otherwise. */ - public function get_item_permissions_check() { + public function get_items_permissions_check( $request ) { /* * Allow access to anyone who can edit posts. */ From e039f82be34c6cdffb9df28be164bfc3ef208625 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Ka=CC=88gy?= Date: Wed, 14 Feb 2024 19:14:50 +0100 Subject: [PATCH 11/14] fix template access permissions --- .../class-gutenberg-rest-templates-controller-6-4.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/compat/wordpress-6.4/class-gutenberg-rest-templates-controller-6-4.php b/lib/compat/wordpress-6.4/class-gutenberg-rest-templates-controller-6-4.php index 3b8de9dfb74f22..786a5b976e81bc 100644 --- a/lib/compat/wordpress-6.4/class-gutenberg-rest-templates-controller-6-4.php +++ b/lib/compat/wordpress-6.4/class-gutenberg-rest-templates-controller-6-4.php @@ -74,14 +74,14 @@ protected function prepare_revision_links( $template ) { } /** - * Checks if the user has permissions to make the request. + * Checks if a given request has access to read templates. * * @since 6.5 * * @param WP_REST_Request $request Full details about the request. * @return true|WP_Error True if the request has read access, WP_Error object otherwise. */ - protected function permissions_check( $request ) { + public function get_items_permissions_check( $request ) { /* * Allow access to anyone who can edit posts. */ @@ -106,7 +106,7 @@ protected function permissions_check( $request ) { * @param WP_REST_Request $request Full details about the request. * @return true|WP_Error True if the request has read access, WP_Error object otherwise. */ - public function get_items_permissions_check( $request ) { + public function get_item_permissions_check( $request ) { /* * Allow access to anyone who can edit posts. */ From dd22cab2bbb1c14b96c5df6f1f320f7717461e05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Ka=CC=88gy?= Date: Wed, 14 Feb 2024 19:29:01 +0100 Subject: [PATCH 12/14] ignore unused variable The variable needs to be accepted in order to not run into the fatal error: Fatal error: Declaration of Gutenberg_REST_Templates_Controller_6_4::get_items_permissions_check() must be compatible with WP_REST_Templates_Controller::get_items_permissions_check($request) in /var/www/html/wp-content/plugins/gutenberg/lib/compat/wordpress-6.4/class-gutenberg-rest-templates-controller-6-4.php on line 83 --- .../class-gutenberg-rest-templates-controller-6-4.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/compat/wordpress-6.4/class-gutenberg-rest-templates-controller-6-4.php b/lib/compat/wordpress-6.4/class-gutenberg-rest-templates-controller-6-4.php index 786a5b976e81bc..e1522d8c3cf835 100644 --- a/lib/compat/wordpress-6.4/class-gutenberg-rest-templates-controller-6-4.php +++ b/lib/compat/wordpress-6.4/class-gutenberg-rest-templates-controller-6-4.php @@ -81,7 +81,7 @@ protected function prepare_revision_links( $template ) { * @param WP_REST_Request $request Full details about the request. * @return true|WP_Error True if the request has read access, WP_Error object otherwise. */ - public function get_items_permissions_check( $request ) { + public function get_items_permissions_check( $request ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable /* * Allow access to anyone who can edit posts. */ @@ -106,7 +106,7 @@ public function get_items_permissions_check( $request ) { * @param WP_REST_Request $request Full details about the request. * @return true|WP_Error True if the request has read access, WP_Error object otherwise. */ - public function get_item_permissions_check( $request ) { + public function get_item_permissions_check( $request ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable /* * Allow access to anyone who can edit posts. */ From a38c4f91730341a1afa7e47d9396109418d7361e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Ka=CC=88gy?= Date: Thu, 21 Mar 2024 12:02:44 +0100 Subject: [PATCH 13/14] move php updates to 6.6 folder --- ...utenberg-rest-templates-controller-6-4.php | 50 -------------- ...utenberg-rest-templates-controller-6-6.php | 66 +++++++++++++++++++ 2 files changed, 66 insertions(+), 50 deletions(-) create mode 100644 lib/compat/wordpress-6.6/class-gutenberg-rest-templates-controller-6-6.php diff --git a/lib/compat/wordpress-6.4/class-gutenberg-rest-templates-controller-6-4.php b/lib/compat/wordpress-6.4/class-gutenberg-rest-templates-controller-6-4.php index e1522d8c3cf835..ec969519f9ac4f 100644 --- a/lib/compat/wordpress-6.4/class-gutenberg-rest-templates-controller-6-4.php +++ b/lib/compat/wordpress-6.4/class-gutenberg-rest-templates-controller-6-4.php @@ -72,54 +72,4 @@ protected function prepare_revision_links( $template ) { return $links; } - - /** - * Checks if a given request has access to read templates. - * - * @since 6.5 - * - * @param WP_REST_Request $request Full details about the request. - * @return true|WP_Error True if the request has read access, WP_Error object otherwise. - */ - public function get_items_permissions_check( $request ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable - /* - * Allow access to anyone who can edit posts. - */ - if ( ! current_user_can( 'edit_posts' ) ) { - return new WP_Error( - 'rest_cannot_manage_templates', - __( 'Sorry, you are not allowed to access the templates on this site.', 'default' ), - array( - 'status' => rest_authorization_required_code(), - ) - ); - } - - return true; - } - - /** - * Checks if a given request has access to read templates. - * - * @since 6.5 - * - * @param WP_REST_Request $request Full details about the request. - * @return true|WP_Error True if the request has read access, WP_Error object otherwise. - */ - public function get_item_permissions_check( $request ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable - /* - * Allow access to anyone who can edit posts. - */ - if ( ! current_user_can( 'edit_posts' ) ) { - return new WP_Error( - 'rest_cannot_manage_templates', - __( 'Sorry, you are not allowed to access the templates on this site.', 'default' ), - array( - 'status' => rest_authorization_required_code(), - ) - ); - } - - return true; - } } diff --git a/lib/compat/wordpress-6.6/class-gutenberg-rest-templates-controller-6-6.php b/lib/compat/wordpress-6.6/class-gutenberg-rest-templates-controller-6-6.php new file mode 100644 index 00000000000000..42f8d0400393ca --- /dev/null +++ b/lib/compat/wordpress-6.6/class-gutenberg-rest-templates-controller-6-6.php @@ -0,0 +1,66 @@ + rest_authorization_required_code(), + ) + ); + } + + return true; + } + + /** + * Checks if a given request has access to read templates. + * + * @since 6.6 + * + * @param WP_REST_Request $request Full details about the request. + * @return true|WP_Error True if the request has read access, WP_Error object otherwise. + */ + public function get_item_permissions_check( $request ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable + /* + * Allow access to anyone who can edit posts. + */ + if ( ! current_user_can( 'edit_posts' ) ) { + return new WP_Error( + 'rest_cannot_manage_templates', + __( 'Sorry, you are not allowed to access the templates on this site.', 'default' ), + array( + 'status' => rest_authorization_required_code(), + ) + ); + } + + return true; + } +} From 74d934be775991ee9f86f182865307ed79148234 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Ka=CC=88gy?= Date: Thu, 21 Mar 2024 12:07:36 +0100 Subject: [PATCH 14/14] load 6.6 compat rest api --- lib/compat/wordpress-6.6/rest-api.php | 31 +++++++++++++++++++++++++++ lib/load.php | 4 ++++ 2 files changed, 35 insertions(+) create mode 100644 lib/compat/wordpress-6.6/rest-api.php diff --git a/lib/compat/wordpress-6.6/rest-api.php b/lib/compat/wordpress-6.6/rest-api.php new file mode 100644 index 00000000000000..bf462cd11ca4b4 --- /dev/null +++ b/lib/compat/wordpress-6.6/rest-api.php @@ -0,0 +1,31 @@ +