Skip to content

Instantly share code, notes, and snippets.

@macbookandrew
Last active April 25, 2019 01:35
Show Gist options
  • Save macbookandrew/b3e08a9e35a44526e47ecb35d1113c8f to your computer and use it in GitHub Desktop.
Save macbookandrew/b3e08a9e35a44526e47ecb35d1113c8f to your computer and use it in GitHub Desktop.
Addon plugin for Seriously Simple Podcasting; includes private podcasts in feed URL
<?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.1.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
*/
if ( ! function_exists( 'ssp_episode_ids' ) ) {
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 object $query WP_Query
*/
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' );
@macbookandrew
Copy link
Author

macbookandrew commented May 8, 2017

Changelog

  • 1.1.5: fix drafts view in admin
  • 1.1.4: prevent subscribers from seeing future scheduled posts
  • 1.1.3: fix PHPCS issues
  • 1.1.2: don’t make posts private by default since that breaks scheduling
  • 1.1.1: remove need to activate this before parent plugin
  • 1.1.0: fix private-by-default issues
  • 1.0.2: make posts private by default
  • 1.0.1: include private podcasts in searches if user is logged in
  • 1.0.0: initial plugin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment