Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WPNotlari icin ornek custom endpoint
<?php
/**
* Plugin Name: WPNotlari Simple Rest
* Plugin URI: http://wpnotlari.com
* Description: Egitim amacli rest api
* Author: Mustafa Uysal
* Version: 0.1.0
* Plugin URI: http://wpnotlari.com
*/
class WPN_REST_Tanitim {
public function __construct() {
$this->namespace = 'wpnotlari/v1';
add_action( 'rest_api_init', array( $this, 'register_routes' ) );
}
function register_routes() {
register_rest_route( $this->namespace, '/selam', array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'merhaba_dunya' ),
'args' => array(
'isim' => array(
'required' => true,
),
),
) );
register_rest_route( 'wpnotlari/v1', '/kullanici-sorgula', array(
'methods' => WP_REST_Server::CREATABLE,
'callback' => array( $this, 'kullanici_sorgula' ),
'args' => array(
'id' => array(
'required' => true,
),
),
) );
}
public function merhaba_dunya( $request ) {
$params = $request->get_params();
return 'Merhaba ' . $params['isim'];
}
public function kullanici_sorgula( $request ) {
$id = $request->get_param( 'id' );
return new WP_User( $id );
}
}
$controller = new WPN_REST_Tanitim;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment