Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure Designers can only edit pages that already have a block template #152

Open
wants to merge 3 commits into
base: trunk
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions source/wp-content/themes/wporg-main-2022/inc/capabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,20 @@ function map_meta_caps( $required_caps, $current_cap, $user_id, $args ) {
// Special safety limits for Designer role when editing pages
// phpcs:disable WordPress.Security.NonceVerification.Missing
if ( user_can( $user_id, 'designer' ) ) {
// If a block template doesn't exist for this page then updates will be live, so stop designer users from editing the page.
// Note that this means a dev will need to create the template first before a designer can edit a page, even if it's an existing page.
$post = get_post( $args[0] );
if ( $post && 'page' === $post->post_type ) {
// There ought to be a way to do this using a function like `locate_block_template()`, but if there is I can't figure out how.
if ( 'page' === get_option( 'show_on_front' ) && get_option( 'page_on_front' ) == $post->ID ) {
$maybe_template = get_stylesheet_directory() . '/templates/front-page.html';
} else {
$maybe_template = get_stylesheet_directory() . '/templates/page-' . $post->post_name . '.html';
}
if ( ! file_exists( $maybe_template ) ) {
$required_caps[] = 'do_not_allow';
}
}
if ( isset( $_SERVER['REQUEST_METHOD'] ) && 'POST' === $_SERVER['REQUEST_METHOD']
&& isset( $_POST['action'] ) && 'inline-save' === $_POST['action']
&& isset( $_POST['post_type'] ) && 'page' === $_POST['post_type'] ) {
Expand Down