Skip to content
Merged
Show file tree
Hide file tree
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
20 changes: 0 additions & 20 deletions lib/experimental/content-guidelines/index.php

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Content Guidelines Post Type registration.
* Guidelines Post Type registration.
*
* @package gutenberg
*/
Expand All @@ -10,9 +10,9 @@
}

/**
* Handles registration of the Content Guidelines custom post type.
* Handles registration of the Guidelines custom post type.
*/
class Gutenberg_Content_Guidelines_Post_Type {
class Gutenberg_Guidelines_Post_Type {

/**
* The post type name.
Expand Down Expand Up @@ -63,7 +63,7 @@ class Gutenberg_Content_Guidelines_Post_Type {
*
* @var string
*/
const BLOCK_META_PREFIX = '_content_guideline_block_';
const BLOCK_META_PREFIX = '_guideline_block_';

/**
* Register the custom post type.
Expand All @@ -79,9 +79,9 @@ public static function register() {
'show_ui' => false,
'show_in_menu' => false,
'show_in_rest' => true,
'rest_base' => 'content-guidelines',
'rest_controller_class' => 'Gutenberg_Content_Guidelines_REST_Controller',
'revisions_rest_controller_class' => 'Gutenberg_Content_Guidelines_Revisions_Controller',
'rest_base' => 'guidelines',
'rest_controller_class' => 'Gutenberg_Guidelines_REST_Controller',
'revisions_rest_controller_class' => 'Gutenberg_Guidelines_Revisions_Controller',
'capability_type' => 'post',
'capabilities' => array(
'read' => 'edit_posts',
Expand Down Expand Up @@ -123,7 +123,7 @@ public static function register_post_meta() {

// Register standard category meta.
foreach ( self::CATEGORY_META_KEYS as $category ) {
register_post_meta( self::POST_TYPE, '_content_guideline_' . $category, $meta_args );
register_post_meta( self::POST_TYPE, '_guideline_' . $category, $meta_args );
}

// Register meta for content blocks.
Expand Down Expand Up @@ -174,7 +174,7 @@ private static function block_has_content_role( $block_type ) {
* Convert a block name to a meta key.
*
* @param string $block_name The block name (e.g., 'core/paragraph').
* @return string The meta key (e.g., '_content_guideline_block_core_paragraph').
* @return string The meta key (e.g., '_guideline_block_core_paragraph').
*/
public static function block_name_to_meta_key( $block_name ) {
// Replace '/' with '_' to create a valid meta key.
Expand All @@ -185,7 +185,7 @@ public static function block_name_to_meta_key( $block_name ) {
/**
* Convert a meta key back to a block name.
*
* @param string $meta_key The meta key (e.g., '_content_guideline_block_core_paragraph').
* @param string $meta_key The meta key (e.g., '_guideline_block_core_paragraph').
* @return string The block name (e.g., 'core/paragraph').
*/
public static function meta_key_to_block_name( $meta_key ) {
Expand Down Expand Up @@ -225,7 +225,7 @@ public static function get_guideline_categories_from_meta( $post_id ) {

// Get standard categories.
foreach ( self::CATEGORY_META_KEYS as $category ) {
$meta_key = '_content_guideline_' . $category;
$meta_key = '_guideline_' . $category;
$value = get_post_meta( $post_id, $meta_key, true );

$guideline_categories[ $category ] = array(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Content Guidelines REST API Controller.
* Guidelines REST API Controller.
*
* Extends WP_REST_Posts_Controller to inherit standard WordPress CRUD behavior,
* permission checks, and response formatting. Follows the pattern used by
Expand All @@ -14,9 +14,9 @@
}

/**
* REST API controller for Content Guidelines.
* REST API controller for Guidelines.
*/
class Gutenberg_Content_Guidelines_REST_Controller extends WP_REST_Posts_Controller {
class Gutenberg_Guidelines_REST_Controller extends WP_REST_Posts_Controller {

/**
* Maximum length for guideline text strings.
Expand All @@ -36,11 +36,11 @@ class Gutenberg_Content_Guidelines_REST_Controller extends WP_REST_Posts_Control
* Constructor.
*/
public function __construct() {
parent::__construct( Gutenberg_Content_Guidelines_Post_Type::POST_TYPE );
parent::__construct( Gutenberg_Guidelines_Post_Type::POST_TYPE );
}

/**
* Registers the routes for content guidelines.
* Registers the routes for guidelines.
*
* Calls parent to register standard /{id} CRUD routes, then overrides the
* collection route with a singleton GET endpoint.
Expand All @@ -61,7 +61,7 @@ public function register_routes() {
'category' => array(
'description' => __( 'Limit response to a specific guideline category.', 'gutenberg' ),
'type' => 'string',
'enum' => Gutenberg_Content_Guidelines_Post_Type::VALID_CATEGORIES,
'enum' => Gutenberg_Guidelines_Post_Type::VALID_CATEGORIES,
'sanitize_callback' => 'sanitize_text_field',
),
'block' => array(
Expand All @@ -72,7 +72,7 @@ public function register_routes() {
'status' => array(
'description' => __( 'Limit response to guidelines with a specific status.', 'gutenberg' ),
'type' => 'string',
'enum' => Gutenberg_Content_Guidelines_Post_Type::VALID_STATUSES,
'enum' => Gutenberg_Guidelines_Post_Type::VALID_STATUSES,
'sanitize_callback' => 'sanitize_text_field',
),
),
Expand Down Expand Up @@ -120,7 +120,7 @@ public function get_guidelines_permissions_check( $request ) { // phpcs:ignore V
}

/**
* Gets the singleton content guidelines.
* Gets the singleton guidelines.
*
* Supports query parameters:
* - ?status=publish|draft - Filter by status
Expand Down Expand Up @@ -149,7 +149,7 @@ public function get_guidelines( $request ) {
}

/**
* Creates content guidelines.
* Creates guidelines.
*
* Enforces singleton pattern — only one guidelines post per site.
*
Expand Down Expand Up @@ -197,7 +197,7 @@ public function create_item( $request ) {
}

/**
* Updates content guidelines.
* Updates guidelines.
*
* Saves guideline categories to meta before updating the post so that
* the revision captures the updated meta values.
Expand Down Expand Up @@ -280,7 +280,7 @@ public function prepare_item_for_response( $post, $request ) {
}

if ( rest_is_field_included( 'guideline_categories', $fields ) ) {
$guideline_categories = Gutenberg_Content_Guidelines_Post_Type::get_guideline_categories_from_meta( $post->ID );
$guideline_categories = Gutenberg_Guidelines_Post_Type::get_guideline_categories_from_meta( $post->ID );

// Handle ?block filter.
$block_filter = $request->get_param( 'block' );
Expand Down Expand Up @@ -388,9 +388,9 @@ protected function prepare_links( $id ) {
*/
protected function save_guideline_categories_to_meta( $post_id, $categories ) {
// Save standard categories.
foreach ( Gutenberg_Content_Guidelines_Post_Type::CATEGORY_META_KEYS as $category ) {
foreach ( Gutenberg_Guidelines_Post_Type::CATEGORY_META_KEYS as $category ) {
if ( isset( $categories[ $category ] ) ) {
$meta_key = '_content_guideline_' . $category;
$meta_key = '_guideline_' . $category;
$value = $categories[ $category ]['guidelines'] ?? '';
update_post_meta( $post_id, $meta_key, $value );
}
Expand All @@ -399,7 +399,7 @@ protected function save_guideline_categories_to_meta( $post_id, $categories ) {
// Handle block-specific guidelines as individual meta keys.
if ( isset( $categories['blocks'] ) && is_array( $categories['blocks'] ) ) {
foreach ( $categories['blocks'] as $block_name => $block_data ) {
$meta_key = Gutenberg_Content_Guidelines_Post_Type::block_name_to_meta_key( $block_name );
$meta_key = Gutenberg_Guidelines_Post_Type::block_name_to_meta_key( $block_name );
$value = $block_data['guidelines'] ?? '';

if ( ! empty( $value ) ) {
Expand All @@ -422,7 +422,7 @@ protected function sanitize_guideline_categories( $categories ) {
return array();
}

$valid_categories = Gutenberg_Content_Guidelines_Post_Type::VALID_CATEGORIES;
$valid_categories = Gutenberg_Guidelines_Post_Type::VALID_CATEGORIES;
$sanitized = array_intersect_key( $categories, array_flip( $valid_categories ) );

foreach ( $sanitized as $key => &$category ) {
Expand Down Expand Up @@ -538,7 +538,7 @@ public function get_item_schema() {

$this->schema = array(
'$schema' => 'http://json-schema.org/draft-04/schema#',
'title' => 'content-guidelines',
'title' => 'guidelines',
'type' => 'object',
'properties' => array(
'id' => array(
Expand All @@ -550,7 +550,7 @@ public function get_item_schema() {
'status' => array(
'description' => __( 'The status of the guidelines (draft or publish).', 'gutenberg' ),
'type' => 'string',
'enum' => Gutenberg_Content_Guidelines_Post_Type::VALID_STATUSES,
'enum' => Gutenberg_Guidelines_Post_Type::VALID_STATUSES,
'context' => array( 'view', 'edit' ),
),
'guideline_categories' => array(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Content Guidelines Revisions REST API Controller.
* Guidelines Revisions REST API Controller.
*
* Extends WP_REST_Revisions_Controller to inherit standard WordPress revision
* list/get behavior and adds guideline_categories to responses + a restore endpoint.
Expand All @@ -13,9 +13,9 @@
}

/**
* REST API controller for Content Guidelines revisions.
* REST API controller for Guidelines revisions.
*/
class Gutenberg_Content_Guidelines_Revisions_Controller extends WP_REST_Revisions_Controller {
class Gutenberg_Guidelines_Revisions_Controller extends WP_REST_Revisions_Controller {

/**
* The base of the parent controller's route.
Expand Down Expand Up @@ -46,7 +46,7 @@ public function __construct( $parent_post_type = 'wp_guideline' ) {
}

/**
* Registers the routes for content guideline revisions.
* Registers the routes for guideline revisions.
*
* Calls parent to register standard list + single revision routes,
* then adds a custom restore endpoint.
Expand Down Expand Up @@ -98,7 +98,7 @@ public function prepare_item_for_response( $item, $request ) {

if ( rest_is_field_included( 'guideline_categories', $fields ) ) {
$data = $response->get_data();
$guideline_categories = Gutenberg_Content_Guidelines_Post_Type::get_guideline_categories_from_meta( $item->ID );
$guideline_categories = Gutenberg_Guidelines_Post_Type::get_guideline_categories_from_meta( $item->ID );
$data['guideline_categories'] = ! empty( $guideline_categories ) ? $guideline_categories : new stdClass();
$response->set_data( $data );
}
Expand Down
20 changes: 20 additions & 0 deletions lib/experimental/guidelines/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
/**
* Guidelines experimental feature.
*
* @package gutenberg
*/

if ( ! defined( 'ABSPATH' ) ) {
exit;
}

require_once __DIR__ . '/class-gutenberg-guidelines-post-type.php';
require_once __DIR__ . '/class-gutenberg-guidelines-rest-controller.php';
require_once __DIR__ . '/class-gutenberg-guidelines-revisions-controller.php';

// Register CPT (controllers auto-instantiated via post type args).
add_action( 'init', array( 'Gutenberg_Guidelines_Post_Type', 'register' ) );

// Register post meta at rest_api_init (block registry needs to be available).
add_action( 'rest_api_init', array( 'Gutenberg_Guidelines_Post_Type', 'register_post_meta' ) );
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<?php
/**
* Bootstraps the Content Guidelines page in wp-admin under Settings.
* Bootstraps the Guidelines page in wp-admin under Settings.
*
* @package gutenberg
*/

add_action( 'admin_menu', 'gutenberg_register_content_guidelines_settings_submenu', 10 );
add_action( 'admin_enqueue_scripts', 'gutenberg_content_guidelines_enqueue_block_registry_scripts', 5 );
add_action( 'admin_menu', 'gutenberg_register_guidelines_settings_submenu', 10 );
add_action( 'admin_enqueue_scripts', 'gutenberg_guidelines_enqueue_block_registry_scripts', 5 );

/**
* Registers the Content Guidelines submenu item under Settings.
* Registers the Guidelines submenu item under Settings.
* Uses the same layout/style as the Font Library admin page (wp-admin integrated).
*/
function gutenberg_register_content_guidelines_settings_submenu() {
function gutenberg_register_guidelines_settings_submenu() {
add_submenu_page(
'options-general.php',
__( 'Guidelines', 'gutenberg' ),
Expand All @@ -24,13 +24,13 @@ function gutenberg_register_content_guidelines_settings_submenu() {
}

/**
* Enqueues wp-block-library on the Content Guidelines admin page so
* Enqueues wp-block-library on the Guidelines admin page so
* registerCoreBlocks() is available when the app bootstraps the block
* registry (Core blocks only) on the client.
*
* Priority 5 ensures this runs before the main asset enqueue (priority 10).
*/
function gutenberg_content_guidelines_enqueue_block_registry_scripts( $hook_suffix ) {
function gutenberg_guidelines_enqueue_block_registry_scripts( $hook_suffix ) {
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/experiments-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,14 @@ function gutenberg_initialize_experiments_settings() {
);

add_settings_field(
'gutenberg-content-guidelines',
'gutenberg-guidelines',
__( 'Guidelines', 'gutenberg' ),
'gutenberg_display_experiment_field',
'gutenberg-experiments',
'gutenberg_experiments_section',
array(
'label' => __( 'Enables guidelines feature for managing editorial voice and tone guidelines under Settings.', 'gutenberg' ),
'id' => 'gutenberg-content-guidelines',
'id' => 'gutenberg-guidelines',
)
);

Expand Down
8 changes: 4 additions & 4 deletions lib/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ function gutenberg_is_experiment_enabled( $name ) {
// Block patterns for navigation overlays.
require __DIR__ . '/overlay-patterns.php';

// Content Guidelines (only load when experiment is enabled).
if ( gutenberg_is_experiment_enabled( 'gutenberg-content-guidelines' ) ) {
require __DIR__ . '/experimental/content-guidelines/load.php';
require __DIR__ . '/experimental/content-guidelines/index.php';
// Guidelines (only load when experiment is enabled).
if ( gutenberg_is_experiment_enabled( 'gutenberg-guidelines' ) ) {
require __DIR__ . '/experimental/guidelines/load.php';
require __DIR__ . '/experimental/guidelines/index.php';
}
Loading
Loading