Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block Library: Try to standardize PHP function names used #20085

Merged
merged 3 commits into from
Feb 10, 2020
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
2 changes: 1 addition & 1 deletion lib/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ function gutenberg_register_legacy_social_link_blocks() {
'type' => 'string',
),
),
'render_callback' => 'gutenberg_render_core_social_link',
'render_callback' => 'gutenberg_render_block_core_social_link',
)
);
}
Expand Down
8 changes: 4 additions & 4 deletions packages/block-library/src/legacy-widget/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*
* @return string Returns the rendered widget as a string.
*/
function render_widget_by_id( $id ) {
function block_core_legacy_widget_render_widget_by_id( $id ) {
// Code extracted from src/wp-includes/widgets.php dynamic_sidebar function.
// Todo: When merging to core extract this part of dynamic_sidebar into its own function.
global $wp_registered_widgets;
Expand Down Expand Up @@ -71,7 +71,7 @@ function render_widget_by_id( $id ) {
*
* @return string Returns the post content with the legacy widget added.
*/
function render_block_legacy_widget( $attributes ) {
function render_block_core_legacy_widget( $attributes ) {
$id = null;
$widget_class = null;
if ( isset( $attributes['id'] ) ) {
Expand All @@ -82,7 +82,7 @@ function render_block_legacy_widget( $attributes ) {
}

if ( $id ) {
return render_widget_by_id( $id );
return block_core_legacy_widget_render_widget_by_id( $id );
}
if ( ! $widget_class ) {
return '';
Expand Down Expand Up @@ -121,7 +121,7 @@ function register_block_core_legacy_widget() {
'type' => 'object',
),
),
'render_callback' => 'render_block_legacy_widget',
'render_callback' => 'render_block_core_legacy_widget',
)
);
}
Expand Down
30 changes: 15 additions & 15 deletions packages/block-library/src/navigation/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* @param array $attributes Navigation block attributes.
* @return array Colors CSS classes and inline styles.
*/
function core_block_navigation_build_css_colors( $attributes ) {
function block_core_navigation_build_css_colors( $attributes ) {
$colors = array(
'css_classes' => array(),
'inline_styles' => '',
Expand Down Expand Up @@ -64,7 +64,7 @@ function core_block_navigation_build_css_colors( $attributes ) {
* @param array $attributes Navigation block attributes.
* @return array Font size CSS classes and inline styles.
*/
function core_block_navigation_build_css_font_sizes( $attributes ) {
function block_core_navigation_build_css_font_sizes( $attributes ) {
// CSS classes.
$font_sizes = array(
'css_classes' => array(),
Expand All @@ -91,7 +91,7 @@ function core_block_navigation_build_css_font_sizes( $attributes ) {
* @param array $blocks Navigation link inner blocks from the Navigation block.
* @return array Blocks that had valid labels
*/
function core_block_navigation_empty_navigation_links_recursive( $blocks ) {
function block_core_navigation_empty_navigation_links_recursive( $blocks ) {
$blocks = array_filter(
$blocks,
function( $block ) {
Expand All @@ -102,7 +102,7 @@ function( $block ) {
if ( ! empty( $blocks ) ) {
foreach ( $blocks as $key => $block ) {
if ( ! empty( $block['innerBlocks'] ) ) {
$blocks[ $key ]['innerBlocks'] = core_block_navigation_empty_navigation_links_recursive( $block['innerBlocks'] );
$blocks[ $key ]['innerBlocks'] = block_core_navigation_empty_navigation_links_recursive( $block['innerBlocks'] );
}
}
}
Expand All @@ -115,7 +115,7 @@ function( $block ) {
*
* @return string
*/
function core_block_navigation_render_submenu_icon() {
function block_core_navigation_render_submenu_icon() {
return '<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" transform="rotate(90)"><path d="M8 5v14l11-7z"/><path d="M0 0h24v24H0z" fill="none"/></svg>';
}

Expand All @@ -127,13 +127,13 @@ function core_block_navigation_render_submenu_icon() {
*
* @return string Returns the post content with the legacy widget added.
*/
function render_block_navigation( $content, $block ) {
function render_block_core_navigation( $content, $block ) {

if ( 'core/navigation' !== $block['blockName'] ) {
return $content;
}

$block['innerBlocks'] = core_block_navigation_empty_navigation_links_recursive( $block['innerBlocks'] );
$block['innerBlocks'] = block_core_navigation_empty_navigation_links_recursive( $block['innerBlocks'] );
$attributes = $block['attrs'];

/**
Expand All @@ -157,8 +157,8 @@ function render_block_navigation( $content, $block ) {
return '';
}

$colors = core_block_navigation_build_css_colors( $attributes );
$font_sizes = core_block_navigation_build_css_font_sizes( $attributes );
$colors = block_core_navigation_build_css_colors( $attributes );
$font_sizes = block_core_navigation_build_css_font_sizes( $attributes );
$classes = array_merge(
$colors['css_classes'],
$font_sizes['css_classes'],
Expand All @@ -176,7 +176,7 @@ function render_block_navigation( $content, $block ) {
'<nav %1$s %2$s>%3$s</nav>',
$class_attribute,
$style_attribute,
core_block_navigation_build_html( $attributes, $block, $colors, $font_sizes, true )
block_core_navigation_build_html( $attributes, $block, $colors, $font_sizes, true )
);
}

Expand All @@ -190,7 +190,7 @@ function render_block_navigation( $content, $block ) {
*
* @return string Returns an HTML list from innerBlocks.
*/
function core_block_navigation_build_html( $attributes, $block, $colors, $font_sizes ) {
function block_core_navigation_build_html( $attributes, $block, $colors, $font_sizes ) {
$html = '';
$classes = array_merge(
$colors['css_classes'],
Expand Down Expand Up @@ -257,14 +257,14 @@ function core_block_navigation_build_html( $attributes, $block, $colors, $font_s
) &&
$has_submenu
) {
$html .= '<span class="wp-block-navigation-link__submenu-icon">' . core_block_navigation_render_submenu_icon() . '</span>';
$html .= '<span class="wp-block-navigation-link__submenu-icon">' . block_core_navigation_render_submenu_icon() . '</span>';
}

$html .= '</a>';
// End anchor tag content.

if ( $has_submenu ) {
$html .= core_block_navigation_build_html( $attributes, $block, $colors, $font_sizes, false );
$html .= block_core_navigation_build_html( $attributes, $block, $colors, $font_sizes, false );
}

$html .= '</li>';
Expand All @@ -275,7 +275,7 @@ function core_block_navigation_build_html( $attributes, $block, $colors, $font_s
/**
* Register the navigation block.
*
* @uses render_block_navigation()
* @uses render_block_core_navigation()
* @throws WP_Error An WP_Error exception parsing the block definition.
*/
function register_block_core_navigation() {
Expand Down Expand Up @@ -325,4 +325,4 @@ function register_block_core_navigation() {
);
}
add_action( 'init', 'register_block_core_navigation' );
add_filter( 'render_block', 'render_block_navigation', 10, 2 );
add_filter( 'render_block', 'render_block_core_navigation', 10, 2 );
18 changes: 9 additions & 9 deletions packages/block-library/src/social-link/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@
*
* @return string Rendered HTML of the referenced block.
*/
function render_core_social_link( $attributes ) {
function render_block_core_social_link( $attributes ) {
$service = ( isset( $attributes['service'] ) ) ? $attributes['service'] : 'Icon';
$url = ( isset( $attributes['url'] ) ) ? $attributes['url'] : false;
$label = ( isset( $attributes['label'] ) ) ? $attributes['label'] : __( 'Link to ' ) . core_social_link_get_name( $service );
$label = ( isset( $attributes['label'] ) ) ? $attributes['label'] : __( 'Link to ' ) . block_core_social_link_get_name( $service );

// Don't render a link if there is no URL set.
if ( ! $url ) {
return '';
}

$icon = core_social_link_get_icon( $service );
$icon = block_core_social_link_get_icon( $service );
return '<li class="wp-social-link wp-social-link-' . $service . '"><a href="' . esc_url( $url ) . '" aria-label="' . esc_attr( $label ) . '"> ' . $icon . '</a></li>';
}

Expand All @@ -38,7 +38,7 @@ function register_block_core_social_link() {
array_merge(
$metadata,
array(
'render_callback' => 'render_core_social_link',
'render_callback' => 'render_block_core_social_link',
)
)
);
Expand All @@ -53,8 +53,8 @@ function register_block_core_social_link() {
*
* @return string SVG Element for site icon.
*/
function core_social_link_get_icon( $site ) {
$sites = core_social_link_sites();
function block_core_social_link_get_icon( $site ) {
$sites = block_core_social_link_sites();
if ( isset( $sites[ $site ] ) && isset( $sites[ $site ]['icon'] ) ) {
return $sites[ $site ]['icon'];
}
Expand All @@ -69,8 +69,8 @@ function core_social_link_get_icon( $site ) {
*
* @return string Brand label.
*/
function core_social_link_get_name( $site ) {
$sites = core_social_link_sites();
function block_core_social_link_get_name( $site ) {
$sites = block_core_social_link_sites();
if ( isset( $sites[ $site ] ) && isset( $sites[ $site ]['name'] ) ) {
return $sites[ $site ]['name'];
}
Expand All @@ -86,7 +86,7 @@ function core_social_link_get_name( $site ) {
*
* @return array|string
*/
function core_social_link_sites( $site = '', $field = '' ) {
function block_core_social_link_sites( $site = '', $field = '' ) {
$sites_data = array(
'fivehundredpx' => array(
'name' => '500px',
Expand Down