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
  }

}
UK Electronic Designer
USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.

Comments

Your email address will not be published.