diff --git a/source/wp-content/themes/wporg-main-2022/inc/capabilities.php b/source/wp-content/themes/wporg-main-2022/inc/capabilities.php index ec816944..ab63911c 100644 --- a/source/wp-content/themes/wporg-main-2022/inc/capabilities.php +++ b/source/wp-content/themes/wporg-main-2022/inc/capabilities.php @@ -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'] ) {