first_name ?? ''; $last_name = $user->last_name ?? ''; $full_name = $first_name && $last_name ? "$first_name $last_name" : $user->display_name ?? ''; $fields = [ [ 'name' => 'from_name', 'type' => 'text', 'label' => __( 'Your Name', 'admin-help-docs' ), 'desc' => __( 'Enter your name to include in the support request.', 'admin-help-docs' ), 'sanitize' => 'sanitize_text_field', 'default' => $full_name, 'required' => true, ], [ 'name' => 'reply_to', 'type' => 'text', 'label' => __( 'Reply-To Email', 'admin-help-docs' ), 'desc' => __( 'The email address where we should send our response.', 'admin-help-docs' ), 'sanitize' => 'sanitize_email', 'default' => $user->user_email, 'required' => true, ], [ 'name' => 'contact_reason', 'type' => 'select', 'label' => __( 'Reason for Contact', 'admin-help-docs' ), 'desc' => __( 'Select the category that best fits your inquiry.', 'admin-help-docs' ), 'choices' => [ [ 'label' => __( '-- Please One ---', 'admin-help-docs' ), 'value' => '', ], [ 'label' => __( 'Technical Support', 'admin-help-docs' ), 'value' => __( 'Technical Support', 'admin-help-docs' ), ], [ 'label' => __( 'Billing Inquiry', 'admin-help-docs' ), 'value' => __( 'Billing Inquiry', 'admin-help-docs' ), ], [ 'label' => __( 'Feature Request', 'admin-help-docs' ), 'value' => __( 'Feature Request', 'admin-help-docs' ), ], [ 'label' => __( 'Other', 'admin-help-docs' ), 'value' => __( 'Other', 'admin-help-docs' ), ], ], 'sanitize' => 'sanitize_text_field', 'required' => true, 'has_condition' => true, ], [ 'name' => 'page_url', 'type' => 'text', 'label' => __( 'URL of Page with Issue', 'admin-help-docs' ), 'desc' => __( 'The URL of the page where you encountered the issue.', 'admin-help-docs' ), 'sanitize' => 'sanitize_text_field', 'condition' => [ 'contact_reason' => __( 'Technical Support', 'admin-help-docs' ) ], ], [ 'name' => 'subject', 'type' => 'text', 'label' => __( 'Subject', 'admin-help-docs' ), 'desc' => __( 'A brief summary of your request.', 'admin-help-docs' ), 'sanitize' => 'sanitize_text_field', 'required' => true, ], [ 'name' => 'message_body', 'type' => 'textarea', 'label' => __( 'How can we help?', 'admin-help-docs' ), 'desc' => __( 'Please provide as much detail as possible.', 'admin-help-docs' ), 'sanitize' => 'sanitize_textarea_field', 'required' => true, ], [ 'name' => 'attachments', 'type' => 'file', 'label' => __( 'Upload Screenshots or Documents', 'admin-help-docs' ), 'desc' => sprintf( __( 'Attach relevant files (JPG, PNG, PDF). Max %dMB.', 'admin-help-docs' ), self::$max_attachment_mb ), 'sanitize' => 'sanitize_files', ], ]; return apply_filters( 'helpdocs_support_form_fields', $fields, $user ); } // End form_fields() /** * Contact info * * @var array */ private static $contact_info = []; /** * Enable or disable logging of support requests * * @var bool */ private static $logging_enabled = true; /** * Quantity of support requests to log * * @var int */ private static $logging_qty = 20; /** * Max attachment size in MB * * @var int */ public static $max_attachment_mb = 10; /** * Date format for logs * * @var string */ public static $log_date_format = 'M j, Y g:i a'; /** * The single instance of the class * * @var self|null */ private static ?Support $instance = null; /** * Get the singleton instance * * @return self */ public static function instance() : self { return self::$instance ??= new self(); } // End instance() /** * Constructor */ private function __construct() { // Store the contact info add_action( 'init', [ $this, 'get_support_contact_info' ] ); // Logging self::$logging_enabled = apply_filters( 'helpdocs_support_logging_enabled', self::$logging_enabled ); self::$logging_qty = apply_filters( 'helpdocs_support_log_quantity', self::$logging_qty ); // Max attachment size self::$max_attachment_mb = apply_filters( 'helpdocs_support_max_attachment_size', self::$max_attachment_mb ); // Date format for logs self::$log_date_format = apply_filters( 'helpdocs_support_log_date_format', self::$log_date_format ); // Add the contact info to the header add_action( 'helpdocs_subheader_right', [ $this, 'render_details_box' ] ); // Handle the AJAX requests add_action( 'wp_ajax_helpdocs_send_support_email', [ $this, 'ajax_process_support_form' ] ); add_action( 'wp_ajax_helpdocs_clear_support_logs', [ $this, 'ajax_clear_support_logs' ] ); } // End __construct() /** * Get support contact info * * @return array */ public function get_support_contact_info() { if ( ! class_exists( Helpers::class ) || ! class_exists( Menu::class ) || ! Menu::is_our_tab( 'support' ) ) { return; } self::$contact_info = apply_filters( 'helpdocs_support_contact_info', [ 'name' => sanitize_text_field( get_option( 'helpdocs_contact_name', '' ) ), 'emails' => array_map( 'trim', explode( ',', sanitize_text_field( get_option( 'helpdocs_contact_emails', implode( ', ', Helpers::get_all_admin_emails() ) ) ) ) ), 'phone' => sanitize_text_field( get_option( 'helpdocs_contact_phone', '' ) ), ] ); } // End get_support_contact_info() /** * Add a details box to the subheader on the support page * * @param string $current_tab The current admin tab * @return void */ public function render_details_box( string $current_tab ) { if ( $current_tab !== 'support' ) { return; } $results = '
' . esc_html__( 'No contact email addresses configured. Please add at least one email address in the settings to contact support.', 'admin-help-docs' ) . '
'; return; } $fields = $this->form_fields(); $box_label = apply_filters( 'helpdocs_support_form_box_label', __( 'Complete the form below to send a message to support.', 'admin-help-docs' ) ); $submit_label = apply_filters( 'helpdocs_support_form_submit_label', __( 'Send Support Request', 'admin-help-docs' ) ); ?>|
|