[WordPress] What Does It Mean to Use WordPress as a Proxy?
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 | |
add_action( 'wp_ajax_get_all_data', 'get_all_data' ); | |
/** | |
* Retrieves the requested data from the specified URL | |
* returns the values in JSON. | |
*/ | |
function get_all_data() { | |
// TODO | |
} |
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
var _get_columns = function() { | |
// Don't forget to use a nonce or security value here. | |
var data = { | |
'action': 'get_all_columns' | |
'security': '<?php echo wp_create_nonce( "acme-security-ajax-nonce" ); ?>' | |
}; | |
// TODO Check for error logging if the response value doesn't exist. | |
$.get( ajaxurl, data, function( response ) { | |
response = $.parseJSON( response ); | |
// Your custom functionality here | |
}); | |
}; |
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 | |
add_action( 'wp_ajax_get_all_data', 'get_all_data' ); | |
/** | |
* Retrieves the requested data from the specified URL | |
* returns the values in JSON. | |
*/ | |
function get_all_data() { | |
// Note $url is up to you. | |
$curl = curl_init( $url ); | |
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, 1 ); | |
curl_setopt( $curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY ); | |
curl_setopt( $curl, CURLOPT_SSL_VERIFYPEER, false ); | |
curl_setopt( $curl, CURLOPT_FOLLOWLOCATION, true ); | |
$response = curl_exec( $curl ); | |
$resultStatus = curl_getinfo( $curl ); | |
if( 200 !== $resultStatus['http_code'] ) { | |
echo 'Call Failed '.print_r( $result_status ); | |
} | |
curl_close( $curl ); | |
echo json_encode( utf8_encode( $response ) ); | |
wp_die(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment