|
1 | 1 | <?php
|
2 | 2 |
|
| 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 | + |
3 | 38 | add_action('admin_menu', function () {
|
4 | 39 | $pageTitle = __('Floating Button');
|
5 | 40 | $menuTitle = $pageTitle;
|
|
26 | 61 |
|
27 | 62 | // split css feature floating
|
28 | 63 | 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); |
31 | 66 | });
|
32 | 67 |
|
33 | 68 | // attach the settings to the admin_init hook
|
|
72 | 107 | if ($selectstyle == 'style-1') {
|
73 | 108 | for ($i = 1; $i <= 5; $i++) {
|
74 | 109 | $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'); |
76 | 111 |
|
77 | 112 | $bgColor = get_option('floating_background_color_'.$i);
|
78 | 113 | $url = get_option('floating_button_url_'.$i);
|
@@ -137,7 +172,7 @@ function media_include_js()
|
137 | 172 | // our custom JS
|
138 | 173 | wp_enqueue_script(
|
139 | 174 | 'popup-media',
|
140 |
| - get_stylesheet_directory_uri() . '/assets/wordpress-floating-button/media.js', |
| 175 | + feature_dir('media.js'), |
141 | 176 | array('jquery')
|
142 | 177 | );
|
143 | 178 | }
|
0 commit comments