implement Gutenberg block to add liveticker without legacy shortcode

* implement react-based JS block
* refactor shortcode and widget to use the same syntax and classes
This commit is contained in:
2019-11-23 17:54:53 +01:00
parent e201d7c02f
commit 9ddcc41c6b
11 changed files with 168 additions and 16 deletions

View File

@ -202,4 +202,35 @@ class SCLiveticker_Admin extends SCLiveticker {
return $result;
}
/**
* Register custom Gutenberg block type.
*
* @return void
* @since 1.1
*/
public static function register_block() {
wp_register_script(
'scliveticker-editor',
SCLIVETICKER_BASE . 'scripts/block.min.js',
array( 'wp-blocks', 'wp-element' ),
self::VERSION,
true
);
wp_register_style(
'scliveticker-editor',
SCLIVETICKER_BASE . 'styles/block.min.css',
array(),
self::VERSION
);
register_block_type(
'scliveticker-block/liveticker',
array(
'editor_script' => 'scliveticker-editor',
'editor_style' => 'scliveticker-editor',
)
);
}
}

View File

@ -70,7 +70,7 @@ class SCLiveticker_Widget extends WP_Widget {
echo '<ul class="sclt-widget';
if ( '1' === $ajax ) {
echo ' sclt-widget-ajax" '
echo ' sclt-ajax" '
. 'data-sclt-ticker="' . esc_attr( $category ) . '" '
. 'data-sclt-limit="' . esc_attr( $count ) . '" '
. 'data-sclt-last="' . esc_attr( current_datetime()->getTimestamp() );

View File

@ -198,14 +198,14 @@ class SCLiveticker {
$show_feed = 1 === self::$options['show_feed'];
}
$output = '<ul class="sclt-ticker';
$output = '<div class="wp-block-scliveticker-ticker';
if ( 1 === self::$options['enable_ajax'] ) {
$output .= ' sclt-ticker-ajax" '
$output .= ' sclt-ajax" '
. 'data-sclt-ticker="' . $ticker . '" '
. 'data-sclt-limit="' . $limit . '" '
. 'data-sclt-last="' . current_datetime()->getTimestamp();
}
$output .= '">';
$output .= '"><ul>';
$args = array(
'post_type' => 'scliveticker_tick',
@ -226,7 +226,7 @@ class SCLiveticker {
$output .= self::tick_html( get_the_time( 'd.m.Y H.i' ), get_the_title(), get_the_content() );
}
$output .= '</ul>';
$output .= '</ul></div>';
// Show RSS feed link, if configured.
if ( $show_feed ) {