@@ -10,530 +10,530 @@ |
||
10 | 10 | */ |
11 | 11 | class LSX_Projects_Admin { |
12 | 12 | |
13 | - public function __construct() { |
|
14 | - $this->load_classes(); |
|
15 | - |
|
16 | - add_action( 'init', array( $this, 'post_type_setup' ) ); |
|
17 | - add_action( 'init', array( $this, 'taxonomy_setup' ) ); |
|
18 | - add_action( 'init', array( $this, 'taxonomy_project_type_setup' ) ); |
|
19 | - add_action( 'init', array( $this, 'taxonomy_project_tag_setup' ) ); |
|
20 | - add_filter( 'cmb2_admin_init', array( $this, 'field_setup' ) ); |
|
21 | - add_filter( 'cmb2_admin_init', array( $this, 'projects_services_metaboxes' ) ); |
|
22 | - add_filter( 'cmb2_admin_init', array( $this, 'projects_testimonials_metaboxes' ) ); |
|
23 | - add_filter( 'cmb2_admin_init', array( $this, 'projects_team_metaboxes' ) ); |
|
24 | - add_filter( 'cmb2_admin_init', array( $this, 'projects_woocommerce_metaboxes' ) ); |
|
25 | - add_filter( 'cmb2_admin_init', array( $this, 'project_field_setup_product' ) ); |
|
26 | - add_action( 'cmb_save_custom', array( $this, 'post_relations' ), 3, 20 ); |
|
27 | - add_action( 'admin_enqueue_scripts', array( $this, 'assets' ) ); |
|
28 | - |
|
29 | - add_filter( 'type_url_form_media', array( $this, 'change_attachment_field_button' ), 20, 1 ); |
|
30 | - add_filter( 'enter_title_here', array( $this, 'change_title_text' ) ); |
|
31 | - } |
|
32 | - |
|
33 | - /** |
|
34 | - * Loads the admin subclasses |
|
35 | - */ |
|
36 | - private function load_classes() { |
|
37 | - require_once LSX_PROJECTS_PATH . 'classes/admin/class-settings.php'; |
|
38 | - $this->settings = \lsx\projects\classes\admin\Settings::get_instance(); |
|
39 | - |
|
40 | - require_once LSX_PROJECTS_PATH . 'classes/admin/class-settings-theme.php'; |
|
41 | - $this->settings_theme = \lsx\projects\classes\admin\Settings_Theme::get_instance(); |
|
42 | - } |
|
43 | - |
|
44 | - /** |
|
45 | - * Register the Project and Product Tag post type |
|
46 | - */ |
|
47 | - public function post_type_setup() { |
|
48 | - $labels = array( |
|
49 | - 'name' => esc_html_x( 'Projects', 'post type general name', 'lsx-projects' ), |
|
50 | - 'singular_name' => esc_html_x( 'Project', 'post type singular name', 'lsx-projects' ), |
|
51 | - 'add_new' => esc_html_x( 'Add New', 'post type general name', 'lsx-projects' ), |
|
52 | - 'add_new_item' => esc_html__( 'Add New Project', 'lsx-projects' ), |
|
53 | - 'edit_item' => esc_html__( 'Edit Project', 'lsx-projects' ), |
|
54 | - 'new_item' => esc_html__( 'New Project', 'lsx-projects' ), |
|
55 | - 'all_items' => esc_html__( 'All Projects', 'lsx-projects' ), |
|
56 | - 'view_item' => esc_html__( 'View Project', 'lsx-projects' ), |
|
57 | - 'search_items' => esc_html__( 'Search Projects', 'lsx-projects' ), |
|
58 | - 'not_found' => esc_html__( 'No projects found', 'lsx-projects' ), |
|
59 | - 'not_found_in_trash' => esc_html__( 'No projects found in Trash', 'lsx-projects' ), |
|
60 | - 'parent_item_colon' => '', |
|
61 | - 'menu_name' => esc_html_x( 'Projects', 'admin menu', 'lsx-projects' ), |
|
62 | - ); |
|
63 | - |
|
64 | - $args = array( |
|
65 | - 'labels' => $labels, |
|
66 | - 'public' => true, |
|
67 | - 'publicly_queryable' => true, |
|
68 | - 'show_ui' => true, |
|
69 | - 'show_in_menu' => true, |
|
70 | - 'menu_icon' => 'dashicons-portfolio', |
|
71 | - 'query_var' => true, |
|
72 | - 'rewrite' => array( |
|
73 | - 'slug' => 'portfolio', |
|
74 | - ), |
|
75 | - 'capability_type' => 'post', |
|
76 | - 'has_archive' => 'portfolio', |
|
77 | - 'hierarchical' => false, |
|
78 | - 'menu_position' => null, |
|
79 | - 'supports' => array( |
|
80 | - 'title', |
|
81 | - 'editor', |
|
82 | - 'thumbnail', |
|
83 | - 'excerpt', |
|
84 | - 'custom-fields', |
|
85 | - ), |
|
86 | - 'show_in_rest' => true, |
|
87 | - ); |
|
88 | - |
|
89 | - register_post_type( 'project', $args ); |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * Register the Group taxonomy |
|
94 | - */ |
|
95 | - public function taxonomy_setup() { |
|
96 | - $labels = array( |
|
97 | - 'name' => esc_html_x( 'Project Groups', 'taxonomy general name', 'lsx-projects' ), |
|
98 | - 'singular_name' => esc_html_x( 'Group', 'taxonomy singular name', 'lsx-projects' ), |
|
99 | - 'search_items' => esc_html__( 'Search Groups', 'lsx-projects' ), |
|
100 | - 'all_items' => esc_html__( 'All Groups', 'lsx-projects' ), |
|
101 | - 'parent_item' => esc_html__( 'Parent Group', 'lsx-projects' ), |
|
102 | - 'parent_item_colon' => esc_html__( 'Parent Group:', 'lsx-projects' ), |
|
103 | - 'edit_item' => esc_html__( 'Edit Group', 'lsx-projects' ), |
|
104 | - 'update_item' => esc_html__( 'Update Group', 'lsx-projects' ), |
|
105 | - 'add_new_item' => esc_html__( 'Add New Group', 'lsx-projects' ), |
|
106 | - 'new_item_name' => esc_html__( 'New Group Name', 'lsx-projects' ), |
|
107 | - 'menu_name' => esc_html__( 'Groups', 'lsx-projects' ), |
|
108 | - ); |
|
109 | - |
|
110 | - $args = array( |
|
111 | - 'hierarchical' => true, |
|
112 | - 'labels' => $labels, |
|
113 | - 'show_ui' => true, |
|
114 | - 'show_admin_column' => true, |
|
115 | - 'query_var' => true, |
|
116 | - 'rewrite' => array( |
|
117 | - 'slug' => 'portfolio-group', |
|
118 | - ), |
|
119 | - ); |
|
120 | - |
|
121 | - register_taxonomy( 'project-group', array( 'project' ), $args ); |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * Register the Type taxonomy |
|
126 | - */ |
|
127 | - public function taxonomy_project_type_setup() { |
|
128 | - $labels = array( |
|
129 | - 'name' => esc_html_x( 'Project Types', 'taxonomy general name', 'lsx-projects' ), |
|
130 | - 'singular_name' => esc_html_x( 'Type', 'taxonomy singular name', 'lsx-projects' ), |
|
131 | - 'search_items' => esc_html__( 'Search Types', 'lsx-projects' ), |
|
132 | - 'all_items' => esc_html__( 'All Types', 'lsx-projects' ), |
|
133 | - 'parent_item' => esc_html__( 'Parent Type', 'lsx-projects' ), |
|
134 | - 'parent_item_colon' => esc_html__( 'Parent Type:', 'lsx-projects' ), |
|
135 | - 'edit_item' => esc_html__( 'Edit Type', 'lsx-projects' ), |
|
136 | - 'update_item' => esc_html__( 'Update Type', 'lsx-projects' ), |
|
137 | - 'add_new_item' => esc_html__( 'Add New Type', 'lsx-projects' ), |
|
138 | - 'new_item_name' => esc_html__( 'New Type Name', 'lsx-projects' ), |
|
139 | - 'menu_name' => esc_html__( 'Types', 'lsx-projects' ), |
|
140 | - ); |
|
141 | - |
|
142 | - $args = array( |
|
143 | - 'hierarchical' => true, |
|
144 | - 'labels' => $labels, |
|
145 | - 'show_ui' => true, |
|
146 | - 'show_admin_column' => true, |
|
147 | - 'query_var' => true, |
|
148 | - 'rewrite' => array( |
|
149 | - 'slug' => 'project-type', |
|
150 | - ), |
|
151 | - 'show_in_rest' => true, |
|
152 | - ); |
|
153 | - |
|
154 | - register_taxonomy( 'project-type', array( 'project' ), $args ); |
|
155 | - } |
|
156 | - |
|
157 | - /** |
|
158 | - * Register the Tag taxonomy |
|
159 | - */ |
|
160 | - public function taxonomy_project_tag_setup() { |
|
161 | - $labels = array( |
|
162 | - 'name' => esc_html_x( 'Project Tags', 'taxonomy general name', 'lsx-projects' ), |
|
163 | - 'singular_name' => esc_html_x( 'Tag', 'taxonomy singular name', 'lsx-projects' ), |
|
164 | - 'search_items' => esc_html__( 'Search Tags', 'lsx-projects' ), |
|
165 | - 'all_items' => esc_html__( 'All Tags', 'lsx-projects' ), |
|
166 | - 'parent_item' => esc_html__( 'Parent Tag', 'lsx-projects' ), |
|
167 | - 'parent_item_colon' => esc_html__( 'Parent Tag:', 'lsx-projects' ), |
|
168 | - 'edit_item' => esc_html__( 'Edit Tag', 'lsx-projects' ), |
|
169 | - 'update_item' => esc_html__( 'Update Tag', 'lsx-projects' ), |
|
170 | - 'add_new_item' => esc_html__( 'Add New Tag', 'lsx-projects' ), |
|
171 | - 'new_item_name' => esc_html__( 'New Tag Name', 'lsx-projects' ), |
|
172 | - 'menu_name' => esc_html__( 'Tags', 'lsx-projects' ), |
|
173 | - ); |
|
174 | - |
|
175 | - $args = array( |
|
176 | - 'hierarchical' => true, |
|
177 | - 'labels' => $labels, |
|
178 | - 'show_ui' => true, |
|
179 | - 'show_admin_column' => true, |
|
180 | - 'query_var' => true, |
|
181 | - 'rewrite' => array( |
|
182 | - 'slug' => 'project-tag', |
|
183 | - ), |
|
184 | - 'show_in_rest' => true, |
|
185 | - ); |
|
186 | - |
|
187 | - register_taxonomy( 'project-tag', array( 'project' ), $args ); |
|
188 | - } |
|
189 | - |
|
190 | - /** |
|
191 | - * Add metabox with custom fields to the Project post type |
|
192 | - */ |
|
193 | - public function field_setup() { |
|
194 | - $prefix = 'lsx_project_'; |
|
195 | - |
|
196 | - $cmb = new_cmb2_box( |
|
197 | - array( |
|
198 | - 'id' => $prefix . '_project', |
|
199 | - 'title' => __( 'General', 'lsx-projects' ), |
|
200 | - 'object_types' => 'project', |
|
201 | - 'context' => 'normal', |
|
202 | - 'priority' => 'low', |
|
203 | - 'show_names' => true, |
|
204 | - ) |
|
205 | - ); |
|
206 | - |
|
207 | - $cmb->add_field( |
|
208 | - array( |
|
209 | - 'name' => esc_html__( 'Featured:', 'lsx-projects' ), |
|
210 | - 'id' => $prefix . 'featured', |
|
211 | - 'type' => 'checkbox', |
|
212 | - 'value' => 1, |
|
213 | - 'default' => 0, |
|
214 | - 'show_in_rest' => true, |
|
215 | - ) |
|
216 | - ); |
|
217 | - |
|
218 | - $cmb->add_field( |
|
219 | - array( |
|
220 | - 'name' => esc_html__( 'Client:', 'lsx-projects' ), |
|
221 | - 'id' => $prefix . 'client', |
|
222 | - 'type' => 'text', |
|
223 | - 'show_in_rest' => true, |
|
224 | - ) |
|
225 | - ); |
|
226 | - |
|
227 | - $cmb->add_field( |
|
228 | - array( |
|
229 | - 'name' => esc_html__( 'Client logo:', 'lsx-projects' ), |
|
230 | - 'id' => $prefix . 'client_logo', |
|
231 | - 'type' => 'file', |
|
232 | - 'desc' => esc_html__( 'Recommended image size: 320 x 50~60', 'lsx-projects' ), |
|
233 | - 'options' => array( |
|
234 | - 'url' => false, // Hide the text input for the url. |
|
235 | - ), |
|
236 | - 'text' => array( |
|
237 | - 'add_upload_file_text' => 'Choose Image', |
|
238 | - ), |
|
239 | - 'show_in_rest' => true, |
|
240 | - ) |
|
241 | - ); |
|
242 | - |
|
243 | - $cmb->add_field( |
|
244 | - array( |
|
245 | - 'name' => esc_html__( 'URL for the finished project:', 'lsx-projects' ), |
|
246 | - 'id' => $prefix . 'url', |
|
247 | - 'type' => 'text', |
|
248 | - 'show_in_rest' => true, |
|
249 | - ) |
|
250 | - ); |
|
251 | - } |
|
252 | - |
|
253 | - /** |
|
254 | - * Project Services Metaboxes. |
|
255 | - */ |
|
256 | - public function projects_services_metaboxes() { |
|
257 | - $prefix = 'lsx_project_'; |
|
258 | - |
|
259 | - $cmb = new_cmb2_box( |
|
260 | - array( |
|
261 | - 'id' => $prefix . '_project', |
|
262 | - 'object_types' => 'projects', |
|
263 | - 'context' => 'normal', |
|
264 | - 'priority' => 'low', |
|
265 | - 'show_names' => true, |
|
266 | - ) |
|
267 | - ); |
|
268 | - |
|
269 | - $cmb->add_field( |
|
270 | - array( |
|
271 | - 'name' => esc_html__( 'Services related to this project:', 'lsx-projects' ), |
|
272 | - 'id' => 'page_to_project', |
|
273 | - 'type' => 'post_search_ajax', |
|
274 | - 'show_in_rest' => true, |
|
275 | - 'limit' => 15, |
|
276 | - 'sortable' => true, |
|
277 | - 'query_args' => array( |
|
278 | - 'post_type' => array( 'project' ), |
|
279 | - 'post_status' => array( 'publish' ), |
|
280 | - 'nopagin' => true, |
|
281 | - 'posts_per_page' => '50', |
|
282 | - 'orderby' => 'title', |
|
283 | - 'order' => 'ASC', |
|
284 | - ), |
|
285 | - ) |
|
286 | - ); |
|
287 | - } |
|
288 | - |
|
289 | - /** |
|
290 | - * Project Testimonials Metaboxes. |
|
291 | - */ |
|
292 | - public function projects_testimonials_metaboxes() { |
|
293 | - $prefix = 'lsx_project_'; |
|
294 | - |
|
295 | - $cmb = new_cmb2_box( |
|
296 | - array( |
|
297 | - 'id' => $prefix . '_project', |
|
298 | - 'object_types' => 'projects', |
|
299 | - 'context' => 'normal', |
|
300 | - 'priority' => 'low', |
|
301 | - 'show_names' => true, |
|
302 | - ) |
|
303 | - ); |
|
304 | - |
|
305 | - if ( class_exists( 'LSX_Testimonials' ) ) { |
|
306 | - $cmb->add_field( |
|
307 | - array( |
|
308 | - 'name' => esc_html__( 'Testimonials related to this project:', 'lsx-projects' ), |
|
309 | - 'id' => 'testimonial_to_project', |
|
310 | - 'type' => 'post_search_ajax', |
|
311 | - 'show_in_rest' => true, |
|
312 | - 'limit' => 15, |
|
313 | - 'sortable' => true, |
|
314 | - 'query_args' => array( |
|
315 | - 'post_type' => array( 'testimonial' ), |
|
316 | - 'post_status' => array( 'publish' ), |
|
317 | - 'nopagin' => true, |
|
318 | - 'posts_per_page' => '50', |
|
319 | - 'orderby' => 'title', |
|
320 | - 'order' => 'ASC', |
|
321 | - ), |
|
322 | - ) |
|
323 | - ); |
|
324 | - } |
|
325 | - } |
|
326 | - |
|
327 | - /** |
|
328 | - * Project Team Metaboxes. |
|
329 | - */ |
|
330 | - public function projects_team_metaboxes() { |
|
331 | - $prefix = 'lsx_project_'; |
|
332 | - |
|
333 | - $cmb = new_cmb2_box( |
|
334 | - array( |
|
335 | - 'id' => $prefix . '_project', |
|
336 | - 'object_types' => 'project', |
|
337 | - 'context' => 'normal', |
|
338 | - 'priority' => 'low', |
|
339 | - 'show_names' => true, |
|
340 | - ) |
|
341 | - ); |
|
342 | - |
|
343 | - if ( class_exists( 'LSX_Team' ) ) { |
|
344 | - $cmb->add_field( |
|
345 | - array( |
|
346 | - 'name' => esc_html__( 'Team members involved with this project:', 'lsx-projects' ), |
|
347 | - 'id' => 'team_to_project', |
|
348 | - 'type' => 'post_search_ajax', |
|
349 | - 'show_in_rest' => true, |
|
350 | - 'limit' => 15, |
|
351 | - 'sortable' => true, |
|
352 | - 'query_args' => array( |
|
353 | - 'post_type' => array( 'team' ), |
|
354 | - 'post_status' => array( 'publish' ), |
|
355 | - 'nopagin' => true, |
|
356 | - 'posts_per_page' => '50', |
|
357 | - 'orderby' => 'title', |
|
358 | - 'order' => 'ASC', |
|
359 | - ), |
|
360 | - ) |
|
361 | - ); |
|
362 | - } |
|
363 | - } |
|
364 | - |
|
365 | - /** |
|
366 | - * Project Woocommerce Metaboxes. |
|
367 | - */ |
|
368 | - public function projects_woocommerce_metaboxes() { |
|
369 | - $prefix = 'lsx_project_'; |
|
370 | - |
|
371 | - $cmb = new_cmb2_box( |
|
372 | - array( |
|
373 | - 'id' => $prefix . '_project', |
|
374 | - 'object_types' => 'projects', |
|
375 | - 'context' => 'normal', |
|
376 | - 'priority' => 'low', |
|
377 | - 'show_names' => true, |
|
378 | - ) |
|
379 | - ); |
|
380 | - |
|
381 | - if ( class_exists( 'woocommerce' ) ) { |
|
382 | - $cmb->add_field( |
|
383 | - array( |
|
384 | - 'name' => esc_html__( 'Products used for this project:', 'lsx-projects' ), |
|
385 | - 'id' => 'product_to_project', |
|
386 | - 'type' => 'post_search_ajax', |
|
387 | - 'show_in_rest' => true, |
|
388 | - 'limit' => 15, |
|
389 | - 'sortable' => true, |
|
390 | - 'query_args' => array( |
|
391 | - 'post_type' => array( 'product' ), |
|
392 | - 'post_status' => array( 'publish' ), |
|
393 | - 'nopagin' => true, |
|
394 | - 'posts_per_page' => '50', |
|
395 | - 'orderby' => 'title', |
|
396 | - 'order' => 'ASC', |
|
397 | - ), |
|
398 | - ) |
|
399 | - ); |
|
400 | - } |
|
401 | - } |
|
402 | - |
|
403 | - /** |
|
404 | - * Add Alt Product metabox with custom fields to the Project post type |
|
405 | - */ |
|
406 | - public function project_field_setup_product() { |
|
407 | - $prefix = 'lsx_project_'; |
|
408 | - |
|
409 | - $cmb = new_cmb2_box( |
|
410 | - array( |
|
411 | - 'id' => $prefix . '_project', |
|
412 | - 'title' => __( 'General', 'lsx-projects' ), |
|
413 | - 'object_types' => 'project', |
|
414 | - 'context' => 'normal', |
|
415 | - 'priority' => 'low', |
|
416 | - 'show_names' => true, |
|
417 | - ) |
|
418 | - ); |
|
419 | - |
|
420 | - $tip_group = $cmb->add_field( |
|
421 | - array( |
|
422 | - 'id' => $prefix . '_alt_products', |
|
423 | - 'type' => 'group', |
|
424 | - 'options' => array( |
|
425 | - 'group_title' => __( 'Alternative Products', 'lsx-projects' ), |
|
426 | - 'add_button' => __( 'Add Product', 'lsx-projects' ), |
|
427 | - 'remove_button' => __( 'Remove Product', 'lsx-projects' ), |
|
428 | - 'sortable' => true, |
|
429 | - ), |
|
430 | - 'classes' => 'lsx-admin-row', |
|
431 | - ) |
|
432 | - ); |
|
433 | - |
|
434 | - $cmb->add_group_field( |
|
435 | - $tip_group, |
|
436 | - array( |
|
437 | - 'name' => esc_html__( 'Alt Product Name:', 'lsx-projects' ), |
|
438 | - 'id' => $prefix . 'alt_product_title', |
|
439 | - 'type' => 'text', |
|
440 | - 'show_in_rest' => true, |
|
441 | - ) |
|
442 | - ); |
|
443 | - |
|
444 | - $cmb->add_group_field( |
|
445 | - $tip_group, |
|
446 | - array( |
|
447 | - 'name' => esc_html__( 'Alt Product Link:', 'lsx-projects' ), |
|
448 | - 'id' => $prefix . 'alt_product_link', |
|
449 | - 'type' => 'text', |
|
450 | - 'show_in_rest' => true, |
|
451 | - ) |
|
452 | - ); |
|
453 | - |
|
454 | - } |
|
455 | - |
|
456 | - /** |
|
457 | - * Sets up the "post relations". |
|
458 | - */ |
|
459 | - public function post_relations( $post_id, $field, $value ) { |
|
460 | - $connections = array( |
|
461 | - // 'project_to_project', |
|
462 | - |
|
463 | - 'page_to_project', |
|
464 | - 'project_to_page', |
|
465 | - |
|
466 | - 'project_to_service', |
|
467 | - 'service_to_project', |
|
468 | - |
|
469 | - 'project_to_testimonial', |
|
470 | - 'testimonial_to_project', |
|
471 | - |
|
472 | - 'project_to_team', |
|
473 | - 'team_to_project', |
|
474 | - ); |
|
475 | - |
|
476 | - if ( in_array( $field['id'], $connections ) ) { |
|
477 | - $this->save_related_post( $connections, $post_id, $field, $value ); |
|
478 | - } |
|
479 | - } |
|
480 | - |
|
481 | - /** |
|
482 | - * Save the reverse post relation. |
|
483 | - */ |
|
484 | - public function save_related_post( $connections, $post_id, $field, $value ) { |
|
485 | - $ids = explode( '_to_', $field['id'] ); |
|
486 | - $relation = $ids[1] . '_to_' . $ids[0]; |
|
487 | - |
|
488 | - if ( in_array( $relation, $connections ) ) { |
|
489 | - $previous_values = get_post_meta( $post_id, $field['id'], false ); |
|
490 | - |
|
491 | - if ( ! empty( $previous_values ) ) { |
|
492 | - foreach ( $previous_values as $v ) { |
|
493 | - delete_post_meta( $v, $relation, $post_id ); |
|
494 | - } |
|
495 | - } |
|
496 | - |
|
497 | - if ( is_array( $value ) ) { |
|
498 | - foreach ( $value as $v ) { |
|
499 | - if ( ! empty( $v ) ) { |
|
500 | - add_post_meta( $v, $relation, $post_id ); |
|
501 | - } |
|
502 | - } |
|
503 | - } |
|
504 | - } |
|
505 | - } |
|
506 | - |
|
507 | - public function assets() { |
|
508 | - //wp_enqueue_media(); |
|
509 | - wp_enqueue_script( 'media-upload' ); |
|
510 | - wp_enqueue_script( 'thickbox' ); |
|
511 | - wp_enqueue_style( 'thickbox' ); |
|
512 | - |
|
513 | - wp_enqueue_script( 'lsx-projects-admin', LSX_PROJECTS_URL . 'assets/js/lsx-projects-admin.min.js', array( 'jquery' ), LSX_PROJECTS_VER, true ); |
|
514 | - wp_enqueue_style( 'lsx-projects-admin', LSX_PROJECTS_URL . 'assets/css/lsx-projects-admin.css', array(), LSX_PROJECTS_VER ); |
|
515 | - } |
|
516 | - |
|
517 | - /** |
|
518 | - * Change the "Insert into Post" button text when media modal is used for feature images |
|
519 | - */ |
|
520 | - public function change_attachment_field_button( $html ) { |
|
521 | - if ( isset( $_GET['feature_image_text_button'] ) ) { |
|
522 | - $html = str_replace( 'value="Insert into Post"', sprintf( 'value="%s"', esc_html__( 'Select featured image', 'lsx-projects' ) ), $html ); |
|
523 | - } |
|
524 | - |
|
525 | - return $html; |
|
526 | - } |
|
527 | - |
|
528 | - public function change_title_text( $title ) { |
|
529 | - $screen = get_current_screen(); |
|
530 | - |
|
531 | - if ( 'project' === $screen->post_type ) { |
|
532 | - $title = esc_attr__( 'Enter project title', 'lsx-projects' ); |
|
533 | - } |
|
534 | - |
|
535 | - return $title; |
|
536 | - } |
|
13 | + public function __construct() { |
|
14 | + $this->load_classes(); |
|
15 | + |
|
16 | + add_action( 'init', array( $this, 'post_type_setup' ) ); |
|
17 | + add_action( 'init', array( $this, 'taxonomy_setup' ) ); |
|
18 | + add_action( 'init', array( $this, 'taxonomy_project_type_setup' ) ); |
|
19 | + add_action( 'init', array( $this, 'taxonomy_project_tag_setup' ) ); |
|
20 | + add_filter( 'cmb2_admin_init', array( $this, 'field_setup' ) ); |
|
21 | + add_filter( 'cmb2_admin_init', array( $this, 'projects_services_metaboxes' ) ); |
|
22 | + add_filter( 'cmb2_admin_init', array( $this, 'projects_testimonials_metaboxes' ) ); |
|
23 | + add_filter( 'cmb2_admin_init', array( $this, 'projects_team_metaboxes' ) ); |
|
24 | + add_filter( 'cmb2_admin_init', array( $this, 'projects_woocommerce_metaboxes' ) ); |
|
25 | + add_filter( 'cmb2_admin_init', array( $this, 'project_field_setup_product' ) ); |
|
26 | + add_action( 'cmb_save_custom', array( $this, 'post_relations' ), 3, 20 ); |
|
27 | + add_action( 'admin_enqueue_scripts', array( $this, 'assets' ) ); |
|
28 | + |
|
29 | + add_filter( 'type_url_form_media', array( $this, 'change_attachment_field_button' ), 20, 1 ); |
|
30 | + add_filter( 'enter_title_here', array( $this, 'change_title_text' ) ); |
|
31 | + } |
|
32 | + |
|
33 | + /** |
|
34 | + * Loads the admin subclasses |
|
35 | + */ |
|
36 | + private function load_classes() { |
|
37 | + require_once LSX_PROJECTS_PATH . 'classes/admin/class-settings.php'; |
|
38 | + $this->settings = \lsx\projects\classes\admin\Settings::get_instance(); |
|
39 | + |
|
40 | + require_once LSX_PROJECTS_PATH . 'classes/admin/class-settings-theme.php'; |
|
41 | + $this->settings_theme = \lsx\projects\classes\admin\Settings_Theme::get_instance(); |
|
42 | + } |
|
43 | + |
|
44 | + /** |
|
45 | + * Register the Project and Product Tag post type |
|
46 | + */ |
|
47 | + public function post_type_setup() { |
|
48 | + $labels = array( |
|
49 | + 'name' => esc_html_x( 'Projects', 'post type general name', 'lsx-projects' ), |
|
50 | + 'singular_name' => esc_html_x( 'Project', 'post type singular name', 'lsx-projects' ), |
|
51 | + 'add_new' => esc_html_x( 'Add New', 'post type general name', 'lsx-projects' ), |
|
52 | + 'add_new_item' => esc_html__( 'Add New Project', 'lsx-projects' ), |
|
53 | + 'edit_item' => esc_html__( 'Edit Project', 'lsx-projects' ), |
|
54 | + 'new_item' => esc_html__( 'New Project', 'lsx-projects' ), |
|
55 | + 'all_items' => esc_html__( 'All Projects', 'lsx-projects' ), |
|
56 | + 'view_item' => esc_html__( 'View Project', 'lsx-projects' ), |
|
57 | + 'search_items' => esc_html__( 'Search Projects', 'lsx-projects' ), |
|
58 | + 'not_found' => esc_html__( 'No projects found', 'lsx-projects' ), |
|
59 | + 'not_found_in_trash' => esc_html__( 'No projects found in Trash', 'lsx-projects' ), |
|
60 | + 'parent_item_colon' => '', |
|
61 | + 'menu_name' => esc_html_x( 'Projects', 'admin menu', 'lsx-projects' ), |
|
62 | + ); |
|
63 | + |
|
64 | + $args = array( |
|
65 | + 'labels' => $labels, |
|
66 | + 'public' => true, |
|
67 | + 'publicly_queryable' => true, |
|
68 | + 'show_ui' => true, |
|
69 | + 'show_in_menu' => true, |
|
70 | + 'menu_icon' => 'dashicons-portfolio', |
|
71 | + 'query_var' => true, |
|
72 | + 'rewrite' => array( |
|
73 | + 'slug' => 'portfolio', |
|
74 | + ), |
|
75 | + 'capability_type' => 'post', |
|
76 | + 'has_archive' => 'portfolio', |
|
77 | + 'hierarchical' => false, |
|
78 | + 'menu_position' => null, |
|
79 | + 'supports' => array( |
|
80 | + 'title', |
|
81 | + 'editor', |
|
82 | + 'thumbnail', |
|
83 | + 'excerpt', |
|
84 | + 'custom-fields', |
|
85 | + ), |
|
86 | + 'show_in_rest' => true, |
|
87 | + ); |
|
88 | + |
|
89 | + register_post_type( 'project', $args ); |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * Register the Group taxonomy |
|
94 | + */ |
|
95 | + public function taxonomy_setup() { |
|
96 | + $labels = array( |
|
97 | + 'name' => esc_html_x( 'Project Groups', 'taxonomy general name', 'lsx-projects' ), |
|
98 | + 'singular_name' => esc_html_x( 'Group', 'taxonomy singular name', 'lsx-projects' ), |
|
99 | + 'search_items' => esc_html__( 'Search Groups', 'lsx-projects' ), |
|
100 | + 'all_items' => esc_html__( 'All Groups', 'lsx-projects' ), |
|
101 | + 'parent_item' => esc_html__( 'Parent Group', 'lsx-projects' ), |
|
102 | + 'parent_item_colon' => esc_html__( 'Parent Group:', 'lsx-projects' ), |
|
103 | + 'edit_item' => esc_html__( 'Edit Group', 'lsx-projects' ), |
|
104 | + 'update_item' => esc_html__( 'Update Group', 'lsx-projects' ), |
|
105 | + 'add_new_item' => esc_html__( 'Add New Group', 'lsx-projects' ), |
|
106 | + 'new_item_name' => esc_html__( 'New Group Name', 'lsx-projects' ), |
|
107 | + 'menu_name' => esc_html__( 'Groups', 'lsx-projects' ), |
|
108 | + ); |
|
109 | + |
|
110 | + $args = array( |
|
111 | + 'hierarchical' => true, |
|
112 | + 'labels' => $labels, |
|
113 | + 'show_ui' => true, |
|
114 | + 'show_admin_column' => true, |
|
115 | + 'query_var' => true, |
|
116 | + 'rewrite' => array( |
|
117 | + 'slug' => 'portfolio-group', |
|
118 | + ), |
|
119 | + ); |
|
120 | + |
|
121 | + register_taxonomy( 'project-group', array( 'project' ), $args ); |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * Register the Type taxonomy |
|
126 | + */ |
|
127 | + public function taxonomy_project_type_setup() { |
|
128 | + $labels = array( |
|
129 | + 'name' => esc_html_x( 'Project Types', 'taxonomy general name', 'lsx-projects' ), |
|
130 | + 'singular_name' => esc_html_x( 'Type', 'taxonomy singular name', 'lsx-projects' ), |
|
131 | + 'search_items' => esc_html__( 'Search Types', 'lsx-projects' ), |
|
132 | + 'all_items' => esc_html__( 'All Types', 'lsx-projects' ), |
|
133 | + 'parent_item' => esc_html__( 'Parent Type', 'lsx-projects' ), |
|
134 | + 'parent_item_colon' => esc_html__( 'Parent Type:', 'lsx-projects' ), |
|
135 | + 'edit_item' => esc_html__( 'Edit Type', 'lsx-projects' ), |
|
136 | + 'update_item' => esc_html__( 'Update Type', 'lsx-projects' ), |
|
137 | + 'add_new_item' => esc_html__( 'Add New Type', 'lsx-projects' ), |
|
138 | + 'new_item_name' => esc_html__( 'New Type Name', 'lsx-projects' ), |
|
139 | + 'menu_name' => esc_html__( 'Types', 'lsx-projects' ), |
|
140 | + ); |
|
141 | + |
|
142 | + $args = array( |
|
143 | + 'hierarchical' => true, |
|
144 | + 'labels' => $labels, |
|
145 | + 'show_ui' => true, |
|
146 | + 'show_admin_column' => true, |
|
147 | + 'query_var' => true, |
|
148 | + 'rewrite' => array( |
|
149 | + 'slug' => 'project-type', |
|
150 | + ), |
|
151 | + 'show_in_rest' => true, |
|
152 | + ); |
|
153 | + |
|
154 | + register_taxonomy( 'project-type', array( 'project' ), $args ); |
|
155 | + } |
|
156 | + |
|
157 | + /** |
|
158 | + * Register the Tag taxonomy |
|
159 | + */ |
|
160 | + public function taxonomy_project_tag_setup() { |
|
161 | + $labels = array( |
|
162 | + 'name' => esc_html_x( 'Project Tags', 'taxonomy general name', 'lsx-projects' ), |
|
163 | + 'singular_name' => esc_html_x( 'Tag', 'taxonomy singular name', 'lsx-projects' ), |
|
164 | + 'search_items' => esc_html__( 'Search Tags', 'lsx-projects' ), |
|
165 | + 'all_items' => esc_html__( 'All Tags', 'lsx-projects' ), |
|
166 | + 'parent_item' => esc_html__( 'Parent Tag', 'lsx-projects' ), |
|
167 | + 'parent_item_colon' => esc_html__( 'Parent Tag:', 'lsx-projects' ), |
|
168 | + 'edit_item' => esc_html__( 'Edit Tag', 'lsx-projects' ), |
|
169 | + 'update_item' => esc_html__( 'Update Tag', 'lsx-projects' ), |
|
170 | + 'add_new_item' => esc_html__( 'Add New Tag', 'lsx-projects' ), |
|
171 | + 'new_item_name' => esc_html__( 'New Tag Name', 'lsx-projects' ), |
|
172 | + 'menu_name' => esc_html__( 'Tags', 'lsx-projects' ), |
|
173 | + ); |
|
174 | + |
|
175 | + $args = array( |
|
176 | + 'hierarchical' => true, |
|
177 | + 'labels' => $labels, |
|
178 | + 'show_ui' => true, |
|
179 | + 'show_admin_column' => true, |
|
180 | + 'query_var' => true, |
|
181 | + 'rewrite' => array( |
|
182 | + 'slug' => 'project-tag', |
|
183 | + ), |
|
184 | + 'show_in_rest' => true, |
|
185 | + ); |
|
186 | + |
|
187 | + register_taxonomy( 'project-tag', array( 'project' ), $args ); |
|
188 | + } |
|
189 | + |
|
190 | + /** |
|
191 | + * Add metabox with custom fields to the Project post type |
|
192 | + */ |
|
193 | + public function field_setup() { |
|
194 | + $prefix = 'lsx_project_'; |
|
195 | + |
|
196 | + $cmb = new_cmb2_box( |
|
197 | + array( |
|
198 | + 'id' => $prefix . '_project', |
|
199 | + 'title' => __( 'General', 'lsx-projects' ), |
|
200 | + 'object_types' => 'project', |
|
201 | + 'context' => 'normal', |
|
202 | + 'priority' => 'low', |
|
203 | + 'show_names' => true, |
|
204 | + ) |
|
205 | + ); |
|
206 | + |
|
207 | + $cmb->add_field( |
|
208 | + array( |
|
209 | + 'name' => esc_html__( 'Featured:', 'lsx-projects' ), |
|
210 | + 'id' => $prefix . 'featured', |
|
211 | + 'type' => 'checkbox', |
|
212 | + 'value' => 1, |
|
213 | + 'default' => 0, |
|
214 | + 'show_in_rest' => true, |
|
215 | + ) |
|
216 | + ); |
|
217 | + |
|
218 | + $cmb->add_field( |
|
219 | + array( |
|
220 | + 'name' => esc_html__( 'Client:', 'lsx-projects' ), |
|
221 | + 'id' => $prefix . 'client', |
|
222 | + 'type' => 'text', |
|
223 | + 'show_in_rest' => true, |
|
224 | + ) |
|
225 | + ); |
|
226 | + |
|
227 | + $cmb->add_field( |
|
228 | + array( |
|
229 | + 'name' => esc_html__( 'Client logo:', 'lsx-projects' ), |
|
230 | + 'id' => $prefix . 'client_logo', |
|
231 | + 'type' => 'file', |
|
232 | + 'desc' => esc_html__( 'Recommended image size: 320 x 50~60', 'lsx-projects' ), |
|
233 | + 'options' => array( |
|
234 | + 'url' => false, // Hide the text input for the url. |
|
235 | + ), |
|
236 | + 'text' => array( |
|
237 | + 'add_upload_file_text' => 'Choose Image', |
|
238 | + ), |
|
239 | + 'show_in_rest' => true, |
|
240 | + ) |
|
241 | + ); |
|
242 | + |
|
243 | + $cmb->add_field( |
|
244 | + array( |
|
245 | + 'name' => esc_html__( 'URL for the finished project:', 'lsx-projects' ), |
|
246 | + 'id' => $prefix . 'url', |
|
247 | + 'type' => 'text', |
|
248 | + 'show_in_rest' => true, |
|
249 | + ) |
|
250 | + ); |
|
251 | + } |
|
252 | + |
|
253 | + /** |
|
254 | + * Project Services Metaboxes. |
|
255 | + */ |
|
256 | + public function projects_services_metaboxes() { |
|
257 | + $prefix = 'lsx_project_'; |
|
258 | + |
|
259 | + $cmb = new_cmb2_box( |
|
260 | + array( |
|
261 | + 'id' => $prefix . '_project', |
|
262 | + 'object_types' => 'projects', |
|
263 | + 'context' => 'normal', |
|
264 | + 'priority' => 'low', |
|
265 | + 'show_names' => true, |
|
266 | + ) |
|
267 | + ); |
|
268 | + |
|
269 | + $cmb->add_field( |
|
270 | + array( |
|
271 | + 'name' => esc_html__( 'Services related to this project:', 'lsx-projects' ), |
|
272 | + 'id' => 'page_to_project', |
|
273 | + 'type' => 'post_search_ajax', |
|
274 | + 'show_in_rest' => true, |
|
275 | + 'limit' => 15, |
|
276 | + 'sortable' => true, |
|
277 | + 'query_args' => array( |
|
278 | + 'post_type' => array( 'project' ), |
|
279 | + 'post_status' => array( 'publish' ), |
|
280 | + 'nopagin' => true, |
|
281 | + 'posts_per_page' => '50', |
|
282 | + 'orderby' => 'title', |
|
283 | + 'order' => 'ASC', |
|
284 | + ), |
|
285 | + ) |
|
286 | + ); |
|
287 | + } |
|
288 | + |
|
289 | + /** |
|
290 | + * Project Testimonials Metaboxes. |
|
291 | + */ |
|
292 | + public function projects_testimonials_metaboxes() { |
|
293 | + $prefix = 'lsx_project_'; |
|
294 | + |
|
295 | + $cmb = new_cmb2_box( |
|
296 | + array( |
|
297 | + 'id' => $prefix . '_project', |
|
298 | + 'object_types' => 'projects', |
|
299 | + 'context' => 'normal', |
|
300 | + 'priority' => 'low', |
|
301 | + 'show_names' => true, |
|
302 | + ) |
|
303 | + ); |
|
304 | + |
|
305 | + if ( class_exists( 'LSX_Testimonials' ) ) { |
|
306 | + $cmb->add_field( |
|
307 | + array( |
|
308 | + 'name' => esc_html__( 'Testimonials related to this project:', 'lsx-projects' ), |
|
309 | + 'id' => 'testimonial_to_project', |
|
310 | + 'type' => 'post_search_ajax', |
|
311 | + 'show_in_rest' => true, |
|
312 | + 'limit' => 15, |
|
313 | + 'sortable' => true, |
|
314 | + 'query_args' => array( |
|
315 | + 'post_type' => array( 'testimonial' ), |
|
316 | + 'post_status' => array( 'publish' ), |
|
317 | + 'nopagin' => true, |
|
318 | + 'posts_per_page' => '50', |
|
319 | + 'orderby' => 'title', |
|
320 | + 'order' => 'ASC', |
|
321 | + ), |
|
322 | + ) |
|
323 | + ); |
|
324 | + } |
|
325 | + } |
|
326 | + |
|
327 | + /** |
|
328 | + * Project Team Metaboxes. |
|
329 | + */ |
|
330 | + public function projects_team_metaboxes() { |
|
331 | + $prefix = 'lsx_project_'; |
|
332 | + |
|
333 | + $cmb = new_cmb2_box( |
|
334 | + array( |
|
335 | + 'id' => $prefix . '_project', |
|
336 | + 'object_types' => 'project', |
|
337 | + 'context' => 'normal', |
|
338 | + 'priority' => 'low', |
|
339 | + 'show_names' => true, |
|
340 | + ) |
|
341 | + ); |
|
342 | + |
|
343 | + if ( class_exists( 'LSX_Team' ) ) { |
|
344 | + $cmb->add_field( |
|
345 | + array( |
|
346 | + 'name' => esc_html__( 'Team members involved with this project:', 'lsx-projects' ), |
|
347 | + 'id' => 'team_to_project', |
|
348 | + 'type' => 'post_search_ajax', |
|
349 | + 'show_in_rest' => true, |
|
350 | + 'limit' => 15, |
|
351 | + 'sortable' => true, |
|
352 | + 'query_args' => array( |
|
353 | + 'post_type' => array( 'team' ), |
|
354 | + 'post_status' => array( 'publish' ), |
|
355 | + 'nopagin' => true, |
|
356 | + 'posts_per_page' => '50', |
|
357 | + 'orderby' => 'title', |
|
358 | + 'order' => 'ASC', |
|
359 | + ), |
|
360 | + ) |
|
361 | + ); |
|
362 | + } |
|
363 | + } |
|
364 | + |
|
365 | + /** |
|
366 | + * Project Woocommerce Metaboxes. |
|
367 | + */ |
|
368 | + public function projects_woocommerce_metaboxes() { |
|
369 | + $prefix = 'lsx_project_'; |
|
370 | + |
|
371 | + $cmb = new_cmb2_box( |
|
372 | + array( |
|
373 | + 'id' => $prefix . '_project', |
|
374 | + 'object_types' => 'projects', |
|
375 | + 'context' => 'normal', |
|
376 | + 'priority' => 'low', |
|
377 | + 'show_names' => true, |
|
378 | + ) |
|
379 | + ); |
|
380 | + |
|
381 | + if ( class_exists( 'woocommerce' ) ) { |
|
382 | + $cmb->add_field( |
|
383 | + array( |
|
384 | + 'name' => esc_html__( 'Products used for this project:', 'lsx-projects' ), |
|
385 | + 'id' => 'product_to_project', |
|
386 | + 'type' => 'post_search_ajax', |
|
387 | + 'show_in_rest' => true, |
|
388 | + 'limit' => 15, |
|
389 | + 'sortable' => true, |
|
390 | + 'query_args' => array( |
|
391 | + 'post_type' => array( 'product' ), |
|
392 | + 'post_status' => array( 'publish' ), |
|
393 | + 'nopagin' => true, |
|
394 | + 'posts_per_page' => '50', |
|
395 | + 'orderby' => 'title', |
|
396 | + 'order' => 'ASC', |
|
397 | + ), |
|
398 | + ) |
|
399 | + ); |
|
400 | + } |
|
401 | + } |
|
402 | + |
|
403 | + /** |
|
404 | + * Add Alt Product metabox with custom fields to the Project post type |
|
405 | + */ |
|
406 | + public function project_field_setup_product() { |
|
407 | + $prefix = 'lsx_project_'; |
|
408 | + |
|
409 | + $cmb = new_cmb2_box( |
|
410 | + array( |
|
411 | + 'id' => $prefix . '_project', |
|
412 | + 'title' => __( 'General', 'lsx-projects' ), |
|
413 | + 'object_types' => 'project', |
|
414 | + 'context' => 'normal', |
|
415 | + 'priority' => 'low', |
|
416 | + 'show_names' => true, |
|
417 | + ) |
|
418 | + ); |
|
419 | + |
|
420 | + $tip_group = $cmb->add_field( |
|
421 | + array( |
|
422 | + 'id' => $prefix . '_alt_products', |
|
423 | + 'type' => 'group', |
|
424 | + 'options' => array( |
|
425 | + 'group_title' => __( 'Alternative Products', 'lsx-projects' ), |
|
426 | + 'add_button' => __( 'Add Product', 'lsx-projects' ), |
|
427 | + 'remove_button' => __( 'Remove Product', 'lsx-projects' ), |
|
428 | + 'sortable' => true, |
|
429 | + ), |
|
430 | + 'classes' => 'lsx-admin-row', |
|
431 | + ) |
|
432 | + ); |
|
433 | + |
|
434 | + $cmb->add_group_field( |
|
435 | + $tip_group, |
|
436 | + array( |
|
437 | + 'name' => esc_html__( 'Alt Product Name:', 'lsx-projects' ), |
|
438 | + 'id' => $prefix . 'alt_product_title', |
|
439 | + 'type' => 'text', |
|
440 | + 'show_in_rest' => true, |
|
441 | + ) |
|
442 | + ); |
|
443 | + |
|
444 | + $cmb->add_group_field( |
|
445 | + $tip_group, |
|
446 | + array( |
|
447 | + 'name' => esc_html__( 'Alt Product Link:', 'lsx-projects' ), |
|
448 | + 'id' => $prefix . 'alt_product_link', |
|
449 | + 'type' => 'text', |
|
450 | + 'show_in_rest' => true, |
|
451 | + ) |
|
452 | + ); |
|
453 | + |
|
454 | + } |
|
455 | + |
|
456 | + /** |
|
457 | + * Sets up the "post relations". |
|
458 | + */ |
|
459 | + public function post_relations( $post_id, $field, $value ) { |
|
460 | + $connections = array( |
|
461 | + // 'project_to_project', |
|
462 | + |
|
463 | + 'page_to_project', |
|
464 | + 'project_to_page', |
|
465 | + |
|
466 | + 'project_to_service', |
|
467 | + 'service_to_project', |
|
468 | + |
|
469 | + 'project_to_testimonial', |
|
470 | + 'testimonial_to_project', |
|
471 | + |
|
472 | + 'project_to_team', |
|
473 | + 'team_to_project', |
|
474 | + ); |
|
475 | + |
|
476 | + if ( in_array( $field['id'], $connections ) ) { |
|
477 | + $this->save_related_post( $connections, $post_id, $field, $value ); |
|
478 | + } |
|
479 | + } |
|
480 | + |
|
481 | + /** |
|
482 | + * Save the reverse post relation. |
|
483 | + */ |
|
484 | + public function save_related_post( $connections, $post_id, $field, $value ) { |
|
485 | + $ids = explode( '_to_', $field['id'] ); |
|
486 | + $relation = $ids[1] . '_to_' . $ids[0]; |
|
487 | + |
|
488 | + if ( in_array( $relation, $connections ) ) { |
|
489 | + $previous_values = get_post_meta( $post_id, $field['id'], false ); |
|
490 | + |
|
491 | + if ( ! empty( $previous_values ) ) { |
|
492 | + foreach ( $previous_values as $v ) { |
|
493 | + delete_post_meta( $v, $relation, $post_id ); |
|
494 | + } |
|
495 | + } |
|
496 | + |
|
497 | + if ( is_array( $value ) ) { |
|
498 | + foreach ( $value as $v ) { |
|
499 | + if ( ! empty( $v ) ) { |
|
500 | + add_post_meta( $v, $relation, $post_id ); |
|
501 | + } |
|
502 | + } |
|
503 | + } |
|
504 | + } |
|
505 | + } |
|
506 | + |
|
507 | + public function assets() { |
|
508 | + //wp_enqueue_media(); |
|
509 | + wp_enqueue_script( 'media-upload' ); |
|
510 | + wp_enqueue_script( 'thickbox' ); |
|
511 | + wp_enqueue_style( 'thickbox' ); |
|
512 | + |
|
513 | + wp_enqueue_script( 'lsx-projects-admin', LSX_PROJECTS_URL . 'assets/js/lsx-projects-admin.min.js', array( 'jquery' ), LSX_PROJECTS_VER, true ); |
|
514 | + wp_enqueue_style( 'lsx-projects-admin', LSX_PROJECTS_URL . 'assets/css/lsx-projects-admin.css', array(), LSX_PROJECTS_VER ); |
|
515 | + } |
|
516 | + |
|
517 | + /** |
|
518 | + * Change the "Insert into Post" button text when media modal is used for feature images |
|
519 | + */ |
|
520 | + public function change_attachment_field_button( $html ) { |
|
521 | + if ( isset( $_GET['feature_image_text_button'] ) ) { |
|
522 | + $html = str_replace( 'value="Insert into Post"', sprintf( 'value="%s"', esc_html__( 'Select featured image', 'lsx-projects' ) ), $html ); |
|
523 | + } |
|
524 | + |
|
525 | + return $html; |
|
526 | + } |
|
527 | + |
|
528 | + public function change_title_text( $title ) { |
|
529 | + $screen = get_current_screen(); |
|
530 | + |
|
531 | + if ( 'project' === $screen->post_type ) { |
|
532 | + $title = esc_attr__( 'Enter project title', 'lsx-projects' ); |
|
533 | + } |
|
534 | + |
|
535 | + return $title; |
|
536 | + } |
|
537 | 537 | } |
538 | 538 | |
539 | 539 | $lsx_projects_admin = new LSX_Projects_Admin(); |
@@ -13,21 +13,21 @@ discard block |
||
13 | 13 | public function __construct() { |
14 | 14 | $this->load_classes(); |
15 | 15 | |
16 | - add_action( 'init', array( $this, 'post_type_setup' ) ); |
|
17 | - add_action( 'init', array( $this, 'taxonomy_setup' ) ); |
|
18 | - add_action( 'init', array( $this, 'taxonomy_project_type_setup' ) ); |
|
19 | - add_action( 'init', array( $this, 'taxonomy_project_tag_setup' ) ); |
|
20 | - add_filter( 'cmb2_admin_init', array( $this, 'field_setup' ) ); |
|
21 | - add_filter( 'cmb2_admin_init', array( $this, 'projects_services_metaboxes' ) ); |
|
22 | - add_filter( 'cmb2_admin_init', array( $this, 'projects_testimonials_metaboxes' ) ); |
|
23 | - add_filter( 'cmb2_admin_init', array( $this, 'projects_team_metaboxes' ) ); |
|
24 | - add_filter( 'cmb2_admin_init', array( $this, 'projects_woocommerce_metaboxes' ) ); |
|
25 | - add_filter( 'cmb2_admin_init', array( $this, 'project_field_setup_product' ) ); |
|
26 | - add_action( 'cmb_save_custom', array( $this, 'post_relations' ), 3, 20 ); |
|
27 | - add_action( 'admin_enqueue_scripts', array( $this, 'assets' ) ); |
|
28 | - |
|
29 | - add_filter( 'type_url_form_media', array( $this, 'change_attachment_field_button' ), 20, 1 ); |
|
30 | - add_filter( 'enter_title_here', array( $this, 'change_title_text' ) ); |
|
16 | + add_action('init', array($this, 'post_type_setup')); |
|
17 | + add_action('init', array($this, 'taxonomy_setup')); |
|
18 | + add_action('init', array($this, 'taxonomy_project_type_setup')); |
|
19 | + add_action('init', array($this, 'taxonomy_project_tag_setup')); |
|
20 | + add_filter('cmb2_admin_init', array($this, 'field_setup')); |
|
21 | + add_filter('cmb2_admin_init', array($this, 'projects_services_metaboxes')); |
|
22 | + add_filter('cmb2_admin_init', array($this, 'projects_testimonials_metaboxes')); |
|
23 | + add_filter('cmb2_admin_init', array($this, 'projects_team_metaboxes')); |
|
24 | + add_filter('cmb2_admin_init', array($this, 'projects_woocommerce_metaboxes')); |
|
25 | + add_filter('cmb2_admin_init', array($this, 'project_field_setup_product')); |
|
26 | + add_action('cmb_save_custom', array($this, 'post_relations'), 3, 20); |
|
27 | + add_action('admin_enqueue_scripts', array($this, 'assets')); |
|
28 | + |
|
29 | + add_filter('type_url_form_media', array($this, 'change_attachment_field_button'), 20, 1); |
|
30 | + add_filter('enter_title_here', array($this, 'change_title_text')); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
@@ -46,19 +46,19 @@ discard block |
||
46 | 46 | */ |
47 | 47 | public function post_type_setup() { |
48 | 48 | $labels = array( |
49 | - 'name' => esc_html_x( 'Projects', 'post type general name', 'lsx-projects' ), |
|
50 | - 'singular_name' => esc_html_x( 'Project', 'post type singular name', 'lsx-projects' ), |
|
51 | - 'add_new' => esc_html_x( 'Add New', 'post type general name', 'lsx-projects' ), |
|
52 | - 'add_new_item' => esc_html__( 'Add New Project', 'lsx-projects' ), |
|
53 | - 'edit_item' => esc_html__( 'Edit Project', 'lsx-projects' ), |
|
54 | - 'new_item' => esc_html__( 'New Project', 'lsx-projects' ), |
|
55 | - 'all_items' => esc_html__( 'All Projects', 'lsx-projects' ), |
|
56 | - 'view_item' => esc_html__( 'View Project', 'lsx-projects' ), |
|
57 | - 'search_items' => esc_html__( 'Search Projects', 'lsx-projects' ), |
|
58 | - 'not_found' => esc_html__( 'No projects found', 'lsx-projects' ), |
|
59 | - 'not_found_in_trash' => esc_html__( 'No projects found in Trash', 'lsx-projects' ), |
|
49 | + 'name' => esc_html_x('Projects', 'post type general name', 'lsx-projects'), |
|
50 | + 'singular_name' => esc_html_x('Project', 'post type singular name', 'lsx-projects'), |
|
51 | + 'add_new' => esc_html_x('Add New', 'post type general name', 'lsx-projects'), |
|
52 | + 'add_new_item' => esc_html__('Add New Project', 'lsx-projects'), |
|
53 | + 'edit_item' => esc_html__('Edit Project', 'lsx-projects'), |
|
54 | + 'new_item' => esc_html__('New Project', 'lsx-projects'), |
|
55 | + 'all_items' => esc_html__('All Projects', 'lsx-projects'), |
|
56 | + 'view_item' => esc_html__('View Project', 'lsx-projects'), |
|
57 | + 'search_items' => esc_html__('Search Projects', 'lsx-projects'), |
|
58 | + 'not_found' => esc_html__('No projects found', 'lsx-projects'), |
|
59 | + 'not_found_in_trash' => esc_html__('No projects found in Trash', 'lsx-projects'), |
|
60 | 60 | 'parent_item_colon' => '', |
61 | - 'menu_name' => esc_html_x( 'Projects', 'admin menu', 'lsx-projects' ), |
|
61 | + 'menu_name' => esc_html_x('Projects', 'admin menu', 'lsx-projects'), |
|
62 | 62 | ); |
63 | 63 | |
64 | 64 | $args = array( |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | 'show_in_rest' => true, |
87 | 87 | ); |
88 | 88 | |
89 | - register_post_type( 'project', $args ); |
|
89 | + register_post_type('project', $args); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
@@ -94,17 +94,17 @@ discard block |
||
94 | 94 | */ |
95 | 95 | public function taxonomy_setup() { |
96 | 96 | $labels = array( |
97 | - 'name' => esc_html_x( 'Project Groups', 'taxonomy general name', 'lsx-projects' ), |
|
98 | - 'singular_name' => esc_html_x( 'Group', 'taxonomy singular name', 'lsx-projects' ), |
|
99 | - 'search_items' => esc_html__( 'Search Groups', 'lsx-projects' ), |
|
100 | - 'all_items' => esc_html__( 'All Groups', 'lsx-projects' ), |
|
101 | - 'parent_item' => esc_html__( 'Parent Group', 'lsx-projects' ), |
|
102 | - 'parent_item_colon' => esc_html__( 'Parent Group:', 'lsx-projects' ), |
|
103 | - 'edit_item' => esc_html__( 'Edit Group', 'lsx-projects' ), |
|
104 | - 'update_item' => esc_html__( 'Update Group', 'lsx-projects' ), |
|
105 | - 'add_new_item' => esc_html__( 'Add New Group', 'lsx-projects' ), |
|
106 | - 'new_item_name' => esc_html__( 'New Group Name', 'lsx-projects' ), |
|
107 | - 'menu_name' => esc_html__( 'Groups', 'lsx-projects' ), |
|
97 | + 'name' => esc_html_x('Project Groups', 'taxonomy general name', 'lsx-projects'), |
|
98 | + 'singular_name' => esc_html_x('Group', 'taxonomy singular name', 'lsx-projects'), |
|
99 | + 'search_items' => esc_html__('Search Groups', 'lsx-projects'), |
|
100 | + 'all_items' => esc_html__('All Groups', 'lsx-projects'), |
|
101 | + 'parent_item' => esc_html__('Parent Group', 'lsx-projects'), |
|
102 | + 'parent_item_colon' => esc_html__('Parent Group:', 'lsx-projects'), |
|
103 | + 'edit_item' => esc_html__('Edit Group', 'lsx-projects'), |
|
104 | + 'update_item' => esc_html__('Update Group', 'lsx-projects'), |
|
105 | + 'add_new_item' => esc_html__('Add New Group', 'lsx-projects'), |
|
106 | + 'new_item_name' => esc_html__('New Group Name', 'lsx-projects'), |
|
107 | + 'menu_name' => esc_html__('Groups', 'lsx-projects'), |
|
108 | 108 | ); |
109 | 109 | |
110 | 110 | $args = array( |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | ), |
119 | 119 | ); |
120 | 120 | |
121 | - register_taxonomy( 'project-group', array( 'project' ), $args ); |
|
121 | + register_taxonomy('project-group', array('project'), $args); |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | /** |
@@ -126,17 +126,17 @@ discard block |
||
126 | 126 | */ |
127 | 127 | public function taxonomy_project_type_setup() { |
128 | 128 | $labels = array( |
129 | - 'name' => esc_html_x( 'Project Types', 'taxonomy general name', 'lsx-projects' ), |
|
130 | - 'singular_name' => esc_html_x( 'Type', 'taxonomy singular name', 'lsx-projects' ), |
|
131 | - 'search_items' => esc_html__( 'Search Types', 'lsx-projects' ), |
|
132 | - 'all_items' => esc_html__( 'All Types', 'lsx-projects' ), |
|
133 | - 'parent_item' => esc_html__( 'Parent Type', 'lsx-projects' ), |
|
134 | - 'parent_item_colon' => esc_html__( 'Parent Type:', 'lsx-projects' ), |
|
135 | - 'edit_item' => esc_html__( 'Edit Type', 'lsx-projects' ), |
|
136 | - 'update_item' => esc_html__( 'Update Type', 'lsx-projects' ), |
|
137 | - 'add_new_item' => esc_html__( 'Add New Type', 'lsx-projects' ), |
|
138 | - 'new_item_name' => esc_html__( 'New Type Name', 'lsx-projects' ), |
|
139 | - 'menu_name' => esc_html__( 'Types', 'lsx-projects' ), |
|
129 | + 'name' => esc_html_x('Project Types', 'taxonomy general name', 'lsx-projects'), |
|
130 | + 'singular_name' => esc_html_x('Type', 'taxonomy singular name', 'lsx-projects'), |
|
131 | + 'search_items' => esc_html__('Search Types', 'lsx-projects'), |
|
132 | + 'all_items' => esc_html__('All Types', 'lsx-projects'), |
|
133 | + 'parent_item' => esc_html__('Parent Type', 'lsx-projects'), |
|
134 | + 'parent_item_colon' => esc_html__('Parent Type:', 'lsx-projects'), |
|
135 | + 'edit_item' => esc_html__('Edit Type', 'lsx-projects'), |
|
136 | + 'update_item' => esc_html__('Update Type', 'lsx-projects'), |
|
137 | + 'add_new_item' => esc_html__('Add New Type', 'lsx-projects'), |
|
138 | + 'new_item_name' => esc_html__('New Type Name', 'lsx-projects'), |
|
139 | + 'menu_name' => esc_html__('Types', 'lsx-projects'), |
|
140 | 140 | ); |
141 | 141 | |
142 | 142 | $args = array( |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | 'show_in_rest' => true, |
152 | 152 | ); |
153 | 153 | |
154 | - register_taxonomy( 'project-type', array( 'project' ), $args ); |
|
154 | + register_taxonomy('project-type', array('project'), $args); |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | /** |
@@ -159,17 +159,17 @@ discard block |
||
159 | 159 | */ |
160 | 160 | public function taxonomy_project_tag_setup() { |
161 | 161 | $labels = array( |
162 | - 'name' => esc_html_x( 'Project Tags', 'taxonomy general name', 'lsx-projects' ), |
|
163 | - 'singular_name' => esc_html_x( 'Tag', 'taxonomy singular name', 'lsx-projects' ), |
|
164 | - 'search_items' => esc_html__( 'Search Tags', 'lsx-projects' ), |
|
165 | - 'all_items' => esc_html__( 'All Tags', 'lsx-projects' ), |
|
166 | - 'parent_item' => esc_html__( 'Parent Tag', 'lsx-projects' ), |
|
167 | - 'parent_item_colon' => esc_html__( 'Parent Tag:', 'lsx-projects' ), |
|
168 | - 'edit_item' => esc_html__( 'Edit Tag', 'lsx-projects' ), |
|
169 | - 'update_item' => esc_html__( 'Update Tag', 'lsx-projects' ), |
|
170 | - 'add_new_item' => esc_html__( 'Add New Tag', 'lsx-projects' ), |
|
171 | - 'new_item_name' => esc_html__( 'New Tag Name', 'lsx-projects' ), |
|
172 | - 'menu_name' => esc_html__( 'Tags', 'lsx-projects' ), |
|
162 | + 'name' => esc_html_x('Project Tags', 'taxonomy general name', 'lsx-projects'), |
|
163 | + 'singular_name' => esc_html_x('Tag', 'taxonomy singular name', 'lsx-projects'), |
|
164 | + 'search_items' => esc_html__('Search Tags', 'lsx-projects'), |
|
165 | + 'all_items' => esc_html__('All Tags', 'lsx-projects'), |
|
166 | + 'parent_item' => esc_html__('Parent Tag', 'lsx-projects'), |
|
167 | + 'parent_item_colon' => esc_html__('Parent Tag:', 'lsx-projects'), |
|
168 | + 'edit_item' => esc_html__('Edit Tag', 'lsx-projects'), |
|
169 | + 'update_item' => esc_html__('Update Tag', 'lsx-projects'), |
|
170 | + 'add_new_item' => esc_html__('Add New Tag', 'lsx-projects'), |
|
171 | + 'new_item_name' => esc_html__('New Tag Name', 'lsx-projects'), |
|
172 | + 'menu_name' => esc_html__('Tags', 'lsx-projects'), |
|
173 | 173 | ); |
174 | 174 | |
175 | 175 | $args = array( |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | 'show_in_rest' => true, |
185 | 185 | ); |
186 | 186 | |
187 | - register_taxonomy( 'project-tag', array( 'project' ), $args ); |
|
187 | + register_taxonomy('project-tag', array('project'), $args); |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | /** |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | $cmb = new_cmb2_box( |
197 | 197 | array( |
198 | 198 | 'id' => $prefix . '_project', |
199 | - 'title' => __( 'General', 'lsx-projects' ), |
|
199 | + 'title' => __('General', 'lsx-projects'), |
|
200 | 200 | 'object_types' => 'project', |
201 | 201 | 'context' => 'normal', |
202 | 202 | 'priority' => 'low', |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | |
207 | 207 | $cmb->add_field( |
208 | 208 | array( |
209 | - 'name' => esc_html__( 'Featured:', 'lsx-projects' ), |
|
209 | + 'name' => esc_html__('Featured:', 'lsx-projects'), |
|
210 | 210 | 'id' => $prefix . 'featured', |
211 | 211 | 'type' => 'checkbox', |
212 | 212 | 'value' => 1, |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | |
218 | 218 | $cmb->add_field( |
219 | 219 | array( |
220 | - 'name' => esc_html__( 'Client:', 'lsx-projects' ), |
|
220 | + 'name' => esc_html__('Client:', 'lsx-projects'), |
|
221 | 221 | 'id' => $prefix . 'client', |
222 | 222 | 'type' => 'text', |
223 | 223 | 'show_in_rest' => true, |
@@ -226,10 +226,10 @@ discard block |
||
226 | 226 | |
227 | 227 | $cmb->add_field( |
228 | 228 | array( |
229 | - 'name' => esc_html__( 'Client logo:', 'lsx-projects' ), |
|
229 | + 'name' => esc_html__('Client logo:', 'lsx-projects'), |
|
230 | 230 | 'id' => $prefix . 'client_logo', |
231 | 231 | 'type' => 'file', |
232 | - 'desc' => esc_html__( 'Recommended image size: 320 x 50~60', 'lsx-projects' ), |
|
232 | + 'desc' => esc_html__('Recommended image size: 320 x 50~60', 'lsx-projects'), |
|
233 | 233 | 'options' => array( |
234 | 234 | 'url' => false, // Hide the text input for the url. |
235 | 235 | ), |
@@ -242,7 +242,7 @@ discard block |
||
242 | 242 | |
243 | 243 | $cmb->add_field( |
244 | 244 | array( |
245 | - 'name' => esc_html__( 'URL for the finished project:', 'lsx-projects' ), |
|
245 | + 'name' => esc_html__('URL for the finished project:', 'lsx-projects'), |
|
246 | 246 | 'id' => $prefix . 'url', |
247 | 247 | 'type' => 'text', |
248 | 248 | 'show_in_rest' => true, |
@@ -268,15 +268,15 @@ discard block |
||
268 | 268 | |
269 | 269 | $cmb->add_field( |
270 | 270 | array( |
271 | - 'name' => esc_html__( 'Services related to this project:', 'lsx-projects' ), |
|
271 | + 'name' => esc_html__('Services related to this project:', 'lsx-projects'), |
|
272 | 272 | 'id' => 'page_to_project', |
273 | 273 | 'type' => 'post_search_ajax', |
274 | 274 | 'show_in_rest' => true, |
275 | 275 | 'limit' => 15, |
276 | 276 | 'sortable' => true, |
277 | 277 | 'query_args' => array( |
278 | - 'post_type' => array( 'project' ), |
|
279 | - 'post_status' => array( 'publish' ), |
|
278 | + 'post_type' => array('project'), |
|
279 | + 'post_status' => array('publish'), |
|
280 | 280 | 'nopagin' => true, |
281 | 281 | 'posts_per_page' => '50', |
282 | 282 | 'orderby' => 'title', |
@@ -302,18 +302,18 @@ discard block |
||
302 | 302 | ) |
303 | 303 | ); |
304 | 304 | |
305 | - if ( class_exists( 'LSX_Testimonials' ) ) { |
|
305 | + if (class_exists('LSX_Testimonials')) { |
|
306 | 306 | $cmb->add_field( |
307 | 307 | array( |
308 | - 'name' => esc_html__( 'Testimonials related to this project:', 'lsx-projects' ), |
|
308 | + 'name' => esc_html__('Testimonials related to this project:', 'lsx-projects'), |
|
309 | 309 | 'id' => 'testimonial_to_project', |
310 | 310 | 'type' => 'post_search_ajax', |
311 | 311 | 'show_in_rest' => true, |
312 | 312 | 'limit' => 15, |
313 | 313 | 'sortable' => true, |
314 | 314 | 'query_args' => array( |
315 | - 'post_type' => array( 'testimonial' ), |
|
316 | - 'post_status' => array( 'publish' ), |
|
315 | + 'post_type' => array('testimonial'), |
|
316 | + 'post_status' => array('publish'), |
|
317 | 317 | 'nopagin' => true, |
318 | 318 | 'posts_per_page' => '50', |
319 | 319 | 'orderby' => 'title', |
@@ -340,18 +340,18 @@ discard block |
||
340 | 340 | ) |
341 | 341 | ); |
342 | 342 | |
343 | - if ( class_exists( 'LSX_Team' ) ) { |
|
343 | + if (class_exists('LSX_Team')) { |
|
344 | 344 | $cmb->add_field( |
345 | 345 | array( |
346 | - 'name' => esc_html__( 'Team members involved with this project:', 'lsx-projects' ), |
|
346 | + 'name' => esc_html__('Team members involved with this project:', 'lsx-projects'), |
|
347 | 347 | 'id' => 'team_to_project', |
348 | 348 | 'type' => 'post_search_ajax', |
349 | 349 | 'show_in_rest' => true, |
350 | 350 | 'limit' => 15, |
351 | 351 | 'sortable' => true, |
352 | 352 | 'query_args' => array( |
353 | - 'post_type' => array( 'team' ), |
|
354 | - 'post_status' => array( 'publish' ), |
|
353 | + 'post_type' => array('team'), |
|
354 | + 'post_status' => array('publish'), |
|
355 | 355 | 'nopagin' => true, |
356 | 356 | 'posts_per_page' => '50', |
357 | 357 | 'orderby' => 'title', |
@@ -378,18 +378,18 @@ discard block |
||
378 | 378 | ) |
379 | 379 | ); |
380 | 380 | |
381 | - if ( class_exists( 'woocommerce' ) ) { |
|
381 | + if (class_exists('woocommerce')) { |
|
382 | 382 | $cmb->add_field( |
383 | 383 | array( |
384 | - 'name' => esc_html__( 'Products used for this project:', 'lsx-projects' ), |
|
384 | + 'name' => esc_html__('Products used for this project:', 'lsx-projects'), |
|
385 | 385 | 'id' => 'product_to_project', |
386 | 386 | 'type' => 'post_search_ajax', |
387 | 387 | 'show_in_rest' => true, |
388 | 388 | 'limit' => 15, |
389 | 389 | 'sortable' => true, |
390 | 390 | 'query_args' => array( |
391 | - 'post_type' => array( 'product' ), |
|
392 | - 'post_status' => array( 'publish' ), |
|
391 | + 'post_type' => array('product'), |
|
392 | + 'post_status' => array('publish'), |
|
393 | 393 | 'nopagin' => true, |
394 | 394 | 'posts_per_page' => '50', |
395 | 395 | 'orderby' => 'title', |
@@ -409,7 +409,7 @@ discard block |
||
409 | 409 | $cmb = new_cmb2_box( |
410 | 410 | array( |
411 | 411 | 'id' => $prefix . '_project', |
412 | - 'title' => __( 'General', 'lsx-projects' ), |
|
412 | + 'title' => __('General', 'lsx-projects'), |
|
413 | 413 | 'object_types' => 'project', |
414 | 414 | 'context' => 'normal', |
415 | 415 | 'priority' => 'low', |
@@ -422,9 +422,9 @@ discard block |
||
422 | 422 | 'id' => $prefix . '_alt_products', |
423 | 423 | 'type' => 'group', |
424 | 424 | 'options' => array( |
425 | - 'group_title' => __( 'Alternative Products', 'lsx-projects' ), |
|
426 | - 'add_button' => __( 'Add Product', 'lsx-projects' ), |
|
427 | - 'remove_button' => __( 'Remove Product', 'lsx-projects' ), |
|
425 | + 'group_title' => __('Alternative Products', 'lsx-projects'), |
|
426 | + 'add_button' => __('Add Product', 'lsx-projects'), |
|
427 | + 'remove_button' => __('Remove Product', 'lsx-projects'), |
|
428 | 428 | 'sortable' => true, |
429 | 429 | ), |
430 | 430 | 'classes' => 'lsx-admin-row', |
@@ -434,7 +434,7 @@ discard block |
||
434 | 434 | $cmb->add_group_field( |
435 | 435 | $tip_group, |
436 | 436 | array( |
437 | - 'name' => esc_html__( 'Alt Product Name:', 'lsx-projects' ), |
|
437 | + 'name' => esc_html__('Alt Product Name:', 'lsx-projects'), |
|
438 | 438 | 'id' => $prefix . 'alt_product_title', |
439 | 439 | 'type' => 'text', |
440 | 440 | 'show_in_rest' => true, |
@@ -444,7 +444,7 @@ discard block |
||
444 | 444 | $cmb->add_group_field( |
445 | 445 | $tip_group, |
446 | 446 | array( |
447 | - 'name' => esc_html__( 'Alt Product Link:', 'lsx-projects' ), |
|
447 | + 'name' => esc_html__('Alt Product Link:', 'lsx-projects'), |
|
448 | 448 | 'id' => $prefix . 'alt_product_link', |
449 | 449 | 'type' => 'text', |
450 | 450 | 'show_in_rest' => true, |
@@ -456,7 +456,7 @@ discard block |
||
456 | 456 | /** |
457 | 457 | * Sets up the "post relations". |
458 | 458 | */ |
459 | - public function post_relations( $post_id, $field, $value ) { |
|
459 | + public function post_relations($post_id, $field, $value) { |
|
460 | 460 | $connections = array( |
461 | 461 | // 'project_to_project', |
462 | 462 | |
@@ -473,31 +473,31 @@ discard block |
||
473 | 473 | 'team_to_project', |
474 | 474 | ); |
475 | 475 | |
476 | - if ( in_array( $field['id'], $connections ) ) { |
|
477 | - $this->save_related_post( $connections, $post_id, $field, $value ); |
|
476 | + if (in_array($field['id'], $connections)) { |
|
477 | + $this->save_related_post($connections, $post_id, $field, $value); |
|
478 | 478 | } |
479 | 479 | } |
480 | 480 | |
481 | 481 | /** |
482 | 482 | * Save the reverse post relation. |
483 | 483 | */ |
484 | - public function save_related_post( $connections, $post_id, $field, $value ) { |
|
485 | - $ids = explode( '_to_', $field['id'] ); |
|
484 | + public function save_related_post($connections, $post_id, $field, $value) { |
|
485 | + $ids = explode('_to_', $field['id']); |
|
486 | 486 | $relation = $ids[1] . '_to_' . $ids[0]; |
487 | 487 | |
488 | - if ( in_array( $relation, $connections ) ) { |
|
489 | - $previous_values = get_post_meta( $post_id, $field['id'], false ); |
|
488 | + if (in_array($relation, $connections)) { |
|
489 | + $previous_values = get_post_meta($post_id, $field['id'], false); |
|
490 | 490 | |
491 | - if ( ! empty( $previous_values ) ) { |
|
492 | - foreach ( $previous_values as $v ) { |
|
493 | - delete_post_meta( $v, $relation, $post_id ); |
|
491 | + if ( ! empty($previous_values)) { |
|
492 | + foreach ($previous_values as $v) { |
|
493 | + delete_post_meta($v, $relation, $post_id); |
|
494 | 494 | } |
495 | 495 | } |
496 | 496 | |
497 | - if ( is_array( $value ) ) { |
|
498 | - foreach ( $value as $v ) { |
|
499 | - if ( ! empty( $v ) ) { |
|
500 | - add_post_meta( $v, $relation, $post_id ); |
|
497 | + if (is_array($value)) { |
|
498 | + foreach ($value as $v) { |
|
499 | + if ( ! empty($v)) { |
|
500 | + add_post_meta($v, $relation, $post_id); |
|
501 | 501 | } |
502 | 502 | } |
503 | 503 | } |
@@ -506,30 +506,30 @@ discard block |
||
506 | 506 | |
507 | 507 | public function assets() { |
508 | 508 | //wp_enqueue_media(); |
509 | - wp_enqueue_script( 'media-upload' ); |
|
510 | - wp_enqueue_script( 'thickbox' ); |
|
511 | - wp_enqueue_style( 'thickbox' ); |
|
509 | + wp_enqueue_script('media-upload'); |
|
510 | + wp_enqueue_script('thickbox'); |
|
511 | + wp_enqueue_style('thickbox'); |
|
512 | 512 | |
513 | - wp_enqueue_script( 'lsx-projects-admin', LSX_PROJECTS_URL . 'assets/js/lsx-projects-admin.min.js', array( 'jquery' ), LSX_PROJECTS_VER, true ); |
|
514 | - wp_enqueue_style( 'lsx-projects-admin', LSX_PROJECTS_URL . 'assets/css/lsx-projects-admin.css', array(), LSX_PROJECTS_VER ); |
|
513 | + wp_enqueue_script('lsx-projects-admin', LSX_PROJECTS_URL . 'assets/js/lsx-projects-admin.min.js', array('jquery'), LSX_PROJECTS_VER, true); |
|
514 | + wp_enqueue_style('lsx-projects-admin', LSX_PROJECTS_URL . 'assets/css/lsx-projects-admin.css', array(), LSX_PROJECTS_VER); |
|
515 | 515 | } |
516 | 516 | |
517 | 517 | /** |
518 | 518 | * Change the "Insert into Post" button text when media modal is used for feature images |
519 | 519 | */ |
520 | - public function change_attachment_field_button( $html ) { |
|
521 | - if ( isset( $_GET['feature_image_text_button'] ) ) { |
|
522 | - $html = str_replace( 'value="Insert into Post"', sprintf( 'value="%s"', esc_html__( 'Select featured image', 'lsx-projects' ) ), $html ); |
|
520 | + public function change_attachment_field_button($html) { |
|
521 | + if (isset($_GET['feature_image_text_button'])) { |
|
522 | + $html = str_replace('value="Insert into Post"', sprintf('value="%s"', esc_html__('Select featured image', 'lsx-projects')), $html); |
|
523 | 523 | } |
524 | 524 | |
525 | 525 | return $html; |
526 | 526 | } |
527 | 527 | |
528 | - public function change_title_text( $title ) { |
|
528 | + public function change_title_text($title) { |
|
529 | 529 | $screen = get_current_screen(); |
530 | 530 | |
531 | - if ( 'project' === $screen->post_type ) { |
|
532 | - $title = esc_attr__( 'Enter project title', 'lsx-projects' ); |
|
531 | + if ('project' === $screen->post_type) { |
|
532 | + $title = esc_attr__('Enter project title', 'lsx-projects'); |
|
533 | 533 | } |
534 | 534 | |
535 | 535 | return $title; |