Skip to content

Commit

Permalink
Inline Commenting: Change the PHP compat directory (WordPress#68846)
Browse files Browse the repository at this point in the history
Relocates the backport log file for block comments to the experimental feature directory. The feature is currently experimental and will not be included in WordPress 6.8.

Co-authored-by: Mamaduka <[email protected]>
Co-authored-by: shail-mehta <[email protected]>
  • Loading branch information
3 people authored Jan 23, 2025
1 parent 3c1bbcc commit 654bace
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 23 deletions.
3 changes: 0 additions & 3 deletions backport-changelog/6.8/7488.md

This file was deleted.

3 changes: 0 additions & 3 deletions backport-changelog/6.8/7498.md

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Updates the comment type in the REST API for WordPress version 6.7.
* Updates the comment type in the REST API.
*
* This function is used as a filter callback for the 'rest_pre_insert_comment' hook.
* It checks if the 'comment_type' parameter is set to 'block_comment' in the REST API request,
Expand All @@ -10,7 +10,7 @@
* @param WP_REST_Request $request The REST API request object.
* @return array The updated prepared comment data.
*/
if ( ! function_exists( 'update_comment_type_in_rest_api_6_8' ) && gutenberg_is_experiment_enabled( 'gutenberg-block-comment' ) ) {
if ( ! function_exists( 'update_comment_type_in_rest_api_6_8' ) ) {
function update_comment_type_in_rest_api_6_8( $prepared_comment, $request ) {
if ( ! empty( $request['comment_type'] ) && 'block_comment' === $request['comment_type'] ) {
$prepared_comment['comment_type'] = $request['comment_type'];
Expand All @@ -31,7 +31,7 @@ function update_comment_type_in_rest_api_6_8( $prepared_comment, $request ) {
* @param array $comment_type The array of comment types.
* @return array The updated array of comment types.
*/
if ( ! function_exists( 'update_get_avatar_comment_type' ) && gutenberg_is_experiment_enabled( 'gutenberg-block-comment' ) ) {
if ( ! function_exists( 'update_get_avatar_comment_type' ) ) {
function update_get_avatar_comment_type( $comment_type ) {
$comment_type[] = 'block_comment';
return $comment_type;
Expand All @@ -49,7 +49,7 @@ function update_get_avatar_comment_type( $comment_type ) {
*
* @return void
*/
if ( ! function_exists( 'exclude_block_comments_from_admin' ) && gutenberg_is_experiment_enabled( 'gutenberg-block-comment' ) ) {
if ( ! function_exists( 'exclude_block_comments_from_admin' ) ) {
function exclude_block_comments_from_admin( $query ) {
// Only modify the query if it's for comments
if ( isset( $query->query_vars['type'] ) && '' === $query->query_vars['type'] ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

// Create a new class that extends WP_REST_Comments_Controller
class Gutenberg_REST_Comment_Controller_6_8 extends WP_REST_Comments_Controller {
class Gutenberg_REST_Comment_Controller extends WP_REST_Comments_Controller {

public function create_item_permissions_check( $request ) {
if ( empty( $request['comment_type'] ) || 'comment' === $request['comment_type'] ) {
Expand All @@ -18,7 +18,7 @@ public function create_item_permissions_check( $request ) {
if ( get_option( 'comment_registration' ) ) {
return new WP_Error(
'rest_comment_login_required',
__( 'Sorry, you must be logged in to comment.' ),
__( 'Sorry, you must be logged in to comment.', 'gutenberg' ),
array( 'status' => 401 )
);
}
Expand All @@ -40,7 +40,7 @@ public function create_item_permissions_check( $request ) {
if ( ! $allow_anonymous ) {
return new WP_Error(
'rest_comment_login_required',
__( 'Sorry, you must be logged in to comment.' ),
__( 'Sorry, you must be logged in to comment.', 'gutenberg' ),
array( 'status' => 401 )
);
}
Expand All @@ -51,7 +51,7 @@ public function create_item_permissions_check( $request ) {
return new WP_Error(
'rest_comment_invalid_author',
/* translators: %s: Request parameter. */
sprintf( __( "Sorry, you are not allowed to edit '%s' for comments." ), 'author' ),
sprintf( __( "Sorry, you are not allowed to edit '%s' for comments.", 'gutenberg' ), 'author' ),
array( 'status' => rest_authorization_required_code() )
);
}
Expand All @@ -61,7 +61,7 @@ public function create_item_permissions_check( $request ) {
return new WP_Error(
'rest_comment_invalid_author_ip',
/* translators: %s: Request parameter. */
sprintf( __( "Sorry, you are not allowed to edit '%s' for comments." ), 'author_ip' ),
sprintf( __( "Sorry, you are not allowed to edit '%s' for comments.", 'gutenberg' ), 'author_ip' ),
array( 'status' => rest_authorization_required_code() )
);
}
Expand All @@ -71,15 +71,15 @@ public function create_item_permissions_check( $request ) {
return new WP_Error(
'rest_comment_invalid_status',
/* translators: %s: Request parameter. */
sprintf( __( "Sorry, you are not allowed to edit '%s' for comments." ), 'status' ),
sprintf( __( "Sorry, you are not allowed to edit '%s' for comments.", 'gutenberg' ), 'status' ),
array( 'status' => rest_authorization_required_code() )
);
}

if ( empty( $request['post'] ) ) {
return new WP_Error(
'rest_comment_invalid_post_id',
__( 'Sorry, you are not allowed to create this comment without a post.' ),
__( 'Sorry, you are not allowed to create this comment without a post.', 'gutenberg' ),
array( 'status' => 403 )
);
}
Expand All @@ -89,23 +89,23 @@ public function create_item_permissions_check( $request ) {
if ( ! $post ) {
return new WP_Error(
'rest_comment_invalid_post_id',
__( 'Sorry, you are not allowed to create this comment without a post.' ),
__( 'Sorry, you are not allowed to create this comment without a post.', 'gutenberg' ),
array( 'status' => 403 )
);
}

if ( 'trash' === $post->post_status ) {
return new WP_Error(
'rest_comment_trash_post',
__( 'Sorry, you are not allowed to create a comment on this post.' ),
__( 'Sorry, you are not allowed to create a comment on this post.', 'gutenberg' ),
array( 'status' => 403 )
);
}

if ( ! $this->check_read_post_permission( $post, $request ) ) {
return new WP_Error(
'rest_cannot_read_post',
__( 'Sorry, you are not allowed to read the post for this comment.' ),
__( 'Sorry, you are not allowed to read the post for this comment.', 'gutenberg' ),
array( 'status' => rest_authorization_required_code() )
);
}
Expand All @@ -117,7 +117,7 @@ public function create_item_permissions_check( $request ) {
add_action(
'rest_api_init',
function () {
$controller = new Gutenberg_REST_Comment_Controller_6_8();
$controller = new Gutenberg_REST_Comment_Controller();
$controller->register_routes();
}
);
8 changes: 6 additions & 2 deletions lib/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ function gutenberg_is_experiment_enabled( $name ) {
require __DIR__ . '/compat/wordpress-6.7/rest-api.php';

// WordPress 6.8 compat.
require __DIR__ . '/compat/wordpress-6.8/block-comments.php';
require __DIR__ . '/compat/wordpress-6.8/class-gutenberg-rest-comment-controller-6-8.php';
require __DIR__ . '/compat/wordpress-6.8/class-gutenberg-hierarchical-sort.php';
require __DIR__ . '/compat/wordpress-6.8/rest-api.php';

Expand All @@ -54,6 +52,12 @@ function gutenberg_is_experiment_enabled( $name ) {

require_once __DIR__ . '/experimental/rest-api.php';
require_once __DIR__ . '/experimental/kses-allowed-html.php';

// Block Comments.
if ( gutenberg_is_experiment_enabled( 'gutenberg-block-comment' ) ) {
require __DIR__ . '/experimental/block-comments.php';
require __DIR__ . '/experimental/class-gutenberg-rest-comment-controller.php';
}
}

// Experimental signaling server.
Expand Down

0 comments on commit 654bace

Please sign in to comment.