>}> block => shortcode function, title, attributes */ function fipeo_blocks() { $label = array( 'label' => array( 'type' => 'string', 'default' => '' ) ); $height = array( 'height' => array( 'type' => 'string', 'default' => '' ) ); return array( 'booking' => array( 'fipeo_sc_booking', 'Fipeo: prices and booking', $height ), 'assistant' => array( 'fipeo_sc_assistant', 'Fipeo: assistant on this page', array( 'open' => array( 'type' => 'string', 'default' => '0' ) ) ), 'reviews' => array( 'fipeo_sc_reviews', 'Fipeo: reviews', $height ), 'placement-test' => array( 'fipeo_sc_placement_test', 'Fipeo: placement test', $label ), 'agents-button' => array( 'fipeo_sc_agents_button', 'Fipeo: agents button', $label ), 'student-app' => array( 'fipeo_sc_student_app', 'Fipeo: student app', $label ), ); } function fipeo_register_blocks() { if ( ! function_exists( 'register_block_type' ) ) { return; } wp_register_script( 'fipeo-blocks', FIPEO_URL . 'assets/blocks.js', array( 'wp-blocks', 'wp-element', 'wp-components', 'wp-block-editor', 'wp-i18n' ), FIPEO_VERSION, true ); foreach ( fipeo_blocks() as $name => $b ) { $fn = $b[0]; register_block_type( 'fipeo/' . $name, array( 'editor_script' => 'fipeo-blocks', 'attributes' => $b[2], 'render_callback' => function ( $attributes ) use ( $fn ) { $atts = array(); foreach ( (array) $attributes as $k => $v ) { if ( is_string( $v ) && '' !== $v ) { $atts[ sanitize_key( $k ) ] = sanitize_text_field( $v ); } } return call_user_func( $fn, $atts ); }, ) ); } }