Advertisement
Guest User

Untitled

a guest
Sep 26th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. add_action( 'init', 'wpse9870_init_external' );
  2. function wpse9870_init_external()
  3. {
  4. global $wp_rewrite;
  5. $plugin_url = plugins_url( 'api.php', __FILE__ );
  6. $plugin_url = substr( $plugin_url, strlen( home_url() ) + 1 );
  7. $wp_rewrite->add_external_rule( 'api.php$', $plugin_url );
  8. }
  9. add_action( 'init', 'wpse9870_init_internal' );
  10. function wpse9870_init_internal()
  11. {
  12. add_rewrite_rule( 'api.php$', 'index.php?wpse9870_api=1', 'top' );
  13. }
  14. add_filter( 'query_vars', 'wpse9870_query_vars' );
  15. function wpse9870_query_vars( $query_vars )
  16. {
  17. $query_vars[] = 'wpse9870_api';
  18. return $query_vars;
  19. }
  20. add_action( 'parse_request', 'wpse9870_parse_request' );
  21. function wpse9870_parse_request( &$wp )
  22. {
  23. if ( array_key_exists( 'wpse9870_api', $wp->query_vars ) ) {
  24. include 'api.php';
  25. exit();
  26. }
  27. return;
  28. }
  29.  
  30. if(strpos($_SERVER['REQUEST_URI'], "index.php?wpse9870_api=1"))
  31. {
  32. header("HTTP/1.1 200 OK");
  33. echo "v1p";
  34. }
  35.  
  36. $.ajax({
  37. type: 'POST',
  38. url: '/index.php?wpse9870_api=1',
  39.  
  40. {"readyState":4,"responseText":"v1p","status":500,"statusText":"Internal Server Error"}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement