', esc_url( $src ), esc_attr__( 'Electricity price today per hour, via voltij.nl', 'voltij-stroomprijs' ) ); if ( $link ) { $img = sprintf( '%3$s', esc_url( 'https://voltij.nl/?utm_source=wordpress' ), esc_attr__( 'Electricity price per hour on voltij.nl', 'voltij-stroomprijs' ), $img ); } return '
' . $img . '
'; } /** * Registers the editor script and the block. */ function voltij_stroomprijs_register_block() { wp_register_script( 'voltij-stroomprijs-editor', plugins_url( 'blocks/stroomprijs/index.js', __FILE__ ), array( 'wp-blocks', 'wp-element', 'wp-block-editor', 'wp-components', 'wp-i18n' ), VOLTIJ_STROOMPRIJS_VERSION, true ); wp_set_script_translations( 'voltij-stroomprijs-editor', 'voltij-stroomprijs' ); register_block_type( __DIR__ . '/blocks/stroomprijs', array( 'render_callback' => 'voltij_stroomprijs_render_block' ) ); } add_action( 'init', 'voltij_stroomprijs_register_block' ); /** * Server-side render of the block. * * @param array $attributes Block attributes. * @return string */ function voltij_stroomprijs_render_block( $attributes ) { $theme = ( isset( $attributes['theme'] ) && 'dark' === $attributes['theme'] ) ? 'dark' : 'light'; $link = ! empty( $attributes['link'] ); return voltij_stroomprijs_html( $theme, $link, get_block_wrapper_attributes( array( 'class' => 'voltij-stroomprijs' ) ) ); } /** * Shortcode: [voltij_stroomprijs theme="dark" link="yes"] * * @param array|string $atts Shortcode attributes. * @return string */ function voltij_stroomprijs_shortcode( $atts ) { $atts = shortcode_atts( array( 'theme' => 'light', 'link' => 'no', ), $atts, 'voltij_stroomprijs' ); $theme = ( 'dark' === $atts['theme'] ) ? 'dark' : 'light'; $link = in_array( strtolower( (string) $atts['link'] ), array( 'yes', 'ja', '1', 'true' ), true ); return voltij_stroomprijs_html( $theme, $link ); } add_shortcode( 'voltij_stroomprijs', 'voltij_stroomprijs_shortcode' ); require_once __DIR__ . '/includes/class-voltij-stroomprijs-widget.php'; /** * Registers the classic widget. */ function voltij_stroomprijs_register_widget() { register_widget( 'Voltij_Stroomprijs_Widget' ); } add_action( 'widgets_init', 'voltij_stroomprijs_register_widget' );