ajax_action, array( $this, 'send_suggestion' ) ); } /** * Hands the settings app what its "Request a feature" dialog posts to * send_suggestion(), plus the dialog's strings. * * @param array $data Settings app boot data. * @return array */ public function add_settings_app_data( $data ) { $data['requestFeature'] = array( 'action' => $this->ajax_action, 'nonce' => wp_create_nonce( $this->nonce_key ), ); return $data; } public function send_suggestion() { $nonce = isset( $_POST['wtofe_rf_nonce'] ) ? sanitize_text_field( wp_unslash( $_POST['wtofe_rf_nonce'] ) ) : ''; if ( ! $nonce || ! wp_verify_nonce( $nonce, $this->nonce_key ) ) { wp_send_json( array( 'success' => false, 'msg' => __( 'Security check failed.', 'ai-content-generator-for-woocommerce' ) ) ); } if ( ! current_user_can( 'manage_options' ) ) { wp_send_json( array( 'success' => false, 'msg' => __( 'Permission denied.', 'ai-content-generator-for-woocommerce' ) ) ); } $msg = isset( $_POST['wtofe_rf_msg'] ) ? sanitize_textarea_field( wp_unslash( $_POST['wtofe_rf_msg'] ) ) : ''; $contact_ok = isset( $_POST['wtofe_rf_contact_ok'] ) ? sanitize_text_field( wp_unslash( $_POST['wtofe_rf_contact_ok'] ) ) : 'no'; $email = isset( $_POST['wtofe_rf_email'] ) ? sanitize_email( wp_unslash( $_POST['wtofe_rf_email'] ) ) : ''; if ( '' === $msg ) { wp_send_json( array( 'success' => false, 'msg' => __( 'Please enter a message.', 'ai-content-generator-for-woocommerce' ) ) ); } if ( 'yes' === $contact_ok && '' === $email ) { wp_send_json( array( 'success' => false, 'msg' => __( 'We need your email address to contact you back.', 'ai-content-generator-for-woocommerce' ) ) ); } $data = array( 'msg' => $msg, 'user_email' => $email, 'plugin_version' => WTOFE_AI_VERSION, 'plugin' => 'aicontentgenerator', ); wp_remote_post( $this->end_point, array( 'method' => 'POST', 'timeout' => 45, 'blocking' => false, 'body' => $data, 'cookies' => array(), ) ); wp_send_json( array( 'success' => true ) ); } } AI_Content_Generator_Request_Feature::get_instance();