Example #1
0
/**
 * Enclose audio file for podcast on save and store in custom fields.
 * Using meta boxes validation filter.
 * Added by T Hyde 9 Oct 2013; Updated by Jack 4/4/14
 *
 * @param $new
 * @param $post_id
 * @param $field
 * @return $new unchanged
 */
function wpfc_sermon_audio_validate($new, $post_id, $field)
{
    // only for sermon audio
    if ($field['id'] != 'sermon_audio') {
        return $new;
    }
    $audio = get_post_meta($post_id, 'sermon_audio', 'true');
    // Stop if PowerPress plugin is active
    // Solves conflict regarding enclosure field: http://wordpress.org/support/topic/breaks-blubrry-powerpress-plugin?replies=6
    if (defined('POWERPRESS_VERSION')) {
        return false;
    }
    // Populate enclosure field with URL, length and format, if valid URL found
    // This will set the length of the enclosure automatically
    do_enclose($audio, $post_id);
    // Set duration as post meta
    $current = get_post_meta($post_id, 'sermon_audio', 'true');
    $currentduration = get_post_meta($post_id, '_wpfc_sermon_duration', 'true');
    // only grab if different (getting data from dropbox can be a bit slow)
    if ($new != '' && ($new != $current || empty($currentduration))) {
        // get file data
        $duration = wpfc_mp3_duration($new);
        // store in hidden custom fields
        update_post_meta($post_id, '_wpfc_sermon_duration', $duration);
    } elseif ($new == '') {
        // clean up if file removed
        delete_post_meta($post_id, '_wpfc_sermon_duration');
    }
    return $new;
}
Example #2
0
function wpfc_sermon_update()
{
    $sermon_settings = get_option('wpfc_options');
    $sermon_version = $sermon_settings['version'];
    $args = array('post_type' => 'wpfc_sermon', 'posts_per_page' => '-0');
    $wpfc_sermon_update_query = new WP_Query($args);
    while ($wpfc_sermon_update_query->have_posts()) {
        $wpfc_sermon_update_query->the_post();
        global $post;
        if (empty($sermon_version)) {
            $service_type = get_post_meta($post->ID, 'service_type', 'true');
            if (!has_term('wpfc_service_type')) {
                wp_set_object_terms($post->ID, $service_type, 'wpfc_service_type');
            }
            $current = get_post_meta($post->ID, 'sermon_audio', 'true');
            $currentsize = get_post_meta($post->ID, '_wpfc_sermon_size', 'true');
            // only grab if different (getting data from dropbox can be a bit slow)
            if (empty($currentsize)) {
                // get file data
                $size = wpfc_get_filesize($current);
                $duration = wpfc_mp3_duration($current);
                // store in hidden custom fields
                update_post_meta($post->ID, '_wpfc_sermon_duration', $duration);
                update_post_meta($post->ID, '_wpfc_sermon_size', $size);
            }
            //Alter the options array appropriately
            $sermon_settings['version'] = wpfc_plugin_get_version();
            //Update entire array
            update_option('wpfc_options', $sermon_settings);
        }
        if ($sermon_version < '1.8') {
            $current = get_post_meta($post->ID, 'sermon_audio', 'true');
            $currentsize = get_post_meta($post->ID, '_wpfc_sermon_size', 'true');
            // only grab if different (getting data from dropbox can be a bit slow)
            if (empty($currentsize)) {
                // get file data
                $size = wpfc_get_filesize($current);
                $duration = wpfc_mp3_duration($current);
                // store in hidden custom fields
                update_post_meta($post->ID, '_wpfc_sermon_duration', $duration);
                update_post_meta($post->ID, '_wpfc_sermon_size', $size);
            }
            //Alter the options array appropriately
            $sermon_settings['version'] = wpfc_plugin_get_version();
            //Update entire array
            update_option('wpfc_options', $sermon_settings);
        }
    }
    wp_reset_query();
}