WP Custom REST API
Beginner WordPress plugin with custom REST API endpoint
by Mrityunjoy Mukherjee · github.com/mrityunjoy-systems/wp-custom-rest-api
★ 0stars
0forks
Install
No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:
wp plugin install https://github.com/mrityunjoy-systems/wp-custom-rest-api/archive/refs/heads/main.zip<?php /**
- Plugin Name: WP Custom REST API
- Description: A beginner plugin to create a custom REST API endpoint.
- Version: 1.0
- Author: Mrityunjoy Mukherjee */
if ( ! defined( 'ABSPATH' ) ) { exit; // Stop direct access }
// Register custom REST API route add_action( 'rest_api_init', function () { register_rest_route( 'myapi/v1', '/hello', array( 'methods' => 'GET', 'callback' => 'myapi_hello_message', )); });
// Callback function function myapi_hello_message() { return array( 'message' => 'Hello from my custom WordPress REST API!', 'status' => 'success' ); }