-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
215 lines (184 loc) · 7.02 KB
/
functions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
<?php
/**
* UnderStrap functions and definitions
*
* @package understrap
*/
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;
$understrap_includes = array(
'/theme-settings.php', // Initialize theme default settings.
'/setup.php', // Theme setup and custom theme supports.
'/widgets.php', // Register widget area.
'/enqueue.php', // Enqueue scripts and styles.
'/template-tags.php', // Custom template tags for this theme.
'/pagination.php', // Custom pagination for this theme.
'/hooks.php', // Custom hooks.
'/extras.php', // Custom functions that act independently of the theme templates.
'/customizer.php', // Customizer additions.
'/custom-comments.php', // Custom Comments file.
'/jetpack.php', // Load Jetpack compatibility file.
'/class-wp-bootstrap-navwalker.php', // Load custom WordPress nav walker. Trying to get deeper navigation? Check out: https://github.com/understrap/understrap/issues/567
'/woocommerce.php', // Load WooCommerce functions.
'/editor.php', // Load Editor functions.
'/deprecated.php', // Load deprecated functions.
'/custom-post-types.php', // Load custom post types
'/acf.php', // Load ACF specific functions
);
foreach ( $understrap_includes as $file ) {
require_once get_template_directory() . '/inc' . $file;
}
//LOGGER -- like frogger but more useful
if ( ! function_exists('write_log')) {
function write_log ( $log ) {
if ( is_array( $log ) || is_object( $log ) ) {
error_log( print_r( $log, true ) );
} else {
error_log( $log );
}
}
}
//print("<pre>".print_r($a,true)."</pre>");
//GRAVITY FORMS PIECES
add_action( 'gform_after_submission_3', 'internship_update_post_content', 10, 2 ); //runs after form with specific ID (3 in this case) is submitted
function internship_update_post_content( $entry, $form ) {
//getting post
$post_id = get_post( $entry['post_id'] );
$company = rgar( $entry, '1' );
$compensation = rgar( $entry, '7' );
$contact_email = rgar($entry, '2');
$credit_or_not = rgar($entry, '11');
$job_description = rgar($entry, '12');
$submission_requirements = rgar($entry, '13');
$start_date = rgar($entry, '8');
$end_date = rgar($entry, '9');
update_field('field_5e34451b767eb', $company, $post_id);//company name
update_field('field_5e3447c544472', $compensation, $post_id);//compensation
update_field('field_5e3989d11d4c6', $contact_email, $post_id);//email
update_field('field_604655142ece8', $credit_or_not, $post_id);//credit
update_field('field_6046430cbc137', $job_description, $post_id);//job descr
update_field('field_60464339f745d', $submission_requirements, $post_id);//requirements
update_field('field_5e344550767ee', $start_date, $post_id);//start date
update_field('field_5e344567767ef', $end_date, $post_id);//end date
//ADDRESS
$street = rgar( $entry, '4.1' );
$street_two =rgar( $entry, '4.2' );
$city = rgar( $entry, '4.3' );
$state = rgar( $entry, '4.4' );
$zip = rgar( $entry, '4.5' );
$country = rgar( $entry, '4.6' );
$address_pieces = array(
'street_1' => $street,
'street_2' => $street_two,
'city' => $city,
'state' => $state,
'zip_code' => $zip,
);
update_field( 'field_5e3992e1480ec', $address_pieces, $post_id );//ADDRESS
//DATES GROUP
// $start_date = rgar( $entry, '8' );
// $end_date = rgar( $entry, '9' );
// $dates = array(
// 'start_date' => $start_date,
// 'end_date' => $end_date,
// );
// update_field( 'field_5e344533767ed', $dates, $post_id );//start and end date group
// $i = wp_update_post( $post_id );
}
//Shortcode for displaying custom post and field info
function create_shortcode_internship_post_type(){
make_dated_posts_draft();
$args = array(
'post_type' => 'internship',
'posts_per_page' => -1,
'numberposts' => -1,
'publish_status' => 'publish',
);
$query = new WP_Query($args);
if($query->have_posts()) :
$result = '';
while($query->have_posts()) :
$query->the_post() ;
$ymdFormat = get_field( "start_date" ); // , $post_id
// var_dump($ymdFormat);
$newFormat = switch_date_format($ymdFormat);
$result .= '<div class="intern-list">';
$result .= '<div class="row"><div class="job-title col-md-4"><strong><a href="' . get_permalink() .'">' . get_the_title() . '</a></strong></div><div class="job-title col-md-4">' . get_field( "company_name") . '</div><div class="job-title col-md-4">' . $newFormat . '</div></div>';
$result .= '</div>';
endwhile;
wp_reset_postdata();
endif;
return $result;
}
add_shortcode( 'internship-list', 'create_shortcode_internship_post_type' );
//internship reviews
function internship_get_reviews(){
global $post;
$search_criteria = array(
'status' => 'active',
'field_filters' => array(
array(
'key' => '2', // This is the field ID (psot ID) of the form
'value' => $post->ID,
)
)
);
$entries = GFAPI::get_entries( 4, $search_criteria ); //This is the GF form ID for the rating
if ($entries){
$html = '';
$all_ratings = array();
foreach ($entries as $key => $entry) {
$rating = $entry[3];
$comment = $entry[4];
$date = date_format(new DateTime($entry["date_created"]), 'Y-m-d');
array_push($all_ratings, $rating);
$html .= '<li>' . star_maker($rating) . '<span class="review-date">' . $date . '</span><div class="comment">' . $comment .'</div></li>';
}
$average = array_sum($all_ratings) / count($all_ratings);
return 'Average rating: ' . round($average) . ' <ul class="review-list">' . $html . '</ul>';
} else {
return 'No reviews of this internship yet.';
}
}
function star_maker($number){
if ($number == 1){
return '⭐';
}
if ($number == 2){
return '⭐⭐';
}
if ($number == 3){
return '⭐⭐⭐';
}
if ($number == 4){
return '⭐⭐⭐⭐';
}
}
//Check date to see if Internship Post should show
function make_dated_posts_draft() {
$the_query = get_posts( 'post_type=internship' );
foreach($the_query as $single_post) {
$id = $single_post->ID;
$ad_close_date = get_field('start_date', $id );
if($ad_close_date !='') {
$today = date("Ymd");
// var_dump($today);
// var_dump($ad_close_date);
if(new DateTime($ad_close_date) < new DateTime($today)) {
$update_post = array(
'ID' => $id,
'post_status' => 'draft',
'post_type' => 'internship' );
wp_update_post($update_post);
}
}
}
}
function switch_date_format($ymdFormat) {
// $oldDateString = $ymdFormat;
// var_dump($oldDateString);
$newDateString = DateTime::createFromFormat('Ymd', $ymdFormat);
$newFormat = $newDateString->format('m-d-Y');
// var_dump($newFormat);
return $newFormat;
}