-
Notifications
You must be signed in to change notification settings - Fork 0
/
trds-visitor-counter-settings.php
181 lines (160 loc) · 6.33 KB
/
trds-visitor-counter-settings.php
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<?php
/**
* TRDS Website Visitor Counter Settings Page
*
* This page allows users to customize the display options for the TRDS Website Visitor Counter plugin.
* Users can configure settings such as title text, colors, alignment, and labels for visitor counts.
*/
// Add settings page
function custom_visitor_settings_page()
{
add_options_page(
'TRDS Website Counter',
'TRDS Web Counter',
'manage_options',
'custom-visitor-settings',
'custom_visitor_settings_callback'
);
}
add_action('admin_menu', 'custom_visitor_settings_page');
// Settings page callback function
function custom_visitor_settings_callback()
{
?>
<div class="wrap">
<h2>TRDS Web Counter Settings</h2>
<form method="post" action="options.php">
<?php settings_fields('custom_visitor_settings_group'); ?>
<?php do_settings_sections('custom-visitor-settings'); ?>
<?php submit_button(); ?>
</form>
</div>
<?php
}
// Register and define settings
function custom_visitor_register_settings()
{
register_setting('custom_visitor_settings_group', 'custom_visitor_input');
register_setting('custom_visitor_settings_group', 'custom_visitor_input_color');
register_setting('custom_visitor_settings_group', 'custom_visitor_input_alignment');
register_setting('custom_visitor_settings_group', 'custom_visitor_views_text_today');
register_setting('custom_visitor_settings_group', 'custom_visitor_views_text_month');
register_setting('custom_visitor_settings_group', 'custom_visitor_views_color');
register_setting('custom_visitor_settings_group', 'custom_visitor_views_alignment');
add_settings_section(
'custom_visitor_settings_section',
'Visitor Count Display Options',
'custom_visitor_settings_section_callback',
'custom-visitor-settings'
);
add_settings_field(
'custom_visitor_input',
'Web Counter Title',
'custom_visitor_input_callback',
'custom-visitor-settings',
'custom_visitor_settings_section'
);
add_settings_field(
'custom_visitor_input_color',
'Web Counter Title Color',
'custom_visitor_input_color_callback',
'custom-visitor-settings',
'custom_visitor_settings_section'
);
add_settings_field(
'custom_visitor_input_alignment',
'Web Counter Title Alignment',
'custom_visitor_input_alignment_callback',
'custom-visitor-settings',
'custom_visitor_settings_section'
);
add_settings_field(
'custom_visitor_views_text_today',
'Views Today (Label)',
'custom_visitor_views_text_today_callback',
'custom-visitor-settings',
'custom_visitor_settings_section'
);
add_settings_field(
'custom_visitor_views_text_month',
'Views this month (Label)',
'custom_visitor_views_text_month_callback',
'custom-visitor-settings',
'custom_visitor_settings_section'
);
add_settings_field(
'custom_visitor_views_color',
'Label Color',
'custom_visitor_views_color_callback',
'custom-visitor-settings',
'custom_visitor_settings_section'
);
add_settings_field(
'custom_visitor_views_alignment',
'Label Alignment',
'custom_visitor_views_alignment_callback',
'custom-visitor-settings',
'custom_visitor_settings_section'
);
}
add_action('admin_init', 'custom_visitor_register_settings');
// Section callback function
function custom_visitor_settings_section_callback()
{
echo '<p>To display visitor counts on any part of the site, Insert this shortcode : <code>[trds_custom_visitor_count]</code> into any post, page, or widget content. Save the changes and preview the page to see the visitor counts.</p>';
}
// Input callback function
function custom_visitor_input_callback()
{
$input = get_option('custom_visitor_input');
echo "<input type='text' name='custom_visitor_input' value='" . esc_attr($input) . "' />";
}
// Input color callback function
function custom_visitor_input_color_callback()
{
$input_color = get_option('custom_visitor_input_color', '#000000');
echo "<input type='color' name='custom_visitor_input_color' value='" . esc_attr($input_color) . "' />";
}
// Input alignment callback function
function custom_visitor_input_alignment_callback()
{
$input_alignment = get_option('custom_visitor_input_alignment', 'left');
$options = array('left', 'center', 'right');
echo '<select name="custom_visitor_input_alignment">';
foreach ($options as $option) {
$selected = ($input_alignment == $option) ? 'selected' : '';
echo '<option value="' . esc_attr($option) . '" ' . esc_attr($selected) . '>' . esc_html($option) . '</option>';
}
echo '</select>';
}
// Views text today callback function
function custom_visitor_views_text_today_callback()
{
$views_text_today = get_option('custom_visitor_views_text_today', 'Views Today');
echo "<input type='text' name='custom_visitor_views_text_today' value='" . esc_attr($views_text_today) . "' />";
}
// Views text month callback function
function custom_visitor_views_text_month_callback()
{
$views_text_month = get_option('custom_visitor_views_text_month', 'Views This Month');
echo "<input type='text' name='custom_visitor_views_text_month' value='" . esc_attr($views_text_month) . "' />";
}
// Views color callback function
function custom_visitor_views_color_callback()
{
$views_color = get_option('custom_visitor_views_color', '#815b0a');
echo "<input type='color' name='custom_visitor_views_color' value='" . esc_attr($views_color) . "' />";
}
// Views alignment callback function
function custom_visitor_views_alignment_callback()
{
$views_alignment = get_option('custom_visitor_views_alignment', 'left');
$options = array('left', 'center', 'right');
echo '<select name="custom_visitor_views_alignment">';
foreach ($options as $option) {
$selected = ($views_alignment == $option) ? 'selected' : '';
echo '<option value="' . esc_attr($option) . '" ' . esc_attr($selected) . '>' . esc_html($option) . '</option>';
}
echo '</select>';
}
?>