WPDK  1.5.0
WordPress Development Kit
 All Data Structures Files Functions Variables Pages
wpdk-http.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * [DRAFT]
6  *
7  * THE FOLLOWING CODE IS A DRAFT. FEEL FREE TO USE IT TO MAKE SOME EXPERIMENTS, BUT DO NOT USE IT IN ANY CASE IN
8  * PRODUCTION ENVIRONMENT. ALL CLASSES AND RELATIVE METHODS BELOW CAN CHNAGE IN THE FUTURE RELEASES.
9  *
10  */
11 
23 class WPDKHTTPVerbs {
24 
25  const DELETE = 'DELETE';
26  const GET = 'GET';
27  const POST = 'POST';
28  const PUT = 'PUT';
29  const PATCH = "PATCH";
30 
36  public function requestMethods()
37  {
38  /* Standard default verbs. */
39  $verbs = array(
40  self::POST => self::POST,
41  self::GET => self::GET,
42  self::DELETE => self::DELETE,
43  self::PUT => self::PUT,
44  );
45 
46  return apply_filters( 'wpdk_http_verbs', $verbs );
47  }
48 }
49 
61 class WPDKHTTPRequest {
62 
71  public static function isAjax()
72  {
73  if ( defined( 'DOING_AJAX' ) ) {
74  return true;
75  }
76  if ( isset( $_SERVER['HTTP_X_REQUESTED_WITH'] ) &&
77  strtolower( $_SERVER['HTTP_X_REQUESTED_WITH'] ) == 'xmlhttprequest'
78  ) {
79  return true;
80  }
81  else {
82  return false;
83  }
84  }
85 
95  public static function isRequest( $verb )
96  {
97  $verb = strtolower( $verb );
98  return ( $verb == strtolower( $_SERVER['REQUEST_METHOD'] ) );
99  }
100 
108  public static function isRequestGET()
109  {
110  return self::isRequest( WPDKHTTPVerbs::GET );
111  }
112 
120  public static function isRequestPOST()
121  {
122  return self::isRequest( WPDKHTTPVerbs::POST );
123  }
124 
125 
126 }
127 
128