/**
 * Check if Sticky Expired
 * -----------------------------------------------------------------------------
 * @return  bool        Post has expired, true/false.
 */
function kaitain_has_sticky_been_set()
{
    $set = false;
    if ($set = kaitain_get_sticky_id()) {
        if (!($set = date('U') <= kaitain_get_sticky_expiry())) {
            kaitain_remove_sticky_post();
        }
    }
    return $set;
}
Esempio n. 2
0
/**
 * Update Featured Post Meta
 * -----------------------------------------------------------------------------
 * Validate /ALL/ the things!
 * 
 * @param   int      $post_id           Post object ID.
 */
function kaitain_update_featured_meta_box($post_id)
{
    if (!isset($_POST['kaitain_featured_box_nonce'])) {
        return;
    }
    if (!wp_verify_nonce($_POST['kaitain_featured_box_nonce'], 'kaitain_featured_box_data')) {
        return;
    }
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
        return;
    }
    if (!current_user_can('edit_post', $post_id)) {
        return;
    }
    $make_featured = isset($_POST['make_featured']) && $_POST['make_featured'] === 'on';
    $make_sticky = isset($_POST['make_sticky']) && $_POST['make_sticky'] === 'on';
    // Update meta.
    kaitain_update_featured_posts($post_id, $make_featured);
    if ($make_featured && $make_sticky) {
        // Sanitiize date input and mkdate.
        $year = filter_var($_POST['stickyexpires-year'], FILTER_SANITIZE_NUMBER_INT);
        $month = filter_var($_POST['stickyexpires-month'], FILTER_SANITIZE_NUMBER_INT);
        $day = filter_var($_POST['stickyexpires-day'], FILTER_SANITIZE_NUMBER_INT);
        $hour = filter_var($_POST['stickyexpires-hour'], FILTER_SANITIZE_NUMBER_INT);
        $hour--;
        $minute = filter_var($_POST['stickyexpires-minute'], FILTER_SANITIZE_NUMBER_INT);
        $expiry = mktime($hour, $minute, 0, $month, $day, $year);
        if ($expiry) {
            // Set sticky if validated.
            kaitain_set_sticky_post($post_id, $expiry);
        }
    } else {
        if (!$make_sticky && kaitain_is_post_sticky($post_id)) {
            // If post was sticky, but no longer.
            kaitain_remove_sticky_post();
        }
    }
}