| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: Floating Contact Button |
| 4 |
Description: Integrates a floating contact button and opens an modal with your favorite contact form. |
| 5 |
Version: 2.6 |
| 6 |
Author: Christoph Nagel |
| 7 |
Author URI: https://www.cms-geek.de |
| 8 |
Text Domain: floating-contact |
| 9 |
Domain Path: /languages |
| 10 |
License: GPL2 |
| 11 |
License URI: https://www.gnu.org/licenses/gpl-2.0.html |
| 12 |
|
| 13 |
Floating Contact Button is free software: you can redistribute it and/or modify |
| 14 |
it under the terms of the GNU General Public License as published by |
| 15 |
the Free Software Foundation, either version 2 of the License, or |
| 16 |
any later version. |
| 17 |
|
| 18 |
Floating Contact Button is distributed in the hope that it will be useful, |
| 19 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 |
GNU General Public License for more details. |
| 22 |
|
| 23 |
You should have received a copy of the GNU General Public License |
| 24 |
along with Floating Contact Button. If not, see License URI: https://www.gnu.org/licenses/gpl-2.0.html. |
| 25 |
*/ |
| 26 |
|
| 27 |
defined( 'ABSPATH' ) or die( 'Are you ok?' ); |
| 28 |
|
| 29 |
function fcb_files() { |
| 30 |
wp_enqueue_style( 'custom', plugin_dir_url(__FILE__) . 'assets/css/style.min.css', array(), 1.0, 'screen' ); |
| 31 |
} |
| 32 |
add_action( 'wp_enqueue_scripts', 'fcb_files'); |
| 33 |
|
| 34 |
function fcb_load_dashicons(){ |
| 35 |
wp_enqueue_style('dashicons'); |
| 36 |
} |
| 37 |
add_action('wp_enqueue_scripts', 'fcb_load_dashicons', 999); |
| 38 |
|
| 39 |
add_action('plugins_loaded', 'fcb_load_textdomain'); |
| 40 |
function fcb_load_textdomain() { |
| 41 |
load_plugin_textdomain( 'floating-contact', false, dirname( plugin_basename(__FILE__) ) . '/languages/' ); |
| 42 |
} |
| 43 |
|
| 44 |
function fcb_styles_method() { |
| 45 |
wp_enqueue_style('custom-style', plugin_dir_url(__FILE__) . 'assets/css/style.min.css'); |
| 46 |
$options = get_option( 'fcb_options' ); |
| 47 |
if ( ! empty( $options['fcb_field_rotate'] ) ) { |
| 48 |
$rotate = "none"; |
| 49 |
} else { |
| 50 |
$rotate = "rotate(90deg)";} |
| 51 |
$color = get_option( 'fcb_options' )['fcb_field_bgcolor']; |
| 52 |
$custom_css = " |
| 53 |
i.fcb-icons { |
| 54 |
background: {$color} !important; |
| 55 |
border-color: {$color} !important; |
| 56 |
} |
| 57 |
i.fcb-icons:hover { |
| 58 |
color: {$color} !important; |
| 59 |
} |
| 60 |
i.fcb-icons:after { |
| 61 |
border-color: {$color} !important; |
| 62 |
} |
| 63 |
i.fcb-icons:hover { |
| 64 |
transform: {$rotate} !important; |
| 65 |
} |
| 66 |
#fcb-modal input[type=\"submit\"]:hover { |
| 67 |
border: 1px solid {$color} !important; |
| 68 |
background-color: {$color} !important; |
| 69 |
}"; |
| 70 |
wp_add_inline_style( 'custom-style', $custom_css ); |
| 71 |
} |
| 72 |
add_action( 'wp_enqueue_scripts', 'fcb_styles_method' ); |
| 73 |
|
| 74 |
function fcb_settings_init() { |
| 75 |
|
| 76 |
register_setting( 'floating-contact', 'fcb_options' ); |
| 77 |
add_settings_section('fcb_section_developers',__( 'Plugin Settings', 'floating-contact' ),'fcb_section_developers_cb','floating-contact'); |
| 78 |
|
| 79 |
add_settings_field('floating-contact_field_shortcode',__( 'Insert here your shortcode:', 'floating-contact' ),'fcb_field_shortcode_cb','floating-contact','fcb_section_developers', |
| 80 |
[ |
| 81 |
'label_for' => 'fcb_field_shortcode', |
| 82 |
'class' => 'fcb_row', |
| 83 |
'fcb_custom_data' => 'custom', |
| 84 |
] |
| 85 |
); |
| 86 |
|
| 87 |
add_settings_field('floating-contact_field_bgcolor',__( 'Button color (optional):', 'floating-contact' ),'fcb_field_bgcolor_cb','floating-contact','fcb_section_developers', |
| 88 |
[ |
| 89 |
'label_for' => 'fcb_field_bgcolor', |
| 90 |
'class' => 'fcb_row', |
| 91 |
'fcb_custom_data' => 'custom', |
| 92 |
] |
| 93 |
); |
| 94 |
|
| 95 |
add_settings_field('floating-contact_field_rotate',__( 'Disable rotation:', 'floating-contact' ),'fcb_field_rotate_cb','floating-contact','fcb_section_developers', |
| 96 |
[ |
| 97 |
'label_for' => 'fcb_field_rotate', |
| 98 |
'class' => 'fcb_row', |
| 99 |
'fcb_custom_data' => 'custom', |
| 100 |
] |
| 101 |
); |
| 102 |
} |
| 103 |
add_action( 'admin_init', 'fcb_settings_init' ); |
| 104 |
|
| 105 |
function fcb_section_developers_cb( $args ) { |
| 106 |
?> |
| 107 |
<p id="<?php echo esc_attr( $args['id'] ); ?>"><?php esc_html_e( '1. Install your favorite contact form plugin. Tested with Contact Form 7, Ninja Forms & Caldera Forms.', 'floating-contact' ); ?></p> |
| 108 |
<p id="<?php echo esc_attr( $args['id'] ); ?>"><?php esc_html_e( '2. Generate a form and entering the shortcode into the field. This form will shown in the modal, when the Floating Contact Button is clicked.', 'floating-contact' ); ?></p> |
| 109 |
<p id="<?php echo esc_attr( $args['id'] ); ?>"><?php esc_html_e( '3. Change the main color of the button (default value: #ff0000).', 'floating-contact' ); ?></p> |
| 110 |
<?php |
| 111 |
} |
| 112 |
|
| 113 |
function fcb_field_shortcode_cb( $args ) { |
| 114 |
$options = get_option( 'fcb_options' ); |
| 115 |
?> |
| 116 |
<input type="text" name="fcb_options[fcb_field_shortcode]" value="<?php echo str_replace('"', '"', $options['fcb_field_shortcode']); ?>" style="width: 450px;"> |
| 117 |
<?php |
| 118 |
} |
| 119 |
|
| 120 |
function fcb_field_bgcolor_cb( $args ) { |
| 121 |
$options = get_option( 'fcb_options' ); |
| 122 |
?> |
| 123 |
<input type="text" name="fcb_options[fcb_field_bgcolor]" value="<?php echo str_replace('"', '"', $options['fcb_field_bgcolor']); ?>" style="width: 80px;"> |
| 124 |
<?php |
| 125 |
} |
| 126 |
|
| 127 |
function fcb_field_rotate_cb() { |
| 128 |
$options = get_option( 'fcb_options' ); |
| 129 |
if( !isset( $options['fcb_field_rotate'] ) ) $options['fcb_field_rotate'] = 0; |
| 130 |
$html = '<input type="checkbox" name="fcb_options[fcb_field_rotate]" value="1"' . checked( 1, $options['fcb_field_rotate'], false ) . '/>'; |
| 131 |
echo $html; |
| 132 |
} |
| 133 |
|
| 134 |
function fcb_options_page() { |
| 135 |
add_menu_page('Floating Contact Button','Floating Contact','manage_options','floating-contact','fcb_options_page_html','dashicons-format-chat', 99); |
| 136 |
} |
| 137 |
|
| 138 |
add_action( 'admin_menu', 'fcb_options_page' ); |
| 139 |
|
| 140 |
function fcb_options_page_html() { |
| 141 |
if ( ! current_user_can( 'manage_options' ) ) { |
| 142 |
return; |
| 143 |
} |
| 144 |
|
| 145 |
if ( isset( $_GET['settings-updated'] ) ) { |
| 146 |
add_settings_error( 'fcb_messages', 'fcb_message', __( 'Settings Saved', 'floating-contact' ), 'updated' ); |
| 147 |
} |
| 148 |
|
| 149 |
settings_errors( 'fcb_messages' ); |
| 150 |
?> |
| 151 |
<div class="wrap"> |
| 152 |
<h1><?php echo esc_html( get_admin_page_title() ); ?></h1> |
| 153 |
<form action="options.php" method="post"> |
| 154 |
<?php |
| 155 |
settings_fields( 'floating-contact' ); |
| 156 |
do_settings_sections( 'floating-contact' ); |
| 157 |
submit_button(__( 'Save Settings', 'floating-contact' )); |
| 158 |
?> |
| 159 |
</form> |
| 160 |
</div> |
| 161 |
<?php |
| 162 |
} |
| 163 |
|
| 164 |
add_action('wp_footer', 'fcb_body_code'); |
| 165 |
function fcb_body_code() { |
| 166 |
|
| 167 |
$fcb_shortcode = get_option( 'fcb_options' )['fcb_field_shortcode']; |
| 168 |
|
| 169 |
echo ' <a href="#fcb-modal" class="fcb-link-button"><i class="fcb-icons"><span class="dashicons dashicons-format-chat"></span></i></a>'; |
| 170 |
echo ' <div id="fcb-modal">'; |
| 171 |
echo ' <div class="fcb-header"><a href="#" class="close-fcb-modal"><div class="fcb-header-close"><span class="fcb-close">X</span></div></a></div>'; |
| 172 |
echo ' <div class="fcb-modal-content"> '; |
| 173 |
echo ' <p>'.do_shortcode($fcb_shortcode).'</p>'; |
| 174 |
echo ' </div>'; |
| 175 |
echo ' <div class="overlay"></div>'; |
| 176 |
echo ' </div>'; |
| 177 |
} |
| 178 |
?> |