Wordpress plugin: Hook on custom url

非 Y 不嫁゛ 提交于 2019-12-03 00:15:46

A simple

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

Should work wonders.

zarazan

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();
   }
}

If you wanted to return regular wordpress data you could just include wp-blogheader.php into your custom php file like so


//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 theming tags to return the content you desire. This

Where is your table data coming from though? Are you trying to show this information on the admin side or the viewer side?

Also see for a full breakdown of calling hooked functions with wp_ajax http://codex.wordpress.org/AJAX_in_Plugins

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 since this action is fired after WordPress has finished loading, but before any headers are sent. Most of WP is loaded at this stage, and the user is authenticated.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!