You may want a url to be used for say remote devices to connect to your site and pass information using say URL parameters and a response string.

You can create a special url and trap it using the code below. However for it to work in all instances you need to have a real wordpress page created with the url. Otherwise when using wget under linux for example, you can get a 404 not found error returned

//*************************************************
//*************************************************
//********** TEMPLATE PAGE ABOUT TO LOAD **********
//*************************************************
//*************************************************
//Hook executes just before WordPress determines which template page to load. It is a good hook to use if you need to do a redirect with full knowledge of the
//content that has been queried.
add_action("template_redirect", 'mysite_template_redirect');
function mysite_template_redirect()
{
  
  //----------------------------
  //----- OUR API URL PAGE -----
  //----------------------------  
  //URL to access this api function: "mysitename.com/api-v1"
  if (strpos($_SERVER["REQUEST_URI"], '/api-v1') !== false)     //<<<There must be a real worldpress page for this url otherwise using wget from linux will not work and give a 404 not found error
  {
    //GET URL ARGUMENTS
    $AuthCode = "";
    if (isset($_REQUEST['auth']))
      $AuthCode = $_REQUEST['auth'];

      die("OK-Auth-" . $AuthCode);    //<<<<This string is returned as the output to the device taht has used this url
  }

}
Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.

Comments

Your email address will not be published. Required fields are marked *