| 1 |
<?php if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly ?> |
| 2 |
<?php |
| 3 |
|
| 4 |
// ======================================================================================================== |
| 5 |
// Get all the data and ouput it into the page |
| 6 |
// ======================================================================================================== |
| 7 |
|
| 8 |
$getting_plugin_data = get_option($wp_options_name); |
| 9 |
|
| 10 |
if( !empty($getting_plugin_data) ) { |
| 11 |
|
| 12 |
// ---------------------------------------------- |
| 13 |
// breaking the string into to 2 variables. the array namd and vakue |
| 14 |
// ---------------------------------------------- |
| 15 |
|
| 16 |
$break_array = explode("***", $getting_plugin_data); |
| 17 |
|
| 18 |
$item_name = explode("####", $break_array[0]); |
| 19 |
$key_name = explode("####", $break_array[1]); |
| 20 |
|
| 21 |
$array_count = count($key_name); |
| 22 |
|
| 23 |
// ---------------------------------------------- |
| 24 |
// creating an organized array with all values |
| 25 |
// ---------------------------------------------- |
| 26 |
|
| 27 |
for($count_number = 0; $count_number < $array_count; $count_number++) { |
| 28 |
$phone_btn_data_array[ $item_name[$count_number] ] = $key_name[$count_number]; |
| 29 |
} // for($count_number = 0; $count_number < $array_count; $count_number++) { |
| 30 |
|
| 31 |
// ---------------------------------------------- |
| 32 |
// gettting all the plugin data |
| 33 |
// ---------------------------------------------- |
| 34 |
|
| 35 |
$display_button_checkbox = intval($phone_btn_data_array['display_button_checkbox']); |
| 36 |
$phone_number = $phone_btn_data_array['phone_number']; |
| 37 |
$button_width = intval($phone_btn_data_array['button_width']); |
| 38 |
$button_height = intval($phone_btn_data_array['button_height']); |
| 39 |
$border_radius = esc_attr($phone_btn_data_array['border_radius']); |
| 40 |
$horizontal_position = esc_attr($phone_btn_data_array['horizontal_position']); |
| 41 |
$horizontal_spacing = esc_attr($phone_btn_data_array['horizontal_spacing']); |
| 42 |
$vertical_position = esc_attr($phone_btn_data_array['vertical_position']); |
| 43 |
$vertical_spacing = esc_attr($phone_btn_data_array['vertical_spacing']); |
| 44 |
$background_color = esc_attr($phone_btn_data_array['background_color']); |
| 45 |
$background_position = esc_attr($phone_btn_data_array['background_position']); |
| 46 |
$button_z_index = intval($phone_btn_data_array['button_z_index']); |
| 47 |
$button_border = esc_attr($phone_btn_data_array['button_border']); |
| 48 |
$icon_image_url = esc_url($phone_btn_data_array['icon_image_url']); |
| 49 |
$hide_button_on_desktop = intval($phone_btn_data_array['hide_button_on_desktop']); |
| 50 |
$hide_button_on_mobile = intval($phone_btn_data_array['hide_button_on_mobile']); |
| 51 |
$mobile_width = intval($phone_btn_data_array['mobile_width']); |
| 52 |
$mobile_button_position_checkbox = intval($phone_btn_data_array['mobile_button_position_checkbox']); |
| 53 |
$mobile_horizontal_position = esc_attr($phone_btn_data_array['mobile_horizontal_position']); |
| 54 |
$mobile_horizontal_spacing = esc_attr($phone_btn_data_array['mobile_horizontal_spacing']); |
| 55 |
$mobile_vertical_position = esc_attr($phone_btn_data_array['mobile_vertical_position']); |
| 56 |
$mobile_vertical_spacing = esc_attr($phone_btn_data_array['mobile_vertical_spacing']); |
| 57 |
|
| 58 |
// ---------------------------------------------- |
| 59 |
// dealing with exclude or include pages |
| 60 |
// ---------------------------------------------- |
| 61 |
|
| 62 |
$phone_btn_exclude_option = esc_attr($phone_btn_data_array['exclude_option']); |
| 63 |
$exclude_ids = esc_attr($phone_btn_data_array['exclude_ids']); |
| 64 |
|
| 65 |
// creating an array with all the ids |
| 66 |
$phone_btn_exclude_ids_array = []; |
| 67 |
$exclude_ids_explode = explode( ',', $exclude_ids); |
| 68 |
|
| 69 |
foreach($exclude_ids_explode as $exclude_id) { |
| 70 |
|
| 71 |
$exclude_id = intval( trim($exclude_id) ); |
| 72 |
|
| 73 |
if( !empty($exclude_id) ) { |
| 74 |
$phone_btn_exclude_ids_array[] = $exclude_id; |
| 75 |
} // if( !empty($exclude_id) ) { |
| 76 |
|
| 77 |
} // foreach($exclude_ids_explode as $exclude_id) { |
| 78 |
|
| 79 |
|
| 80 |
// making sure the back to top button active |
| 81 |
if( $display_button_checkbox == 1 ) { |
| 82 |
|
| 83 |
// ---------------------------------------------- |
| 84 |
// create button css code |
| 85 |
// ---------------------------------------------- |
| 86 |
|
| 87 |
$button_html_code = "<a href='tel:" . $phone_number . "' class='yydev-phone-button activeButtons' data-activevalue='#phone-button'><span></span></a>"; |
| 88 |
|
| 89 |
// ---------------------------------------------- |
| 90 |
// create button css code |
| 91 |
// ---------------------------------------------- |
| 92 |
|
| 93 |
$phone_btn_style = ''; |
| 94 |
|
| 95 |
// dealing with button style |
| 96 |
$phone_btn_style .= '<style>'; |
| 97 |
$phone_btn_style .= 'a.yydev-phone-button {'; |
| 98 |
|
| 99 |
$phone_btn_style .= 'background:' . $background_color . ';'; |
| 100 |
$phone_btn_style .= 'width:' . $button_width . 'px;'; |
| 101 |
$phone_btn_style .= 'height:' . $button_height . 'px;'; |
| 102 |
$phone_btn_style .= 'border-radius:' . $border_radius . ';'; |
| 103 |
$phone_btn_style .= $horizontal_position . ':' . $horizontal_spacing . ';'; |
| 104 |
$phone_btn_style .= $vertical_position . ':' . $vertical_spacing . ';'; |
| 105 |
$phone_btn_style .= 'border:' . $button_border . ';'; |
| 106 |
$phone_btn_style .= 'position:fixed;'; |
| 107 |
$phone_btn_style .= 'text-indent:-9999px;'; |
| 108 |
|
| 109 |
$current_button_z_index = "9999"; |
| 110 |
if(!empty($button_z_index)) { $current_button_z_index = $button_z_index; } |
| 111 |
$phone_btn_style .= 'z-index:' . $current_button_z_index . ';'; |
| 112 |
|
| 113 |
// if we hide this one desktop |
| 114 |
if($hide_button_on_desktop == 1) { |
| 115 |
$phone_btn_style .= 'display:none;'; |
| 116 |
} else { // if($hide_button_on_desktop == 1) { |
| 117 |
$phone_btn_style .= 'display:block;'; |
| 118 |
} // } else { // if($hide_button_on_desktop == 1) { |
| 119 |
|
| 120 |
$phone_btn_style .= '}'; |
| 121 |
|
| 122 |
$phone_btn_style .= 'a.yydev-phone-button span {'; |
| 123 |
|
| 124 |
$phone_btn_style .= 'display:block;'; |
| 125 |
$phone_btn_style .= 'height: 100%;'; |
| 126 |
$phone_btn_style .= 'width: 100%;'; |
| 127 |
$phone_btn_style .= 'background: transparent url(' . $icon_image_url .') no-repeat;'; |
| 128 |
|
| 129 |
$current_background_position = "50% 50%"; |
| 130 |
if(!empty($background_position)) { $current_background_position = $background_position; } |
| 131 |
$phone_btn_style .= 'background-position: ' . $current_background_position . ';'; |
| 132 |
|
| 133 |
$phone_btn_style .= '}'; |
| 134 |
|
| 135 |
// ------------------------------------------- |
| 136 |
// dealing with button mobile style |
| 137 |
// ------------------------------------------- |
| 138 |
$phone_btn_style .= '@media only screen and (max-width: ' . $mobile_width . 'px) {'; |
| 139 |
|
| 140 |
$phone_btn_style .= 'a.yydev-phone-button {'; |
| 141 |
|
| 142 |
if($mobile_button_position_checkbox == 1 ) { |
| 143 |
$phone_btn_style .= $horizontal_position . ':auto;'; |
| 144 |
$phone_btn_style .= $vertical_position . ':auto;'; |
| 145 |
$phone_btn_style .= $mobile_horizontal_position . ':' . $mobile_horizontal_spacing . ';'; |
| 146 |
$phone_btn_style .= $mobile_vertical_position . ':' . $mobile_vertical_spacing . ';'; |
| 147 |
} // if($mobile_button_position_checkbox == 1 ) { |
| 148 |
|
| 149 |
// if the button is showed only on desktop |
| 150 |
if($hide_button_on_mobile == 1) { |
| 151 |
$phone_btn_style .= 'display:none;'; |
| 152 |
} else { // if($hide_button_on_mobile == 0) { |
| 153 |
$phone_btn_style .= 'display:block;'; |
| 154 |
} // } else { // if($hide_button_on_mobile == 0) { |
| 155 |
|
| 156 |
$phone_btn_style .= '}'; |
| 157 |
|
| 158 |
$phone_btn_style .= '}'; |
| 159 |
|
| 160 |
$phone_btn_style .= '</style>'; |
| 161 |
|
| 162 |
// ---------------------------------------------- |
| 163 |
// add css and javascript code to header |
| 164 |
// ---------------------------------------------- |
| 165 |
|
| 166 |
add_action( 'wp_head', function() use ($phone_btn_style, $phone_btn_exclude_option, $phone_btn_exclude_ids_array) { |
| 167 |
|
| 168 |
$page_id = yydev_phone_btn_find_page_id(); |
| 169 |
$phone_btn_exclude_option = $phone_btn_exclude_option; // checking if we should exclude or include pages |
| 170 |
$exclude_ids = $phone_btn_exclude_ids_array; // pages we should display on or ignore |
| 171 |
$output_phone_button = 1; |
| 172 |
|
| 173 |
// incase we exclude pages |
| 174 |
if( $phone_btn_exclude_option === 'exclude' ) { |
| 175 |
|
| 176 |
// incase we choose to exclude an id |
| 177 |
if( in_array( $page_id, $exclude_ids) ) { |
| 178 |
$output_phone_button = 0; |
| 179 |
} // if( in_array( $page_id, $exclude_ids) ) { |
| 180 |
|
| 181 |
} // if( $phone_btn_exclude_option === 'exclude' ) { |
| 182 |
|
| 183 |
// incase we exclude pages |
| 184 |
if( $phone_btn_exclude_option === 'include' ) { |
| 185 |
|
| 186 |
// incase we choose to include only on some pages |
| 187 |
if( !in_array( $page_id, $exclude_ids) ) { |
| 188 |
$output_phone_button = 0; |
| 189 |
} // if( !in_array( $page_id, $exclude_ids) ) { |
| 190 |
|
| 191 |
} // if( $phone_btn_exclude_option === 'exclude' ) { |
| 192 |
|
| 193 |
// checking if we should output the button |
| 194 |
if( $output_phone_button ) { |
| 195 |
|
| 196 |
// echo css code to page |
| 197 |
echo $phone_btn_style; |
| 198 |
|
| 199 |
} // if( $output_phone_button ) { |
| 200 |
|
| 201 |
}); // add_action( 'wp_head', function() use ($phone_btn_style, $phone_btn_exclude_option, $phone_btn_exclude_ids_array) { |
| 202 |
|
| 203 |
// ---------------------------------------------- |
| 204 |
// add the button html to footer |
| 205 |
// ---------------------------------------------- |
| 206 |
|
| 207 |
add_action( 'wp_footer', function() use ($button_html_code, $phone_btn_exclude_option, $phone_btn_exclude_ids_array) { |
| 208 |
|
| 209 |
$page_id = yydev_phone_btn_find_page_id(); |
| 210 |
$phone_btn_exclude_option = $phone_btn_exclude_option; // checking if we should exclude or include pages |
| 211 |
$exclude_ids = $phone_btn_exclude_ids_array; // pages we should display on or ignore |
| 212 |
$output_phone_button = 1; |
| 213 |
|
| 214 |
// incase we exclude pages |
| 215 |
if( $phone_btn_exclude_option === 'exclude' ) { |
| 216 |
|
| 217 |
// incase we choose to exclude an id |
| 218 |
if( in_array( $page_id, $exclude_ids) ) { |
| 219 |
$output_phone_button = 0; |
| 220 |
} // if( in_array( $page_id, $exclude_ids) ) { |
| 221 |
|
| 222 |
} // if( $phone_btn_exclude_option === 'exclude' ) { |
| 223 |
|
| 224 |
// incase we exclude pages |
| 225 |
if( $phone_btn_exclude_option === 'include' ) { |
| 226 |
|
| 227 |
// incase we choose to include only on some pages |
| 228 |
if( !in_array( $page_id, $exclude_ids) ) { |
| 229 |
$output_phone_button = 0; |
| 230 |
} // if( !in_array( $page_id, $exclude_ids) ) { |
| 231 |
|
| 232 |
} // if( $phone_btn_exclude_option === 'exclude' ) { |
| 233 |
|
| 234 |
// checking if we should output the button |
| 235 |
if( $output_phone_button ) { |
| 236 |
|
| 237 |
// echo html button |
| 238 |
echo $button_html_code; |
| 239 |
|
| 240 |
} // if( $output_phone_button ) { |
| 241 |
|
| 242 |
}); // add_action( 'wp_footer', function() use ($button_html_code, $phone_btn_exclude_option, $phone_btn_exclude_ids_array) { |
| 243 |
|
| 244 |
} // if( $display_button_checkbox == 1 ) { |
| 245 |
|
| 246 |
} // if( !empty($getting_plugin_data) ) { |
| 247 |
|
| 248 |
|