Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 21 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| Util | |
0.00% |
0 / 21 |
|
0.00% |
0 / 1 |
20 | |
0.00% |
0 / 1 |
| post_feedback | |
0.00% |
0 / 21 |
|
0.00% |
0 / 1 |
20 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace NewfoldLabs\WP\Module\HelpCenter; |
| 4 | |
| 5 | /** |
| 6 | * The utility pass through for interacting with the |
| 7 | * AI service |
| 8 | */ |
| 9 | class Util { |
| 10 | /** |
| 11 | * The function to proxy to the AI service and get a response |
| 12 | * |
| 13 | * @param integer $post_id the Post Id |
| 14 | * @param string $feedback the feedback |
| 15 | */ |
| 16 | public static function post_feedback( |
| 17 | $post_id, |
| 18 | $feedback |
| 19 | ) { |
| 20 | if ( ! function_exists( 'wp_json_encode' ) ) { |
| 21 | require_once ABSPATH . 'wp-includes/functions.php'; |
| 22 | } |
| 23 | |
| 24 | $response = wp_remote_post( |
| 25 | USER_INTERACTION_SERVICE_BASE . 'incrementMeta/', |
| 26 | array( |
| 27 | 'method' => 'POST', |
| 28 | 'headers' => array( |
| 29 | 'Content-Type' => 'application/json', |
| 30 | ), |
| 31 | 'timeout' => 60, |
| 32 | 'body' => wp_json_encode( |
| 33 | array( |
| 34 | 'postId' => $post_id, |
| 35 | 'meta' => 'helpful' === $feedback ? 'likes' : 'dislikes', |
| 36 | ) |
| 37 | ), |
| 38 | ) |
| 39 | ); |
| 40 | if ( wp_remote_retrieve_response_code( $response ) !== 200 ) { |
| 41 | return false; |
| 42 | } |
| 43 | return true; |
| 44 | } |
| 45 | } |