true, 'strategy' => 'defer', ) ); wp_register_script( 'dicegem-games-play', DICEGEM_URL . 'assets/play.js', array(), DICEGEM_VERSION, array( 'in_footer' => true, 'strategy' => 'defer', ) ); wp_register_script( 'dicegem-games-editor', DICEGEM_URL . 'assets/editor.js', array( 'wp-blocks', 'wp-block-editor', 'wp-components', 'wp-element', 'wp-i18n' ), DICEGEM_VERSION, true ); wp_set_script_translations( 'dicegem-games-editor', 'dicegem-games' ); add_shortcode( 'dicegem', function ( $atts ) { return dicegem_render_game( $atts ); } ); add_shortcode( 'dicegem_grid', function ( $atts ) { return dicegem_render_grid( $atts ); } ); register_block_type( DICEGEM_DIR . 'blocks/game', array( 'render_callback' => function ( $attributes ) { return dicegem_render_game( $attributes, get_block_wrapper_attributes( array( 'class' => 'dicegem-game' ) ) ); }, ) ); register_block_type( DICEGEM_DIR . 'blocks/grid', array( 'render_callback' => function ( $attributes ) { return dicegem_render_grid( $attributes, get_block_wrapper_attributes( array( 'class' => 'dicegem-grid' ) ) ); }, ) ); } add_action( 'init', 'dicegem_init' ); /** * Hands the game list to the editor script, so the editor never fetches from dicegem.com. */ function dicegem_editor_data() { $games = array(); foreach ( dicegem_games() as $game ) { $games[] = array( 'slug' => $game['slug'], 'title' => $game['title'], 'category' => $game['category'], 'categorySlug' => $game['category_slug'], 'thumb' => $game['thumb'], 'portrait' => 'portrait' === $game['orientation'], ); } wp_add_inline_script( 'dicegem-games-editor', 'window.dicegemGames = ' . wp_json_encode( array( 'games' => $games, 'categories' => dicegem_categories(), 'ratios' => DICEGEM_RATIOS, 'ratio' => dicegem_settings()['ratio'], ) ) . ';', 'before' ); } add_action( 'enqueue_block_editor_assets', 'dicegem_editor_data' );