acf-helper.php
5 months ago
ajax-helper.php
5 months ago
device-detector.php
5 months ago
element-feedback.php
5 months ago
pa-nav-menu-walker.php
5 months ago
papro-promotion.php
5 months ago
query-helper.php
5 months ago
widget-class-map.php
5 months ago
widget-name-map.php
5 months ago
element-feedback.php
113 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Element Feedback |
| 4 | * |
| 5 | * Handles element feedback functionality. |
| 6 | */ |
| 7 | |
| 8 | namespace PremiumAddons\Includes\Helpers; |
| 9 | |
| 10 | if ( ! defined( 'ABSPATH' ) ) { |
| 11 | exit; // Exit if accessed directly. |
| 12 | } |
| 13 | |
| 14 | /** |
| 15 | * Class Element_Feedback. |
| 16 | */ |
| 17 | class Element_Feedback { |
| 18 | |
| 19 | |
| 20 | /** |
| 21 | * Class instance |
| 22 | * |
| 23 | * @var instance |
| 24 | */ |
| 25 | private static $instance = null; |
| 26 | |
| 27 | public function __construct() { |
| 28 | |
| 29 | add_action( 'wp_ajax_pa_send_element_feedback', array( $this, 'send' ) ); |
| 30 | } |
| 31 | |
| 32 | public function send() { |
| 33 | |
| 34 | check_ajax_referer( 'pa-editor', 'security' ); |
| 35 | |
| 36 | $user_msg = isset( $_POST['user_message'] ) ? sanitize_text_field( wp_unslash( $_POST['user_message'] ) ) : ''; |
| 37 | |
| 38 | if( empty( $user_msg ) ) { |
| 39 | wp_send_json_error( array( 'message' => esc_html__( 'Message cannot be empty.', 'premium-addons-for-elementor' ) ) ); |
| 40 | } |
| 41 | |
| 42 | $user = wp_get_current_user(); |
| 43 | |
| 44 | $email = $user->user_email; |
| 45 | |
| 46 | if( empty( $email ) ) { |
| 47 | wp_send_json_error( array( 'message' => esc_html__( 'User email not found.', 'premium-addons-for-elementor' ) ) ); |
| 48 | } |
| 49 | |
| 50 | $element = isset( $_POST['element_name'] ) ? sanitize_text_field( wp_unslash( $_POST['element_name'] ) ) : ''; |
| 51 | |
| 52 | $body = array( |
| 53 | 'email' => $email, |
| 54 | 'element' => $element, |
| 55 | 'message' => $user_msg, |
| 56 | ); |
| 57 | |
| 58 | $api_url = 'https://feedbackpa.leap13.com/wp-json/element-feedback/v2/add'; |
| 59 | |
| 60 | $response = wp_safe_remote_request( |
| 61 | $api_url, |
| 62 | array( |
| 63 | 'headers' => array( |
| 64 | 'Content-Type' => 'application/json', |
| 65 | ), |
| 66 | 'body' => wp_json_encode( $body ), |
| 67 | 'timeout' => 20, |
| 68 | 'method' => 'POST', |
| 69 | 'httpversion' => '1.1', |
| 70 | ) |
| 71 | ); |
| 72 | |
| 73 | if ( is_wp_error( $response ) ) { |
| 74 | wp_send_json_error( 'REQUEST ERR' ); |
| 75 | |
| 76 | } |
| 77 | |
| 78 | if ( ! isset( $response['response'] ) || ! is_array( $response['response'] ) ) { |
| 79 | wp_send_json_error( 'REQUEST UNKNOWN' ); |
| 80 | |
| 81 | } |
| 82 | |
| 83 | if ( ! isset( $response['body'] ) ) { |
| 84 | wp_send_json_error( 'REQUEST PAYLOAD EMPTY' ); |
| 85 | |
| 86 | } |
| 87 | |
| 88 | wp_send_json_success( ( $response['body'] ) ); |
| 89 | |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Creates and returns an instance of the class |
| 94 | * |
| 95 | * @since 1.0.0 |
| 96 | * @access public |
| 97 | * |
| 98 | * @return object |
| 99 | */ |
| 100 | public static function get_instance() { |
| 101 | |
| 102 | if ( ! isset( self::$instance ) ) { |
| 103 | |
| 104 | self::$instance = new self(); |
| 105 | |
| 106 | } |
| 107 | |
| 108 | return self::$instance; |
| 109 | } |
| 110 | |
| 111 | |
| 112 | } |
| 113 |