PluginProbe
Floating Contact Button / 2.7
Floating Contact Button v2.7
trunk 1.0 1.1 1.2 1.3 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7
floating-contact / floating-contact.php

floating-contact.php in Floating Contact Button 2.7, at floating-contact.php

214 lines 8.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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.7
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_settings_field('floating-contact_field_mode',__( 'Choose the integration mode:', 'floating-contact' ),'fcb_field_mode_cb','floating-contact','fcb_section_developers',
104 [
105 'label_for' => 'fcb_field_mode',
106 'class' => 'fcb_row',
107 'fcb_custom_data' => 'custom',
108 ]
109 );
110
111 }
112 add_action( 'admin_init', 'fcb_settings_init' );
113
114 function fcb_section_developers_cb( $args ) {
115 ?>
116 <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>
117 <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>
118 <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>
119 <p id="<?php echo esc_attr( $args['id'] ); ?>"><?php esc_html_e( '4. Please change the integration mode if there are problems with the theme you are using.', 'floating-contact' ); ?></p>
120 <?php
121 }
122
123 function fcb_field_shortcode_cb( $args ) {
124 $options = get_option( 'fcb_options' );
125 ?>
126 <input type="text" name="fcb_options[fcb_field_shortcode]" value="<?php echo str_replace('"', '&quot;', $options['fcb_field_shortcode']); ?>" style="width: 450px;">
127 <?php
128 }
129
130 function fcb_field_bgcolor_cb( $args ) {
131 $options = get_option( 'fcb_options' );
132 ?>
133 <input type="text" name="fcb_options[fcb_field_bgcolor]" value="<?php echo str_replace('"', '&quot;', $options['fcb_field_bgcolor']); ?>" style="width: 80px;">
134 <?php
135 }
136
137 function fcb_field_rotate_cb() {
138 $options = get_option( 'fcb_options' );
139 if( !isset( $options['fcb_field_rotate'] ) ) $options['fcb_field_rotate'] = 0;
140 $html = '<input type="checkbox" name="fcb_options[fcb_field_rotate]" value="1"' . checked( 1, $options['fcb_field_rotate'], false ) . '/>';
141 echo $html;
142 }
143
144 function fcb_field_mode_cb() {
145 $options = get_option( 'fcb_options' );
146 $html = '<input type="radio" id="cssmode" name="fcb_options[fcb_field_mode]" value="css"' . checked( "css", $options['fcb_field_mode'], false ) . '/><label for="cssmode">CSS</label> <input type="radio" style="margin-left:15px;" id="jquerymode" name="fcb_options[fcb_field_mode]" value="jquery" ' . checked( "jquery", $options['fcb_field_mode'], false ) . '/><label for="jquerymode">jQuery</label>';
147 echo $html;
148 }
149
150 function fcb_options_page() {
151 add_menu_page('Floating Contact Button','Floating Contact','manage_options','floating-contact','fcb_options_page_html','dashicons-format-chat', 99);
152 }
153
154 add_action( 'admin_menu', 'fcb_options_page' );
155
156 function fcb_options_page_html() {
157 if ( ! current_user_can( 'manage_options' ) ) {
158 return;
159 }
160
161 if ( isset( $_GET['settings-updated'] ) ) {
162 add_settings_error( 'fcb_messages', 'fcb_message', __( 'Settings Saved', 'floating-contact' ), 'updated' );
163 }
164
165 settings_errors( 'fcb_messages' );
166 ?>
167 <div class="wrap">
168 <h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
169 <form action="options.php" method="post">
170 <?php
171 settings_fields( 'floating-contact' );
172 do_settings_sections( 'floating-contact' );
173 submit_button(__( 'Save Settings', 'floating-contact' ));
174 ?>
175 </form>
176 </div>
177 <?php
178 }
179
180 add_action('wp_footer', 'fcb_body_code');
181 function fcb_body_code() {
182
183 $fcb_shortcode = get_option( 'fcb_options' )['fcb_field_shortcode'];
184 $fcb_mode = get_option( 'fcb_options' )['fcb_field_mode'];
185
186 if ($fcb_mode == 'css') {
187
188 echo ' <a href="#fcb-modal" class="fcb-link-button"><i class="fcb-icons"><span class="dashicons dashicons-format-chat"></span></i></a>';
189 echo ' <div id="fcb-modal">';
190 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>';
191 echo ' <div class="fcb-modal-content"> ';
192 echo ' <p>'.do_shortcode($fcb_shortcode).'</p>';
193 echo ' </div>';
194 echo ' <div class="overlay"></div>';
195 echo ' </div>';
196
197 }
198
199 if ($fcb_mode == 'jquery') {
200
201 echo ' <script> jQuery(function ($) { $( ".fcb-link-button" ).on( "click", function() { $("#fcb-modal").css("opacity", "1"); $("#fcb-modal").css("visibility", "visible"); $("#fcb-modal").css("top", "12%"); $("#fcb-modal").css("left", "50%"); $("#fcb-modal").css("margin-left", "-200px"); }); $( ".close-fcb-modal" ).on( "click", function() { $("#fcb-modal").css("opacity", "0"); $("#fcb-modal").css("visibility", "hidden"); }); }); </script>';
202 echo ' <a href="#" class="fcb-link-button"><i class="fcb-icons"><span class="dashicons dashicons-format-chat"></span></i></a>';
203 echo ' <div id="fcb-modal">';
204 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>';
205 echo ' <div class="fcb-modal-content"> ';
206 echo ' <p>'.do_shortcode($fcb_shortcode).'</p>';
207 echo ' </div>';
208 echo ' <div class="overlay"></div>';
209 echo ' </div>';
210
211 }
212
213 }
214 ?>