diff options
Diffstat (limited to 'plugins/jetpack/extensions/blocks/business-hours/business-hours.php')
-rw-r--r-- | plugins/jetpack/extensions/blocks/business-hours/business-hours.php | 38 |
1 files changed, 27 insertions, 11 deletions
diff --git a/plugins/jetpack/extensions/blocks/business-hours/business-hours.php b/plugins/jetpack/extensions/blocks/business-hours/business-hours.php index d3afa01d..4de0593a 100644 --- a/plugins/jetpack/extensions/blocks/business-hours/business-hours.php +++ b/plugins/jetpack/extensions/blocks/business-hours/business-hours.php @@ -4,20 +4,36 @@ * * @since 7.1.0 * - * @package Jetpack + * @package automattic/jetpack */ -jetpack_register_block( - 'jetpack/business-hours', - array( 'render_callback' => 'jetpack_business_hours_render' ) -); +namespace Automattic\Jetpack\Extensions\Business_Hours; + +use Automattic\Jetpack\Blocks; +use Jetpack_Gutenberg; + +const FEATURE_NAME = 'business-hours'; +const BLOCK_NAME = 'jetpack/' . FEATURE_NAME; + +/** + * Registers the block for use in Gutenberg + * This is done via an action so that we can disable + * registration if we need to. + */ +function register_block() { + Blocks::jetpack_register_block( + BLOCK_NAME, + array( 'render_callback' => __NAMESPACE__ . '\render' ) + ); +} +add_action( 'init', __NAMESPACE__ . '\register_block' ); /** * Get's default days / hours to render a business hour block with no data provided. * * @return array */ -function jetpack_business_hours_get_default_days() { +function get_default_days() { return array( array( 'name' => 'Sun', @@ -82,11 +98,11 @@ function jetpack_business_hours_get_default_days() { * * @return string */ -function jetpack_business_hours_render( $attributes ) { +function render( $attributes ) { global $wp_locale; if ( empty( $attributes['days'] ) || ! is_array( $attributes['days'] ) ) { - $attributes['days'] = jetpack_business_hours_get_default_days(); + $attributes['days'] = get_default_days(); } $start_of_week = (int) get_option( 'start_of_week', 0 ); @@ -119,8 +135,8 @@ function jetpack_business_hours_render( $attributes ) { } $days_hours .= sprintf( '%1$s - %2$s', - date( $time_format, $opening ), - date( $time_format, $closing ) + gmdate( $time_format, $opening ), + gmdate( $time_format, $closing ) ); if ( $key + 1 < count( $day['hours'] ) ) { $days_hours .= ', '; @@ -136,7 +152,7 @@ function jetpack_business_hours_render( $attributes ) { $content .= '</dl>'; - Jetpack_Gutenberg::load_assets_as_required( 'business-hours' ); + Jetpack_Gutenberg::load_assets_as_required( FEATURE_NAME ); /** * Allows folks to filter the HTML content for the Business Hours block |