get_col($wpdb->prepare("SELECT o.poll_id FROM $table o JOIN $wpdb->posts p ON p.ID=o.poll_id WHERE p.post_type='onyxpolls' AND p.post_status='publish' AND o.expired=0 AND o.end IS NOT NULL AND o.end<=%s", current_time('mysql'))); if ($wpdb->last_error) { return new WP_Error('onyx_cron_database', __('The poll expiration check could not be completed.', 'acf-onyx-poll'), array('status' => 500)); } if (!$ids) { return null; } foreach ($ids as $id) { if ($wpdb->update($table, array('expired' => 1), array('poll_id' => $id)) === false) { return new WP_Error('onyx_cron_database', __('The poll expiration check could not be completed.', 'acf-onyx-poll'), array('status' => 500)); } } return array_map('intval', $ids); } /** * Verify if has active polls * * @param bool $noexpired optional * @param bool $onlymodal optional * @return $post->ID */ public static function has_polls($noexpired = false, $onlymodal = false) { $ids = OnyxPollsStorage::ids(0, $noexpired, $onlymodal); return $ids ? $ids[0] : false; } /** * Verify if poll id exist (even expired) * * @param int $id required */ public static function has_poll($id = false) { if ($id) { OnyxPollsStorage::get($id); } $ids = OnyxPollsStorage::ids($id); return $ids ? $ids[0] : false; } /** * Get asset variables for enqueue * @param string $path required */ public static function get_asset_vars($path = null) { if ($path) { $a = new stdClass(); $a->path = $path; $a->url = plugins_url($path, ACF_ONYX_POLL_FILE); $a->ver = ACF_ONYX_POLL_VERSION . '.' . filemtime(ACF_ONYX_POLL_PATH . $path); return $a; } return false; } /** * Enqueue assets */ public static function add_assets() { // Include scripts on front end $js = self::get_asset_vars('assets/js/onyx-poll.min.js'); wp_enqueue_script('acf-onyx-poll', $js->url, array(), $js->ver, true); if (!OnyxPollsStorage::settings()['css']) { $css = self::get_asset_vars('assets/css/onyx-poll.min.css'); wp_enqueue_style('acf-onyx-poll', $css->url, array(), $css->ver); } wp_localize_script('acf-onyx-poll', 'onyxpoll', array( 'apiurl' => rest_url(), 'modaltime' => OnyxPollsStorage::settings()['modal_time'], 'labels' => array( 'vote' => __('Vote', 'acf-onyx-poll'), 'votes' => __('votes', 'acf-onyx-poll'), 'view' => __('Views result', 'acf-onyx-poll'), 'total' => __('Total votes', 'acf-onyx-poll'), 'success' => __('Vote was submitted successfully.', 'acf-onyx-poll'), 'error' => __('Poll vote error, try again.', 'acf-onyx-poll') ) ) ); } } ?>