$language ) { $languages[] = array( 'value' => $id, 'label' => $language[0], ); } $settings = onlinecompiler_settings(); wp_add_inline_script( 'onlinecompiler-block-editor', 'window.onlinecompilerBlock = ' . wp_json_encode( array( 'languages' => $languages, 'defaultLang' => $settings['lang'], 'hasKey' => '' !== $settings['key'], 'settingsUrl' => admin_url( 'options-general.php?page=onlinecompiler' ), ) ) . ';', 'before' ); wp_set_script_translations( 'onlinecompiler-block-editor', 'onlinecompiler-io-code-runner' ); register_block_type( ONLINECOMPILER_DIR . 'blocks/code-runner', array( 'render_callback' => 'onlinecompiler_render_block' ) ); } add_action( 'init', 'onlinecompiler_register_block' ); /** * Renders the block on the page. * * @param array $attributes The block's attributes. * @return string */ function onlinecompiler_render_block( $attributes ) { $wrapper = get_block_wrapper_attributes(); $classes = preg_match( '/class="([^"]*)"/', $wrapper, $match ) ? html_entity_decode( $match[1], ENT_QUOTES, 'UTF-8' ) : ''; return onlinecompiler_render( array( 'code' => isset( $attributes['code'] ) ? $attributes['code'] : '', 'stdin' => isset( $attributes['stdin'] ) ? $attributes['stdin'] : '', 'lang' => isset( $attributes['lang'] ) ? $attributes['lang'] : '', 'theme' => isset( $attributes['theme'] ) ? $attributes['theme'] : '', 'height' => isset( $attributes['height'] ) ? $attributes['height'] : 0, 'readonly' => ! empty( $attributes['readOnly'] ), 'langSelect' => isset( $attributes['langSelect'] ) ? $attributes['langSelect'] : '', 'problem' => isset( $attributes['problem'] ) ? $attributes['problem'] : '', 'className' => $classes, ) ); }