Last active
April 25, 2019 01:35
-
-
Save macbookandrew/b3e08a9e35a44526e47ecb35d1113c8f to your computer and use it in GitHub Desktop.
Addon plugin for Seriously Simple Podcasting; includes private podcasts in feed URL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Plugin Name: Seriously Simple Private Podcasting | |
* Plugin URL: https://gist.github.com/macbookandrew/b3e08a9e35a44526e47ecb35d1113c8f | |
* Description: Include posts marked “private” in podcast feed. Note: activate this <strong>first</strong>, then the Seriously Simple Podcasting plugin. | |
* Version: 1.0.2 | |
* Author: AndrewRMinion Design | |
* Author URI: https://andrewrminion.com | |
*/ | |
if (!defined('ABSPATH')) { | |
exit; | |
} | |
/** | |
* Get post IDs of all podcast episodes for all post types | |
* | |
* Overrides ssp_episode_ids function in main plugin | |
* | |
* @since 1.8.2 | |
* @return array | |
*/ | |
function ssp_episode_ids() { | |
global $ss_podcasting; | |
// Remove action to prevent infinite loop | |
remove_action( 'pre_get_posts', array( $ss_podcasting, 'add_all_post_types' ) ); | |
// Setup the default args | |
$args = array( | |
'post_type' => array( 'podcast' ), | |
'post_status' => array( 'publish', 'private' ), | |
'posts_per_page' => -1, | |
'fields' => 'ids', | |
); | |
// Do we have any additional post types to add? | |
$podcast_post_types = ssp_post_types( false ); | |
if ( ! empty( $podcast_post_types ) ) { | |
$args['post_type'] = ssp_post_types(); | |
$args['meta_query'] = array( | |
array( | |
'key' => apply_filters( 'ssp_audio_file_meta_key', 'audio_file' ), | |
'compare' => '!=', | |
'value' => '', | |
), | |
); | |
} | |
// Do we have this stored in the cache? | |
$key = 'episode_ids'; | |
$group = 'ssp'; | |
$podcast_episodes = wp_cache_get( $key, $group ); | |
// If nothing in cache then fetch episodes again and store in cache | |
if ( $podcast_episodes === false ) { | |
$podcast_episodes = get_posts( $args ); | |
wp_cache_set( $key, $podcast_episodes, $group, HOUR_IN_SECONDS * 12 ); | |
} | |
// Reinstate action for future queries | |
add_action( 'pre_get_posts', array( $ss_podcasting, 'add_all_post_types' ) ); | |
return $podcast_episodes; | |
} | |
/** | |
* Add private posts to the podcast list | |
* @param array $args array of WPQuery args | |
* @return array array of WPQuery args | |
*/ | |
function ssp_private_add_private_podcast_episodes( $args ) { | |
$args['post_status'] = array( 'publish', 'private' ); | |
return $args; | |
} | |
add_filter( 'ssp_episode_query_args', 'ssp_private_add_private_podcast_episodes' ); | |
/** | |
* Include private podcasts in search | |
* @param [[Type]] $query [[Description]] | |
*/ | |
function ssp_private_include_private_in_search( $query ) { | |
if ( $query->is_search() && is_user_logged_in() ) { | |
$query->set( 'post_status', array( 'publish', 'private' ) ); | |
} | |
} | |
add_action( 'pre_get_posts', 'ssp_private_include_private_in_search' ); | |
/** | |
* Remove “Private:” from private posts | |
* @param string $content title | |
* @return string title | |
*/ | |
function ssp_private_private_title_format( $content ) { | |
return '%s'; | |
} | |
add_filter( 'private_title_format', 'ssp_private_private_title_format' ); | |
add_filter( 'protected_title_format', 'ssp_private_private_title_format' ); | |
/** | |
* Allow subscribers to view private podcasts | |
*/ | |
function ssp_private_allow_subscribers_private_access() { | |
$subscriber = get_role( 'subscriber' ); | |
$subscriber->add_cap( 'read_private_posts' ); | |
$subscriber->add_cap( 'read_private_pages' ); | |
} | |
add_action( 'init', 'ssp_private_allow_subscribers_private_access' ); | |
/** | |
* Make podcasts private by default | |
*/ | |
function ssp_private_default_post_visibility() { | |
global $post; | |
if ( 'publish' == $post->post_status ) { | |
$visibility = 'public'; | |
$visibility_trans = __( 'Public' ); | |
} elseif ( !empty( $post->post_password ) ) { | |
$visibility = 'password'; | |
$visibility_trans = __( 'Password protected' ); | |
} elseif ( $post->post_type == 'podcast' && is_sticky( $post->ID ) ) { | |
$visibility = 'public'; | |
$visibility_trans = __( 'Public, Sticky' ); | |
} else { | |
$post->post_password = ''; | |
$visibility = 'private'; | |
$visibility_trans = __( 'Private' ); | |
} ?> | |
<script type='text/javascript'> | |
(function($) { | |
try { | |
$('#post-visibility-display').text('<?php echo $visibility_trans; ?>'); | |
$('#hidden-post-visibility').val('<?php echo $visibility; ?>'); | |
$('#visibility-radio-<?php echo $visibility; ?>').attr('checked', true); | |
} catch(e) {} | |
})(jQuery); | |
</script> | |
<?php | |
} | |
add_action( 'post_submitbox_misc_actions' , 'ssp_private_default_post_visibility' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Changelog