$widgets ) ); register_block_type( 'hey-feedback/widget', array( 'editor_script' => 'hey-feedback-block', 'render_callback' => array( __CLASS__, 'render' ), 'attributes' => array( 'widgetId' => array( 'type' => 'number', 'default' => 0, ), ), ) ); } /** * Server-side render callback for the block. * * @param array $attributes Block attributes. * @return string */ public static function render( array $attributes ): string { $id = absint( $attributes['widgetId'] ?? 0 ); if ( 0 === $id ) { return ''; } return Shortcode::render( array( 'id' => $id ) ); } /** * Returns widget options for the block editor dropdown. * * @return array */ private static function get_widget_options(): array { global $wpdb; $table = Database::items_table(); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $rows = $wpdb->get_results( $wpdb->prepare( "SELECT id, title, type FROM %i WHERE status = %s ORDER BY title ASC", $table, 'active' ) ); $options = array(); foreach ( $rows as $row ) { $options[] = array( 'value' => (int) $row->id, 'label' => $row->title ? $row->title : sprintf( '#%d (%s)', $row->id, $row->type ), ); } return $options; } }