PluginProbe
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts / trunk
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts vtrunk
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 +63 -106 2.4.4trunk View file →
@@ -1,12 +1,9 @@
1 1 <?php
2 2 /**
3 3 * Insertion locations
4 4 *
5 - * @author Artem Prihodko <webtemyk@yandex.ru>
6 - * @copyright (c) 2021, Creative Motion
7 - * @version 1.0
8 - * @since 2.4
5 + * @package Woody_Code_Snippets
9 6 */
10 7
11 8 // Exit if accessed directly
12 9 if ( ! defined( 'ABSPATH' ) ) {
@@ -26,19 +23,17 @@
26 23 'header' => [
27 24 __( 'Header', 'insert-php' ),
28 25 __( 'Snippet will be placed in the source code before </head>.', 'insert-php' ),
29 26 [
30 - 'hide' => '.factory-control-snippet_p_number',
31 - 'show' => '',
32 - ]
27 + 'requiresLocationNumber' => false,
28 + ],
33 29 ],
34 30 'footer' => [
35 31 __( 'Footer', 'insert-php' ),
36 32 __( 'Snippet will be placed in the source code before </body>.', 'insert-php' ),
37 33 [
38 - 'hide' => '.factory-control-snippet_p_number',
39 - 'show' => '',
40 - ]
34 + 'requiresLocationNumber' => false,
35 + ],
41 36 ],
42 37 ],
43 38 'posts' => [
44 39 'before_post' => [
@@ -44,51 +39,45 @@
44 39 'before_post' => [
45 40 __( 'Insert Before Post', 'insert-php' ),
46 41 __( 'Snippet will be placed before the title of the post/page.', 'insert-php' ),
47 42 [
48 - 'hide' => '.factory-control-snippet_p_number',
49 - 'show' => '',
50 - ]
43 + 'requiresLocationNumber' => false,
44 + ],
51 45 ],
52 46 'before_content' => [
53 47 __( 'Insert Before Content', 'insert-php' ),
54 48 __( 'Snippet will be placed before the content of the post/page.', 'insert-php' ),
55 49 [
56 - 'hide' => '.factory-control-snippet_p_number',
57 - 'show' => '',
58 - ]
50 + 'requiresLocationNumber' => false,
51 + ],
59 52 ],
60 53 'before_paragraph' => [
61 54 __( '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' ),
55 + __( 'Snippet will be placed before the specified paragraph number.', 'insert-php' ),
63 56 [
64 - 'hide' => '',
65 - 'show' => '.factory-control-snippet_p_number',
66 - ]
57 + 'requiresLocationNumber' => true,
58 + ],
67 59 ],
68 60 'after_paragraph' => [
69 61 __( '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' ),
62 + __( 'Snippet will be placed after the specified paragraph number.', 'insert-php' ),
71 63 [
72 - 'hide' => '',
73 - 'show' => '.factory-control-snippet_p_number',
74 - ]
64 + 'requiresLocationNumber' => true,
65 + ],
75 66 ],
76 67 'after_content' => [
77 68 __( 'Insert After Content', 'insert-php' ),
78 69 __( 'Snippet will be placed after the content of the post/page.', 'insert-php' ),
79 70 [
80 - 'hide' => '.factory-control-snippet_p_number',
81 - 'show' => '',
82 - ]
71 + 'requiresLocationNumber' => false,
72 + ],
83 73 ],
84 74 'after_post' => [
85 75 __( 'Insert After Post', 'insert-php' ),
86 76 __( 'Snippet will be placed in the very end of the post/page.', 'insert-php' ),
87 77 [
88 - 'hide' => '.factory-control-snippet_p_number',
89 - 'show' => '',
90 - ]
78 + 'requiresLocationNumber' => false,
79 + ],
91 80 ],
92 81 ],
93 82 'pages' => [
94 83 'before_excerpt' => [
@@ -94,43 +83,38 @@
94 83 'before_excerpt' => [
95 84 __( 'Insert Before Excerpt', 'insert-php' ),
96 85 __( 'Snippet will be placed before the excerpt of the post/page.', 'insert-php' ),
97 86 [
98 - 'hide' => '.factory-control-snippet_p_number',
99 - 'show' => '',
100 - ]
87 + 'requiresLocationNumber' => false,
88 + ],
101 89 ],
102 90 'after_excerpt' => [
103 91 __( 'Insert After Excerpt', 'insert-php' ),
104 92 __( 'Snippet will be placed after the excerpt of the post/page.', 'insert-php' ),
105 93 [
106 - 'hide' => '.factory-control-snippet_p_number',
107 - 'show' => '',
108 - ]
94 + 'requiresLocationNumber' => false,
95 + ],
109 96 ],
110 97 'between_posts' => [
111 98 __( 'Between Posts', 'insert-php' ),
112 99 __( 'Snippet will be placed between each post.', 'insert-php' ),
113 100 [
114 - 'hide' => '.factory-control-snippet_p_number',
115 - 'show' => '',
116 - ]
101 + 'requiresLocationNumber' => false,
102 + ],
117 103 ],
118 104 'before_posts' => [
119 105 __( 'Before post', 'insert-php' ),
120 - __( 'Snippet will be placed before the post, which number you can specify in the Location number field.', 'insert-php' ),
106 + __( 'Snippet will be placed before the specified post number.', 'insert-php' ),
121 107 [
122 - 'hide' => '',
123 - 'show' => '.factory-control-snippet_p_number',
124 - ]
108 + 'requiresLocationNumber' => true,
109 + ],
125 110 ],
126 111 'after_posts' => [
127 112 __( 'After post', 'insert-php' ),
128 - __( 'Snippet will be placed after the post, which number you can specify in the Location number field.', 'insert-php' ),
113 + __( 'Snippet will be placed after the specified post number.', 'insert-php' ),
129 114 [
130 - 'hide' => '',
131 - 'show' => '.factory-control-snippet_p_number',
132 - ]
115 + 'requiresLocationNumber' => true,
116 + ],
133 117 ],
134 118 ],
135 119 'woocommerce' => [
136 120 'woo_before_shop_loop' => [
@@ -136,75 +120,66 @@
136 120 'woo_before_shop_loop' => [
137 121 __( 'Before the list of products', 'insert-php' ),
138 122 __( 'Snippet will be placed before the list of products.', 'insert-php' ),
139 123 [
140 - 'hide' => '.factory-control-snippet_p_number',
141 - 'show' => '',
142 - ]
124 + 'requiresLocationNumber' => false,
125 + ],
143 126 ],
144 127 'woo_after_shop_loop' => [
145 128 __( 'After the list of products', 'insert-php' ),
146 129 __( 'Snippet will be placed after the list of products.', 'insert-php' ),
147 130 [
148 - 'hide' => '.factory-control-snippet_p_number',
149 - 'show' => '',
150 - ]
131 + 'requiresLocationNumber' => false,
132 + ],
151 133 ],
152 134 'woo_before_single_product' => [
153 135 __( 'Before a single product', 'insert-php' ),
154 - __( 'Snippet will be placed before a single product', 'insert-php' ),
136 + __( 'Snippet will be placed before a single product.', 'insert-php' ),
155 137 [
156 - 'hide' => '.factory-control-snippet_p_number',
157 - 'show' => '',
158 - ]
138 + 'requiresLocationNumber' => false,
139 + ],
159 140 ],
160 141 'woo_after_single_product' => [
161 142 __( 'After a single product', 'insert-php' ),
162 - __( 'Snippet will be placed after a single product', 'insert-php' ),
143 + __( 'Snippet will be placed after a single product.', 'insert-php' ),
163 144 [
164 - 'hide' => '.factory-control-snippet_p_number',
165 - 'show' => '',
166 - ]
145 + 'requiresLocationNumber' => false,
146 + ],
167 147 ],
168 148 'woo_before_single_product_summary' => [
169 149 __( 'Before a single product summary', 'insert-php' ),
170 - __( 'Snippet will be placed before a single product summary', 'insert-php' ),
150 + __( 'Snippet will be placed before a single product summary.', 'insert-php' ),
171 151 [
172 - 'hide' => '.factory-control-snippet_p_number',
173 - 'show' => '',
174 - ]
152 + 'requiresLocationNumber' => false,
153 + ],
175 154 ],
176 155 'woo_after_single_product_summary' => [
177 156 __( 'After a single product summary', 'insert-php' ),
178 - __( 'Snippet will be placed after a single product summary', 'insert-php' ),
157 + __( 'Snippet will be placed after a single product summary.', 'insert-php' ),
179 158 [
180 - 'hide' => '.factory-control-snippet_p_number',
181 - 'show' => '',
182 - ]
159 + 'requiresLocationNumber' => false,
160 + ],
183 161 ],
184 162 'woo_single_product_summary_title' => [
185 163 __( 'After a product title', 'insert-php' ),
186 - __( 'Snippet will be placed after a product title', 'insert-php' ),
164 + __( 'Snippet will be placed after a product title.', 'insert-php' ),
187 165 [
188 - 'hide' => '.factory-control-snippet_p_number',
189 - 'show' => '',
190 - ]
166 + 'requiresLocationNumber' => false,
167 + ],
191 168 ],
192 169 'woo_single_product_summary_price' => [
193 170 __( 'After a product price', 'insert-php' ),
194 - __( 'Snippet will be placed after a product price', 'insert-php' ),
171 + __( 'Snippet will be placed after a product price.', 'insert-php' ),
195 172 [
196 - 'hide' => '.factory-control-snippet_p_number',
197 - 'show' => '',
198 - ]
173 + 'requiresLocationNumber' => false,
174 + ],
199 175 ],
200 176 'woo_single_product_summary_excerpt' => [
201 177 __( 'After a product excerpt', 'insert-php' ),
202 - __( 'Snippet will be placed after a product excerpt', 'insert-php' ),
178 + __( 'Snippet will be placed after a product excerpt.', 'insert-php' ),
203 179 [
204 - 'hide' => '.factory-control-snippet_p_number',
205 - 'show' => '',
206 - ]
180 + 'requiresLocationNumber' => false,
181 + ],
207 182 ],
208 183 ],
209 184 ];
210 185
@@ -215,15 +190,14 @@
215 190 * 'before_2' => [
216 191 * __( 'Before 2', 'insert-php' ),
217 192 * __( 'Before 2 desc.', 'insert-php' ),
218 193 * [
219 - * 'hide' => '.factory-control-snippet_p_number',
220 - * 'show' => '',
194 + * 'requiresLocationNumber' => false, // true if location needs paragraph/post number input
221 195 * ]
222 196 * ]
223 197 * ]
224 198 *
225 - * @param array The array of custom location data.
199 + * @param array<string, array<string, array<int|string, mixed>>> $locations The array of custom location data.
226 200 *
227 201 * @since 2.4
228 202 */
229 203 $custom_data = apply_filters( 'wbcr/woody/add_custom_location', [] );
@@ -297,31 +271,14 @@
297 271 */
298 272 public function getInsertionForOptions( $insertion ) {
299 273 $return = [];
300 274 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 - ];
275 + $requires_number = false;
276 + if ( isset( $locations[2] ) && is_array( $locations[2] ) && isset( $locations[2]['requiresLocationNumber'] ) ) {
277 + $requires_number = $locations[2]['requiresLocationNumber'];
321 278 }
279 + $return[] = [ $key, $locations[0] ?? '', $locations[1] ?? '', $requires_number ];
322 280 }
323 281
324 282 return $return;
325 283 }
326 -
327 -}
284 +}