*/ public static function kinds() { return array( 'suggestion' => __( 'Suggestion', 'aslansheed-login' ), 'feature' => __( 'Feature request', 'aslansheed-login' ), 'bug' => __( 'Bug report', 'aslansheed-login' ), 'question' => __( 'Question', 'aslansheed-login' ), ); } /** * Prints the form. * * @return void */ public function render() { $user = wp_get_current_user(); // The card stays one line tall until the administrator opens it. echo '
'; echo ''; Admin_Ui::collapse_open( false, array( 'id' => 'aslo-fb-body' ) ); echo '
'; echo '
'; echo ''; wp_nonce_field( self::ACTION ); Admin_Ui::row_open( __( 'What is it about?', 'aslansheed-login' ), '', 'aslo-fb-kind' ); echo ''; Admin_Ui::row_close(); Admin_Ui::row_open( __( 'Your message', 'aslansheed-login' ), __( 'For a bug, tell us what you did, what you expected and what happened instead.', 'aslansheed-login' ), 'aslo-fb-message' ); echo ''; Admin_Ui::row_close(); Admin_Ui::row_open( __( 'Your email', 'aslansheed-login' ), __( 'Optional. Only so we can answer you.', 'aslansheed-login' ), 'aslo-fb-email' ); echo ''; Admin_Ui::row_close(); Admin_Ui::row_open( __( 'Technical details', 'aslansheed-login' ), __( 'Helps us find a bug. Untick to leave them out.', 'aslansheed-login' ), 'aslo-fb-tech' ); Admin_Ui::switch_input( 'include_tech', true, 'aslo-fb-tech', __( 'Include', 'aslansheed-login' ) ); echo '
' . esc_html__( 'What is included', 'aslansheed-login' ) . '

' . esc_html__( 'Plugin, WordPress, PHP, WooCommerce and Elementor versions, the site language, and whether this is a multisite. No passwords, keys, user data or settings values.', 'aslansheed-login' ) . '

'; Admin_Ui::row_close(); Admin_Ui::row_open( __( 'Site address', 'aslansheed-login' ), __( 'Off by default. Turn it on if you want us to look at your site.', 'aslansheed-login' ), 'aslo-fb-site' ); Admin_Ui::switch_input( 'include_site', false, 'aslo-fb-site', __( 'Include', 'aslansheed-login' ) ); Admin_Ui::row_close(); // A field real visitors never see; a bot that fills it is ignored. echo ''; echo '
'; echo '

' . esc_html__( 'Nothing is sent until you press Send. The message is emailed from this site to the Aslansheed team and is used only to answer you and improve the plugin.', 'aslansheed-login' ) . '

'; echo '
'; echo '
'; Admin_Ui::collapse_close(); echo '
'; } /** * Handles the form post. * * @return void */ public function handle() { if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'You are not allowed to do this.', 'aslansheed-login' ), '', array( 'response' => 403 ) ); } check_admin_referer( self::ACTION ); // phpcs:disable WordPress.Security.NonceVerification.Missing -- Verified by check_admin_referer() above. $result = self::send( array( 'kind' => isset( $_POST['kind'] ) ? sanitize_key( wp_unslash( $_POST['kind'] ) ) : '', 'message' => isset( $_POST['message'] ) ? sanitize_textarea_field( wp_unslash( $_POST['message'] ) ) : '', 'reply_to' => isset( $_POST['reply_to'] ) ? sanitize_email( wp_unslash( $_POST['reply_to'] ) ) : '', 'include_tech' => ! empty( $_POST['include_tech'] ), 'include_site' => ! empty( $_POST['include_site'] ), 'website' => isset( $_POST['website'] ) ? sanitize_text_field( wp_unslash( $_POST['website'] ) ) : '', ), get_current_user_id() ); $ajax = ! empty( $_POST['aslansheed_ajax'] ); // phpcs:enable $ok = ! is_wp_error( $result ); $message = $ok ? __( 'Thank you! Your message was sent.', 'aslansheed-login' ) : $result->get_error_message(); if ( $ajax ) { wp_send_json( array( 'ok' => $ok, 'message' => $message, ) ); } set_transient( 'aslansheed_notice_' . get_current_user_id(), array( 'type' => $ok ? 'success' : 'error', 'message' => $message, ), 60 ); wp_safe_redirect( add_query_arg( array( 'page' => Settings_Page::PAGE_SLUG, 'tab' => 'about', ), admin_url( 'admin.php' ) ) ); exit; } /** * Checks a message and emails it. * * @param array $input Keys: kind, message, reply_to, include_tech, include_site, website. * @param int $user_id Administrator sending it. * @return true|WP_Error */ public static function send( array $input, $user_id ) { // A filled trap field means a bot. Pretend it worked. if ( ! empty( $input['website'] ) ) { return true; } $kinds = self::kinds(); $kind = isset( $input['kind'], $kinds[ $input['kind'] ] ) ? (string) $input['kind'] : 'suggestion'; $message = trim( isset( $input['message'] ) ? (string) $input['message'] : '' ); $length = function_exists( 'mb_strlen' ) ? mb_strlen( $message, 'UTF-8' ) : strlen( $message ); if ( $length < self::MIN_LENGTH ) { return new WP_Error( 'aslansheed_feedback_short', __( 'Please write a little more so we can understand.', 'aslansheed-login' ) ); } if ( $length > self::MAX_LENGTH ) { return new WP_Error( 'aslansheed_feedback_long', __( 'Your message is too long. Please shorten it.', 'aslansheed-login' ) ); } $key = self::LIMIT_KEY . (int) $user_id; $sent = (int) get_transient( $key ); if ( $sent >= self::MAX_PER_HR ) { return new WP_Error( 'aslansheed_feedback_limit', __( 'You have sent several messages already. Please try again in an hour.', 'aslansheed-login' ) ); } $reply_to = isset( $input['reply_to'] ) && is_email( (string) $input['reply_to'] ) ? (string) $input['reply_to'] : ''; $site = wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ); $lines = array( $kinds[ $kind ], '', $message, '', '---', 'Reply to: ' . ( '' !== $reply_to ? $reply_to : '(none given)' ), ); if ( ! empty( $input['include_site'] ) ) { $lines[] = 'Site: ' . home_url( '/' ); } if ( ! empty( $input['include_tech'] ) ) { $lines[] = 'Plugin: ' . ASLANSHEED_OTP_VERSION; $lines[] = 'WordPress: ' . get_bloginfo( 'version' ); $lines[] = 'PHP: ' . PHP_VERSION; $lines[] = 'Locale: ' . get_locale(); $lines[] = 'Multisite: ' . ( is_multisite() ? 'yes' : 'no' ); $lines[] = 'WooCommerce: ' . ( defined( 'WC_VERSION' ) ? WC_VERSION : 'not active' ); $lines[] = 'Elementor: ' . ( defined( 'ELEMENTOR_VERSION' ) ? ELEMENTOR_VERSION : 'not active' ); } $headers = array( 'Content-Type: text/plain; charset=UTF-8' ); if ( '' !== $reply_to ) { $headers[] = 'Reply-To: ' . str_replace( array( "\r", "\n", '<', '>', ',', '"' ), '', $reply_to ); } $subject = str_replace( array( "\r", "\n" ), ' ', '[Aslansheed Login] ' . $kinds[ $kind ] . ( '' !== $reply_to || ! empty( $input['include_site'] ) ? ' - ' . $site : '' ) ); if ( ! wp_mail( self::RECIPIENT, $subject, implode( "\n", $lines ), $headers ) ) { return new WP_Error( 'aslansheed_feedback_failed', sprintf( /* translators: %s: email address of the developers. */ __( 'This site could not send the email. You can write to us directly at %s.', 'aslansheed-login' ), self::RECIPIENT ) ); } set_transient( $key, $sent + 1, HOUR_IN_SECONDS ); return true; } }