Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wordpress plugin: Hook on custom url

Tags:

php

wordpress

I want to make a plugin, that I will use for some jQuery AJAX loading of table data.

I have a function that prints the data correctly, but how do I "hook" into a specific url?

Like say, I want the function to be run, and the data to be printed whenever a request to /mycustomplugin/myurl.php is run? (Please note that the url/file should not exist)

I have no experience with WP plugins.

like image 493
Martind Avatar asked Dec 06 '10 09:12

Martind


2 Answers

To filter your custom URL before Wordpress starts executing queries for other things use something like this:

add_action('parse_request', 'my_custom_url_handler');

function my_custom_url_handler() {
   if($_SERVER["REQUEST_URI"] == '/custom_url') {
      echo "<h1>TEST</h1>";
      exit();
   }
}
like image 162
zarazan Avatar answered Oct 04 '22 19:10

zarazan


A simple

if ($_SERVER["REQUEST_URI"] == '/mycustomplugin/myurl.php') {
  echo "<my ajax code>";
}

Should work wonders.

like image 42
code_burgar Avatar answered Oct 04 '22 21:10

code_burgar