-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontact-buttons.php
More file actions
92 lines (83 loc) · 3.27 KB
/
contact-buttons.php
File metadata and controls
92 lines (83 loc) · 3.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
/*
Plugin Name: Chat & Call Sticky Button
Description: Adds floating chat (WhatsApp) and Call Us buttons to your website.
Version: 2.0
Author: Faisal Khan
License: GPLv2 or later
Text Domain: chat-call-sticky-button
Tested up to: 6.6.2 // Ensure this is the current WordPress version
*/
// Unique prefix for functions
function ccsb_enqueue_styles() {
wp_enqueue_style('ccsb-style', plugin_dir_url(__FILE__) . 'contact-buttons.css');
}
add_action('wp_enqueue_scripts', 'ccsb_enqueue_styles');
// Add buttons to the footer
function ccsb_add_contact_buttons() {
$whatsapp_link = get_option('ccsb_whatsapp', 'https://wa.me/yourwhatsappnumber');
$phone_number = get_option('ccsb_phone', 'yourphonenumber');
echo '<div class="contact-buttons">
<a href="' . esc_url($whatsapp_link) . '" class="whatsapp-button">WhatsApp</a>
<a href="tel:' . esc_attr($phone_number) . '" class="call-button">Call us</a>
</div>';
}
add_action('wp_footer', 'ccsb_add_contact_buttons');
// Create a settings page
function ccsb_create_menu() {
add_menu_page(
'Chat & Call Sticky Button',
'Chat & Call Sticky Button',
'manage_options',
'chat-call-sticky-button',
'ccsb_settings_page',
'dashicons-phone',
90
);
}
add_action('admin_menu', 'ccsb_create_menu');
function ccsb_settings_page() {
?>
<div class="wrap">
<h1>Chat & Call Sticky Buttons Settings</h1>
<p>Please add your full WhatsApp link in the format <b>https://wa.me/number</b> and your phone number.</p>
<?php settings_errors(); ?>
<form method="post" action="options.php">
<?php
settings_fields('ccsb-settings-group');
do_settings_sections('ccsb-settings-group');
?>
<table class="form-table">
<tr valign="top">
<th scope="row">WhatsApp Link</th>
<td>
<input type="text" name="ccsb_whatsapp" placeholder="https://wa.me/number" value="<?php echo esc_attr(get_option('ccsb_whatsapp')); ?>" />
</td>
</tr>
<tr valign="top">
<th scope="row">Phone Number</th>
<td>
<input type="text" name="ccsb_phone" placeholder="xxxxxxxxxx" value="<?php echo esc_attr(get_option('ccsb_phone')); ?>" />
</td>
</tr>
</table>
<?php submit_button(); ?>
</form>
</div>
<?php
}
// Validation function for WhatsApp link
function ccsb_validate_whatsapp_link($input) {
if (filter_var($input, FILTER_VALIDATE_URL) && strpos($input, 'https://wa.me/') === 0) {
return esc_url_raw($input);
} else {
add_settings_error('ccsb_whatsapp', 'invalid_whatsapp_link', 'Please enter a valid WhatsApp link starting with https://wa.me/');
return '';
}
}
function ccsb_register_settings() {
register_setting('ccsb-settings-group', 'ccsb_whatsapp', 'ccsb_validate_whatsapp_link');
register_setting('ccsb-settings-group', 'ccsb_phone');
}
add_action('admin_init', 'ccsb_register_settings');
?>