Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Deleted terms are not removed from ES #2365

Closed
felipeelia opened this issue Sep 24, 2021 · 0 comments · Fixed by #2366
Closed

BUG: Deleted terms are not removed from ES #2365

felipeelia opened this issue Sep 24, 2021 · 0 comments · Fixed by #2366

Comments

@felipeelia
Copy link
Member

Describe the bug

Currently, if you delete a term, it will not be removed from the ES index, requiring a full re-index to sync terms again.

Steps to Reproduce

  1. Create a new term called Test Term
  2. Add the following code to your themes header.php, for debug purposes:
$terms = get_terms( array( 'taxonomy' => 'category', 'search' => 'test', 'hide_empty' => false, 'ep_integrate' => true, ) );
echo '<pre>';
print_r( $terms );
echo '</pre>';
  1. Visit the front end
  2. See [name] => Test Term
  3. Delete the term
  4. Visit the front end (refreshing)
  5. See [name] => Test Term still there

Expected behavior

After the term deletion, it should not be returned anymore.

Additional context
It seems we are trying to delete the term too late. So, when the code hits the current_user_can( 'delete_term', $term_id ) check inside ElasticPress\Indexable\Term\SyncManager::action_sync_on_delete() (here), the term does not exist anymore and current_user_can returns false.

Changing
add_action( 'delete_term', [ $this, 'action_sync_on_delete' ] );
to
add_action( 'pre_delete_term', [ $this, 'action_sync_on_delete' ] );
fixes the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant