Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
dparker1005 committed Oct 16, 2020
2 parents 9e19de3 + 5120ae2 commit 9c21f4c
Show file tree
Hide file tree
Showing 6 changed files with 888 additions and 669 deletions.
49 changes: 40 additions & 9 deletions classes/class.pmproseries.php
Expand Up @@ -127,13 +127,27 @@ function removePost( $post_id ) {
* [getPosts] Get array of all posts in this series.
* force = ignore cache and get data from DB.
*
* @param boolean
* @param boolean $force update from database.
* @param null|string $status of posts to return.
* @return array of posts with status, if applicable. $this->posts will not be filtered by $status.
*/
function getPosts( $force = false ) {
function getPosts( $force = false, $status = null ) {
if ( ! isset( $this->posts ) || $force ) {
$this->posts = get_post_meta( $this->id, '_series_posts', true );
if ( ! is_array( $this->posts ) ) {
$this->posts = array();
}
}

if ( ! empty( $status ) ) {
$posts_with_status = array();
foreach ($this->posts as $key => $post) {
if ( $status === get_post_status( $post->id ) ) {
$posts_with_status[] = $post;
}
}
return $posts_with_status;
}
return $this->posts;
}

Expand Down Expand Up @@ -197,6 +211,23 @@ function getDelayForPost( $post_id ) {
}
}

/**
* [getLongestPostDelay]
*
* @param null|string $status of posts to consider.
* @return int longest post delay.
*/
function getLongestPostDelay( $status = null ) {
$posts = $this->getPosts( false, $status );
$delay = 0;
foreach ( $posts as $post ) {
if ( ! empty( $post->delay ) && $post->delay > $delay ) {
$delay = $post->delay;
}
}
return $delay;
}

/**
* [sortByDelay] Sort posts by delay.
*
Expand Down Expand Up @@ -252,7 +283,7 @@ function sendEmail( $post_ids, $user_id ) {
$email->subject = sprintf( __( 'New content is available at %s', 'pmpro-series' ), get_option( 'blogname' ) );
$email->template = 'new_content';

$email->body .= file_get_contents( dirname( __FILE__ ) . '/email/new_content.html' );
$email->body .= file_get_contents( $template_path );

$email->data = array(
'name' => $user->display_name,
Expand Down Expand Up @@ -375,33 +406,33 @@ static function seriesMetaBox() {
*/
function getPostList( $echo = false ) {
global $current_user;
$this->getPosts();
if ( ! empty( $this->posts ) ) {
$posts = $this->getPosts( false, 'publish' );
if ( ! empty( $posts ) ) {
ob_start();
?>

<ul id="pmpro_series-<?php echo $this->id; ?>" class="pmpro_series_list">
<?php
$member_days = pmpro_getMemberDays( $current_user->ID );
$post_list_posts = $this->posts;
$post_list_posts = $posts;

// Filter to allow plugins to modify the posts included in the Series.
$post_list_posts = apply_filters('pmpro_series_post_list_posts', $post_list_posts, $this);

foreach ( $post_list_posts as $sp ) {
$days_left = ceil( $sp->delay - $member_days );
$date = date( get_option( 'date_format' ), strtotime( "+ $days_left Days", current_time( 'timestamp' ) ) );
$date = date_i18n( get_option( 'date_format' ), strtotime( "+ $days_left Days", current_time( 'timestamp' ) ) );
?>
<li class="pmpro_series_item-li-
<?php
if ( max( 0, $member_days ) >= $sp->delay ) {
if ( apply_filters( 'pmpro_series_override_delay', ( max( 0, $member_days ) >= $sp->delay ), $member_days, $sp->delay, $current_user->ID ) ) {
?>
available
<?php
} else {
?>
unavailable<?php } ?>">
<?php if ( max( 0, $member_days ) >= $sp->delay ) { ?>
<?php if ( apply_filters( 'pmpro_series_override_delay', ( max( 0, $member_days ) >= $sp->delay ), $member_days, $sp->delay, $current_user->ID ) ) { ?>
<span class="pmpro_series_item-title"><a href="<?php echo get_permalink( $sp->id ); ?>"><?php echo get_the_title( $sp->id ); ?></a></span>
<span class="pmpro_series_item-available"><a class="pmpro_btn pmpro_btn-primary" href="<?php echo get_permalink( $sp->id ); ?>"><?php _e( 'Available Now', 'pmpro-series' );?></a></span>
<?php } else { ?>
Expand Down
4 changes: 4 additions & 0 deletions css/pmpro-series-admin.css
Expand Up @@ -3,4 +3,8 @@
}
#postcustomstuff table input {
margin: 2px;
}

#newmeta .select2 {
width: 100%;
}

0 comments on commit 9c21f4c

Please sign in to comment.