mirrored from git://develop.git.wordpress.org/
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rebuild using the proper packages versions
- Loading branch information
Showing
14 changed files
with
24,787 additions
and
24,395 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
/** | ||
* Server-side rendering of the `core/comments-title` block. | ||
* | ||
* @package WordPress | ||
*/ | ||
|
||
/** | ||
* Renders the `core/comments-title` block on the server. | ||
* | ||
* @param array $attributes Block attributes. | ||
* | ||
* @return string Return the post comments title. | ||
*/ | ||
function render_block_core_comments_title( $attributes ) { | ||
|
||
$align_class_name = empty( $attributes['textAlign'] ) ? '' : "has-text-align-{$attributes['textAlign']}"; | ||
$show_post_title = ! empty( $attributes['showPostTitle'] ) && $attributes['showPostTitle']; | ||
$show_comments_count = ! empty( $attributes['showCommentsCount'] ) && $attributes['showCommentsCount']; | ||
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $align_class_name ) ); | ||
$post_title = $show_post_title ? sprintf( '"%1$s"', get_the_title() ) : null; | ||
$comments_count = number_format_i18n( get_comments_number() ); | ||
$tag_name = 'h2'; | ||
if ( isset( $attributes['level'] ) ) { | ||
$tag_name = 'h' . $attributes['level']; | ||
} | ||
|
||
if ( '0' === $comments_count ) { | ||
return; | ||
} | ||
|
||
$single_default_comment_label = $show_post_title ? __( 'One response to' ) : __( 'One response' ); | ||
$single_comment_label = ! empty( $attributes['singleCommentLabel'] ) ? $attributes['singleCommentLabel'] : $single_default_comment_label; | ||
|
||
$multiple_default_comment_label = $show_post_title ? __( 'Responses to' ) : __( 'Responses' ); | ||
$multiple_comment_label = ! empty( $attributes['multipleCommentsLabel'] ) ? $attributes['multipleCommentsLabel'] : $multiple_default_comment_label; | ||
|
||
$comments_title = '%1$s %2$s %3$s'; | ||
|
||
$comments_title = sprintf( | ||
$comments_title, | ||
// If there is only one comment, only display the label. | ||
'1' !== $comments_count && $show_comments_count ? $comments_count : null, | ||
'1' === $comments_count ? $single_comment_label : $multiple_comment_label, | ||
$post_title | ||
); | ||
|
||
return sprintf( | ||
'<%1$s id="comments" %2$s>%3$s</%1$s>', | ||
$tag_name, | ||
$wrapper_attributes, | ||
$comments_title | ||
); | ||
} | ||
|
||
/** | ||
* Registers the `core/comments-title` block on the server. | ||
*/ | ||
function register_block_core_comments_title() { | ||
register_block_type_from_metadata( | ||
__DIR__ . '/comments-title', | ||
array( | ||
'render_callback' => 'render_block_core_comments_title', | ||
) | ||
); | ||
} | ||
|
||
add_action( 'init', 'register_block_core_comments_title' ); |
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 @@ | ||
{ | ||
"$schema": "https://schemas.wp.org/trunk/block.json", | ||
"apiVersion": 2, | ||
"name": "core/comments-title", | ||
"title": "Comments Title", | ||
"category": "theme", | ||
"ancestor": [ "core/comments-query-loop" ], | ||
"description": "Displays a title with the number of comments", | ||
"textdomain": "default", | ||
"usesContext": [ "postId", "postType" ], | ||
"attributes": { | ||
"textAlign": { | ||
"type": "string" | ||
}, | ||
"singleCommentLabel": { | ||
"type": "string" | ||
}, | ||
"multipleCommentsLabel": { | ||
"type": "string" | ||
}, | ||
"showPostTitle": { | ||
"type": "boolean", | ||
"default": true | ||
}, | ||
"showCommentsCount": { | ||
"type": "boolean", | ||
"default": true | ||
}, | ||
"level": { | ||
"type": "number", | ||
"default": 2 | ||
} | ||
}, | ||
"supports": { | ||
"anchor": false, | ||
"align": true, | ||
"html": false, | ||
"__experimentalBorder": { | ||
"radius": true, | ||
"color": true, | ||
"width": true, | ||
"style": true | ||
}, | ||
"color": { | ||
"gradients": true, | ||
"__experimentalDefaultControls": { | ||
"background": true, | ||
"text": true | ||
} | ||
}, | ||
"spacing": { | ||
"margin": true, | ||
"padding": true | ||
}, | ||
"typography": { | ||
"fontSize": true, | ||
"lineHeight": true, | ||
"__experimentalFontStyle": true, | ||
"__experimentalFontWeight": true, | ||
"__experimentalFontFamily": true, | ||
"__experimentalTextTransform": true, | ||
"__experimentalDefaultControls": { | ||
"fontSize": true, | ||
"__experimentalFontFamily": true, | ||
"__experimentalFontStyle": true, | ||
"__experimentalFontWeight": true | ||
} | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
/** | ||
* Server-side rendering of the `core/post-comments-form` block. | ||
* | ||
* @package WordPress | ||
*/ | ||
|
||
/** | ||
* Renders the `core/post-comments-form` block on the server. | ||
* | ||
* @param array $attributes Block attributes. | ||
* @param string $content Block default content. | ||
* @param WP_Block $block Block instance. | ||
* @return string Returns the filtered post comments form for the current post. | ||
*/ | ||
function render_block_core_post_comments_form( $attributes, $content, $block ) { | ||
if ( ! isset( $block->context['postId'] ) ) { | ||
return ''; | ||
} | ||
|
||
$classes = 'comment-respond'; // See comment further below. | ||
if ( isset( $attributes['textAlign'] ) ) { | ||
$classes .= 'has-text-align-' . $attributes['textAlign']; | ||
} | ||
|
||
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classes ) ); | ||
|
||
ob_start(); | ||
comment_form( array(), $block->context['postId'] ); | ||
$form = ob_get_clean(); | ||
|
||
// We use the outermost wrapping `<div />` returned by `comment_form()` | ||
// which is identified by its default classname `comment-respond` to inject | ||
// our wrapper attributes. This way, it is guaranteed that all styling applied | ||
// to the block is carried along when the comment form is moved to the location | ||
// of the 'Reply' link that the user clicked by Core's `comment-reply.js` script. | ||
$form = str_replace( 'class="comment-respond"', $wrapper_attributes, $form ); | ||
|
||
// Enqueue the comment-reply script. | ||
wp_enqueue_script( 'comment-reply' ); | ||
|
||
return $form; | ||
} | ||
|
||
/** | ||
* Registers the `core/post-comments-form` block on the server. | ||
*/ | ||
function register_block_core_post_comments_form() { | ||
register_block_type_from_metadata( | ||
__DIR__ . '/post-comments-form', | ||
array( | ||
'render_callback' => 'render_block_core_post_comments_form', | ||
) | ||
); | ||
} | ||
add_action( 'init', 'register_block_core_post_comments_form' ); | ||
|
||
/** | ||
* Use the button block classes for the form-submit button. | ||
* | ||
* @param array $fields The default comment form arguments. | ||
* | ||
* @return array Returns the modified fields. | ||
*/ | ||
function post_comments_form_block_form_defaults( $fields ) { | ||
if ( wp_is_block_theme() ) { | ||
$fields['submit_button'] = '<input name="%1$s" type="submit" id="%2$s" class="%3$s wp-block-button__link" value="%4$s" />'; | ||
$fields['submit_field'] = '<p class="form-submit wp-block-button">%1$s %2$s</p>'; | ||
} | ||
|
||
return $fields; | ||
} | ||
add_filter( 'comment_form_defaults', 'post_comments_form_block_form_defaults' ); |
Oops, something went wrong.