' . esc_html__('Access Denied', 'rapidchat') . '
'
. esc_html__('You do not have permission to access this page.', 'rapidchat') . '
';
return;
}
$saves = array();
foreach ($allowed_tabs as $slug) {
if (!empty($tabs[$slug]['save']) && is_callable($tabs[$slug]['save']) && !in_array($tabs[$slug]['save'], $saves, true)) {
$saves[] = $tabs[$slug]['save'];
}
}
foreach ($saves as $save) {
call_user_func($save);
}
$current_tab = isset($_GET['tab']) ? sanitize_key(wp_unslash($_GET['tab'])) : $allowed_tabs[0]; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only tab switch.
if (!in_array($current_tab, $allowed_tabs, true)) {
$current_tab = $allowed_tabs[0];
}
$tab = $tabs[$current_tab];
$rapidchat_nav = array();
foreach ($allowed_tabs as $slug) {
$rapidchat_nav[$slug] = array(
'icon' => $tabs[$slug]['icon'],
'label' => $tabs[$slug]['label'],
'url' => admin_url('admin.php?page=rapidchat-settings&tab=' . $slug),
'active' => $current_tab === $slug,
);
}
$rapidchat_actions = '';
if (current_user_can('rapidchat_view')) {
$rapidchat_actions .= rapidchat_admin_action(__('Open Workspace', 'rapidchat'), admin_url('admin.php?page=rapidchat-inbox'), 'secondary', 'dashicons-format-chat');
}
if (!empty($tab['save_form'])) {
$rapidchat_actions .= '';
}
rapidchat_admin_shell_open(array(
'title' => $tab['label'],
'nav' => $rapidchat_nav,
'actions' => $rapidchat_actions,
));
echo '' . esc_html($tab['summary']) . '
';
if (!empty($tab['render']) && is_callable($tab['render'])) {
call_user_func($tab['render']);
}
rapidchat_admin_shell_close();
}
function rapidchat_settings_toggle_row($name, $label, $desc, $checked, $id = '') {
$id = $id ? $id : 'rc-toggle-' . sanitize_html_class(str_replace('_', '-', $name));
?>
'Classic Navy', 'color' => '#1e3c72'),
array('name' => 'Modern Indigo', 'color' => '#4f46e5'),
array('name' => 'Emerald Green', 'color' => '#059669'),
array('name' => 'Sunset Coral', 'color' => '#e11d48'),
array('name' => 'Royal Violet', 'color' => '#7c3aed'),
array('name' => 'Ocean Cyan', 'color' => '#0891b2'),
array('name' => 'Dark Slate', 'color' => '#1e293b'),
array('name' => 'Amber Gold', 'color' => '#d97706'),
);
?>
array(RAPIDCHAT_CAP_OPERATE, RAPIDCHAT_CAP_MANAGE), 'orderby' => 'display_name'));
$role_names = wp_roles()->get_names();
?>
get_results($wpdb->prepare('SELECT * FROM %i ORDER BY shortcut ASC', $wpdb->rapidchat_canned_responses));
?>
rapidchat_canned_responses || $wpdb->get_var($wpdb->prepare('SHOW TABLES LIKE %s', $wpdb->esc_like($wpdb->rapidchat_canned_responses))) !== $wpdb->rapidchat_canned_responses) {
return;
}
if (isset($_GET['delete_canned'])) {
check_admin_referer('rapidchat_delete_canned');
$id = absint(wp_unslash($_GET['delete_canned']));
$wpdb->delete($wpdb->rapidchat_canned_responses, array('id' => $id), array('%d'));
echo '' . esc_html__('Canned response deleted.', 'rapidchat') . '
';
return;
}
if (!isset($_POST['rapidchat_canned_nonce'])) {
return;
}
check_admin_referer('rapidchat_canned', 'rapidchat_canned_nonce');
$shortcut = isset($_POST['shortcut']) ? sanitize_key(wp_unslash($_POST['shortcut'])) : '';
$title = isset($_POST['title']) ? sanitize_text_field(wp_unslash($_POST['title'])) : '';
$content = isset($_POST['content']) ? sanitize_textarea_field(wp_unslash($_POST['content'])) : '';
if ($shortcut === '' || $content === '') {
echo '' . esc_html__('Shortcut and template content are required.', 'rapidchat') . '
';
return;
}
$wpdb->insert(
$wpdb->rapidchat_canned_responses,
array(
'shortcut' => $shortcut,
'title' => $title,
'content' => $content,
'created_at' => current_time('mysql'),
),
array('%s', '%s', '%s', '%s')
);
echo '' . esc_html__('Canned response added!', 'rapidchat') . '
';
}
function rapidchat_handle_settings_save() {
if (!isset($_POST['rapidchat_settings_nonce'])) {
return;
}
check_admin_referer('rapidchat_settings', 'rapidchat_settings_nonce');
if (!rapidchat_settings_can('general')) {
wp_die(esc_html__('You do not have permission to do that.', 'rapidchat'));
}
$tab = isset($_POST['rapidchat_tab']) ? sanitize_key(wp_unslash($_POST['rapidchat_tab'])) : 'general';
if ($tab === 'branding') {
if (isset($_POST['rapidchat_widget_mode'])) {
$mode = sanitize_key(wp_unslash($_POST['rapidchat_widget_mode']));
if ($mode === 'direct' || $mode === 'hub') {
update_option('rapidchat_widget_mode', $mode);
}
}
update_option('rapidchat_show_home_tab', isset($_POST['rapidchat_show_home_tab']) ? 1 : 0);
if (isset($_POST['rapidchat_brand_title'])) {
update_option('rapidchat_brand_title', rapidchat_encode_emoji_option(sanitize_text_field(wp_unslash($_POST['rapidchat_brand_title']))));
}
if (isset($_POST['rapidchat_greeting_title'])) {
update_option('rapidchat_greeting_title', rapidchat_encode_emoji_option(sanitize_text_field(wp_unslash($_POST['rapidchat_greeting_title']))));
}
if (isset($_POST['rapidchat_greeting_desc'])) {
update_option('rapidchat_greeting_desc', rapidchat_encode_emoji_option(sanitize_textarea_field(wp_unslash($_POST['rapidchat_greeting_desc']))));
}
if (isset($_POST['rapidchat_home_action_title'])) {
update_option('rapidchat_home_action_title', rapidchat_encode_emoji_option(sanitize_text_field(wp_unslash($_POST['rapidchat_home_action_title']))));
}
if (isset($_POST['rapidchat_home_action_sub'])) {
update_option('rapidchat_home_action_sub', rapidchat_encode_emoji_option(sanitize_text_field(wp_unslash($_POST['rapidchat_home_action_sub']))));
}
if (isset($_POST['rapidchat_offline_message'])) {
update_option('rapidchat_offline_message', rapidchat_encode_emoji_option(sanitize_textarea_field(wp_unslash($_POST['rapidchat_offline_message']))));
}
if (isset($_POST['rapidchat_primary_color'])) {
$color = sanitize_hex_color(wp_unslash($_POST['rapidchat_primary_color']));
if ($color) {
update_option('rapidchat_primary_color', $color);
}
}
if (isset($_POST['rapidchat_widget_position'])) {
$pos = sanitize_key(wp_unslash($_POST['rapidchat_widget_position']));
if ($pos === 'left' || $pos === 'right') {
update_option('rapidchat_widget_position', $pos);
}
}
update_option('rapidchat_auto_display', isset($_POST['rapidchat_auto_display']) ? 1 : 0);
update_option('rapidchat_prechat_show_message', isset($_POST['rapidchat_prechat_show_message']) ? 1 : 0);
update_option('rapidchat_prechat_require_message', isset($_POST['rapidchat_prechat_require_message']) ? 1 : 0);
if (isset($_POST['rapidchat_prechat_intro_title'])) {
update_option('rapidchat_prechat_intro_title', rapidchat_encode_emoji_option(sanitize_text_field(wp_unslash($_POST['rapidchat_prechat_intro_title']))));
}
if (isset($_POST['rapidchat_prechat_intro_text'])) {
update_option('rapidchat_prechat_intro_text', rapidchat_encode_emoji_option(sanitize_textarea_field(wp_unslash($_POST['rapidchat_prechat_intro_text']))));
}
} else {
update_option('rapidchat_geolocate', isset($_POST['rapidchat_geolocate']) ? 1 : 0);
update_option('rapidchat_trust_proxy', isset($_POST['rapidchat_trust_proxy']) ? 1 : 0);
}
do_action('rapidchat_settings_save_' . $tab);
if ($tab === 'general') {
rapidchat_register_capabilities();
do_action('rapidchat_settings_saved', (array) get_option('rapidchat_operator_roles', array('administrator')));
}
echo '' . esc_html__('Settings saved successfully.', 'rapidchat') . '
';
}
/** The Widget Customizer's live-preview script, enqueued with its two translated labels. */
function rapidchat_enqueue_settings_preview() {
wp_enqueue_script('rapidchat-settings-preview', RAPIDCHAT_JS . '/settings-preview.js', array('jquery'), rapidchat_asset_version('js/settings-preview.js'), true);
wp_localize_script('rapidchat-settings-preview', 'rapidchatPreview', array(
'direct' => __('Direct chat', 'rapidchat'),
'hub' => __('Hub', 'rapidchat'),
'directTag' => __('Direct Live Chat', 'rapidchat'),
'hubTag' => __('Self-Service Hub', 'rapidchat'),
));
}