/block.json; the editor script is * blocks/editor.js (no build step). */ class Blocks { /** Block folder => render callback on this class. */ const BLOCKS = array( 'course-catalog' => 'render_course_catalog', 'my-courses' => 'render_my_courses', 'student-dashboard' => 'render_student_dashboard', ); public static function init() { add_action( 'init', array( __CLASS__, 'register' ) ); } /** * Names of the plugin's blocks (for asset loading). * * @return string[] */ public static function names() { return array_map( function ( $folder ) { return 'accessnow-lms/' . $folder; }, array_keys( self::BLOCKS ) ); } public static function register() { // Handles named in block.json must exist before the blocks are registered. Frontend::register_assets(); wp_register_script( 'accessnow-slms-blocks', ACCESSNOW_SLMS_PLUGIN_URL . 'blocks/editor.js', array( 'wp-blocks', 'wp-element', 'wp-block-editor', 'wp-components', 'wp-i18n', 'wp-server-side-render' ), ACCESSNOW_SLMS_VERSION, true ); $languages = array(); foreach ( I18n::get_supported_languages() as $code => $lang ) { $languages[] = array( 'label' => $lang['label'], 'value' => $code, ); } wp_add_inline_script( 'accessnow-slms-blocks', 'window.accessnowSlmsBlocks = ' . wp_json_encode( array( 'languages' => $languages ) ) . ';', 'before' ); wp_set_script_translations( 'accessnow-slms-blocks', 'accessnow-lms', ACCESSNOW_SLMS_PLUGIN_DIR . 'languages' ); foreach ( self::BLOCKS as $folder => $callback ) { register_block_type( ACCESSNOW_SLMS_PLUGIN_DIR . 'blocks/' . $folder, array( 'render_callback' => array( __CLASS__, $callback ) ) ); } } /** * Wrap a block's output in its wrapper element (alignment and custom classes). * * @param string $html Inner HTML. * @return string */ private static function wrap( $html ) { return '