Skip to content

Instantly share code, notes, and snippets.

@mustafauysal
Created July 6, 2017 22:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mustafauysal/ee53c301a2bddbc7d0cf2269aa307a23 to your computer and use it in GitHub Desktop.
Save mustafauysal/ee53c301a2bddbc7d0cf2269aa307a23 to your computer and use it in GitHub Desktop.
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