$this->group_options(), 'styles' => $this->style_options(), ) ); // Register the frontend stylesheet handle so the block's style / // editorStyle (referenced in block.json) load on the frontend and // inside the editor iframe. Assets::register_style(); register_block_type( ADVANCED_TESTIMONIAL_DIR . 'blocks', array( 'render_callback' => array( $this, 'render' ) ) ); } /** * Server-side render callback. * * @param array $attributes Block attributes. * @return string */ public function render( $attributes ) { $attributes = is_array( $attributes ) ? $attributes : array(); $align = isset( $attributes['align'] ) ? $attributes['align'] : ''; $width = in_array( $align, array( 'wide', 'full' ), true ) ? $align : ''; $atts = array( 'title' => isset( $attributes['title'] ) ? $attributes['title'] : '', 'layout' => isset( $attributes['layout'] ) ? $attributes['layout'] : 'grid', 'style' => isset( $attributes['cardStyle'] ) ? $attributes['cardStyle'] : '', 'group' => isset( $attributes['group'] ) ? $attributes['group'] : '', 'columns' => isset( $attributes['columns'] ) ? (int) $attributes['columns'] : 3, 'limit' => isset( $attributes['limit'] ) ? (int) $attributes['limit'] : 9, 'order' => isset( $attributes['order'] ) ? $attributes['order'] : 'desc', 'orderby' => isset( $attributes['orderby'] ) ? $attributes['orderby'] : 'date', 'verified' => (bool) ( $attributes['verifiedOnly'] ?? false ), 'autoplay' => isset( $attributes['autoplay'] ) ? (int) $attributes['autoplay'] : 0, 'width' => $width, 'show_rating' => (bool) ( $attributes['showRating'] ?? true ), 'show_image' => (bool) ( $attributes['showImage'] ?? true ), 'show_company' => (bool) ( $attributes['showCompany'] ?? true ), 'show_designation' => (bool) ( $attributes['showDesignation'] ?? true ), 'show_location' => (bool) ( $attributes['showLocation'] ?? true ), 'show_date' => (bool) ( $attributes['showDate'] ?? false ), 'show_verified' => (bool) ( $attributes['showVerified'] ?? true ), 'show_website' => (bool) ( $attributes['showWebsite'] ?? true ), 'show_headline' => (bool) ( $attributes['showHeadline'] ?? true ), 'show_video' => (bool) ( $attributes['showVideo'] ?? true ), 'show_filter' => (bool) ( $attributes['showFilter'] ?? false ), 'read_more' => (bool) ( $attributes['readMore'] ?? false ), 'load_more' => (bool) ( $attributes['loadMore'] ?? false ), 'speed' => isset( $attributes['speed'] ) ? (string) $attributes['speed'] : '', 'card_width' => isset( $attributes['cardWidth'] ) ? (int) $attributes['cardWidth'] : 0, 'fade' => (bool) ( $attributes['fade'] ?? true ), 'direction' => isset( $attributes['direction'] ) ? (string) $attributes['direction'] : '', ); return Renderer::render( $atts ); } /** * Build card style options for the editor select control. * * @return array> */ private function style_options() { $options = array( array( 'value' => '', 'label' => __( 'Default (from settings)', 'advanced-testimonial' ), ), ); foreach ( Renderer::card_styles() as $slug => $label ) { $options[] = array( 'value' => $slug, 'label' => $label, ); } return $options; } /** * Build group options for the editor select control. * * @return array> */ private function group_options() { $options = array( array( 'value' => '', 'label' => __( 'All groups', 'advanced-testimonial' ), ), ); $terms = get_terms( array( 'taxonomy' => Taxonomy::TAXONOMY, 'hide_empty' => false, ) ); if ( ! is_wp_error( $terms ) ) { foreach ( $terms as $term ) { $options[] = array( 'value' => $term->slug, 'label' => $term->name, ); } } return $options; } }