-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Inline comment experimental flag (#60622)
Co-authored-by: MD-sunilprajapati <spmultidots@git.wordpress.org> Co-authored-by: poojabhimani12 <poojabhimani@git.wordpress.org> Co-authored-by: rishishah-multidots <rishishah@git.wordpress.org> Co-authored-by: ingeniumed <ingeniumed@git.wordpress.org> Co-authored-by: ellatrix <ellatrix@git.wordpress.org> Co-authored-by: tyxla <tyxla@git.wordpress.org> Co-authored-by: ciampo <mciampini@git.wordpress.org> Co-authored-by: mtias <matveb@git.wordpress.org> Co-authored-by: jasmussen <joen@git.wordpress.org> Co-authored-by: youknowriad <youknowriad@git.wordpress.org> Co-authored-by: annezazu <annezazu@git.wordpress.org> Co-authored-by: jameskoster <jameskoster@git.wordpress.org>
- Loading branch information
1 parent
1ca8001
commit a775b7c
Showing
22 changed files
with
1,276 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
https://github.com/WordPress/wordpress-develop/pull/7488 | ||
|
||
* https://github.com/WordPress/gutenberg/pull/60622 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
https://github.com/WordPress/wordpress-develop/pull/7498 | ||
|
||
* https://github.com/WordPress/gutenberg/pull/60622 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
/** | ||
* Updates the comment type in the REST API for WordPress version 6.7. | ||
* | ||
* 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, | ||
* and if so, updates the 'comment_type' and 'comment_approved' properties of the prepared comment. | ||
* | ||
* @param array $prepared_comment The prepared comment data. | ||
* @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' ) ) { | ||
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']; | ||
$prepared_comment['comment_approved'] = $request['comment_approved']; | ||
} | ||
|
||
return $prepared_comment; | ||
} | ||
add_filter( 'rest_pre_insert_comment', 'update_comment_type_in_rest_api_6_8', 10, 2 ); | ||
} | ||
|
||
/** | ||
* Updates the comment type for avatars in the WordPress REST API. | ||
* | ||
* This function adds the 'block_comment' type to the list of comment types | ||
* for which avatars should be retrieved in the WordPress REST API. | ||
* | ||
* @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' ) ) { | ||
function update_get_avatar_comment_type( $comment_type ) { | ||
$comment_type[] = 'block_comment'; | ||
return $comment_type; | ||
} | ||
add_filter( 'get_avatar_comment_types', 'update_get_avatar_comment_type' ); | ||
} | ||
|
||
/** | ||
* Excludes block comments from the admin comments query. | ||
* | ||
* This function modifies the comments query to exclude comments of type 'block_comment' | ||
* when the query is for comments in the WordPress admin. | ||
* | ||
* @param WP_Comment_Query $query The current comments query. | ||
* | ||
* @return void | ||
*/ | ||
if ( ! function_exists( 'exclude_block_comments_from_admin' ) && gutenberg_is_experiment_enabled( 'gutenberg-block-comment' ) ) { | ||
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'] ) { | ||
$query->set( 'type', '' ); | ||
|
||
add_filter( | ||
'comments_clauses', | ||
function ( $clauses ) { | ||
global $wpdb; | ||
// Exclude comments of type 'block_comment' | ||
$clauses['where'] .= " AND {$wpdb->comments}.comment_type != 'block_comment'"; | ||
return $clauses; | ||
} | ||
); | ||
} | ||
} | ||
add_action( 'pre_get_comments', 'exclude_block_comments_from_admin' ); | ||
} |
135 changes: 135 additions & 0 deletions
135
lib/compat/wordpress-6.8/class-gutenberg-rest-comment-controller-6-8.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
<?php | ||
/** | ||
* A custom REST server for Gutenberg. | ||
* | ||
* @package gutenberg | ||
* @since 6.8.0 | ||
*/ | ||
|
||
// Create a new class that extends WP_REST_Comments_Controller | ||
class Gutenberg_REST_Comment_Controller_6_8 extends WP_REST_Comments_Controller { | ||
|
||
public function create_item_permissions_check( $request ) { | ||
if ( ! is_user_logged_in() ) { | ||
if ( get_option( 'comment_registration' ) ) { | ||
return new WP_Error( | ||
'rest_comment_login_required', | ||
__( 'Sorry, you must be logged in to comment.' ), | ||
array( 'status' => 401 ) | ||
); | ||
} | ||
|
||
/** | ||
* Filters whether comments can be created via the REST API without authentication. | ||
* | ||
* Enables creating comments for anonymous users. | ||
* | ||
* @since 4.7.0 | ||
* | ||
* @param bool $allow_anonymous Whether to allow anonymous comments to | ||
* be created. Default `false`. | ||
* @param WP_REST_Request $request Request used to generate the | ||
* response. | ||
*/ | ||
$allow_anonymous = apply_filters( 'rest_allow_anonymous_comments', false, $request ); | ||
|
||
if ( ! $allow_anonymous ) { | ||
return new WP_Error( | ||
'rest_comment_login_required', | ||
__( 'Sorry, you must be logged in to comment.' ), | ||
array( 'status' => 401 ) | ||
); | ||
} | ||
} | ||
|
||
// Limit who can set comment `author`, `author_ip` or `status` to anything other than the default. | ||
if ( isset( $request['author'] ) && get_current_user_id() !== $request['author'] && ! current_user_can( 'moderate_comments' ) ) { | ||
return new WP_Error( | ||
'rest_comment_invalid_author', | ||
/* translators: %s: Request parameter. */ | ||
sprintf( __( "Sorry, you are not allowed to edit '%s' for comments." ), 'author' ), | ||
array( 'status' => rest_authorization_required_code() ) | ||
); | ||
} | ||
|
||
if ( isset( $request['author_ip'] ) && ! current_user_can( 'moderate_comments' ) ) { | ||
if ( empty( $_SERVER['REMOTE_ADDR'] ) || $request['author_ip'] !== $_SERVER['REMOTE_ADDR'] ) { | ||
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' ), | ||
array( 'status' => rest_authorization_required_code() ) | ||
); | ||
} | ||
} | ||
|
||
if ( isset( $request['status'] ) && ! current_user_can( 'moderate_comments' ) ) { | ||
return new WP_Error( | ||
'rest_comment_invalid_status', | ||
/* translators: %s: Request parameter. */ | ||
sprintf( __( "Sorry, you are not allowed to edit '%s' for comments." ), '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.' ), | ||
array( 'status' => 403 ) | ||
); | ||
} | ||
|
||
$post = get_post( (int) $request['post'] ); | ||
|
||
if ( ! $post ) { | ||
return new WP_Error( | ||
'rest_comment_invalid_post_id', | ||
__( 'Sorry, you are not allowed to create this comment without a post.' ), | ||
array( 'status' => 403 ) | ||
); | ||
} | ||
|
||
if ( 'draft' === $post->post_status && 'comment' === $request['comment_type'] ) { | ||
return new WP_Error( | ||
'rest_comment_draft_post', | ||
__( 'Sorry, you are not allowed to create a comment on this post.' ), | ||
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.' ), | ||
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.' ), | ||
array( 'status' => rest_authorization_required_code() ) | ||
); | ||
} | ||
|
||
if ( ! comments_open( $post->ID ) && 'comment' === $request['comment_type'] ) { | ||
return new WP_Error( | ||
'rest_comment_closed', | ||
__( 'Sorry, comments are closed for this item.' ), | ||
array( 'status' => 403 ) | ||
); | ||
} | ||
|
||
return true; | ||
} | ||
} | ||
|
||
add_action( | ||
'rest_api_init', | ||
function () { | ||
$controller = new Gutenberg_REST_Comment_Controller_6_8(); | ||
$controller->register_routes(); | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
packages/block-editor/src/components/collab/block-comment-icon-slot.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { createSlotFill } from '@wordpress/components'; | ||
|
||
const { Fill: __unstableCommentIconFill, Slot } = createSlotFill( | ||
'__unstableCommentIconFill' | ||
); | ||
|
||
__unstableCommentIconFill.Slot = Slot; | ||
|
||
export default __unstableCommentIconFill; |
12 changes: 12 additions & 0 deletions
12
packages/block-editor/src/components/collab/block-comment-icon-toolbar-slot.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { createSlotFill } from '@wordpress/components'; | ||
|
||
const { Fill: __unstableCommentIconToolbarFill, Slot } = createSlotFill( | ||
'__unstableCommentIconToolbarFill' | ||
); | ||
|
||
__unstableCommentIconToolbarFill.Slot = Slot; | ||
|
||
export default __unstableCommentIconToolbarFill; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
a775b7c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flaky tests detected in a775b7c.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.
🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/11484220856
📝 Reported issues:
/test/e2e/specs/editor/blocks/navigation-frontend-interactivity.spec.js