Skip to content

Commit e09802d

Browse files
authored
Merge pull request #1 from gradints/danar
update feature
2 parents 6b258cf + b322169 commit e09802d

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

dashboard.php

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
<!-- -> style-2 : 1 button floating wrap all button selected -->
7878

7979
<h1>Floating Button</h1>
80+
<p>Default icon is Whatsapp if you want to change the icon, click upload image button</p>
8081

8182
<form action="options.php" method="POST">
8283
<?php settings_fields('floating_button_settings'); ?>

logic.php

+39-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,40 @@
11
<?php
22

3+
/**
4+
* Format backslash to slash
5+
* @param string $text text to be formatted
6+
* @return string formatted text
7+
*/
8+
function format_slash($text) {
9+
return str_replace( "\\", "/", $text);
10+
}
11+
12+
/**
13+
* Get formatted WP absolute path
14+
* @return string WP absolute path (formatted)
15+
*/
16+
function get_absolute_path() {
17+
return format_slash(rtrim(ABSPATH, "/"));
18+
}
19+
20+
/**
21+
* Get formatted relative directory of feature
22+
* @param string $path path to file or folder
23+
* @return string relative directory of feature (formatted)
24+
*/
25+
function feature_dir($path = "") {
26+
return str_replace(get_absolute_path(), "", feature_absolute_dir($path));
27+
}
28+
29+
/**
30+
* Get formatted absolute directory of feature
31+
* @param string $path path to file or folder
32+
* @return string absolute directory of feature (formatted)
33+
*/
34+
function feature_absolute_dir($path = "") {
35+
return format_slash(realpath(dirname(__FILE__) ."/". $path));
36+
}
37+
338
add_action('admin_menu', function () {
439
$pageTitle = __('Floating Button');
540
$menuTitle = $pageTitle;
@@ -26,8 +61,8 @@
2661

2762
// split css feature floating
2863
add_action('wp_print_styles', function () {
29-
wp_enqueue_style('floating-style', get_stylesheet_directory_uri() . '/assets/feature_floating/floating.css' . '?' . filemtime(get_stylesheet_directory() . '/assets/feature_floating/floating.css'), array(), null);
30-
wp_enqueue_script('floating-script', get_stylesheet_directory_uri() . '/assets/feature_floating/floating.js', array('jquery'), filemtime(get_stylesheet_directory() . '/assets/feature_floating/floating.js'), true);
64+
wp_enqueue_style('floating-style', feature_dir('floating.css'), array(), filemtime(feature_absolute_dir('floating.css')));
65+
wp_enqueue_script('floating-script', feature_dir('floating.js'), array('jquery'), filemtime(feature_absolute_dir('floating.js')), true);
3166
});
3267

3368
// attach the settings to the admin_init hook
@@ -72,7 +107,7 @@
72107
if ($selectstyle == 'style-1') {
73108
for ($i = 1; $i <= 5; $i++) {
74109
$image = get_option('floating_image_'.$i);
75-
$imageUrl = wp_get_attachment_image_url($image, 'original');
110+
$imageUrl = wp_get_attachment_image_url($image, 'original') ?: feature_dir('./img/wa-xl.svg');
76111

77112
$bgColor = get_option('floating_background_color_'.$i);
78113
$url = get_option('floating_button_url_'.$i);
@@ -137,7 +172,7 @@ function media_include_js()
137172
// our custom JS
138173
wp_enqueue_script(
139174
'popup-media',
140-
get_stylesheet_directory_uri() . '/assets/wordpress-floating-button/media.js',
175+
feature_dir('media.js'),
141176
array('jquery')
142177
);
143178
}

0 commit comments

Comments
 (0)