public static function process_complete() { global $wpdb; $sql = "SELECT * from {$wpdb->postmeta} where meta_key = 'faf_process_expire_date'"; $q = $wpdb->get_results($sql, ARRAY_A); foreach ($q as $process) { $timestamp = $process["meta_value"]; $post_id = $process["post_id"]; $meta = get_post_meta($post_id); $options = $meta["_expiration-date-options"]; _scheduleExpiratorEvent($post_id, $timestamp, $options); } $sql = "DELETE from {$wpdb->postmeta} where meta_key = 'faf_process_expire_date'"; $wpdb->query($sql); }
/** * Called when post is saved - stores expiration-date meta value */ function expirationdate_update_post_meta($id) { // don't run the echo if this is an auto save if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return; } // don't run the echo if the function is called for saving revision. $posttype = get_post_type($id); if ($posttype == 'revision') { return; } if (!isset($_POST['expirationdate_formcheck'])) { return; } if (isset($_POST['enable-expirationdate'])) { $default = get_option('expirationdateDefaultDate', POSTEXPIRATOR_EXPIREDEFAULT); if ($default == 'publish') { $month = intval($_POST['mm']); $day = intval($_POST['jj']); $year = intval($_POST['aa']); $hour = intval($_POST['hh']); $minute = intval($_POST['mn']); } else { $month = intval($_POST['expirationdate_month']); $day = intval($_POST['expirationdate_day']); $year = intval($_POST['expirationdate_year']); $hour = intval($_POST['expirationdate_hour']); $minute = intval($_POST['expirationdate_minute']); } $category = isset($_POST['expirationdate_category']) ? $_POST['expirationdate_category'] : 0; $opts = array(); $ts = get_gmt_from_date("{$year}-{$month}-{$day} {$hour}:{$minute}:0", 'U'); // Schedule/Update Expiration $opts['expireType'] = $_POST['expirationdate_expiretype']; $opts['id'] = $id; if ($opts['expireType'] == 'category' || $opts['expireType'] == 'category-add' || $opts['expireType'] == 'category-remove') { if (isset($category) && !empty($category)) { if (!empty($category)) { $opts['category'] = $category; $opts['categoryTaxonomy'] = $_POST['taxonomy-heirarchical']; } } } _scheduleExpiratorEvent($id, $ts, $opts); } else { _unscheduleExpiratorEvent($id); } }
/** * Add ChurchApp events to WP */ function import_churchapp_events() { $ch = curl_init(APP_URL); curl_setopt_array($ch, array(CURLOPT_TIMEOUT => 0, CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_HTTPHEADER => array('X-Account: ' . APP_ACCOUNT, 'X-Application: ' . APP_APPLICATION, 'X-Auth: ' . APP_AUTH))); $result = curl_exec($ch); curl_close($ch); $json = json_decode($result); $events = $json->events; $email = ""; foreach ($events as $event) { if ($event->public_visible == 1 && $event->signup_options->public->featured == 1) { //Check against currently added events $wp_event = new WP_Query(array('post_count' => -1, 'post_type' => 'event', 'meta_key' => 'identifier', 'meta_value' => $event->identifier)); // If it's not found in the DB we can add it if ($wp_event->post_count == 0) { $post_id = wp_insert_post(array('post_type' => 'event', 'post_title' => $event->name, 'post_content' => $event->description, 'post_status' => 'publish', 'post_author' => 2, 'comment_status' => 'closed', 'ping_status' => 'closed')); // If it's successfully added to the DB if ($post_id) { $email .= "Successfully added " . $event->name . " <a href='" . get_edit_post_link($post_id) . "'>(ID: " . $post_id . ")</a> to WP<br/>"; // Add expiry date _scheduleExpiratorEvent($post_id, strtotime($event->datetime_end)); // Update ACF fields update_field('field_582456c4b953e', $event->identifier, $post_id); update_field('field_582456d0b953f', $event->datetime_start, $post_id); update_field('field_58249be78d880', strtotime($event->datetime_start), $post_id); update_field('field_582456e3b9540', $event->datetime_end, $post_id); if (count($event->location) != 0) { update_field('field_582456f3b9541', $event->location->name, $post_id); update_field('field_582456ffb9542', $event->location->address, $post_id); update_field('field_58245707b9543', $event->location->latitude, $post_id); update_field('field_5824570fb9544', $event->location->longitude, $post_id); } update_field('field_5824571ab9545', $event->signup_options->tickets->enabled, $post_id); update_field('field_58245724b9546', $event->signup_options->tickets->url, $post_id); // Add created and updated date(s) update_field('field_583313e481783', strtotime('now'), $post_id); update_field('field_583313f681784', strtotime('now'), $post_id); // Try and get the image if (count($event->images) > 0) { $file = $event->images->original_1000; add_media_to_wp($event, $file, $post_id); } } else { $email .= "Couldn't add " . $event->name . " to WP<br/>"; } } else { $post_to_update = $wp_event->posts[0]; $post_id = $post_to_update->ID; $update_count = 1; //Basic object to add data to $updated_info = array('ID' => $post_id); //If title has changed if (esc_html($post_to_update->post_title) != esc_html($event->name)) { $updated_info["post_title"] = $event->name; $update_count++; } if ($post_to_update->post_content != $event->description) { $updated_info["post_content"] = $event->description; $update_count++; } if (get_field('identifier', $post_to_update) != $event->identifier) { update_field('field_582456c4b953e', $event->identifier, $post_id); $update_count++; } if (get_field('datetimes_start', $post_to_update) != $event->datetimestamp_start) { update_field('field_582456d0b953f', $event->datetimestamp_start, $post_id); $update_count++; } if (get_field('datetimestamp_start', $post_to_update) != strtotime($event->datetime_start)) { update_field('field_58249be78d880', strtotime($event->datetime_start), $post_id); $update_count++; } if (get_field('datetime_end', $post_to_update) != $event->datetime_end) { update_field('field_582456e3b9540', $event->datetime_end, $post_id); $update_count++; } if (count($event->location) != 0) { if (get_field('location', $post_to_update) != $event->location->name) { update_field('field_582456f3b9541', $event->location->name, $post_id); $update_count++; } if (get_field('location_address', $post_to_update) != $event->location->address) { update_field('field_582456ffb9542', $event->location->address, $post_id); $update_count++; } if (get_field('location_latitude', $post_to_update) != $event->location->latitude) { update_field('field_58245707b9543', $event->location->latitude, $post_id); $update_count++; } if (get_field('location_longitude', $post_to_update) != $event->location->longitude) { update_field('field_5824570fb9544', $event->location->longitude, $post_id); $update_count++; } } if (get_field('signup_available', $post_to_update) != $event->signup_options->tickets->enabled) { update_field('field_5824571ab9545', $event->signup_options->tickets->enabled, $post_id); $update_count++; } if (get_field('signup_url', $post_to_update) != $event->signup_options->tickets->url) { update_field('field_58245724b9546', $event->signup_options->tickets->url, $post_id); $update_count++; } //Update post if there's more data than just ID if ($update_count > 1) { wp_update_post($updated_info); update_field('field_583313f681784', strtotime('now'), $post_id); $email .= "Updated " . $event->name . " (ID: " . $post_id . ")<br/>"; } else { $email .= "No need to update " . $event->name . " <a href='" . get_edit_post_link($post_id) . "'>(ID: " . $post_id . ")</a><br/>"; } // See if there's a featured image to add if (count($event->images) > 0 && !has_post_thumbnail($post_id)) { $file = $event->images->original_1000; add_media_to_wp($event, $file, $post_id); } } } } if (!empty($email)) { wp_mail('*****@*****.**', 'ChurchApp event import ' . date('d/m/Y'), $email, array('Content-Type: text/html; charset=UTF-8')); } }