PHP code example of thebbapp / rest-api-bbpress

1. Go to this page and download the library: Download thebbapp/rest-api-bbpress library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

thebbapp / rest-api-bbpress example snippets




use BbApp\RestAPI\BbPress\BbPressRESTAPI;

// Create an instance
$bbpress_rest_api = new BbPressRESTAPI();

// Register hooks and filters (call on 'rest_api_init' hook)
add_action('rest_api_init', function() use ($bbpress_rest_api) {
    $bbpress_rest_api->register();
});

// Initialize post types and meta fields (call on 'init' hook or during plugin init)
$bbpress_rest_api->init();



use BbApp\RestAPI\BbPress\BbPressRESTAPI;

class MyCustomBbPressRESTAPI extends BbPressRESTAPI {
    public function register(): void {
        parent::register();

        // Add your custom REST fields, routes, or filters here
        register_rest_field('forum', 'my_custom_field', [
            'get_callback' => function($post) {
                return get_post_meta($post['id'], 'my_custom_meta', true);
            },
            'schema' => [
                'type' => 'string',
                'context' => ['view', 'edit']
            ]
        ]);
    }
}