1 | <?php |
||||||
2 | |||||||
3 | namespace Helick\GTM; |
||||||
4 | |||||||
5 | use WP_Taxonomy; |
||||||
0 ignored issues
–
show
|
|||||||
6 | |||||||
7 | /** |
||||||
8 | * Get the container ID. |
||||||
9 | * |
||||||
10 | * @return string |
||||||
11 | */ |
||||||
12 | function container_id(): string |
||||||
13 | { |
||||||
14 | return defined('GTM_CONTAINER_ID') ? GTM_CONTAINER_ID : ''; |
||||||
0 ignored issues
–
show
|
|||||||
15 | } |
||||||
16 | |||||||
17 | /** |
||||||
18 | * Get the data layer variable. |
||||||
19 | * |
||||||
20 | * @return string |
||||||
21 | */ |
||||||
22 | function data_layer_variable(): string |
||||||
23 | { |
||||||
24 | $dataLayerVar = 'dataLayer'; |
||||||
25 | |||||||
26 | /** |
||||||
27 | * Control the data layer variable. |
||||||
28 | * |
||||||
29 | * @param string $dataLayerVar |
||||||
30 | */ |
||||||
31 | $dataLayerVar = apply_filters('helick_gtm_data_layer_variable', $dataLayerVar); |
||||||
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
![]() |
|||||||
32 | |||||||
33 | $dataLayerVar = preg_replace('/[^a-z0-9_\-]/i', '', (string)$dataLayerVar); |
||||||
34 | |||||||
35 | return $dataLayerVar; |
||||||
36 | } |
||||||
37 | |||||||
38 | /** |
||||||
39 | * Get the data layer. |
||||||
40 | * |
||||||
41 | * @return array |
||||||
42 | */ |
||||||
43 | function data_layer(): array |
||||||
44 | { |
||||||
45 | $dataLayer = []; |
||||||
46 | |||||||
47 | if (is_multisite()) { |
||||||
0 ignored issues
–
show
The function
is_multisite 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
![]() |
|||||||
48 | $dataLayer['network'] = [ |
||||||
49 | 'id' => get_main_site_id(), |
||||||
0 ignored issues
–
show
The function
get_main_site_id 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 | 'url' => get_site_url(get_main_site_id()), |
||||||
0 ignored issues
–
show
The function
get_site_url 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
![]() |
|||||||
51 | ]; |
||||||
52 | } |
||||||
53 | |||||||
54 | $dataLayer['site'] = [ |
||||||
55 | 'id' => is_multisite() ? get_current_blog_id() : 0, |
||||||
0 ignored issues
–
show
The function
get_current_blog_id 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
![]() |
|||||||
56 | 'url' => home_url(), |
||||||
0 ignored issues
–
show
The function
home_url 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
![]() |
|||||||
57 | ]; |
||||||
58 | |||||||
59 | $dataLayer['context'] = [ |
||||||
60 | 'is_home' => is_home(), |
||||||
0 ignored issues
–
show
The function
is_home 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
![]() |
|||||||
61 | 'is_front_page' => is_front_page(), |
||||||
0 ignored issues
–
show
The function
is_front_page 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
![]() |
|||||||
62 | 'is_post_type_archive' => is_post_type_archive(), |
||||||
0 ignored issues
–
show
The function
is_post_type_archive 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
![]() |
|||||||
63 | 'is_tax' => is_tax(), |
||||||
0 ignored issues
–
show
The function
is_tax 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
![]() |
|||||||
64 | 'is_author' => is_author(), |
||||||
0 ignored issues
–
show
The function
is_author 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
![]() |
|||||||
65 | 'is_date' => is_date(), |
||||||
0 ignored issues
–
show
The function
is_date 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
![]() |
|||||||
66 | 'is_search' => is_search(), |
||||||
0 ignored issues
–
show
The function
is_search 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
![]() |
|||||||
67 | 'is_singular' => is_singular(), |
||||||
0 ignored issues
–
show
The function
is_singular 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
![]() |
|||||||
68 | 'is_404' => is_404(), |
||||||
0 ignored issues
–
show
The function
is_404 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
![]() |
|||||||
69 | ]; |
||||||
70 | |||||||
71 | if (is_archive()) { |
||||||
0 ignored issues
–
show
The function
is_archive 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
![]() |
|||||||
72 | if (is_date()) { |
||||||
73 | $dataLayer['date'] = get_the_date(); |
||||||
0 ignored issues
–
show
The function
get_the_date 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
![]() |
|||||||
74 | } |
||||||
75 | |||||||
76 | if (is_search()) { |
||||||
77 | $dataLayer['search'] = get_search_query(); |
||||||
0 ignored issues
–
show
The function
get_search_query 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 | if (is_post_type_archive()) { |
||||||
81 | $dataLayer['post_type'] = get_post_type(); |
||||||
0 ignored issues
–
show
The function
get_post_type 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
![]() |
|||||||
82 | } |
||||||
83 | |||||||
84 | if (is_tag() || is_category() || is_tax()) { |
||||||
0 ignored issues
–
show
The function
is_category 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
![]() The function
is_tag 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
![]() |
|||||||
85 | $term = get_queried_object(); |
||||||
0 ignored issues
–
show
The function
get_queried_object 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
![]() |
|||||||
86 | |||||||
87 | $dataLayer[$term->taxonomy] = [ |
||||||
88 | 'id' => $term->term_id, |
||||||
89 | 'slug' => $term->slug, |
||||||
90 | 'name' => $term->name, |
||||||
91 | ]; |
||||||
92 | } |
||||||
93 | |||||||
94 | if (is_author()) { |
||||||
95 | $user = get_queried_object(); |
||||||
96 | |||||||
97 | $dataLayer['author'] = [ |
||||||
98 | 'id' => $user->ID, |
||||||
99 | 'slug' => $user->user_nicename, |
||||||
100 | 'name' => $user->display_name, |
||||||
101 | ]; |
||||||
102 | } |
||||||
103 | } |
||||||
104 | |||||||
105 | if (is_singular()) { |
||||||
106 | $dataLayer[get_post_type()] = [ |
||||||
107 | 'id' => get_the_ID(), |
||||||
0 ignored issues
–
show
The function
get_the_ID 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
![]() |
|||||||
108 | 'slug' => get_post_field('post_name'), |
||||||
0 ignored issues
–
show
The function
get_post_field 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
![]() |
|||||||
109 | 'title' => get_the_title(), |
||||||
0 ignored issues
–
show
The function
get_the_title 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
![]() |
|||||||
110 | 'template' => get_page_template_slug(), |
||||||
0 ignored issues
–
show
The function
get_page_template_slug 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
![]() |
|||||||
111 | 'comments' => (int)get_comments_number(), |
||||||
0 ignored issues
–
show
The function
get_comments_number 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
![]() |
|||||||
112 | 'published_at' => get_the_date('c'), |
||||||
113 | 'modified_at' => get_the_modified_date('c'), |
||||||
0 ignored issues
–
show
The function
get_the_modified_date 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
![]() |
|||||||
114 | ]; |
||||||
115 | |||||||
116 | $dataLayer[get_post_type()]['author'] = [ |
||||||
117 | 'id' => get_the_author_meta('ID'), |
||||||
0 ignored issues
–
show
The function
get_the_author_meta 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
![]() |
|||||||
118 | 'slug' => get_the_author_meta('user_nicename'), |
||||||
119 | 'name' => get_the_author_meta('display_name'), |
||||||
120 | ]; |
||||||
121 | |||||||
122 | $taxonomies = get_object_taxonomies(get_post_type(), 'objects'); |
||||||
0 ignored issues
–
show
The function
get_object_taxonomies 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
![]() |
|||||||
123 | $taxonomies = array_filter($taxonomies, function (WP_Taxonomy $taxonomy) { |
||||||
124 | return $taxonomy->public; |
||||||
125 | }); |
||||||
126 | |||||||
127 | // TODO: ugly :( |
||||||
128 | foreach ($taxonomies as $taxonomy) { |
||||||
129 | $terms = get_the_terms(get_the_ID(), $taxonomy->name); |
||||||
0 ignored issues
–
show
The function
get_the_terms 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
![]() |
|||||||
130 | if (!$terms || is_wp_error($terms)) { |
||||||
0 ignored issues
–
show
The function
is_wp_error 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
![]() |
|||||||
131 | continue; |
||||||
132 | } |
||||||
133 | |||||||
134 | $dataLayer[get_post_type()][$taxonomy->name] = array_column($terms, 'slug'); |
||||||
135 | } |
||||||
136 | } |
||||||
137 | |||||||
138 | if (is_user_logged_in()) { |
||||||
0 ignored issues
–
show
The function
is_user_logged_in 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
![]() |
|||||||
139 | $user = wp_get_current_user(); |
||||||
0 ignored issues
–
show
The function
wp_get_current_user 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
![]() |
|||||||
140 | |||||||
141 | $dataLayer['user'] = [ |
||||||
142 | 'id' => $user->ID, |
||||||
143 | 'slug' => $user->user_nicename, |
||||||
144 | 'name' => $user->display_name, |
||||||
145 | 'capabilities' => array_keys($user->caps), |
||||||
146 | ]; |
||||||
147 | } |
||||||
148 | |||||||
149 | /** |
||||||
150 | * Control the data layer. |
||||||
151 | * |
||||||
152 | * @param array $dataLayer |
||||||
153 | */ |
||||||
154 | $dataLayer = apply_filters('helick_gtm_data_layer', $dataLayer); |
||||||
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
![]() |
|||||||
155 | |||||||
156 | return (array)$dataLayer; |
||||||
157 | } |
||||||
158 |
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