1 | <?php |
||||||
2 | |||||||
3 | namespace Helick\GTM; |
||||||
4 | |||||||
5 | use Helick\Contracts\Bootable; |
||||||
6 | use WP_Admin_Bar; |
||||||
0 ignored issues
–
show
|
|||||||
7 | |||||||
8 | final class AdminBar implements Bootable |
||||||
9 | { |
||||||
10 | /** |
||||||
11 | * Boot the service. |
||||||
12 | * |
||||||
13 | * @return void |
||||||
14 | */ |
||||||
15 | public static function boot(): void |
||||||
16 | { |
||||||
17 | $self = new static; |
||||||
18 | |||||||
19 | add_action('admin_bar_menu', [$self, 'extendMenu']); |
||||||
0 ignored issues
–
show
The function
add_action was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
20 | } |
||||||
21 | |||||||
22 | /** |
||||||
23 | * Extend the admin bar menu. |
||||||
24 | * |
||||||
25 | * @param WP_Admin_Bar $adminBar |
||||||
26 | * |
||||||
27 | * @return void |
||||||
28 | */ |
||||||
29 | public function extendMenu(WP_Admin_Bar $adminBar): void |
||||||
30 | { |
||||||
31 | $isUserAllowed = current_user_can('manage_options'); |
||||||
0 ignored issues
–
show
The function
current_user_can was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
32 | $isBackend = is_admin(); |
||||||
0 ignored issues
–
show
The function
is_admin was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
33 | |||||||
34 | /** |
||||||
35 | * Control whether to show the data layer UI. |
||||||
36 | * |
||||||
37 | * @param bool $isEnabled |
||||||
38 | */ |
||||||
39 | $isEnabled = apply_filters('helick_gtm_enable_data_layer_ui', true); |
||||||
0 ignored issues
–
show
The function
apply_filters was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
40 | |||||||
41 | if (!$isUserAllowed || $isBackend || !$isEnabled) { |
||||||
42 | return; |
||||||
43 | } |
||||||
44 | |||||||
45 | $adminBar->add_menu([ |
||||||
46 | 'id' => 'helick-gtm', |
||||||
47 | 'title' => sprintf( |
||||||
48 | '<span class="ab-icon dashicons-filter"></span> <span class="ab-label">%s</span>', |
||||||
49 | __('Data Layer', DOMAIN) |
||||||
0 ignored issues
–
show
The function
__ was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
50 | ), |
||||||
51 | ]); |
||||||
52 | |||||||
53 | $dataLayer = data_layer(); |
||||||
54 | |||||||
55 | // Flatten data layer |
||||||
56 | $flatten = static function (array $data, string $prefix = '') use (&$flatten) { |
||||||
57 | $flattened = []; |
||||||
58 | |||||||
59 | foreach ($data as $key => $value) { |
||||||
60 | if (is_array($value)) { |
||||||
61 | $flattened = array_merge($flattened, $flatten($value, $prefix . $key . '.')); |
||||||
62 | } else { |
||||||
63 | $flattened[$prefix . $key] = trim(json_encode($value), '"'); |
||||||
64 | } |
||||||
65 | } |
||||||
66 | |||||||
67 | return $flattened; |
||||||
68 | }; |
||||||
69 | |||||||
70 | foreach ($flatten($dataLayer) as $key => $value) { |
||||||
71 | $adminBar->add_node([ |
||||||
72 | 'id' => sanitize_key('helick-gtm-' . $key), |
||||||
0 ignored issues
–
show
The function
sanitize_key was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
73 | 'parent' => 'helick-gtm', |
||||||
74 | 'title' => sprintf( |
||||||
75 | '<span style="font-weight: bold">%s:</span> %s', |
||||||
76 | $key, |
||||||
77 | wp_unslash($value) |
||||||
0 ignored issues
–
show
The function
wp_unslash was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
78 | ), |
||||||
79 | ]); |
||||||
80 | } |
||||||
81 | } |
||||||
82 | } |
||||||
83 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths