Files
wp-strava/src/WPStrava/Blocks/Activity.php
T

49 lines
1.2 KiB
PHP
Raw Normal View History

2020-02-28 13:39:42 -06:00
<?php
/*
* Activity block.
*/
2020-03-27 16:39:57 -05:00
2020-02-28 13:39:42 -06:00
class WPStrava_Blocks_Activity implements WPStrava_Blocks_Interface {
2020-03-27 16:39:57 -05:00
/**
* Register the wp-strava/activity block.
*
* @author Justin Foell <justin@foell.org>
* @since 2.2.0
*/
2020-02-28 13:39:42 -06:00
public function register_block() {
register_block_type(
'wp-strava/activity',
array(
'style' => 'wp-strava-block',
'editor_style' => 'wp-strava-block-editor',
'editor_script' => 'wp-strava-block',
'render_callback' => array( $this, 'render_block' ),
)
);
}
2020-03-27 16:39:57 -05:00
/**
* Render for this block.
*
* @param array $attributes JSON attributes saved in the HTML comment for this block.
* @param string $content The content from JS save() for this block.
* @return string HTML for this block.
2020-03-27 16:56:12 -05:00
* @author Justin Foell <justin@foell.org>
2020-03-27 16:39:57 -05:00
* @since 2.2.0
*/
2020-02-28 13:39:42 -06:00
public function render_block( $attributes, $content ) {
2020-03-27 16:39:57 -05:00
if ( empty( $attributes['url'] ) ) {
return $content;
}
2020-02-28 13:39:42 -06:00
2020-03-27 16:39:57 -05:00
$matches = [];
preg_match( "/\/activities\/([0-9].*)$/", $attributes['url'], $matches );
if ( $matches[1] ) {
$renderer = new WPStrava_ActivityRenderer();
return $renderer->get_html( array( 'id' => $matches[1] ) );
}
return $content;
2020-02-28 13:39:42 -06:00
}
}