'affiliates', 'title' => 'Affiliates', // don't translate 'icon' => 'performance' ) ) ); return $categories; } public static function enqueue_block_editor_assets() { // Our script used to edit and render the blocks. wp_register_script( 'affiliates-dashboard-block', plugins_url( 'js/dashboard-block.js', AFFILIATES_FILE ), array( 'wp-blocks', 'wp-element' ) ); wp_localize_script( 'affiliates-dashboard-block', 'affiliates_dashboard_block', array( 'title' => _x( 'Affiliates Dashboard', 'block title', 'affiliates' ), 'description' => _x( 'Displays the complete Affiliates Dashboard with its sections', 'block description', 'affiliates' ), 'keyword_affiliates' => __( 'Affiliates', 'affiliates' ), 'keyword_dashboard' => __( 'Dashboard', 'affiliates' ), 'dashboard_notice' => _x( 'Affiliates Dashboard', 'Notice shown when editing the Affiliates Dashboard Profile block as a non-affiliate.', 'affiliates' ), 'affiliates_icon' => AFFILIATES_PLUGIN_URL . '/images/affiliates-32.png' ) ); // Our editor stylesheet - not required yet. // wp_register_style( // 'affiliates-dashboard-block-editor', // plugins_url( 'css/dashboard-blocks-editor.css', AFFILIATES_FILE ), // array( 'wp-edit-blocks' ), // AFFILIATES_CORE_VERSION // ); } public static function enqueue_block_assets() { // Our front end stylesheet - not required yet. // wp_register_style( // 'affiliates-dashboard-block', // plugins_url( 'css/dashboard-blocks.css', AFFILIATES_FILE ), // array(), // AFFILIATES_CORE_VERSION // ); } /** * Initialization - registers the block. */ public static function wp_init() { if ( function_exists( 'register_block_type' ) ) { register_block_type( 'affiliates/dashboard', array( 'editor_script' => 'affiliates-dashboard-block', 'render_callback' => array( __CLASS__, 'block' ) ) ); } } /** * Callback that renders the dashboard block. * * @param array $atts attributes * @param string $content not used * * @return string */ public static function block( $atts, $content = '' ) { // Render the dashboard: $dashboard = Affiliates_Dashboard_Factory::get_dashboard_instance(); ob_start(); $dashboard->render(); $output = ob_get_clean(); // The following fixes a Gutenberg UX/UI bug : if the callback returns an empty string, you would see a spinner that never goes away. // So we render something other than the empty string, to avoid the spinner being shown eternally. // The form obviously won't be rendered when previewing in the editor because you're logged in. // The REST_REQUEST ... part is trying to recognize it's a request to render the block on the back end. if ( ( strlen( $output ) === 0 ) && defined( 'REST_REQUEST' ) && REST_REQUEST && isset( $_REQUEST['context'] ) && $_REQUEST['context'] === 'edit' ) { $output .= '
'; } return $output; } } Affiliates_Dashboard_Block::init();