Skip to content

Commit

Permalink
Rename functions, removing gutenberg_ prefix (#12326)
Browse files Browse the repository at this point in the history
* Rename functions, removing gutenberg_ and prefixing with wp_

* Remove wp_ prefix to match core

* Remove function check per review
  • Loading branch information
mkaz authored and youknowriad committed Dec 9, 2018
1 parent 4ea5094 commit 4bb3b0c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 34 deletions.
5 changes: 1 addition & 4 deletions lib/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,7 @@
if ( ! function_exists( 'render_block_core_categories' ) ) {
require dirname( __FILE__ ) . '/../packages/block-library/src/categories/index.php';
}
// Currently merged in core as `gutenberg_render_block_core_latest_comments`,
// expected to change soon.
if ( ! function_exists( 'render_block_core_latest_comments' )
&& ! function_exists( 'gutenberg_render_block_core_latest_comments' ) ) {
if ( ! function_exists( 'render_block_core_latest_comments' ) ) {
require dirname( __FILE__ ) . '/../packages/block-library/src/latest-comments/index.php';
}
if ( ! function_exists( 'render_block_core_latest_posts' ) ) {
Expand Down
58 changes: 28 additions & 30 deletions packages/block-library/src/latest-comments/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,32 @@
* @package WordPress
*/

if ( ! function_exists( 'gutenberg_draft_or_post_title' ) ) {
/**
* Get the post title.
*
* The post title is fetched and if it is blank then a default string is
* returned.
*
* Copied from `wp-admin/includes/template.php`, but we can't include that
* file because:
*
* 1. It causes bugs with test fixture generation and strange Docker 255 error
* codes.
* 2. It's in the admin; ideally we *shouldn't* be including files from the
* admin for a block's output. It's a very small/simple function as well,
* so duplicating it isn't too terrible.
*
* @since 3.3.0
*
* @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
* @return string The post title if set; "(no title)" if no title is set.
*/
function gutenberg_draft_or_post_title( $post = 0 ) {
$title = get_the_title( $post );
if ( empty( $title ) ) {
$title = __( '(no title)' );
}
return esc_html( $title );
/**
* Get the post title.
*
* The post title is fetched and if it is blank then a default string is
* returned.
*
* Copied from `wp-admin/includes/template.php`, but we can't include that
* file because:
*
* 1. It causes bugs with test fixture generation and strange Docker 255 error
* codes.
* 2. It's in the admin; ideally we *shouldn't* be including files from the
* admin for a block's output. It's a very small/simple function as well,
* so duplicating it isn't too terrible.
*
* @since 3.3.0
*
* @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
* @return string The post title if set; "(no title)" if no title is set.
*/
function wp_latest_comments_draft_or_post_title( $post = 0 ) {
$title = get_the_title( $post );
if ( empty( $title ) ) {
$title = __( '(no title)' );
}
return esc_html( $title );
}

/**
Expand All @@ -42,7 +40,7 @@ function gutenberg_draft_or_post_title( $post = 0 ) {
*
* @return string Returns the post content with latest comments added.
*/
function gutenberg_render_block_core_latest_comments( $attributes = array() ) {
function render_block_core_latest_comments( $attributes = array() ) {
// This filter is documented in wp-includes/widgets/class-wp-widget-recent-comments.php.
$comments = get_comments(
apply_filters(
Expand Down Expand Up @@ -94,7 +92,7 @@ function gutenberg_render_block_core_latest_comments( $attributes = array() ) {

// `_draft_or_post_title` calls `esc_html()` so we don't need to wrap that call in
// `esc_html`.
$post_title = '<a class="wp-block-latest-comments__comment-link" href="' . esc_url( get_comment_link( $comment ) ) . '">' . gutenberg_draft_or_post_title( $comment->comment_post_ID ) . '</a>';
$post_title = '<a class="wp-block-latest-comments__comment-link" href="' . esc_url( get_comment_link( $comment ) ) . '">' . wp_latest_comments_draft_or_post_title( $comment->comment_post_ID ) . '</a>';

$list_items_markup .= sprintf(
/* translators: 1: author name (inside <a> or <span> tag, based on if they have a URL), 2: post title related to this comment */
Expand Down Expand Up @@ -179,6 +177,6 @@ function gutenberg_render_block_core_latest_comments( $attributes = array() ) {
'enum' => array( 'center', 'left', 'right', 'wide', 'full', '' ),
),
),
'render_callback' => 'gutenberg_render_block_core_latest_comments',
'render_callback' => 'render_block_core_latest_comments',
)
);

0 comments on commit 4bb3b0c

Please sign in to comment.