Created
July 6, 2017 22:19
-
-
Save mustafauysal/ee53c301a2bddbc7d0cf2269aa307a23 to your computer and use it in GitHub Desktop.
WPNotlari icin ornek custom endpoint
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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