Skip to content

Commit

Permalink
Use post object for future action
Browse files Browse the repository at this point in the history
  • Loading branch information
keesiemeijer committed Dec 5, 2019
1 parent a748c94 commit 782a7b6
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions includes/post_type.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class CPTDA_Post_Types {
*/
private $post_types = array();

private $name;

public function __construct() {
add_action( 'wp_loaded', array( $this, 'setup' ) );
}
Expand Down Expand Up @@ -153,20 +155,21 @@ private function publish_scheduled_posts() {
}

foreach ( $future_types as $name ) {
remove_action( "future_{$name}", '_future_post_hook' );
add_action( "future_{$name}", array( $this, '_future_post_hook' ) );
remove_action( 'future_' . $name, '_future_post_hook', 5, 2 );
add_action( "future_{$name}", array( $this, '_future_post_hook' ), 10 , 2 );
}
}

/**
* Set new post's post_status to "publish" if the post is sceduled.
*
* @since 1.2.0
* @param int $post_id Post ID.
* @param int $post_id Post ID (deprecated argument).
* @param WP_Post $post Post object.
* @return void
*/
public function _future_post_hook( $post_id ) {
$post = get_post( $post_id );
public function _future_post_hook( $post_id, $post ) {
$post = get_post( $post );

/**
* Filter whether to publish posts with future dates from a specific post type.
Expand All @@ -176,7 +179,7 @@ public function _future_post_hook( $post_id ) {
*/
$publish = apply_filters( "cptda_publish_future_{$post->post_type}", true );
if ( (bool) $publish ) {
wp_publish_post( $post_id );
wp_publish_post( $post );
}
}

Expand Down

0 comments on commit 782a7b6

Please sign in to comment.