Skip to content

Commit

Permalink
Merge pull request #35 from thenewinquiry/1.2.9
Browse files Browse the repository at this point in the history
1.2.9 Functions to Get Array of Subscription-only Posts
  • Loading branch information
frnsys authored Aug 18, 2017
2 parents a43a7bd + 38f7620 commit 07e8bce
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 5 deletions.
62 changes: 62 additions & 0 deletions includes/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,65 @@ function tni_is_subscription_only( $post ) {

return strtotime( $subscription_date ) > strtotime( $today );
}

/**
* Get Unauthorized Posts
*
* @uses tni_is_subscription_only()
* @uses tni_core_check_auth()
* @uses get_transient()
* @uses set_transient()
* @link https://codex.wordpress.org/Transients_API
*
* @since 1.2.9
*
* @return array $posts | false
*
*/
function tni_core_get_unauthorized_posts() {
/* If user is authorized, all posts are shown regardless of whether they are "subscription_only" */
if( !( function_exists( 'tni_core_check_auth' ) ) && $auth = tni_core_check_auth() ) {
return false;
}

$posts = get_transient( 'tni_unauthorized_posts' );

if( false === $posts ) {

$args = array(
'fields' => 'ids',
'posts_per_page' => -1
);
$query = new WP_Query( $args );
$post_query = $query->get_posts();

if( !empty( $post_query ) || !is_wp_error( $post_query ) ) {
$posts = array_values( array_filter( $post_query, 'tni_is_subscription_only' ) );
}

set_transient( 'tni_unauthorized_posts', $posts, HOURS_IN_SECONDS * 12 );

}

return $posts;
}

/**
* Purge Transients
* Each time a post is published, delete the transient
* Currently, disabled but can be activated to delete transients upon publishing post
* Note: It will not run when a post is updated
*
* @uses delete_transient()
*
* @param int $ID
* @param obj $post
*
* @return void
*/
function tni_core_purge_transients( $ID, $post ) {
if( 'post' === $post->post_type ) {
delete_transient( 'tni_unauthorized_posts' );
}
}
//add_action( 'publish_post', 'tni_core_purge_transients' );
9 changes: 6 additions & 3 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributors: misfist
Tags: custom
Requires at least: 4.7
Tested up to: 4.8
Version: 1.2.8
Version: 1.2.9
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand All @@ -22,17 +22,20 @@ This section describes how to install the plugin and get it working.

== Changelog ==

= 1.2.9 Aug 18, 2017 =
* Added function return array of unauthorized post IDs

= 1.2.8 July 6, 2017 =
* #33 Fixed PHP error caused when `TNI_Core_Authorization` class is instantiated without passing required values `$file` and `$version`
* Added new functionality for subscriber-only content - In single.php template, add conditionals `tni_is_subscription_only` and `tni_core_check_auth` to serve alternate content to non-subscribers
* #77 & #78 Added new functionality for subscriber-only content - In single.php template, add conditionals `tni_is_subscription_only` and `tni_core_check_auth` to serve alternate content to non-subscribers
* Added `subscriber_only_date` date field
* Moved new Subscriber Only Content metabox below publish box on edit screen
* Added `tni_is_subscription_only` that returns true or false if content is subscription-only today
* Removed `show_future_posts` function since subscription date will be used instead

= 1.2.7 June 22, 2017 =
* #29 Added `audio_url` custom field.
* To access value: `get_post_meta( post->ID, 'audio_url', true );`
* To access value: `get_post_meta( $post->ID, 'audio_url', true );`

= 1.2.6 June 21, 2017 =
* Show scheduled (future) single posts to authenticated users
Expand Down
4 changes: 2 additions & 2 deletions tni-core-functionality.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Text Domain: tni-core
* Domain Path: /languages
*
* Version: 1.2.8
* Version: 1.2.9
*
* @package Tni_Core_Functionality
*/
Expand Down Expand Up @@ -52,7 +52,7 @@
* @return object Tni_Core
*/
function Tni_Core() {
$instance = Tni_Core::instance( __FILE__, 'l.2.8' );
$instance = Tni_Core::instance( __FILE__, 'l.2.9' );

return $instance;
}
Expand Down

0 comments on commit 07e8bce

Please sign in to comment.