| @@ -5,19 +5,29 @@ | ||
| 5 | 5 | use WPDataAccess\WPDA; |
| 6 | 6 | |
| 7 | 7 | class WPDA_Remote_Call { |
| 8 | 8 | |
| 9 | - public static function post( $url, $body, $die = false, $headers = array() ) { | |
| 9 | + public static function post( | |
| 10 | + $url, | |
| 11 | + $body, | |
| 12 | + $die = false, | |
| 13 | + $headers = array(), | |
| 14 | + $sslverify = true | |
| 15 | + ) { | |
| 10 | 16 | $response = wp_remote_post( |
| 11 | 17 | $url, |
| 12 | 18 | array( |
| 13 | - 'headers' => $headers, | |
| 14 | - 'body' => $body, | |
| 15 | - 'timeout' => 60, | |
| 19 | + 'headers' => $headers, | |
| 20 | + 'body' => $body, | |
| 21 | + 'timeout' => 60, | |
| 22 | + 'sslverify' => $sslverify, | |
| 16 | 23 | ) |
| 17 | 24 | ); |
| 18 | - // var_dump($response); | |
| 19 | 25 | |
| 26 | + if ( 'on' === WPDA::get_option( WPDA::OPTION_PLUGIN_DEBUG ) ) { | |
| 27 | + // WPDA::wpda_log_wp_error( $response ); | |
| 28 | + } | |
| 29 | + | |
| 20 | 30 | if ( is_wp_error( $response ) ) { |
| 21 | 31 | WPDA::wpda_log_wp_error( json_encode( $response ) ); |
| 22 | 32 | if ( $die ) { |
| 23 | 33 | wp_die( 'ERROR: Remote call failed [' . json_encode( $response ) . ']' ); |
| @@ -39,11 +49,14 @@ | ||
| 39 | 49 | } |
| 40 | 50 | |
| 41 | 51 | public static function get( $url, $args = array(), $die = false ) { |
| 42 | 52 | $response = wp_remote_get( $url, $args ); |
| 43 | - // var_dump($response); | |
| 44 | 53 | |
| 45 | - if ( is_wp_error( $response ) ) { | |
| 54 | + if ( 'on' === WPDA::get_option( WPDA::OPTION_PLUGIN_DEBUG ) ) { | |
| 55 | + // WPDA::wpda_log_wp_error( $response ); | |
| 56 | + } | |
| 57 | + | |
| 58 | + if ( is_wp_error( $response ) ) { | |
| 46 | 59 | WPDA::wpda_log_wp_error( json_encode( $response ) ); |
| 47 | 60 | if ( $die ) { |
| 48 | 61 | wp_die( 'ERROR: Remote call failed [' . json_encode( $response ) . ']' ); |
| 49 | 62 | } |
| @@ -62,9 +75,40 @@ | ||
| 62 | 75 | |
| 63 | 76 | return $response; |
| 64 | 77 | } |
| 65 | 78 | |
| 66 | - public static function max_size() { | |
| 79 | + public static function delete( $url, $args = array(), $headers = array(), $die = false ) { | |
| 80 | + $response = wp_remote_request( | |
| 81 | + $url, | |
| 82 | + array( | |
| 83 | + 'method' => 'DELETE', | |
| 84 | + 'headers' => $headers, | |
| 85 | + ) | |
| 86 | + ); | |
| 87 | + | |
| 88 | + if ( 'on' === WPDA::get_option( WPDA::OPTION_PLUGIN_DEBUG ) ) { | |
| 89 | + // WPDA::wpda_log_wp_error( $response ); | |
| 90 | + } | |
| 91 | + | |
| 92 | + if ( is_wp_error( $response ) ) { | |
| 93 | + WPDA::wpda_log_wp_error( json_encode( $response ) ); | |
| 94 | + if ( $die ) { | |
| 95 | + wp_die( 'ERROR: Remote DELETE failed [' . json_encode( $response ) . ']' ); | |
| 96 | + } | |
| 97 | + | |
| 98 | + return false; | |
| 99 | + } | |
| 100 | + | |
| 101 | + $status_code = wp_remote_retrieve_response_code( $response ); | |
| 102 | + if ( $status_code === 204 ) { | |
| 103 | + return true; | |
| 104 | + } | |
| 105 | + | |
| 106 | + WPDA::wpda_log_wp_error("ERROR: Delete failed: HTTP $status_code"); | |
| 107 | + return false; | |
| 108 | + } | |
| 109 | + | |
| 110 | + public static function max_size() { | |
| 67 | 111 | $max = ini_get('post_max_size'); |
| 68 | 112 | $unit = $max[ strlen( $max ) - 1 ]; |
| 69 | 113 | $max = substr( $max, 0, strlen( $max ) - 1 ); |
| 70 | 114 | |