· 7 years ago · Jan 24, 2019, 01:04 PM
1<?php
2
3function enqueue_childtheme_scripts()
4{
5 //wp_enqueue_style('bootstrap_style', get_stylesheet_directory_uri() . 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css');
6
7 //wp_enqueue_scripts('bootstrap-js','https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js');
8
9 wp_enqueue_style('oceanwp-child', get_stylesheet_directory_uri() . '/style.css?ver=1');
10 wp_enqueue_style('new-less-styles', get_stylesheet_directory_uri() . '/assets/css/style.css?ver=2');
11
12
13}
14
15function my_scripts_enqueue() {
16 wp_register_script( 'bootstrap-js', '//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js', array('jquery'), NULL, true );
17 wp_register_style( 'bootstrap-css', '//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css', false, NULL, 'all' );
18 wp_enqueue_script( 'new_js', get_stylesheet_directory_uri().'/assets/js/main.js' , false, NULL, true );
19 wp_enqueue_script( 'bootstrap-js' );
20 wp_enqueue_style( 'bootstrap-css' );
21}
22add_action( 'wp_enqueue_scripts', 'my_scripts_enqueue');
23
24
25
26add_action('wp_enqueue_scripts', 'enqueue_childtheme_scripts', 100);
27
28
29/* Show child pages */
30function company_list_child_pages()
31{
32 //a shortcode should just return the content not echo html
33 //so we start to create an object, and on the end we return it
34 //if we dont do this the shortcode will be displayed in the top of the content
35 ob_start();
36
37 //only start if we are on a single page
38 if (is_page()) {
39
40 //get the ID of the current (parent) page
41 $current_page_id = get_the_ID();
42 $parent_page_id = wp_get_post_parent_id($current_page_id);
43
44 //get all the children of the current page
45 $child_pages = get_pages(array(
46 'child_of' => $current_page_id
47 ));
48
49
50 //start only if we have some childpages
51 if ($child_pages) {
52
53 //if we have some children, display a list wrapper
54 echo '<ul class="childpages">';
55
56 //loop trough each childpage
57 foreach ($child_pages as $child_page) {
58
59 $page_id = $child_page->ID; //get the ID of the childpage
60 $page_link = get_permalink($page_id); //returns the link to childpage
61 $page_img = get_the_post_thumbnail($page_id, 'Thumbnail'); //returns the featured video
62 //get vacancy meta data
63 $company_name = get_post_meta($current_page_id, 'company_name');
64 $vacancy_title = get_post_meta($page_id, 'vacancy_title');
65 $location = get_post_meta($page_id, 'vacancy_location');
66 $salary = get_post_meta($page_id, 'salary');
67?>
68
69 <li class="childpage-<?php
70 echo $page_id;
71?>">
72 <?php
73 echo $page_img;
74 echo "<span>$company_name[0]</span>";
75 echo "<p><strong><a href=\"$page_link\">$vacancy_title[0]</a></strong></p>";
76 echo "$location[0] - $salary[0]";
77?>
78 </a>
79 </li>
80
81 <?php
82
83 } //END foreach ($child_pages as $child_page)
84
85 echo '</ul>';
86
87 } //END if ($child_pages)
88
89 } //END if (is_page())
90
91 //return the object
92 return ob_get_clean();
93}
94
95/* Show sibling pages */
96function company_list_sibling_pages()
97{
98 ob_start();
99
100 //only start if we are on a single page
101 if (is_page()) {
102
103 //get the ID of the current page
104 $current_page_id = get_the_ID();
105 $parent_page_id = wp_get_post_parent_id($current_page_id);
106
107 //get all the children of the current page
108 $sibling_pages = get_pages(array(
109 'child_of' => $parent_page_id,
110 'exclude' => $current_page_id
111 ));
112
113 //start only if we have some childpages
114 if ($sibling_pages) {
115
116 //if we have some siblings, display a list wrapper
117 echo '<ul class="siblingpages">';
118
119 //loop trough each sibling page
120 foreach ($sibling_pages as $sibling_page) {
121
122 $current_page_id = $sibling_page->ID;
123 $page_link = get_permalink($current_page_id); //returns the link to sibling page
124 $page_img = get_the_post_thumbnail($current_page_id, 'Thumbnail'); //returns the featured video
125 //get vacancy meta data
126 $company_name = get_post_meta($parent_page_id, 'company_name');
127 $vacancy_title = get_post_meta($current_page_id, 'vacancy_title');
128 $location = get_post_meta($current_page_id, 'vacancy_location');
129 $salary = get_post_meta($current_page_id, 'salary');
130?>
131
132 <li class="childpage-<?php
133 echo $current_page_id;
134?>">
135 <?php
136 echo $page_img;
137 //var_dump($sibling_page);
138 echo "<span>$company_name[0]</span>";
139 echo "<p><strong><a href=\"$page_link\">$vacancy_title[0]</a></strong></p>";
140 echo "$location[0] - $salary[0]";
141?>
142 </a>
143 </li>
144
145 <?php
146
147 } //END foreach ($sibling_pages as $sibling_page)
148
149 echo '</ul>';
150
151 } //END if ($sibling_pages)
152
153 } //END if (is_page())
154
155 //return the object
156 return ob_get_clean();
157}
158
159add_shortcode('company_vacancies', 'company_list_child_pages');
160add_shortcode('company_other_vacancies', 'company_list_sibling_pages');
161
162//Remove wordpress logo on login/reg screen
163function my_custom_login_logo()
164{
165 echo '<style type="text/css">
166 h1 { display: none; }
167 </style>';
168}
169add_action('login_head', 'my_custom_login_logo');
170
171//Show Company ACF
172function company_acf_user_form_func($atts)
173{
174
175 $a = shortcode_atts(array(
176 'field_group' => ''
177 ), $atts);
178
179 $uid = get_current_user_id();
180
181 if (!empty($a['field_group']) && !empty($uid)) {
182 $options = array(
183 'post_id' => 'user_' . $uid,
184 'field_groups' => array(
185 intval($a['field_group'])
186 ),
187 'return' => add_query_arg('updated', 'true', get_permalink())
188 );
189
190 ob_start();
191 acf_form($options);
192 $form = ob_get_contents();
193
194 ob_end_clean();
195 }
196
197 return $form;
198}
199add_shortcode('company_acf_user_form', 'company_acf_user_form_func');
200
201
202//Add shortcode for ACF create post (vacancy)
203function company_acf_post_func($atts) {
204 acf_form(array(
205 'post_id' => 'new_post',
206 'field_groups' => array(
207 'field_group' => '278'),
208 'new_post' => array(
209 'post_status' => 'publish'
210 ),
211 'submit_value' => 'Create vacancy',
212 'updated_message' => __("Vacancy has been created successfuly", 'acf'),
213 ));
214}
215add_shortcode('company_acf_post_form', 'company_acf_post_func');
216
217
218
219//Adding AFC form head
220function add_acf_form_head()
221{
222 global $post;
223
224 if (!empty($post) && has_shortcode($post->post_content, 'company_acf_user_form')) {
225 acf_form_head();
226 }
227}
228add_action('wp_head', 'add_acf_form_head', 7);
229
230/* Customize admin area
231
232//Remove menu entries
233add_action('admin_init', 'my_remove_menu_pages');
234
235function my_remove_menu_pages()
236{
237 if (!current_user_can('administrator')) {
238 remove_menu_page('edit.php'); //Posts
239 remove_menu_page('upload.php'); //Media
240 remove_menu_page('edit-comments.php'); //Comments
241 remove_menu_page('themes.php'); //Appearance
242 remove_menu_page('users.php'); //Users
243 remove_menu_page('tools.php'); //Tools
244 remove_menu_page('options-general.php'); //Settings
245 remove_menu_page('wpcf7'); //CF7
246 remove_menu_page('index.php'); //Dashboard
247 remove_menu_page('edit.php?post_type=elementor_library'); //Elementor
248 }
249};
250
251//Rename profile to "My Company"
252function edit_admin_menus()
253{
254 if (!current_user_can('administrator')) {
255 global $menu;
256 $menu[70][0] = 'My company'; //Change profile name menu item
257 }
258}
259add_action('admin_menu', 'edit_admin_menus');
260
261//Do not show other's vacancies
262function filter_posts_list($query)
263{
264 //$pagenow holds the name of the current page being viewed
265 global $pagenow;
266
267 //$current_user uses the get_currentuserinfo() method to get the currently logged in user's data
268 global $current_user;
269 get_currentuserinfo();
270
271 //Shouldn't happen for the admin, but for any role with the edit_posts capability and only on the posts list page, that is edit.php
272 if (!current_user_can('administrator') && current_user_can('edit_posts') && ('edit.php' == $pagenow)) {
273 //global $query's set() method for setting the author as the current user's id
274 $query->set('author', $current_user->ID);
275 $screen = get_current_screen();
276 add_filter('views_' . $screen->id, 'remove_post_counts');
277 }
278}
279add_action('pre_get_posts', 'filter_posts_list');
280
281function remove_post_counts($posts_count_disp)
282{
283 //$posts_count_disp contains the 3 links, we keep 'Mine' and remove the other two.
284 unset($posts_count_disp['all']);
285 unset($posts_count_disp['publish']);
286 return $posts_count_disp;
287}
288
289//remove admin editor
290function remove_textarea() {
291 remove_post_type_support( 'vacancy', 'editor' );
292}
293add_action('admin_init', 'remove_textarea');
294
295/**
296 * Redirect user after successful login.
297 *
298 * @param string $redirect_to URL to redirect to.
299 * @param string $request URL the user is coming from.
300 * @param object $user Logged user's data.
301 * @return string
302 */
303
304//redirect after login to My Company
305function my_login_redirect( $redirect_to, $request, $user ) {
306 //is there a user to check?
307 if (isset($user->roles) && is_array($user->roles)) {
308 //check for Employers
309 if (in_array('cs_employer', $user->roles)) {
310 // redirect them to another URL, in this case, the homepage
311 $redirect_to = "/my-company/";
312 }
313 }
314
315 return $redirect_to;
316}
317add_filter( 'login_redirect', 'my_login_redirect', 10, 3 );
318
319//redirect after log out to main page
320function auto_redirect_after_logout(){
321 wp_redirect( home_url() );
322 exit();
323}
324add_action('wp_logout','auto_redirect_after_logout');
325
326//limit media library access
327add_filter( 'ajax_query_attachments_args', 'wpb_show_current_user_attachments' );
328
329function wpb_show_current_user_attachments( $query ) {
330 $user_id = get_current_user_id();
331 if ( $user_id && !current_user_can('activate_plugins') && !current_user_can('edit_others_posts
332') ) {
333 $query['author'] = $user_id;
334 }
335 return $query;
336}
337
338function jp_search_filter( $query ) {
339 if ( $query->is_search && $query->is_main_query() ) {
340 $query->set( 'post__not_in', array( 315,310,181,103,285 ) );
341 }
342 if ( $query->is_search && $query->is_main_query() ) {
343
344 }
345}
346
347add_action( 'pre_get_posts', 'jp_search_filter' );
348
349
350
351
352
353add_action('init', function(){
354 $labels = array(
355 "name" => "Companies",
356 "singular_name" => "Company",
357 "menu_name" => "Companies",
358 "all_items" => "All companies",
359 "add_new" => "Add New",
360 "add_new_item" => "Add New Company",
361 "edit" => "Edit",
362 "edit_item" => "Edit Company",
363 "new_item" => "New Company",
364 "view" => "View",
365 "view_item" => "View Company",
366 "search_items" => "Search Company",
367 "not_found" => "No Company Found",
368 "not_found_in_trash" => "No Company Found in Trash",
369 "parent" => "Parent Company",
370 );
371
372 $args = array(
373 "labels" => $labels,
374 "description" => "",
375 "public" => true,
376 "show_ui" => true,
377 "has_archive" => true,
378 "show_in_menu" => true,
379 "exclude_from_search" => false,
380 "capability_type" => "post",
381 "map_meta_cap" => true,
382 "hierarchical" => true,
383 //"rewrite" => array( "slug" => "company", "with_front" => true ),
384 "query_var" => true,
385 "publicly_queryable" => true,
386 "supports" => array( "title", "revisions", "thumbnail" )
387 );
388
389 register_post_type( "companies", $args );
390
391 $labels = array(
392 "name" => "Vacancies",
393 "singular_name" => "Vacancy",
394 );
395
396 $args = array(
397 "labels" => $labels,
398 "description" => "",
399 "public" => true,
400 "show_ui" => true,
401 "has_archive" => true,
402 "show_in_menu" => true,
403 "exclude_from_search" => false,
404 "capability_type" => "post",
405 "map_meta_cap" => true,
406 "hierarchical" => false,
407 "rewrite" => array( "slug" => "vacancies", "with_front" => false ),
408 "query_var" => true,
409 "publicly_queryable" => true,
410 "supports" => array( "title", "revisions", "thumbnail" ),
411 'taxonomies' => array('post_tag')
412 );
413
414 register_post_type( "vacancies", $args );
415
416});
417
418
419
420
421add_action( 'pre_get_posts','so16299109_pre_get_posts' );
422function so16299109_pre_get_posts( $query )
423{
424
425 $url = $_SERVER['REQUEST_URI'];
426 $url_path = wp_parse_url($url);
427 $url_path_res = substr($url_path['path'],1);
428 $path_arr = explode('/',$url_path_res);
429
430
431
432
433
434 return $path_arr;
435}
436
437
438
439add_action('add_meta_boxes', function() {
440 add_meta_box('vacancies-parent', 'Companies', 'vacancies_attributes_meta_box', 'vacancies', 'side', 'default');
441});
442
443function reg_tag() {
444
445 register_taxonomy_for_object_type('post_tag', 'vacancies');
446}
447add_action('init', 'reg_tag');
448
449
450
451
452function vacancies_attributes_meta_box($post) {
453 $pages = wp_dropdown_pages(array('post_type' => 'companies', 'selected' => $post->post_parent, 'name' => 'parent_id', 'show_option_none' => __('(no parent)'), 'sort_column'=> 'menu_order, post_title', 'echo' => 0));
454 if ( ! empty($pages) ) {
455 echo $pages;
456 } // end empty pages check
457}
458
459
460function gp_remove_cpt_slug( $post_link, $post ) {
461 if ( 'companies' === $post->post_type && 'publish' === $post->post_status ) {
462 $post_link = str_replace( '/' . $post->post_type . '/', '/', $post_link );
463 }
464 return $post_link;
465}
466add_filter( 'post_type_link', 'gp_remove_cpt_slug', 10, 2 );
467
468add_action( 'init', function() {
469 add_rewrite_rule('^(.*)/([^/]+)/?$','index.php?vacancies=$matches[2]','top');
470});
471add_filter('post_type_link', function($link, $post){
472 if('vacancies' == get_post_type($post)){
473 $parentId = wp_get_post_parent_id($post->ID);
474 $parent_post = get_post($parentId);
475 @$parent_slug = $parent_post->post_name;
476
477 if($parentId){
478
479 return str_replace('vacancies', $parent_slug , $link);
480 }
481
482 }
483 return $link;
484}, 10, 2 );
485
486
487
488function gp_add_cpt_post_names_to_main_query( $query ) {
489 // Bail if this is not the main query.
490 if ( ! $query->is_main_query() ) {
491 return;
492 }
493 // Bail if this query doesn't match our very specific rewrite rule.
494 if ( ! isset( $query->query['page'] ) || 2 !== count( $query->query ) ) {
495 return;
496 }
497 // Bail if we're not querying based on the post name.
498 if ( empty( $query->query['name'] ) ) {
499 return;
500 }
501 // Add CPT to the list of post types WP will include when it queries based on the post name.
502 $query->set( 'post_type', array( 'post', 'page', 'companies' ) );
503}
504add_action( 'pre_get_posts', 'gp_add_cpt_post_names_to_main_query' );
505
506
507
508
509function getCompanies(){
510
511
512 $args = array(
513 'post_type' => 'companies',
514 'order' => 'ASK',
515 );
516
517
518 foreach(get_posts($args) as $post) {
519
520 $skill['name'] = $post->post_title;
521 $skill['description'] = $post->post_content;
522 $skill['img_url'] = get_the_post_thumbnail_url($post->ID,'thumbnail');
523 $skills[] = $skill;
524 }
525
526
527
528 return $skills;
529 }
530
531
532function checkIfCompanyCreated($usr){
533
534
535
536 $args = array(
537 'post_type' => 'companies',
538 'order' => 'ASK',
539 'author' => $usr
540 );
541
542 $count_companies = count(get_posts( $args ));
543
544
545
546 return $count_companies;
547
548}
549
550
551function getIdCompanyCreated($usr){
552
553
554
555 $args = array(
556 'post_type' => 'companies',
557 'order' => 'ASK',
558 'author' => $usr
559 );
560
561 $count_companies = get_posts( $args );
562
563 @$company_id = $count_companies[0]->ID;
564
565
566
567 return $company_id;
568
569}
570
571
572
573
574function company_type_from_reg() {
575
576 $args = array(
577 'post_type' => 'companies',
578 'order' => 'ASK',
579 );
580
581 //print_r(get_posts($args));
582
583 $uid = get_current_user_id();
584
585 if(checkIfCompanyCreated($uid) == '0'){
586 acf_form(array(
587 'post_id' => 'new_post',
588 'post_title' => true,
589 'new_post' => array(
590 'post_status' => 'publish',
591 'post_type' => 'companies'
592 ),
593 'submit_value' => 'Create company',
594 'updated_message' => __("Company has been created successfuly", 'acf'),
595 ));
596 }else{
597
598
599
600 acf_form(array(
601 'post_id' => getIdCompanyCreated($uid),
602 'post_title' => true,
603 'new_post' => array(
604 'post_status' => 'publish',
605 'post_type' => 'companies'
606 ),
607 'submit_value' => 'Update',
608 'updated_message' => __("Company has been created successfuly", 'acf'),
609 ));
610
611 }
612
613
614
615
616
617
618}
619add_shortcode('company_type_reg_form', 'company_type_from_reg');
620
621
622
623function wistia_stats_api(){
624
625 $uid = get_current_user_id();
626
627 $post_id = getIdCompanyCreated($uid);
628
629 if($post_id) {
630
631 $username = 'paul_bevan@devpeople.co.uk';
632 $password = '1e67be794efc34c2b286cc96d6134825d8c9a26d9e4537c8e446ed0854e00134';
633
634 $api_key = '4f4f2ae4e84cce50cbc84d825e8b5e02-us19';
635
636
637 $list_id = '60666be05b';
638
639 $i = 0;
640
641
642 $result = [];
643
644
645 $company_acf = get_fields($post_id);
646
647 $company_post = get_post($post_id);
648
649
650
651
652 $result['company']['title'] = $company_post->post_title;
653
654 $result['company']['slug'] = $company_post->guid;
655
656 $result['company']['views'] = pvc_get_post_views($post_id);
657
658
659
660 $url = "https://api.wistia.com/v1/medias/" . $company_acf['video_code'] . ".json";
661
662 $args = array(
663 'headers' => array(
664 'Authorization' => 'Basic ' . base64_encode("$username:$password")),
665 );
666
667 $company_url_stats = "https://api.wistia.com/v1/stats/medias/" . $company_acf['video_code'] . ".json";
668
669 $response_comp = wp_remote_request($company_url_stats, $args);
670
671 $response_body_comp = json_decode(wp_remote_retrieve_body($response_comp), true);
672
673 $result['company']['play_count'] = $response_body_comp['play_count'];
674
675 if($response_body_comp['play_count'] == 0 || $result['company']['views'] == 0){
676 $result['company']['percentOfVisitorsClickingPlay'] = 0;
677 }else{
678
679 $result['company']['percentOfVisitorsClickingPlay'] = round(($response_body_comp['play_count'] / $result['company']['views']) * 100,1);
680
681 }
682
683
684 $response = wp_remote_request($url, $args);
685 $response_body = json_decode(wp_remote_retrieve_body($response), true);
686
687 $result['company']['img'] = $response_body['thumbnail']['url'];
688
689
690 $dc = substr($api_key, strpos($api_key, '-') + 1); // us5, us8 etc
691 $args = array(
692 'headers' => array(
693 'Authorization' => 'Basic ' . base64_encode('user:' . $api_key)
694 )
695 );
696 $response = wp_remote_get('https://' . $dc . '.api.mailchimp.com/3.0/lists/' . $list_id . '/members/', $args);
697 $body = json_decode(wp_remote_retrieve_body($response));
698 $count_subs = 0;
699
700// echo "<pre>";
701// print_r($body);
702// echo "</pre>";
703
704
705 if (wp_remote_retrieve_response_code($response) == 200) {
706 foreach ($body->members as $member) {
707 if ($member->status != 'subscribed')
708 continue;
709
710
711 if ($member->merge_fields->MMERGE4) {
712 $count_subs += 1;
713 }
714
715
716 }
717
718 } else {
719 echo '<b>' . wp_remote_retrieve_response_code($response) . wp_remote_retrieve_response_message($response) . ':</b> ' . $body->detail;
720
721 }
722
723 $args_v = array(
724 'post_type' => 'vacancies',
725 'order' => 'ASK',
726 'author' => $uid
727 );
728
729
730 $vacancies = get_posts($args_v);
731
732 foreach ($vacancies as $item) {
733
734// ECHO $item->ID;
735//
736// $post_type = get_post_type( $item->ID );
737//
738// echo $post_type;
739
740
741 $apply_response = wp_remote_get('https://' . $dc . '.api.mailchimp.com/3.0/lists/0464da6e68/members/', $args);
742
743 $apply_body = json_decode(wp_remote_retrieve_body($apply_response));
744
745 $count_applies = 0;
746
747 foreach ($apply_body->members as $app_member) {
748 if ($app_member->status != 'subscribed')
749 continue;
750// echo "<pre>";
751// print_r($app_member->merge_fields->MMERGE5);
752// echo "<pre>";
753// echo $app_member->MMERGE5;
754
755 if ($app_member->merge_fields->MMERGE5 && $app_member->merge_fields->MMERGE5 == $item->ID) {
756 $count_applies += 1;
757 }
758
759 }
760
761 $refer_response = wp_remote_get('https://' . $dc . '.api.mailchimp.com/3.0/lists/df189e54d9/members/', $args);
762
763 $refer_body = json_decode(wp_remote_retrieve_body($refer_response));
764
765 $count_refers = 0;
766
767 foreach ($refer_body->members as $refer_member) {
768 if ($refer_member->status != 'subscribed')
769 continue;
770// echo "<pre>";
771// print_r($app_member->merge_fields->MMERGE5);
772// echo "<pre>";
773// echo $app_member->MMERGE5;
774
775 if ($refer_member->merge_fields->MMERGE5 && $refer_member->merge_fields->MMERGE5 == $item->ID) {
776 $count_refers += 1;
777 }
778
779 }
780
781
782// echo "<pre>";
783// print_r($apply_body->members);
784// echo "<pre>";
785
786 $args_vv = array(
787 'headers' => array(
788 'Authorization' => 'Basic ' . base64_encode("$username:$password")),
789 );
790
791 $result['vacancies'][$i]['title'] = $item->post_title;
792 $result['vacancies'][$i]['slug'] = $item->guid;
793 $result['vacancies'][$i]['applies'] = $count_applies;
794
795 $result['vacancies'][$i]['refers'] = $count_refers;
796
797 $vacancies_acf = get_fields($item->ID);
798
799
800 $vacancy_url = "https://api.wistia.com/v1/medias/" . $item->video_code . ".json";
801
802 $vacancy_url_stats = "https://api.wistia.com/v1/stats/medias/" . $item->video_code . ".json";
803
804 $response_vacancies = wp_remote_request($vacancy_url, $args_vv);
805
806 $response_body_vacancies = json_decode(wp_remote_retrieve_body($response_vacancies), true);
807
808 $response_vacancies_stats = wp_remote_request($vacancy_url_stats, $args_vv);
809
810 $response_body_vacancies_stats = json_decode(wp_remote_retrieve_body($response_vacancies_stats), true);
811
812
813 $result['vacancies'][$i]['play_count'] = $response_body_vacancies_stats['play_count'];
814
815 @$result['vacancies'][$i]['img'] = $response_body_vacancies['thumbnail']['url'];
816 $result['vacancies'][$i]['visit_count'] = pvc_get_post_views($item->ID);
817
818 if($response_body_vacancies_stats['play_count'] == 0 || $result['vacancies'][$i]['visit_count'] == 0){
819 $result['vacancies'][$i]['percentOfVisitorsClickingPlay'] = 0;
820 }else{
821
822 $result['vacancies'][$i]['percentOfVisitorsClickingPlay'] = round(($response_body_vacancies_stats['play_count'] / $result['vacancies'][$i]['visit_count']) * 100,1);
823
824 }
825
826
827 $i++;
828 }
829
830
831 $result['company']['count_subs'] = $count_subs;
832
833
834
835 echo "<div class='data_stat'>";
836
837 echo "<div class='data_stat-content'>";
838
839 echo "<a href='".$result['company']['slug']."'><div class='title'>" . $result['company']['title'] . "</div></a>";
840
841 echo "<div class='subtitle'>*Includes social media sharing statistics</div>";
842
843 echo "<a href='".$result['company']['slug']."'><img src='" . $result['company']['img'] . "'/></a>";
844
845
846
847 echo "</div>";
848
849 echo "<table class='table-fill'>";
850 echo "<tr>";
851 echo "<td><p>" . $result['company']['count_subs'] ."</p></td>";
852 echo "<td><p>Subscriptions</p></td>";
853 echo "</tr>";
854 echo "<tr>";
855 echo "<td><p>" . $result['company']['views'] ."</p></td>";
856 echo " <td><p>Visitors</p></td>";
857 echo "</tr>";
858 echo "<tr>";
859 echo " <td><p>" . $result['company']['play_count'] ."</p></td>";
860 echo "<td><p>Plays</p></td>";
861 echo "</tr>";
862// echo "<tr>";
863// echo "<td><p>" . $result['company']['percentOfVisitorsClickingPlay'] ."%</p></td>";
864// echo "<td><p>of visitors pressed play</p></td>";
865// echo "</tr>";
866 echo " </table>";
867
868 echo "</div>";
869
870
871
872 echo "<hr/>";
873
874 $q = 0;
875 @$len = count($result['vacancies']);
876
877 if($len !== 0) {
878
879 foreach (@$result['vacancies'] as $vacancy) {
880
881 echo "<div class='data_stat'>";
882
883 echo "<div class='data_stat-content'>";
884
885 echo "<a href='" . $vacancy['slug'] . "'><div class='title'>" . $vacancy['title'] . "</div></a>";
886
887
888
889 echo "<a href='" . $vacancy['slug'] . "'><img src='" . $vacancy['img'] . "'/></a>";
890
891
892 echo "</div>";
893
894 echo "<table class='table-fill'>";
895 echo "<tr>";
896 echo "<td><p>" . $vacancy['applies'] . "</p></td>";
897 echo "<td><p>Applications</p></td>";
898 echo "</tr>";
899 echo "<tr>";
900 echo "<td><p>" . $vacancy['refers'] . "</p></td>";
901 echo "<td><p>Referrals</p></td>";
902 echo "</tr>";
903
904 echo "<tr>";
905 echo "<td><p>" . $vacancy['visit_count'] . "</p></td>";
906 echo " <td><p>Visitors</p></td>";
907 echo "</tr>";
908 echo "<tr>";
909 echo " <td><p>" . $vacancy['play_count'] . "</p></td>";
910 echo "<td><p>Plays</p></td>";
911 echo "</tr>";
912// echo "<tr>";
913// echo "<td><p>" . $vacancy['percentOfVisitorsClickingPlay'] . "%</p></td>";
914// echo "<td><p>of visitors pressed play</p></td>";
915// echo "</tr>";
916 echo " </table>";
917
918 echo "</div>";
919
920 if (!$q == $len - 1) {
921 echo "<hr/>";
922 }
923
924
925// echo "<a href='".$vacancy['slug']."'><img src='" . $vacancy['img'] . "'/></a>";
926//
927// echo "<div class='title'>" . $vacancy['title'] . "</div>";
928//
929// echo "<p>" . $vacancy['applies'] . " Applications</p>";
930//
931// echo "<p>" . $vacancy['refers'] . " Referrals</p>";
932//
933// echo "<p>" . $vacancy['visit_count'] . " Visitors to the vacancy page</p>";
934//
935// echo "<p>" . $vacancy['play_count'] . " Plays of this video</p>";
936//
937// echo "<p>" . $vacancy['percentOfVisitorsClickingPlay'] . "% of people who visited this page played your video</p>";
938
939
940 }
941 }
942
943
944
945
946
947
948 }else{
949 echo "<div class='data_stat'>";
950
951 echo "<div class='title'>You don't have any statistic yet</div></div>";
952
953 echo "</div>";
954 }
955
956}
957
958add_shortcode('wistia_stats_api', 'wistia_stats_api');
959
960
961
962function frontend_change_title_label( $field ) {
963
964
965 // Only do it on the front end
966 if( !is_admin() && $_SERVER['REQUEST_URI'] !== '/new-vacancy/'){
967
968 // Check if the current field is post title
969 if( $field['name'] == 'acf[_post_title]' ){
970
971 // Change the label
972 $field['label'] = 'Company Name';
973
974 }
975
976 }else{
977 if( $field['name'] == 'acf[_post_title]' ){
978
979 // Change the label
980 $field['label'] = 'Job title';
981
982 }
983 }
984
985 return $field;
986
987}
988
989// all
990add_filter('acf/prepare_field', 'frontend_change_title_label');
991
992
993
994function getListOfVacancies(){
995
996
997
998 $uid = get_current_user_id();
999 //echo $uid;
1000
1001
1002 $args = array(
1003 'post_type' => 'vacancies',
1004 'order' => 'ASK',
1005 'author' => $uid
1006 );
1007
1008 $ifVacancyExist = count(get_posts($args));
1009 //echo $ifVacancyExist;
1010
1011 //print_r(get_posts($args));
1012 if(checkIfCompanyCreated($uid) >= '1'){
1013 if($ifVacancyExist >= 1){?>
1014 <div class='row'>
1015
1016 <div class='col-sm-12'>
1017 <ul class="list_vacancy">
1018 <?php foreach(get_posts($args) as $post) {?>
1019 <li>
1020 <a href="<?php echo $post->guid;?>">
1021
1022 <?php echo $post->post_title; ?>
1023
1024 </a>
1025 <a href="/edit-vacancy/?vacancy_id=<?php echo $post->ID;?>" style="float: right">Edit</a>
1026 </li>
1027
1028
1029 <?php } ?>
1030 </ul>
1031 </div>
1032 <hr/><br/>
1033 <div class='col-sm-12 '>
1034 <a href="/new-vacancy"> <div id="add_new_vacancy" class="button button-primary button-large add_new_vacancy" >Create New Vacancy</div></a>
1035
1036 </div>
1037 <br/><br/>
1038<!-- <div class="vacancy_form" >-->
1039<!-- --><?php //do_shortcode('[create_new_vacancy]');?>
1040<!-- </div>-->
1041 <div >
1042 </div>
1043 </div>
1044
1045 <?php }else{ ?>
1046 <div class='row'>
1047 <div class='col-sm-12'>You do not have any vacancies at the moment.</div><hr/><br/>
1048 </div>
1049
1050 <a href="/new-vacancy"><div class='col-sm-12'><div class='button button-primary button-large add_new_vacancy' >Add new vacancy</div></div></a>
1051 <br/><br/>
1052<!-- <div class="vacancy_form" >-->
1053<!-- --><?php //do_shortcode('[create_new_vacancy]');?>
1054<!-- </div>-->
1055
1056 <? }
1057 }else{
1058
1059 $result = "<div class='data_stat'>";
1060 $result .= "<div class='title'>Create your company first.</div>";
1061 $result .= "</div>";
1062
1063
1064
1065
1066
1067 return $result;
1068
1069 }
1070
1071
1072
1073
1074
1075
1076}
1077
1078add_shortcode('list_of_vacancies', 'getListOfVacancies');
1079
1080
1081function createNewVacancy(){
1082
1083
1084 acf_form(array(
1085 'post_id' => 'new_post',
1086 'post_title' => true,
1087 'new_post' => array(
1088 'post_status' => 'publish',
1089 'post_type' => 'vacancies'
1090 ),
1091 'submit_value' => 'Create vacancy',
1092 'html_after_fields' => '<div><input type="hidden" name="vacancy_cheker" value="true"></div>',
1093 'updated_message' => __("Vacancy has been created successfuly", 'acf'),
1094 ));
1095
1096
1097
1098}
1099
1100
1101
1102function vacancy_edit_front() {
1103
1104 $args = array(
1105 'post_type' => 'vacancies',
1106 'order' => 'ASK',
1107 );
1108
1109
1110 if(isset($_GET['vacancy_id'])) {
1111
1112
1113 acf_form(array(
1114 'post_id' => $_GET['vacancy_id'],
1115 'post_title' => true,
1116 'new_post' => array(
1117 'post_status' => 'publish',
1118 'post_type' => 'vacancies'
1119 ),
1120 'submit_value' => 'Update',
1121 'updated_message' => __("Vacancy has been updated successfuly", 'acf'),
1122 ));
1123
1124
1125 }else{
1126
1127 status_header( 404 );
1128 nocache_headers();
1129 include( get_query_template( '404' ) );
1130 die();
1131
1132
1133 }
1134
1135
1136
1137
1138
1139
1140
1141
1142}
1143add_shortcode('vacancy_edit_front', 'vacancy_edit_front');
1144
1145
1146
1147
1148function my_acf_prepare_field( $field ) {
1149
1150 if ( is_page('page-name') ) {
1151
1152 $field['label'] = "My new title";
1153 $field['instructions'] = "My new instruction";
1154 }
1155
1156 if ( $field ) { return $field; } else { exit; }
1157
1158}
1159add_filter('acf/prepare_field/name=_post_title', 'my_acf_prepare_field');
1160
1161add_shortcode('create_new_vacancy', 'createNewVacancy');
1162
1163
1164function get_user_id_company(){
1165
1166 $uid = get_current_user_id();
1167
1168 $args = array(
1169 'post_type' => 'companies',
1170 'order' => 'ASK',
1171 'post_author' => $uid,
1172
1173 );
1174
1175 $comanies = get_posts($args);
1176
1177 $company_id = $comanies[0]->ID;
1178
1179 return $company_id;
1180
1181}
1182
1183add_action('acf/save_post' , 'vacancy_pre_save_post', 10 );
1184
1185
1186function get_vacancy_company($post_id){
1187
1188
1189 $post = get_post($post_id);
1190 $post_parent_id = $post->post_parent;
1191
1192
1193
1194 $category = get_fields($post_parent_id);
1195
1196 $category_logo = $category['logo_upload'];
1197
1198
1199
1200
1201
1202
1203 return $category_logo;
1204}
1205
1206
1207function vacancy_pre_save_post($post_id){
1208
1209 if (isset($_POST['vacancy_cheker'])) {
1210
1211 $companyId = get_user_id_company();
1212
1213 wp_update_post(
1214 array(
1215 'ID' => $post_id,
1216 'post_parent' => $companyId
1217 )
1218 );
1219
1220 }
1221
1222 }
1223
1224
1225 function get_current_openings($post_current_id){
1226
1227 $args = array(
1228 'post_type' => 'vacancies',
1229 'order' => 'ASC',
1230 'post_parent' => $post_current_id,
1231 'posts_per_page' => 3
1232);
1233
1234
1235 foreach(get_posts($args) as $post) {
1236
1237 $open_vac = get_fields($post->ID);
1238 $open_vac['name'] = $post->post_title;
1239 $open_vac['link'] = $post->guid;
1240 $open_vacancies[] = $open_vac;
1241
1242
1243 }
1244
1245 if(!empty($open_vacancies)){
1246 return $open_vacancies;
1247 }
1248
1249
1250 }
1251
1252 function get_companies(){
1253
1254 $args = array(
1255 'post_type' => 'companies',
1256 'order' => 'DESC',
1257 'posts_per_page' => 3,
1258 );
1259 //print_r(get_posts($args));
1260 ?>
1261
1262 <ul class="main_list_companies" style="list-style: none;">
1263 <?php foreach(get_posts($args) as $post) {?>
1264
1265
1266 <li style="float: left;width: 33%;text-align: center;">
1267 <a href="<?php echo $post->guid;?>">
1268 <img style="max-height: 100px;" src="<?php echo get_field('logo_upload',$post->ID);?>"></li>
1269 </a>
1270 </li>
1271
1272
1273
1274 <?php } ?>
1275 </ul>
1276
1277 <div style="clear: both;"></div>
1278 <br/><br/>
1279 <?php
1280
1281
1282 }
1283
1284 add_shortcode('front_page_companies', 'get_companies');
1285
1286 function acf_set_featured_image( $value, $post_id, $field ){
1287 $id = $value;
1288 if( ! is_numeric( $id ) ){
1289 $data = json_decode( stripcslashes($id), true );
1290 $id = $data['cropped_image'];
1291 }
1292 update_post_meta( $post_id, '_thumbnail_id', $id );
1293 return $value;
1294}
1295
1296// acf/update_value/name={$field_name} - filter for a specific field based on it's name
1297//add_filter( 'acf/update_value/name=brand_photo_img', 'acf_set_featured_image2', 10, 3 );
1298
1299apply_filters( 'acf-image-crop/filename_postfix', 'filter_acf_image_crop_filename_postfix' );
1300
1301
1302function filter_acf_image_crop_filename_postfix($file)
1303{
1304 print_r($file);
1305 die;
1306 $img=getimagesize($file['tmp_name']);
1307 $minimum = array('width' => '1280', 'height' => '760');
1308 $width= $img[0];
1309 $height =$img[1];
1310
1311 if ($width < $minimum['width'] )
1312 return array("error"=>"Image dimensions are too small. Minimum width is {$minimum['width']}px. Uploaded image width is $width px");
1313
1314 elseif ($height < $minimum['height'])
1315 return array("error"=>"Image dimensions are too small. Minimum height is {$minimum['height']}px. Uploaded image height is $height px");
1316 else
1317 return $file;
1318}
1319
1320
1321function theme_settings_page()
1322{
1323 ?>
1324 <div class="wrap">
1325 <h1>Theme Panel</h1>
1326 <form method="post" action="options.php">
1327 <?php
1328 settings_fields("section");
1329 do_settings_sections("theme-options");
1330 submit_button();
1331 ?>
1332 </form>
1333 </div>
1334 <?php
1335}
1336
1337
1338function add_theme_menu_item()
1339{
1340 add_menu_page("Theme Panel", "Theme Panel", "manage_options", "theme-panel", "theme_settings_page", null, 99);
1341}
1342
1343add_action("admin_menu", "add_theme_menu_item");
1344
1345
1346function display_logo_element()
1347{
1348 ?>
1349 <img src="<?php echo get_option('logo_url'); ?>" />
1350 <input type="file" name="logo_url" id="logo_url" value="<?php echo get_option('logo_url'); ?>" />
1351 <?php
1352}
1353
1354function display_ld_element()
1355{
1356 ?>
1357 <input type="text" name="ld_url" id="ld_url" value="<?php echo get_option('ld_url'); ?>" />
1358
1359 <?php
1360}
1361
1362function display_message_element()
1363{
1364 ?>
1365 <input type="text" name="message_url" id="message_url" value="<?php echo get_option('message_url'); ?>" />
1366
1367 <?php
1368}
1369function display_youtube_element()
1370{
1371 ?>
1372 <input type="text" name="youtube_url" id="youtube_url" value="<?php echo get_option('youtube_url'); ?>" />
1373
1374 <?php
1375}
1376
1377function display_facebook_element()
1378{
1379 ?>
1380 <input type="text" name="facebook_url" id="facebook_url" value="<?php echo get_option('facebook_url'); ?>" />
1381
1382 <?php
1383}
1384
1385function display_footer_f_description()
1386{
1387 ?>
1388
1389 <input type="text" name="footer_text1" id="footer_text1" value="<?php echo get_option('footer_text1'); ?>" />
1390
1391 <?php
1392}
1393
1394function display_footer_s_description()
1395{
1396 ?>
1397
1398 <input type="text" name="footer_text2" id="footer_text2" value="<?php echo get_option('footer_text2'); ?>" />
1399
1400 <?php
1401}
1402
1403function display_footer_t_description()
1404{
1405 ?>
1406
1407 <input type="text" name="footer_text3" id="footer_text3" value="<?php echo get_option('footer_text3'); ?>" />
1408
1409 <?php
1410}
1411
1412function display_footer_fr_description()
1413{
1414 ?>
1415
1416 <input type="text" name="footer_text4" id="footer_text4" value="<?php echo get_option('footer_text4'); ?>" />
1417
1418 <?php
1419}
1420
1421
1422
1423
1424function display_theme_panel_fields()
1425{
1426 add_settings_section("section", "All Settings", null, "theme-options");
1427
1428// add_settings_field("logo_url", "Logo text", "display_logo_element", "theme-options", "section");
1429 add_settings_field("insta_url", "LinkedIn Profile Url", "display_ld_element", "theme-options", "section");
1430 add_settings_field("message_url", "Twitter Profile Url", "display_message_element", "theme-options", "section");
1431 add_settings_field("facebook_url", "Facebook Profile Url", "display_facebook_element", "theme-options", "section");
1432 add_settings_field("youtube_url", "Youtube Profile Url", "display_youtube_element", "theme-options", "section");
1433
1434 add_settings_field("footer_text1", "Name(Footer description)", "display_footer_f_description", "theme-options", "section");
1435 add_settings_field("footer_text2", "Street(Footer description)", "display_footer_s_description", "theme-options", "section");
1436 add_settings_field("footer_text3", "City(Footer description)", "display_footer_t_description", "theme-options", "section");
1437 add_settings_field("footer_text4", "Tel(Footer description)", "display_footer_fr_description", "theme-options", "section");
1438
1439 register_setting("section", "logo_url");
1440 register_setting("section", "ld_url");
1441 register_setting("section", "message_url");
1442 register_setting("section", "youtube_url");
1443 register_setting("section", "facebook_url");
1444 register_setting("section", "footer_text1");
1445 register_setting("section", "footer_text2");
1446 register_setting("section", "footer_text3");
1447 register_setting("section", "footer_text4");
1448}
1449
1450add_action("admin_init", "display_theme_panel_fields");
1451
1452add_filter('wpcf7_autop_or_not', '__return_false');
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463function get_related_vacancy($post_id){
1464
1465
1466
1467 $current_post = get_post($post_id);
1468
1469
1470 $args = array(
1471 'post_type' => 'vacancies',
1472 'order' => 'ASC',
1473 'post_parent' => $current_post->post_parent,
1474 'posts_per_page' => 3
1475
1476
1477 );
1478
1479 foreach(get_posts($args) as $post) {
1480
1481 if($post->ID !== $post_id) {
1482 $open_vac = get_fields($post->ID);
1483 $open_vac['id'] = $post->ID;
1484 $open_vac['video_code'] = $open_vac['video_code'];
1485 $open_vac['name'] = $post->post_title;
1486 $open_vac['link'] = $post->guid;
1487 $open_vacancies[] = $open_vac;
1488 }
1489
1490 }
1491
1492
1493
1494 $parent_post = get_post($current_post->post_parent);
1495 $open_vacancies_fields = get_fields($parent_post->ID);
1496
1497 $parent_comp['video_code'] = $open_vacancies_fields['video_code'];
1498 $parent_comp['id'] = $post->ID;
1499 $parent_comp['name'] = $parent_post->post_title;
1500 $parent_comp['link'] = $parent_post->guid;
1501 $open_vacancies[] = $parent_comp;
1502
1503
1504
1505
1506
1507
1508 return $open_vacancies;
1509}
1510
1511function get_parent_name($post_id){
1512
1513 $current_post = get_post($post_id);
1514
1515 $parent_post = get_post($current_post->post_parent);
1516
1517 return $parent_post->post_title;
1518
1519}
1520
1521function get_parent_video_code($post_id){
1522
1523 $current_post = get_post($post_id);
1524
1525 $parent_post = get_post($current_post->post_parent);
1526
1527 return $parent_post->video_code;
1528
1529}
1530
1531function get_parent_id($post_id){
1532 $current_post = get_post($post_id);
1533
1534 return $current_post->post_parent;
1535}
1536
1537
1538
1539function cf7_add_post_id(){
1540
1541 global $post;
1542
1543 return $post->ID;
1544
1545}
1546
1547add_shortcode('CF7_ADD_POST_ID', 'cf7_add_post_id');
1548
1549function cf7_add_company_name(){
1550
1551 global $post;
1552
1553
1554 $current_post = get_post($post->ID);
1555
1556 $paret_post = get_post($current_post->post_parent);
1557
1558 return $paret_post->post_title;
1559
1560}
1561
1562add_shortcode('CF7_ADD_COMPANY_NAME', 'cf7_add_company_name');
1563
1564function cf7_company_link(){
1565
1566 global $post;
1567
1568
1569 $current_post = get_post($post->ID);
1570
1571 $paret_post = get_post($current_post->post_parent);
1572
1573 return $paret_post->guid;
1574
1575}
1576
1577add_shortcode('CF7_COMPANY_LINK', 'cf7_company_link');
1578
1579function cf7_add_vacancy_name(){
1580
1581 global $post;
1582
1583
1584 $current_post = get_post($post->ID);
1585
1586 return $current_post->post_title;
1587
1588}
1589
1590add_shortcode('CF7_ADD_VAC_NAME', 'cf7_add_vacancy_name');
1591
1592
1593function cf7_add_vacancy_link(){
1594
1595 global $post;
1596
1597 $current_post = get_post($post->ID);
1598
1599
1600 return $current_post->guid;
1601
1602}
1603
1604add_shortcode('CF7_ADD_VAC_LINK', 'cf7_add_vacancy_link');
1605
1606
1607
1608
1609
1610function remove_css_id_filter($var) {
1611 return is_array($var) ? array_intersect($var, array('current-menu-item')) : '';
1612}
1613add_filter( 'page_css_class', 'remove_css_id_filter', 100, 1);
1614add_filter( 'nav_menu_item_id', 'remove_css_id_filter', 100, 1);
1615add_filter( 'nav_menu_css_class', 'remove_css_id_filter', 100, 1);
1616
1617
1618
1619add_filter('acf/validate_value/key=field_5c2e034ce807d', 'company_video_code_acf_validate_value', 10, 4);
1620
1621function company_video_code_acf_validate_value( $valid, $value, $field, $input )
1622{
1623 // bail early if value is already invalid
1624 if (!$valid) {
1625
1626 return $valid;
1627
1628 }
1629
1630 $username = 'paul_bevan@devpeople.co.uk';
1631 $password = '1e67be794efc34c2b286cc96d6134825d8c9a26d9e4537c8e446ed0854e00134';
1632
1633 $url = "https://api.wistia.com/v1/stats/medias/$value.json";
1634
1635 $args = array(
1636 'headers' => array(
1637 'Authorization' => 'Basic ' . base64_encode ( "$username:$password" ) ),
1638 );
1639 $response = wp_remote_request( $url, $args );
1640 $response_body = json_decode( wp_remote_retrieve_body( $response ), true );
1641 if(!$response_body){
1642 $valid = 'Video code not valid';
1643 }
1644 return $valid;
1645
1646}
1647
1648
1649
1650
1651
1652function get_first_paragraph($content){
1653
1654
1655 $str = strip_tags(wpautop($content),'<p><h1><h2><h3><strong><ul><li>');
1656
1657
1658
1659
1660 $arr = explode('</p>',$str);
1661
1662 $res = '<p>' . $arr[0] . '</p>';
1663 $res .= '<p>' . $arr[1] . '</p>';
1664 $res .= '<p>' . $arr[2] . '</p>';
1665
1666
1667
1668 $str = substr( $str, 0, strpos( $str, '</p>' ) + 4 );
1669 return $res;
1670}
1671
1672function get_eccept_first_paragraph($content){
1673
1674
1675 $str = strip_tags(wpautop($content),'<p><h1><h2><h3><strong>');
1676
1677 $arr = explode('</p>',$str);
1678
1679 $lenght = count($arr);
1680 $res = '<p>' . $arr[3] . '</p>';
1681 for($i=4; $i<=$lenght;$i++){
1682 $res .= '<p>' . @$arr[$i] . '</p>';
1683 }
1684// $str = substr( $str, strpos( $str, '</p>' ) + 4 );
1685 return $res;
1686}
1687
1688
1689
1690
1691function my_acf_save_cat_vac( $post_id ) {
1692
1693
1694
1695
1696
1697
1698
1699 if( empty($_POST['acf']['field_5c2e034ce807d'] || $_POST['acf']['field_5c2e064ba2f94']) ) {
1700
1701 return;
1702
1703 }
1704
1705 if(!empty($_POST['acf']['field_5c2e034ce807d'])){
1706 $video_code = $_POST['acf']['field_5c2e034ce807d'];
1707 }else{
1708 $video_code = $_POST['acf']['field_5c2e064ba2f94'];
1709 }
1710
1711
1712
1713
1714 // array of field values
1715
1716 $username = 'paul_bevan@devpeople.co.uk';
1717 $password = '1e67be794efc34c2b286cc96d6134825d8c9a26d9e4537c8e446ed0854e00134';
1718
1719
1720
1721 $url = "https://api.wistia.com/v1/medias/" . $video_code. ".json";
1722
1723 $args = array(
1724 'headers' => array(
1725 'Authorization' => 'Basic ' . base64_encode("$username:$password")),
1726 );
1727
1728
1729 $response_comp = wp_remote_request($url, $args);
1730
1731 $response_body_comp = json_decode(wp_remote_retrieve_body($response_comp), true);
1732
1733
1734
1735
1736
1737
1738 if(!empty($_POST['acf']['field_5c2e034ce807d'])){
1739 $_POST['acf']['field_5c38a05ddddd1'] = $response_body_comp['thumbnail']['url'];
1740 }else{
1741
1742 $_POST['acf']['field_5c38a9225c127'] = $response_body_comp['thumbnail']['url'];
1743 }
1744
1745
1746
1747
1748
1749}
1750
1751add_action('acf/save_post', 'my_acf_save_cat_vac', 1);
1752
1753
1754add_action('init', function() {
1755
1756 if(isset($_GET['tags'])) {
1757
1758 $load= get_template_part( 'archive-tag.php' );
1759
1760
1761
1762// // load the file if exists
1763// $asd = 1;
1764// echo 1;
1765 $load = locate_template('archive-tag.php', true);
1766//
1767// $asd = 1;
1768 if ($load) {
1769 exit(); // just exit if template was found and loaded
1770 }
1771
1772 }
1773});
1774
1775
1776function get_custom_tags(){
1777
1778 global $wpdb;
1779
1780 @$term = get_term_by('slug',$_GET['tags'],'post_tag');
1781
1782 @$termId = $term->term_id;
1783
1784 if($termId) {
1785
1786 $query = "
1787SELECT * FROM $wpdb->posts
1788LEFT JOIN $wpdb->term_relationships ON
1789($wpdb->posts.ID = $wpdb->term_relationships.object_id)
1790LEFT JOIN $wpdb->term_taxonomy ON
1791($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
1792WHERE post_type = 'vacancies'
1793AND $wpdb->posts.post_status = 'publish'
1794AND $wpdb->term_taxonomy.term_taxonomy_id = " . $termId . "
1795ORDER BY post_date DESC
1796";
1797
1798 $results = $wpdb->get_results($query);
1799 }else{
1800 $results = 0;
1801 }
1802 return $results;
1803}