-
Notifications
You must be signed in to change notification settings - Fork 0
/
call-button-py.php
63 lines (60 loc) · 1.99 KB
/
call-button-py.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
<?php
/*
Plugin Name: Call Button Py
Plugin URI: https://github.com/LuisLeguizamon
Description: Call button py
Version: 1.0
Author: Luis Leguizamon
Author URI: https://github.com/LuisLeguizamon
License: GPL2
License URI: https://www.gnu.org/licenses/gpl-2.0.html
*/
// Add a custom section to the WordPress admin panel (it will show inside Settings Section)
function call_button_py_admin_menu() {
add_options_page(
'Call Button Py Settings',
'Call Button Py',
'manage_options',
'call_button_py',
'call_button_py_settings_page',
);
}
add_action( 'admin_menu', 'call_button_py_admin_menu' );
// Callback function for the custom section
function call_button_py_settings_page() {
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
if ( isset( $_POST['call_button_py_phone'] ) ) {
$value = sanitize_text_field( $_POST['call_button_py_phone'] );
update_option( 'call_button_py_phone', $value );
}
$value = get_option( 'call_button_py_phone', '' );
?>
<div class="wrap">
<h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
<form method="post">
<label id="call_button_py_phone">Phone number</label>
<input type="text" id="call_button_py_phone" name="call_button_py_phone" value="<?php echo esc_attr( $value ); ?>"/>
<?php submit_button(); ?>
</form>
</div>
<?php
}
// Add a call button to the end of single posts
function call_button_py_contact($content)
{
$number = get_option( 'call_button_py_phone', '' );
// Only do this when a single post is displayed
if (is_single()) {
// Message you want to display after the post
$content .=
'<p class="follow-us">
Si estás interesado contactanos al
<a href="tel:'.$number.'">'.$number.'</a>
</p>';
}
// Return the content
return $content;
}
add_filter('the_content', 'call_button_py_contact');