array( $this, 'render_block' ), ) ); } public function render_block( $attributes ) { $atts = array( 'layout' => ! empty( $attributes['layout'] ) ? $attributes['layout'] : 'carousel', 'heading' => ! empty( $attributes['heading'] ) ? $attributes['heading'] : '', 'subheading' => ! empty( $attributes['subheading'] ) ? $attributes['subheading'] : '', 'ids' => '', 'limit' => ! empty( $attributes['limit'] ) ? absint( $attributes['limit'] ) : 10, 'columns' => ! empty( $attributes['columns'] ) ? $attributes['columns'] : 3, 'columns_tablet' => ! empty( $attributes['columnsTablet'] ) ? $attributes['columnsTablet'] : 2, 'columns_mobile' => ! empty( $attributes['columnsMobile'] ) ? $attributes['columnsMobile'] : 1, 'scroll_by' => ! empty( $attributes['scrollBy'] ) ? $attributes['scrollBy'] : 1, 'arrows' => ! isset( $attributes['arrows'] ) || $attributes['arrows'] ? 'yes' : 'no', 'dots' => ! isset( $attributes['dots'] ) || $attributes['dots'] ? 'yes' : 'no', 'autoplay' => ! empty( $attributes['autoplay'] ) ? 'yes' : 'no', 'autoplay_speed' => ! empty( $attributes['autoplaySpeed'] ) ? absint( $attributes['autoplaySpeed'] ) : 3000, 'pause_on_hover' => ! isset( $attributes['pauseOnHover'] ) || $attributes['pauseOnHover'] ? 'yes' : 'no', 'infinite' => ! isset( $attributes['infinite'] ) || $attributes['infinite'] ? 'yes' : 'no', ); if ( isset( $attributes['selectMode'] ) && 'specific' === $attributes['selectMode'] && ! empty( $attributes['ids'] ) ) { $atts['ids'] = sanitize_text_field( $attributes['ids'] ); } return ADDOSHVI_Shortcode::render( $atts ); } /** * Give the block editor JS the list of videos (id + title) for the * "choose specific videos" FormTokenField control. */ public function enqueue_editor_data() { if ( ! post_type_exists( ADDOSHVI_POST_TYPE ) ) { return; } $posts = get_posts( array( 'post_type' => ADDOSHVI_POST_TYPE, 'post_status' => 'publish', 'posts_per_page' => 100, 'orderby' => 'title', 'order' => 'ASC', ) ); $videos = array(); foreach ( $posts as $post ) { $videos[] = array( 'id' => $post->ID, 'title' => $post->post_title ? $post->post_title : sprintf( /* translators: %d: video post ID, used as a fallback title for an untitled video. */ __( 'Video #%d', 'addonn-shoppable-video' ), $post->ID ), ); } wp_add_inline_script( 'addoshvi-feed-editor-script', 'window.ADDOSHVI_Block_Data = ' . wp_json_encode( array( 'videos' => $videos ) ) . ';', 'before' ); } }