$current_user->display_name, 'email' => $current_user->user_email, 'phone' => '', 'message' => '', 'consent' => true, ]; $request_method = isset( $_SERVER['REQUEST_METHOD'] ) ? strtoupper( sanitize_text_field( wp_unslash( $_SERVER['REQUEST_METHOD'] ) ) ) : ''; if ( 'POST' === $request_method && isset( $_POST['tpsa_support_submit'] ) ) { $nonce = isset( $_POST['tpsa_support_form_nonce'] ) ? sanitize_text_field( wp_unslash( $_POST['tpsa_support_form_nonce'] ) ) : ''; if ( !wp_verify_nonce( $nonce, 'tpsa_support_form_nonce' ) ) { $errors['general'] = __( 'Your session expired while the form was open. Please send it again.', 'admin-safety-guard' ); } else { $values['name'] = isset( $_POST['tpsa_support_name'] ) ? sanitize_text_field( wp_unslash( $_POST['tpsa_support_name'] ) ) : ''; $values['email'] = isset( $_POST['tpsa_support_email'] ) ? sanitize_email( wp_unslash( $_POST['tpsa_support_email'] ) ) : ''; $values['phone'] = isset( $_POST['tpsa_support_phone'] ) ? sanitize_text_field( wp_unslash( $_POST['tpsa_support_phone'] ) ) : ''; $values['message'] = isset( $_POST['tpsa_support_message'] ) ? sanitize_textarea_field( wp_unslash( $_POST['tpsa_support_message'] ) ) : ''; $values['consent'] = !empty( $_POST['tpsa_support_consent'] ); // Field-level validation, so each problem is shown against its own input // rather than as one message at the top of the page. if ( '' === $values['name'] ) { $errors['name'] = __( 'Please tell us your name.', 'admin-safety-guard' ); } if ( '' === $values['email'] ) { $errors['email'] = __( 'We need an email address to reply to.', 'admin-safety-guard' ); } elseif ( !is_email( $values['email'] ) ) { $errors['email'] = __( 'That email address does not look right.', 'admin-safety-guard' ); } if ( '' === $values['message'] ) { $errors['message'] = __( 'Please describe the problem.', 'admin-safety-guard' ); } elseif ( strlen( $values['message'] ) < 20 ) { $errors['message'] = __( 'A little more detail will help us answer faster — at least 20 characters.', 'admin-safety-guard' ); } if ( empty( $errors ) ) { $body = [ 'name' => $values['name'], 'email' => $values['email'], 'phone' => $values['phone'], 'message' => $values['message'], 'plugin_name' => 'Admin Safety Guard', ]; // Only attach diagnostics when the box is ticked. if ( $values['consent'] ) { global $wp_version; $body['site_url'] = home_url(); $body['wp_version'] = $wp_version; $body['php_version'] = PHP_VERSION; $body['plugin_version'] = TPSA_PLUGIN_VERSION; $body['is_multisite'] = is_multisite() ? 'yes' : 'no'; $body['active_theme'] = wp_get_theme()->get( 'Name' ); } $response = wp_remote_post( 'https://themepaste.com/wp-json/tpsa-support/v1/ticket', [ 'timeout' => 20, 'headers' => ['tpsaapikey' => 'tpsa-support-api'], 'body' => $body, ] ); if ( is_wp_error( $response ) ) { // Never show a raw transport error to a site owner. $api_error = __( 'We could not reach our support server. Your internet connection or a firewall may be blocking it.', 'admin-safety-guard' ); } else { $code = (int) wp_remote_retrieve_response_code( $response ); if ( 200 === $code || 201 === $code ) { $sent = true; } else { $api_error = __( 'Our support server did not accept the request. Please email us directly using the address below.', 'admin-safety-guard' ); } } } } } // Fallback mailto, pre-filled, for when the API is unreachable. $mailto = 'mailto:support@themepaste.com?subject=' . rawurlencode( 'Admin Safety Guard support' ) . '&body=' . rawurlencode( $values['message'] ); ?>

' . esc_html( $values['email'] ) . '' ); ?>

>

>