wp.blocks.registerBlockType( 'bwawwp/minimal', {
    title: 'Przykład minimalnego bloku',
    category: 'common',
    edit() {
        return 'Treść minimalnego bloku edytora.';
    },
    save() {
        return 'Treść minimalnego bloku frontendu.';
    },
} );



/**
 * Nazwa wtyczki: Minimal Block Example
 */
function enqueue_min_block() {
    wp_enqueue_script(
        'minimal-block',
        plugins_url( 'block.js', __FILE__ ),
        array( 'wp-blocks' )
    );
}
add_action( 'enqueue_block_editor_assets', 'enqueue_min_block' );



register_post_type(
    'homework',
    array(
        'labels' => array(
            'name' => __( 'Homework' ),
            'singular_name' => __( 'Homework' )
        ),
        'public' => true,
        'has_archive' => true,
        'supports' => array( 'title', 'editor' ), // Nowa opcja
        'show_in_rest' => true,          // Nowa opcja
    )
);



// Określenie kategorii bloku Homework
function my_block_categories( $categories, $post ) {
    return array_merge(
        $categories,
        array(
            array(
                'slug'  => 'homework',
                'title' => 'Homework',
            ),
        )
    );
}
add_filter( 'block_categories', 'my_block_categories' ), 10, 2 );



// Wyrejestrowanie bloku instructions w postach innych niż typu homework
wp.domReady( function() {
    if( wp.data.select('core/editor').getCurrentPostType() != 'homework' ) {
        wp.blocks.unregisterBlockType( 'homework/instructions' );
    }
});



// W postach typu homework dozwolone jest stosowanie tylko określonych bloków
function my_allowed_block_types( $allowed_blocks, $post ) {
    if ( $post->post_type == 'homework' ) {
        $allowed_blocks = array(
            'core/block',
            'core/image',
            'core/paragraph',
            'core/heading',
            'core/list',
            'homework/instructions',
            'homework/question',
        );
    }
    return $allowed_blocks;
}
add_filter( 'allowed_block_types', 'my_allowed_block_types', 10, 2);



// Rejestracja niestandardowego typu postów
register_homework_post_type(
    'homework',
    array(
        'labels' => array(
            'name' => __( 'Homework' ),
            'singular_name' => __( 'Homework' )
        ),
        'public' => true,
        'has_archive' => true,
    'supports' => array( 'title', 'editor' ),
    'show_in_rest' => true,
    'template' => array(
        array( 'homework/instructions' ),
        array( 'homework/question',
            array( 'content' => 'True/false 1.',
                'question_type' => 'true_false'
            )
        ),
        array( 'homework/question',
            array( 'content' => 'Essay question.',
                'question_type' => 'essay'
            )
        ),
    )
    )
);



<!-- wp:homework/instructions -->
<p class="wp-block-homework-instructions-content">Odeślij pracę domową.</p>
<p class="wp-block-homework-instructions-due_date">Termin: 2020-11-01</p>
<!-- /wp:homework/instructions -->



register_post_meta( 'homework', '_homework_due_date', array(
    'show_in_rest' => true,
    'single' => true,
    'type' => 'string',
    'auth_callback' => function() {
        return current_user_can( 'edit_posts' );
    }
) );



wp.blocks.registerBlockType( 'homework/instructions', {
    // …
    attributes: {
        content: {
            type: 'array',
            source: 'children',
            selector: 'p',
        },
        due_date: {
            type: 'string',
            meta: '_homework_due_date',
            source: 'meta',
            default: '',
        }
    },
    // …
}



wp_register_script(
    'homework-question',
    BWAWWP_URL . 'homework-cpt/blocks/question/blocks.js',
    array( 'wp-blocks',
        'wp-element',
        'wp-editor',
        'wp-components',
        'wp-dom-ready',
        'wp-edit-post',
    ),
    filemtime( BWAWWP_DIR . 'homework-cpt/blocks/question/blocks.js' )
);



