From 921504bafd9cf21790e0cadb7a7ec8af1fed7a3a Mon Sep 17 00:00:00 2001 From: Pea Date: Tue, 10 Oct 2017 15:27:34 -0400 Subject: [PATCH 1/3] #38 Added `subscriber_only` boolean field --- includes/class-tni-core-custom-fields.php | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/includes/class-tni-core-custom-fields.php b/includes/class-tni-core-custom-fields.php index d87372f..b9606c2 100644 --- a/includes/class-tni-core-custom-fields.php +++ b/includes/class-tni-core-custom-fields.php @@ -85,10 +85,29 @@ public function register_field_groups() { 'menu_order' => 0, )); - register_field_group( array ( + register_field_group( array( 'key' => 'group_subscriber_content', 'title' => __( 'Subscriber Only Content', 'tni-core' ), 'fields' => array ( + array ( + 'key' => 'field_subscriber_only', + 'label' => __( 'Subscriber Only', 'tni-core' ), + 'name' => 'subscriber_only', + 'type' => 'true_false', + 'instructions' => __( 'Viewable by Subscribers Only?', 'tni-core' ), + 'required' => 0, + 'conditional_logic' => 0, + 'wrapper' => array ( + 'width' => '', + 'class' => '', + 'id' => '', + ), + 'message' => '', + 'default_value' => 0, + 'ui' => 1, + 'ui_on_text' => __( 'True', 'tni-core' ), + 'ui_off_text' => __( 'False', 'tni-core' ), + ), array ( 'key' => 'field_subscriber_only_date', 'label' => __( 'Date', 'tni-core' ), From 6f318e91fcdc1d08eb4bc24b527e71ceec1bc8e7 Mon Sep 17 00:00:00 2001 From: Pea Date: Tue, 10 Oct 2017 15:28:19 -0400 Subject: [PATCH 2/3] #38 Updated `tni_is_subscription_only` function Updated `tni_is_subscription_only` function to fetch posts where `subscriber_only` is true --- includes/helpers.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/includes/helpers.php b/includes/helpers.php index f1b2467..ae4de41 100644 --- a/includes/helpers.php +++ b/includes/helpers.php @@ -88,6 +88,7 @@ function tni_get_users_meta( $field = null ) { * Checks if content is subscription only today * * @since 1.2.8 + * @since 1.2.13 * * @param int $post * @return bool true|false @@ -95,15 +96,14 @@ function tni_get_users_meta( $field = null ) { function tni_is_subscription_only( $post ) { $post = (int) $post; - $subscription_date = get_post_meta( $post, 'subscriber_only_date', true ); + /* We could just return `get_post_meta( $post, 'subscriber_only', true )`, but I think this is more readable */ + $subscription_only = get_post_meta( $post, 'subscriber_only', true ); - if( !isset( $subscription_date ) || empty( $subscription_date ) ) { + if( !isset( $subscription_only ) || empty( $subscription_only ) ) { return false; } - $today = date( 'Ymd' ); - - return strtotime( $subscription_date ) > strtotime( $today ); + return true; } /** @@ -141,7 +141,7 @@ function tni_core_get_unauthorized_posts() { $posts = array_values( array_filter( $post_query, 'tni_is_subscription_only' ) ); } - set_transient( 'tni_unauthorized_posts', $posts, MINUTE_IN_SECONDS * 5); + set_transient( 'tni_unauthorized_posts', $posts, MINUTE_IN_SECONDS * 5 ); } @@ -151,7 +151,6 @@ function tni_core_get_unauthorized_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() From cbe6d0659801e8086d52820fa7ec70f1adf44465 Mon Sep 17 00:00:00 2001 From: Pea Date: Tue, 10 Oct 2017 15:28:38 -0400 Subject: [PATCH 3/3] #38 Checkbox for subscriber only content * #38 Checkbox for subscriber only content @link https://github.com/thenewinquiry/tni-core-functionality/issues/38 --- readme.txt | 9 +++++++-- tni-core-functionality.php | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/readme.txt b/readme.txt index 370d4dd..4117186 100644 --- a/readme.txt +++ b/readme.txt @@ -2,8 +2,8 @@ Contributors: misfist Tags: custom Requires at least: 4.7 -Tested up to: 4.8 -Version: 1.2.12 +Tested up to: 4.8.2 +Version: 1.2.13 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -22,6 +22,11 @@ This section describes how to install the plugin and get it working. == Changelog == += 1.2.13 October 10, 2017 = +* #38 Checkbox for subscriber only content @link https://github.com/thenewinquiry/tni-core-functionality/issues/38 + * Added `subscriber_only` boolean field + * Updated `tni_is_subscription_only` function to fetch posts where `subscriber_only` is true + = 1.2.12 October 3, 2017 = * Added tags (`post_tag`) taxonomy to blogs post type @link https://github.com/thenewinquiry/tni-theme/issues/91 diff --git a/tni-core-functionality.php b/tni-core-functionality.php index 2bf8d1d..640450d 100644 --- a/tni-core-functionality.php +++ b/tni-core-functionality.php @@ -10,7 +10,7 @@ * Text Domain: tni-core * Domain Path: /languages * - * Version: 1.2.12 + * Version: 1.2.13 * * @package Tni_Core_Functionality */ @@ -52,7 +52,7 @@ * @return object Tni_Core */ function Tni_Core() { - $instance = Tni_Core::instance( __FILE__, 'l.2.12' ); + $instance = Tni_Core::instance( __FILE__, 'l.2.13' ); return $instance; }