Wordpress Plugin: Binding to a Custom URL

I want to create a plugin that I will use to load jQuery AJAX table data.

I have a function that prints data correctly, but how do I "connect" to a specific URL?

How, for example, do I want the function to run, and the data that needs to be printed when the request /mycustomplugin/myurl.php is run? (Note that url / file must not exist)

I have no experience with WP plugins.

+8
php wordpress wordpress-plugin
source share
4 answers

Plain

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

Must work miracles.

+1
source share

To filter your own URL before Wordpress starts querying 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(); } } 
+26
source share

If you want to return the usual Wordpress data, you can simply include wp-blogheader.php in your own php file, for example:

 //Include Wordpress define('WP_USE_THEMES', false); require('Your_Word_Press_Directory/wp-blog-header.php'); query_posts('showposts=10&cat=2'); 

Just use regular tag tags to return your desired content. it

Where does your table data come from? Are you trying to show this information from the administrator or from the viewer?

Also see full call breakdown with wp_ajax http://codex.wordpress.org/AJAX_in_Plugins

0
source share
 add_action( 'init', 'my_url_handler' ); function my_url_handler() { if( isset( $_GET['unique_hidden_field'] ) ) { // process data here } } 

using add_action( 'init', 'your_handler') is the most common way in plugins, because this action is triggered after WordPress download is complete, but before any headers are sent. Most of WP loads at this point and the user is authenticated.

0
source share

All Articles