Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
torounit committed May 23, 2022
1 parent 09f3f84 commit d00ec81
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
4 changes: 4 additions & 0 deletions includes/Schedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ public function get_term(): ?WP_Term {
return null;
}

if ( ! $term ) {
return null;
}

return $term;
}

Expand Down
14 changes: 9 additions & 5 deletions includes/Term_Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Term_Manager {
/**
* Constructor.
*
* @param string $post_meta_key Post meta key.
* @param string $post_meta_key Post meta key.
* @param int|null $time timestamp.
*/
public function __construct( string $post_meta_key, int $time = null ) {
Expand Down Expand Up @@ -91,11 +91,11 @@ public function update_schedule( int $post_id ) {
if ( ! $schedule->is_expired( $this->time ) ) {
$time = $schedule->get_timestamp();
$params = array( $post_id, $schedule->get_taxonomy(), $schedule->get_term() );
wp_clear_scheduled_hook( 'schedule_terms_attach_post_term_relations', $params );
wp_clear_scheduled_hook( 'schedule_terms_detach_post_term_relations', $params );
if ( $schedule->get_type() === 'attach' ) {
wp_clear_scheduled_hook( 'schedule_terms_attach_post_term_relations', $params );
wp_schedule_single_event( $time, 'schedule_terms_attach_post_term_relations', $params );
} else {
wp_clear_scheduled_hook( 'schedule_terms_detach_post_term_relations', $params );
wp_schedule_single_event( $time, 'schedule_terms_detach_post_term_relations', $params );
}
}
Expand All @@ -113,7 +113,9 @@ public function attach_post_term_relations( int $post_id ) {
foreach ( $this->get_filtered_schedules( $post_id, 'attach' ) as $schedule ) {
if ( $schedule->is_expired( $this->time ) ) {
$term = $schedule->get_term();
wp_set_post_terms( $post_id, array( $term->term_id ), $schedule->get_taxonomy(), true );
if ( $term ) {
wp_set_post_terms( $post_id, array( $term->term_id ), $schedule->get_taxonomy(), true );
}
}
}
}
Expand All @@ -129,7 +131,9 @@ public function detach_post_term_relations( int $post_id ) {
foreach ( $this->get_filtered_schedules( $post_id, 'detach' ) as $schedule ) {
if ( $schedule->is_expired( $this->time ) ) {
$term = $schedule->get_term();
wp_remove_object_terms( $post_id, $term->term_id, $schedule->get_taxonomy() );
if ( $term ) {
wp_remove_object_terms( $post_id, $term->term_id, $schedule->get_taxonomy() );
}
}
}
}
Expand Down

0 comments on commit d00ec81

Please sign in to comment.