Esempio n. 1
0
function movie_links_meta_save($post_id)
{
    // Check save status
    $is_autosave = wp_is_post_autosave($post_id);
    $is_revision = wp_is_post_revision($post_id);
    $is_valid_nonce = isset($_POST['movie_links_nonce']) && wp_verify_nonce($_POST['movie_links_nonce'], basename(__FILE__)) ? 'true' : 'false';
    // Exit script depending on save status
    if ($is_autosave || $is_revision || !$is_valid_nonce) {
        return;
    }
    // Grab the value of our hidden 'fetched' input
    // This is a boolean that should only return true if we're saving from the AJAX call
    $fetched = get_post_meta($post_id, 'fetched', true);
    if ($fetched) {
        update_post_meta($post_id, 'fetched', 0);
        return;
    }
    // Check for input and sanitizes/saves if needed
    save_if_changed('trailer', $post_id, true);
    save_if_changed('website', $post_id, true);
    save_if_changed('trailer_confirm', $post_id, true);
    save_if_changed('website_confirm', $post_id, true);
}
Esempio n. 2
0
function movie_details_meta_save($post_id)
{
    // Check save status
    $is_autosave = wp_is_post_autosave($post_id);
    $is_revision = wp_is_post_revision($post_id);
    $is_valid_nonce = isset($_POST['movie_details_nonce']) && wp_verify_nonce($_POST['movie_details_nonce'], basename(__FILE__)) ? 'true' : 'false';
    // Exit script depending on save status
    if ($is_autosave || $is_revision || !$is_valid_nonce) {
        return;
    }
    // Grab the value of our hidden 'fetched' input
    // This is a boolean that should only return true if we're saving from the AJAX call
    $fetched = get_post_meta($post_id, 'fetched', true);
    if ($fetched) {
        update_post_meta($post_id, 'fetched', 0);
        wp_set_object_terms($post_id, null, 'genre');
        return;
    }
    // Check for input and sanitizes/saves if needed
    save_if_changed('starring', $post_id, true);
    save_if_changed('rating', $post_id, false);
    save_if_changed('runtime_minutes', $post_id, true);
    save_if_changed('description', $post_id, true);
    if (isset($_POST['genres'])) {
        // Run through each genre and apply it programmatically
        $set_genres = [];
        $genres_array = explode(',', $_POST['genres']);
        foreach ($genres_array as $genre) {
            $set_genres[] = $genre;
        }
        wp_set_object_terms($post_id, $set_genres, 'genre', true);
    }
}