3, 'title' => __( 'Buildify Template', 'buildify' ), 'description' => __( 'Insert a Buildify section template.', 'buildify' ), 'category' => 'theme', 'icon' => 'layout', 'editor_script' => 'buildify-block', 'render_callback' => array( $this, 'render' ), 'attributes' => array( 'templateId' => array( 'type' => 'integer', 'default' => 0, ), ), 'supports' => array( 'html' => false, 'align' => array( 'wide', 'full' ), ), ) ); add_action( 'enqueue_block_editor_assets', array( $this, 'editor_data' ) ); } /** * Passes the list of section templates to the block. */ public function editor_data() { $options = array(); foreach ( Post_Type::get_ids( 'section' ) as $id ) { $options[] = array( 'value' => $id, 'label' => wp_strip_all_tags( get_the_title( $id ) ), ); } wp_add_inline_script( 'buildify-block', 'window.buildifyBlock = ' . wp_json_encode( array( 'templates' => $options, 'newUrl' => current_user_can( Post_Type::capability() ) ? admin_url( 'admin.php?page=buildify&new=section' ) : '', ) ) . ';', 'before' ); } /** * Renders the block. * * @param array $attributes Attributes. * @return string */ public function render( $attributes ) { $id = isset( $attributes['templateId'] ) ? (int) $attributes['templateId'] : 0; if ( ! $id ) { return ''; } return Shortcode::render_template( $id ); } }