Created
April 22, 2019 14:47
-
-
Save yeriepiscesa/cf03a129e34f955554cd0ae45cc4762b to your computer and use it in GitHub Desktop.
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 | |
class SP_Ajax_Administrative_Action extends WP_AJAX { | |
protected $action = 'administrative-action'; | |
protected function run() { | |
if( isset( $_GET[ 'province' ] ) && $_GET[ 'province' ] != '' ) { | |
$prov = trim( $_GET['province'] ); | |
$remote = wp_remote_get( RAJAONGKIR_BASE_URI . '/city?province=' . $prov, array( | |
'headers' => array( 'key' => RAJAONGKIR_API_KEY ) | |
) ); | |
$data = array(); | |
if( $remote['response']['code'] == 200 ) { | |
$remote_body = json_decode( $remote['body'] ); | |
$rows = $remote_body->rajaongkir->results; | |
foreach( $rows as $row ) { | |
$data[ $row->city_id ] = trim( $row->type . " " . $row->city_name ); | |
} | |
} | |
echo json_encode( $data, true ); | |
} | |
} | |
} | |
SP_Ajax_Administrative_Action::listen(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment