utils.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * Filter to Run WP REST API v2 Endpoints and Fix double Slash in rest_url
  4. */
  5. add_filter( 'rest_url_prefix', function () { return 'wp-json/wp/v2'; } );
  6. //add_filter( 'rest_url_prefix', 'fix_json_endpoint' );
  7. //function fix_json_endpoint (){
  8. // $json_endpoint = 'wp-json/wp/v2';
  9. // return rtrim( $json_endpoint, '/' );
  10. //}
  11. //remove_filter('json_dispatch_request', 'json_v1_compatible_dispatch', 10);
  12. //remove_filter('json_endpoints', 'json_v1_compatible_routes', 1000);
  13. /**
  14. * Build path data for current request.
  15. *
  16. * @return string|bool
  17. */
  18. function _s_backbone_get_request_path() {
  19. global $wp_rewrite;
  20. if ( $wp_rewrite->using_permalinks() ) {
  21. global $wp;
  22. // If called too early, bail
  23. if ( ! isset( $wp->request ) ) {
  24. return false;
  25. }
  26. // Determine path for paginated version of current request
  27. if ( false != preg_match( '#' . $wp_rewrite->pagination_base . '/\d+/?$#i', $wp->request ) ) {
  28. $path = preg_replace( '#' . $wp_rewrite->pagination_base . '/\d+$#i', $wp_rewrite->pagination_base . '/%d', $wp->request );
  29. } else {
  30. $path = $wp->request . '/' . $wp_rewrite->pagination_base . '/%d';
  31. }
  32. // Slashes everywhere we need them
  33. if ( 0 !== strpos( $path, '/' ) )
  34. $path = '/' . $path;
  35. $path = user_trailingslashit( $path );
  36. } else {
  37. // Clean up raw $_REQUEST input
  38. $path = array_map( 'sanitize_text_field', $_REQUEST );
  39. $path = array_filter( $path );
  40. $path['paged'] = '%d';
  41. $path = add_query_arg( $path, '/' );
  42. }
  43. return empty( $path ) ? false : $path;
  44. }
  45. /**
  46. * Return query string for current request, prefixed with '?'.
  47. *
  48. * @return string
  49. */
  50. function _s_backbone_get_request_parameters() {
  51. $uri = $_SERVER[ 'REQUEST_URI' ];
  52. $uri = preg_replace( '/^[^?]*(\?.*$)/', '$1', $uri, 1, $count );
  53. if ( $count != 1 ) {
  54. return '';
  55. }
  56. return $uri;
  57. }