'', 'label' => __( '— Select a search widget —', 'webcasata-filterx' ) ) ); foreach ( $items as $item ) { $item_options[] = array( 'value' => $item->ID, 'label' => $item->post_title, ); } wp_localize_script( 'webcasata-filterx-block-editor', 'filterxBlock', array( 'searchItems' => $item_options, ) ); register_block_type( 'webcasata-filterx/widget', array( 'editor_script' => 'webcasata-filterx-block-editor', 'attributes' => array( 'searchId' => array( 'type' => 'number', 'default' => 0 ), 'columns' => array( 'type' => 'number', 'default' => 0 ), 'posts' => array( 'type' => 'number', 'default' => 0 ), 'pagination'=> array( 'type' => 'string', 'default' => '' ), ), 'render_callback' => array( __CLASS__, 'render_block' ), ) ); } /** * Server-side render of the block (same as shortcode). * * @param array $atts Block attributes. * @return string */ public static function render_block( $atts ) { if ( empty( $atts['searchId'] ) ) { return '
' . esc_html__( 'Webcasata FilterX: Please select a search widget in the block settings.', 'webcasata-filterx' ) . '
'; } return do_shortcode( sprintf( '[filterx id="%d" columns="%d" posts="%d" pagination="%s"]', absint( $atts['searchId'] ), absint( $atts['columns'] ?? 0 ), absint( $atts['posts'] ?? 0 ), sanitize_key( $atts['pagination'] ?? '' ) ) ); } }