/** * Fetch all podcast episodes * @param integer $n Number of episodes to fetch * @param string $series Slug of series to fetch * @param boolean $return_args True to return query args, false to return posts * @param string $context Context of query * @since 1.8.2 * @return array Array of posts or array of query args */ function ssp_episodes($n = 10, $series = '', $return_args = false, $context = '') { // Get all podcast episodes IDs $episode_ids = (array) ssp_episode_ids(); if ($context === 'glance') { return $episode_ids; } if (empty($episode_ids)) { return array(); } // Get all valid podcast post types $podcast_post_types = ssp_post_types(true); if (empty($podcast_post_types)) { return array(); } // Fetch podcast episodes $args = array('post_type' => $podcast_post_types, 'post_status' => 'publish', 'posts_per_page' => $n, 'ignore_sticky_posts' => true, 'post__in' => $episode_ids); if ($series) { $args['series'] = esc_attr($series); } $args = apply_filters('ssp_episode_query_args', $args, $context); if ($return_args) { return $args; } // Do we have anything in the cache here? $key = 'episodes'; $group = 'ssp'; $posts = wp_cache_get($key, $group); // If nothing in cache then fetch episodes again and store in cache if ($posts === false) { $posts = get_posts($args); wp_cache_add($key, $posts, $group, HOUR_IN_SECONDS * 12); } return $posts; }
/** * Save episoe meta box content * @param integer $post_id ID of post * @return void */ public function meta_box_save($post_id) { global $ss_podcasting; $podcast_post_types = ssp_post_types(true); // Post type check if (!in_array(get_post_type(), $podcast_post_types)) { return false; } // Security check if (!wp_verify_nonce($_POST['seriouslysimple_' . $this->token . '_nonce'], plugin_basename($this->dir))) { return $post_id; } // User capability check if ('page' == $_POST['post_type']) { if (!current_user_can('edit_page', $post_id)) { return $post_id; } } else { if (!current_user_can('edit_post', $post_id)) { return $post_id; } } $field_data = $this->custom_fields(); $enclosure = ''; foreach ($field_data as $k => $field) { $val = ''; if (isset($_POST[$k])) { $val = strip_tags(trim($_POST[$k])); } if ($k == 'audio_file') { $enclosure = $val; } update_post_meta($post_id, $k, $val); } if ($enclosure) { // Get file duration if (get_post_meta($post_id, 'duration', true) == '') { $duration = $ss_podcasting->get_file_duration($enclosure); if ($duration) { update_post_meta($post_id, 'duration', $duration); } } // Get file size if (get_post_meta($post_id, 'filesize', true) == '') { $filesize = $ss_podcasting->get_file_size($enclosure); if ($filesize) { if (isset($filesize['formatted'])) { update_post_meta($post_id, 'filesize', $filesize['formatted']); } if (isset($filesize['raw'])) { update_post_meta($post_id, 'filesize_raw', $filesize['raw']); } } } // Save audio file to 'enclosure' meta field for standards-sake update_post_meta($post_id, 'enclosure', $enclosure); } }
/** * Clear the cache on post save. * @param int $id POST ID * @param object $post WordPress Post Object * @return void */ public function invalidate_cache($id, $post) { if (in_array($post->post_type, ssp_post_types(true))) { wp_cache_delete('episodes', 'ssp'); wp_cache_delete('episode_ids', 'ssp'); } }
/** * Get episode from audio file * @param string $file File name & path * @return object Episode post object */ public function get_episode_from_file($file = '') { global $post; $episode = false; if ($file != '') { $post_types = ssp_post_types(true); $args = array('post_type' => $post_types, 'post_status' => 'publish', 'posts_per_page' => 1, 'meta_key' => 'audio_file', 'meta_value' => $file); $qry = new WP_Query($args); if ($qry->have_posts()) { while ($qry->have_posts()) { $qry->the_post(); $episode = $post; break; } } } return apply_filters('ssp_episode_from_file', $episode, $file); }
/** * Fetch all podcast episodes * @param integer $n Number of episodes to fetch * @param string $series Slug of series to fetch * @param boolean $return_args True to return query args, false to return posts * @param string $context Context of query * @since 1.8.2 * @return array Array of posts or array of query args */ function ssp_episodes($n = 10, $series = '', $return_args = false, $context = '') { // Get all podcast episodes IDs $episode_ids = (array) ssp_episode_ids(); if (empty($episode_ids)) { return array(); } // Get all valid podcast post types $podcast_post_types = ssp_post_types(true); if (empty($podcast_post_types)) { return array(); } // Fetch podcast episodes $args = array('post_type' => $podcast_post_types, 'post_status' => 'publish', 'posts_per_page' => $n, 'ignore_sticky_posts' => true, 'post__in' => $episode_ids); if ($series) { $args['series'] = esc_attr($series); } $args = apply_filters('ssp_episode_query_args', $args, $context); if ($return_args) { return $args; } return get_posts($args); }