Files
wp-strava/blocks/activity/index.php
T
2019-12-27 14:40:27 -06:00

51 lines
1.4 KiB
PHP

<?php
/**
* Functions to register client-side assets (scripts and stylesheets) for the
* Gutenberg block.
*
* @package wp-strava
*/
/**
* Registers all block assets so that they can be enqueued through Gutenberg in
* the corresponding context.
*
* @see https://wordpress.org/gutenberg/handbook/blocks/writing-your-first-block-type/#enqueuing-block-scripts
*/
function register_activity_block() {
// automatically load dependencies and version
$asset_file = include plugin_dir_path( __FILE__ ) . 'build/index.asset.php';
wp_register_script(
'wp-strava/activity',
plugins_url( 'build/index.js', __FILE__ ),
$asset_file['dependencies'],
$asset_file['version']
);
wp_register_style(
'wp-strava/activity',
plugins_url( 'style.css', __FILE__ ),
array(),
filemtime( plugin_dir_path( __FILE__ ) . 'style.css' )
);
register_block_type(
'wp-strava/activity',
array(
'style' => 'wp-strava/activity',
'editor_script' => 'wp-strava/activity',
)
);
if ( function_exists( 'wp_set_script_translations' ) ) {
/**
* May be extended to wp_set_script_translations( 'my-handle', 'my-domain',
* plugin_dir_path( MY_PLUGIN ) . 'languages' ) ). For details see
* https://make.wordpress.org/core/2018/11/09/new-javascript-i18n-support-in-wordpress/
*/
wp_set_script_translations( 'wp-strava/activity', 'wp-strava' );
}
}
add_action( 'init', 'register_activity_block' );