array( $this, 'render_block' ), 'attributes' => array( 'beforeImage' => array( 'type' => 'string', 'default' => '' ), 'afterImage' => array( 'type' => 'string', 'default' => '' ), 'beforeImageId' => array( 'type' => 'number', 'default' => 0 ), 'afterImageId' => array( 'type' => 'number', 'default' => 0 ), 'startPosition' => array( 'type' => 'number', 'default' => 50 ), 'mode' => array( 'type' => 'string', 'default' => 'slider' ), 'orientation' => array( 'type' => 'string', 'default' => 'horizontal' ), 'labelBefore' => array( 'type' => 'string', 'default' => '' ), 'labelAfter' => array( 'type' => 'string', 'default' => '' ), 'dividerColor' => array( 'type' => 'string', 'default' => '#ffffff' ), 'hoverMode' => array( 'type' => 'boolean', 'default' => false ), 'animateIn' => array( 'type' => 'boolean', 'default' => false ), 'cssClass' => array( 'type' => 'string', 'default' => '' ), ), ) ); } /** * Enqueue editor-only assets (block JS + CSS). */ public function enqueue_editor_assets() { wp_enqueue_script( 'bfas-block-editor', BFAS_PLUGIN_URL . 'block/bfas-block.js', array( 'wp-blocks', 'wp-element', 'wp-block-editor', 'wp-components', 'wp-i18n' ), BFAS_VERSION, true ); wp_enqueue_style( 'bfas-block-editor', BFAS_PLUGIN_URL . 'admin/css/bfas-editor.css', array( 'wp-edit-blocks' ), BFAS_VERSION ); } /** * Server-side render callback for the block. * * @param array $attributes Block attributes. * @return string */ public function render_block( $attributes ) { $shortcode = new BFAS_Shortcode(); $before_url = esc_url( $attributes['beforeImage'] ); $after_url = esc_url( $attributes['afterImage'] ); if ( empty( $before_url ) || empty( $after_url ) ) { return ''; } wp_enqueue_style( 'bfas-frontend' ); wp_enqueue_script( 'bfas-frontend' ); $atts = array( 'before' => $before_url, 'after' => $after_url, 'start' => isset( $attributes['startPosition'] ) ? $attributes['startPosition'] : 50, 'mode' => isset( $attributes['mode'] ) ? $attributes['mode'] : 'slider', 'orientation' => isset( $attributes['orientation'] ) ? $attributes['orientation'] : 'horizontal', 'label_before' => isset( $attributes['labelBefore'] ) ? $attributes['labelBefore'] : '', 'label_after' => isset( $attributes['labelAfter'] ) ? $attributes['labelAfter'] : '', 'divider_color' => isset( $attributes['dividerColor'] ) ? $attributes['dividerColor'] : '#ffffff', 'hover' => ! empty( $attributes['hoverMode'] ) ? '1' : '0', 'animate' => ! empty( $attributes['animateIn'] ) ? '1' : '0', 'css_class' => isset( $attributes['cssClass'] ) ? $attributes['cssClass'] : '', ); return $shortcode->build_html( $atts, $before_url, $after_url ); } }