PHP code example of galatanovidiu / abilities-rest-adapter
1. Go to this page and download the library: Download galatanovidiu/abilities-rest-adapter 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/ */
galatanovidiu / abilities-rest-adapter example snippets
wp_register_ability_from_rest_route( 'my-plugin/list-posts', array(
'route' => '/wp/v2/posts',
'method' => 'GET',
'label' => 'List Posts',
'description' => 'List published posts.',
'category' => 'content', // must already be registered
) );
add_action( 'plugins_loaded', function () {
if ( ! function_exists( 'wp_register_ability_from_rest_route' ) ) {
return;
}
add_action( 'wp_abilities_api_init', function () {
wp_register_ability_from_rest_route( 'my-plugin/get-post', array(
'route' => '/wp/v2/posts/(?P<id>[\d]+)',
'method' => 'GET',
'label' => 'Get a post',
'description' => 'Fetch a single published post by ID.',
'category' => 'content',
) );
} );
} );
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.