Skip to content

Instantly share code, notes, and snippets.

@juslintek
Created May 30, 2019 16:43
Show Gist options
  • Save juslintek/1022759f32a52c13c26c5fdd9ed26c69 to your computer and use it in GitHub Desktop.
Save juslintek/1022759f32a52c13c26c5fdd9ed26c69 to your computer and use it in GitHub Desktop.
I've made this on one plugin
<?php
class Config {
public function __construct() {
add_action( 'init', array( $this, '_wpSoapGetEndPoint' ) );
add_action( 'template_redirect', array( $this, '_wpSoapGetEndPointData' ) );
}
/**
* Idnetify Soap Request Endpoint and Perform URL Pattern Rewrite Rules Validation Checks
* @since 1.0
*/
public function _wpSoapGetEndPoint() {
/**
* @var \WP_Rewrite $wp_rewrite
*/
add_rewrite_tag( '%api%', 'soap' );
add_rewrite_tag( '%soap_action%', 'listening' );
add_rewrite_rule( '^soap-([a-zA-Z0-1]+)', 'index.php?api=soap&soap_action=$matches[1]', 'top' );
flush_rewrite_rules();
}
/**
* Idnetify Soap Request Endpoint and Handle with Soap Server Handle
* @since 1.0
*/
public function _wpSoapGetEndPointData() {
//Remove whitespaces if any
ob_clean();
/**
* Globals to get wp_query
* @var \WP_Query $wp_query
*/
global $wp_query;
//Get query params and identify valid endpoint
$api = $wp_query->get( 'api' );
$soap_action = $wp_query->get( 'soap_action' );
if ( $api == 'soap' && ! empty( $soap_action ) ) {
Web::call( $soap_action );
$error = error_get_last();
if ( ! empty( $error ) ) {
Log::error( $error['message'] . ' at ' . $error['file'] . ':' . $error['line'] );
}
exit;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment