PluginProbe
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts / 2.4.7
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts v2.4.7
2.7.7 2.7.6 2.7.5 2.7.4 trunk 1.3 2.0.4 2.0.6 2.1.91 2.2.4 2.2.7 2.2.9 2.3.1 2.3.10 2.4.10 2.4.2 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.6.0 2.6.1 2.7.0 All 28 releases
← All changes | includes/class.insertion.locations.php +327 -284 trunk2.4.7 View file →
@@ -1,284 +1,327 @@
1 -<?php
2 -/**
3 - * Insertion locations
4 - *
5 - * @package Woody_Code_Snippets
6 - */
7 -
8 -// Exit if accessed directly
9 -if ( ! defined( 'ABSPATH' ) ) {
10 - exit;
11 -}
12 -
13 -class WINP_Insertion_Locations {
14 -
15 - public $locations = [];
16 -
17 - /**
18 - * Constructor.
19 - */
20 - public function __construct() {
21 - $locations = [
22 - 'everywhere' => [
23 - 'header' => [
24 - __( 'Header', 'insert-php' ),
25 - __( 'Snippet will be placed in the source code before </head>.', 'insert-php' ),
26 - [
27 - 'requiresLocationNumber' => false,
28 - ],
29 - ],
30 - 'footer' => [
31 - __( 'Footer', 'insert-php' ),
32 - __( 'Snippet will be placed in the source code before </body>.', 'insert-php' ),
33 - [
34 - 'requiresLocationNumber' => false,
35 - ],
36 - ],
37 - ],
38 - 'posts' => [
39 - 'before_post' => [
40 - __( 'Insert Before Post', 'insert-php' ),
41 - __( 'Snippet will be placed before the title of the post/page.', 'insert-php' ),
42 - [
43 - 'requiresLocationNumber' => false,
44 - ],
45 - ],
46 - 'before_content' => [
47 - __( 'Insert Before Content', 'insert-php' ),
48 - __( 'Snippet will be placed before the content of the post/page.', 'insert-php' ),
49 - [
50 - 'requiresLocationNumber' => false,
51 - ],
52 - ],
53 - 'before_paragraph' => [
54 - __( 'Insert Before Paragraph', 'insert-php' ),
55 - __( 'Snippet will be placed before the specified paragraph number.', 'insert-php' ),
56 - [
57 - 'requiresLocationNumber' => true,
58 - ],
59 - ],
60 - 'after_paragraph' => [
61 - __( 'Insert After Paragraph', 'insert-php' ),
62 - __( 'Snippet will be placed after the specified paragraph number.', 'insert-php' ),
63 - [
64 - 'requiresLocationNumber' => true,
65 - ],
66 - ],
67 - 'after_content' => [
68 - __( 'Insert After Content', 'insert-php' ),
69 - __( 'Snippet will be placed after the content of the post/page.', 'insert-php' ),
70 - [
71 - 'requiresLocationNumber' => false,
72 - ],
73 - ],
74 - 'after_post' => [
75 - __( 'Insert After Post', 'insert-php' ),
76 - __( 'Snippet will be placed in the very end of the post/page.', 'insert-php' ),
77 - [
78 - 'requiresLocationNumber' => false,
79 - ],
80 - ],
81 - ],
82 - 'pages' => [
83 - 'before_excerpt' => [
84 - __( 'Insert Before Excerpt', 'insert-php' ),
85 - __( 'Snippet will be placed before the excerpt of the post/page.', 'insert-php' ),
86 - [
87 - 'requiresLocationNumber' => false,
88 - ],
89 - ],
90 - 'after_excerpt' => [
91 - __( 'Insert After Excerpt', 'insert-php' ),
92 - __( 'Snippet will be placed after the excerpt of the post/page.', 'insert-php' ),
93 - [
94 - 'requiresLocationNumber' => false,
95 - ],
96 - ],
97 - 'between_posts' => [
98 - __( 'Between Posts', 'insert-php' ),
99 - __( 'Snippet will be placed between each post.', 'insert-php' ),
100 - [
101 - 'requiresLocationNumber' => false,
102 - ],
103 - ],
104 - 'before_posts' => [
105 - __( 'Before post', 'insert-php' ),
106 - __( 'Snippet will be placed before the specified post number.', 'insert-php' ),
107 - [
108 - 'requiresLocationNumber' => true,
109 - ],
110 - ],
111 - 'after_posts' => [
112 - __( 'After post', 'insert-php' ),
113 - __( 'Snippet will be placed after the specified post number.', 'insert-php' ),
114 - [
115 - 'requiresLocationNumber' => true,
116 - ],
117 - ],
118 - ],
119 - 'woocommerce' => [
120 - 'woo_before_shop_loop' => [
121 - __( 'Before the list of products', 'insert-php' ),
122 - __( 'Snippet will be placed before the list of products.', 'insert-php' ),
123 - [
124 - 'requiresLocationNumber' => false,
125 - ],
126 - ],
127 - 'woo_after_shop_loop' => [
128 - __( 'After the list of products', 'insert-php' ),
129 - __( 'Snippet will be placed after the list of products.', 'insert-php' ),
130 - [
131 - 'requiresLocationNumber' => false,
132 - ],
133 - ],
134 - 'woo_before_single_product' => [
135 - __( 'Before a single product', 'insert-php' ),
136 - __( 'Snippet will be placed before a single product.', 'insert-php' ),
137 - [
138 - 'requiresLocationNumber' => false,
139 - ],
140 - ],
141 - 'woo_after_single_product' => [
142 - __( 'After a single product', 'insert-php' ),
143 - __( 'Snippet will be placed after a single product.', 'insert-php' ),
144 - [
145 - 'requiresLocationNumber' => false,
146 - ],
147 - ],
148 - 'woo_before_single_product_summary' => [
149 - __( 'Before a single product summary', 'insert-php' ),
150 - __( 'Snippet will be placed before a single product summary.', 'insert-php' ),
151 - [
152 - 'requiresLocationNumber' => false,
153 - ],
154 - ],
155 - 'woo_after_single_product_summary' => [
156 - __( 'After a single product summary', 'insert-php' ),
157 - __( 'Snippet will be placed after a single product summary.', 'insert-php' ),
158 - [
159 - 'requiresLocationNumber' => false,
160 - ],
161 - ],
162 - 'woo_single_product_summary_title' => [
163 - __( 'After a product title', 'insert-php' ),
164 - __( 'Snippet will be placed after a product title.', 'insert-php' ),
165 - [
166 - 'requiresLocationNumber' => false,
167 - ],
168 - ],
169 - 'woo_single_product_summary_price' => [
170 - __( 'After a product price', 'insert-php' ),
171 - __( 'Snippet will be placed after a product price.', 'insert-php' ),
172 - [
173 - 'requiresLocationNumber' => false,
174 - ],
175 - ],
176 - 'woo_single_product_summary_excerpt' => [
177 - __( 'After a product excerpt', 'insert-php' ),
178 - __( 'Snippet will be placed after a product excerpt.', 'insert-php' ),
179 - [
180 - 'requiresLocationNumber' => false,
181 - ],
182 - ],
183 - ],
184 - ];
185 -
186 - /**
187 - * Filters the insertion locations.
188 - *
189 - * [
190 - * 'before_2' => [
191 - * __( 'Before 2', 'insert-php' ),
192 - * __( 'Before 2 desc.', 'insert-php' ),
193 - * [
194 - * 'requiresLocationNumber' => false, // true if location needs paragraph/post number input
195 - * ]
196 - * ]
197 - * ]
198 - *
199 - * @param array<string, array<string, array<int|string, mixed>>> $locations The array of custom location data.
200 - *
201 - * @since 2.4
202 - */
203 - $custom_data = apply_filters( 'wbcr/woody/add_custom_location', [] );
204 -
205 - if ( ! empty( $custom_data ) && is_array( $custom_data ) ) {
206 - $locations['custom'] = $custom_data;
207 - }
208 -
209 - $this->locations = $locations;
210 - }
211 -
212 - /**
213 - * @param $name
214 - *
215 - * @return array|array[]
216 - */
217 - public function __get( $name ) {
218 - return $this->getLocation( $name );
219 - }
220 -
221 - /**
222 - * @param string $insertion
223 - *
224 - * @return array
225 - */
226 - public function getInsertion( $insertion ) {
227 - return $this->locations[ $insertion ] ?? [];
228 - }
229 -
230 - /**
231 - * @param string $location
232 - * @param string $insertion
233 - *
234 - * @return array
235 - */
236 - public function getLocation( $location, $insertion = '' ) {
237 - if ( ! empty( $insertion ) ) {
238 - return $this->locations[ $insertion ][ $location ] ?? [];
239 - } else {
240 - foreach ( $this->locations as $k => $loc ) {
241 - foreach ( $loc as $key => $item ) {
242 - if ( $key == $location ) {
243 - return [ $key => $item ];
244 - }
245 - }
246 - }
247 - }
248 -
249 - return [];
250 - }
251 -
252 - /**
253 - *
254 - * @return array
255 - */
256 - public function getList() {
257 - $list = [];
258 - foreach ( $this->locations as $k => $loc ) {
259 - foreach ( $loc as $key => $item ) {
260 - $list[ $key ] = $item;
261 - }
262 - }
263 -
264 - return $list;
265 - }
266 -
267 - /**
268 - * @param string $insertion
269 - *
270 - * @return array
271 - */
272 - public function getInsertionForOptions( $insertion ) {
273 - $return = [];
274 - foreach ( $this->locations[ $insertion ] ?? [] as $key => $locations ) {
275 - $requires_number = false;
276 - if ( isset( $locations[2] ) && is_array( $locations[2] ) && isset( $locations[2]['requiresLocationNumber'] ) ) {
277 - $requires_number = $locations[2]['requiresLocationNumber'];
278 - }
279 - $return[] = [ $key, $locations[0] ?? '', $locations[1] ?? '', $requires_number ];
280 - }
281 -
282 - return $return;
283 - }
284 -}
1 +<?php
2 +/**
3 + * Insertion locations
4 + *
5 + * @author Artem Prihodko <webtemyk@yandex.ru>
6 + * @copyright (c) 2021, Creative Motion
7 + * @version 1.0
8 + * @since 2.4
9 + */
10 +
11 +// Exit if accessed directly
12 +if ( ! defined( 'ABSPATH' ) ) {
13 + exit;
14 +}
15 +
16 +class WINP_Insertion_Locations {
17 +
18 + public $locations = [];
19 +
20 + /**
21 + * Constructor.
22 + */
23 + public function __construct() {
24 + $locations = [
25 + 'everywhere' => [
26 + 'header' => [
27 + __( 'Header', 'insert-php' ),
28 + __( 'Snippet will be placed in the source code before </head>.', 'insert-php' ),
29 + [
30 + 'hide' => '.factory-control-snippet_p_number',
31 + 'show' => '',
32 + ]
33 + ],
34 + 'footer' => [
35 + __( 'Footer', 'insert-php' ),
36 + __( 'Snippet will be placed in the source code before </body>.', 'insert-php' ),
37 + [
38 + 'hide' => '.factory-control-snippet_p_number',
39 + 'show' => '',
40 + ]
41 + ],
42 + ],
43 + 'posts' => [
44 + 'before_post' => [
45 + __( 'Insert Before Post', 'insert-php' ),
46 + __( 'Snippet will be placed before the title of the post/page.', 'insert-php' ),
47 + [
48 + 'hide' => '.factory-control-snippet_p_number',
49 + 'show' => '',
50 + ]
51 + ],
52 + 'before_content' => [
53 + __( 'Insert Before Content', 'insert-php' ),
54 + __( 'Snippet will be placed before the content of the post/page.', 'insert-php' ),
55 + [
56 + 'hide' => '.factory-control-snippet_p_number',
57 + 'show' => '',
58 + ]
59 + ],
60 + 'before_paragraph' => [
61 + __( 'Insert Before Paragraph', 'insert-php' ),
62 + __( 'Snippet will be placed before the paragraph, which number you can specify in the Location number field.', 'insert-php' ),
63 + [
64 + 'hide' => '',
65 + 'show' => '.factory-control-snippet_p_number',
66 + ]
67 + ],
68 + 'after_paragraph' => [
69 + __( 'Insert After Paragraph', 'insert-php' ),
70 + __( 'Snippet will be placed after the paragraph, which number you can specify in the Location number field.', 'insert-php' ),
71 + [
72 + 'hide' => '',
73 + 'show' => '.factory-control-snippet_p_number',
74 + ]
75 + ],
76 + 'after_content' => [
77 + __( 'Insert After Content', 'insert-php' ),
78 + __( 'Snippet will be placed after the content of the post/page.', 'insert-php' ),
79 + [
80 + 'hide' => '.factory-control-snippet_p_number',
81 + 'show' => '',
82 + ]
83 + ],
84 + 'after_post' => [
85 + __( 'Insert After Post', 'insert-php' ),
86 + __( 'Snippet will be placed in the very end of the post/page.', 'insert-php' ),
87 + [
88 + 'hide' => '.factory-control-snippet_p_number',
89 + 'show' => '',
90 + ]
91 + ],
92 + ],
93 + 'pages' => [
94 + 'before_excerpt' => [
95 + __( 'Insert Before Excerpt', 'insert-php' ),
96 + __( 'Snippet will be placed before the excerpt of the post/page.', 'insert-php' ),
97 + [
98 + 'hide' => '.factory-control-snippet_p_number',
99 + 'show' => '',
100 + ]
101 + ],
102 + 'after_excerpt' => [
103 + __( 'Insert After Excerpt', 'insert-php' ),
104 + __( 'Snippet will be placed after the excerpt of the post/page.', 'insert-php' ),
105 + [
106 + 'hide' => '.factory-control-snippet_p_number',
107 + 'show' => '',
108 + ]
109 + ],
110 + 'between_posts' => [
111 + __( 'Between Posts', 'insert-php' ),
112 + __( 'Snippet will be placed between each post.', 'insert-php' ),
113 + [
114 + 'hide' => '.factory-control-snippet_p_number',
115 + 'show' => '',
116 + ]
117 + ],
118 + 'before_posts' => [
119 + __( 'Before post', 'insert-php' ),
120 + __( 'Snippet will be placed before the post, which number you can specify in the Location number field.', 'insert-php' ),
121 + [
122 + 'hide' => '',
123 + 'show' => '.factory-control-snippet_p_number',
124 + ]
125 + ],
126 + 'after_posts' => [
127 + __( 'After post', 'insert-php' ),
128 + __( 'Snippet will be placed after the post, which number you can specify in the Location number field.', 'insert-php' ),
129 + [
130 + 'hide' => '',
131 + 'show' => '.factory-control-snippet_p_number',
132 + ]
133 + ],
134 + ],
135 + 'woocommerce' => [
136 + 'woo_before_shop_loop' => [
137 + __( 'Before the list of products', 'insert-php' ),
138 + __( 'Snippet will be placed before the list of products.', 'insert-php' ),
139 + [
140 + 'hide' => '.factory-control-snippet_p_number',
141 + 'show' => '',
142 + ]
143 + ],
144 + 'woo_after_shop_loop' => [
145 + __( 'After the list of products', 'insert-php' ),
146 + __( 'Snippet will be placed after the list of products.', 'insert-php' ),
147 + [
148 + 'hide' => '.factory-control-snippet_p_number',
149 + 'show' => '',
150 + ]
151 + ],
152 + 'woo_before_single_product' => [
153 + __( 'Before a single product', 'insert-php' ),
154 + __( 'Snippet will be placed before a single product', 'insert-php' ),
155 + [
156 + 'hide' => '.factory-control-snippet_p_number',
157 + 'show' => '',
158 + ]
159 + ],
160 + 'woo_after_single_product' => [
161 + __( 'After a single product', 'insert-php' ),
162 + __( 'Snippet will be placed after a single product', 'insert-php' ),
163 + [
164 + 'hide' => '.factory-control-snippet_p_number',
165 + 'show' => '',
166 + ]
167 + ],
168 + 'woo_before_single_product_summary' => [
169 + __( 'Before a single product summary', 'insert-php' ),
170 + __( 'Snippet will be placed before a single product summary', 'insert-php' ),
171 + [
172 + 'hide' => '.factory-control-snippet_p_number',
173 + 'show' => '',
174 + ]
175 + ],
176 + 'woo_after_single_product_summary' => [
177 + __( 'After a single product summary', 'insert-php' ),
178 + __( 'Snippet will be placed after a single product summary', 'insert-php' ),
179 + [
180 + 'hide' => '.factory-control-snippet_p_number',
181 + 'show' => '',
182 + ]
183 + ],
184 + 'woo_single_product_summary_title' => [
185 + __( 'After a product title', 'insert-php' ),
186 + __( 'Snippet will be placed after a product title', 'insert-php' ),
187 + [
188 + 'hide' => '.factory-control-snippet_p_number',
189 + 'show' => '',
190 + ]
191 + ],
192 + 'woo_single_product_summary_price' => [
193 + __( 'After a product price', 'insert-php' ),
194 + __( 'Snippet will be placed after a product price', 'insert-php' ),
195 + [
196 + 'hide' => '.factory-control-snippet_p_number',
197 + 'show' => '',
198 + ]
199 + ],
200 + 'woo_single_product_summary_excerpt' => [
201 + __( 'After a product excerpt', 'insert-php' ),
202 + __( 'Snippet will be placed after a product excerpt', 'insert-php' ),
203 + [
204 + 'hide' => '.factory-control-snippet_p_number',
205 + 'show' => '',
206 + ]
207 + ],
208 + ],
209 + ];
210 +
211 + /**
212 + * Filters the insertion locations.
213 + *
214 + * [
215 + * 'before_2' => [
216 + * __( 'Before 2', 'insert-php' ),
217 + * __( 'Before 2 desc.', 'insert-php' ),
218 + * [
219 + * 'hide' => '.factory-control-snippet_p_number',
220 + * 'show' => '',
221 + * ]
222 + * ]
223 + * ]
224 + *
225 + * @param array The array of custom location data.
226 + *
227 + * @since 2.4
228 + */
229 + $custom_data = apply_filters( 'wbcr/woody/add_custom_location', [] );
230 +
231 + if ( ! empty( $custom_data ) && is_array( $custom_data ) ) {
232 + $locations['custom'] = $custom_data;
233 + }
234 +
235 + $this->locations = $locations;
236 + }
237 +
238 + /**
239 + * @param $name
240 + *
241 + * @return array|array[]
242 + */
243 + public function __get( $name ) {
244 + return $this->getLocation( $name );
245 + }
246 +
247 + /**
248 + * @param string $insertion
249 + *
250 + * @return array
251 + */
252 + public function getInsertion( $insertion ) {
253 + return $this->locations[ $insertion ] ?? [];
254 + }
255 +
256 + /**
257 + * @param string $location
258 + * @param string $insertion
259 + *
260 + * @return array
261 + */
262 + public function getLocation( $location, $insertion = '' ) {
263 + if ( ! empty( $insertion ) ) {
264 + return $this->locations[ $insertion ][ $location ] ?? [];
265 + } else {
266 + foreach ( $this->locations as $k => $loc ) {
267 + foreach ( $loc as $key => $item ) {
268 + if ( $key == $location ) {
269 + return [ $key => $item ];
270 + }
271 + }
272 + }
273 + }
274 +
275 + return [];
276 + }
277 +
278 + /**
279 + *
280 + * @return array
281 + */
282 + public function getList() {
283 + $list = [];
284 + foreach ( $this->locations as $k => $loc ) {
285 + foreach ( $loc as $key => $item ) {
286 + $list[ $key ] = $item;
287 + }
288 + }
289 +
290 + return $list;
291 + }
292 +
293 + /**
294 + * @param string $insertion
295 + *
296 + * @return array
297 + */
298 + public function getInsertionForOptions( $insertion ) {
299 + $return = [];
300 + foreach ( $this->locations[ $insertion ] ?? [] as $key => $locations ) {
301 + $return[] = [ $key, $locations[0] ?? '', $locations[1] ?? '' ];
302 + }
303 +
304 + return $return;
305 + }
306 +
307 + /**
308 + * @return array
309 + */
310 + public function getEventsForOptions() {
311 + $return = [];
312 + $list = $this->getList();
313 + foreach ( $list as $key => $locations ) {
314 + if ( isset( $locations[2] ) && is_array( $locations[2] ) ) {
315 + $return[ $key ] = $locations[2];
316 + } else {
317 + $return[ $key ] = [
318 + 'hide' => '.factory-control-snippet_p_number',
319 + 'show' => '',
320 + ];
321 + }
322 + }
323 +
324 + return $return;
325 + }
326 +
327 +}