Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Modify the review values before they are saved
- * Paste this in your active theme's functions.php file.
- */
- add_filter('site-reviews/create/review-values', function (array $values): array {
- // skip category assignment if the review title is empty
- if (empty($values['title'])) {
- return $values;
- }
- // skip category assignment if the review content is empty
- if (empty($values['content'])) {
- return $values;
- }
- // create the category if it doesn't already exist
- $term = wp_create_term('full-review', glsr()->taxonomy);
- if (is_wp_error($term)) {
- // log the error if the category couldn't be created
- glsr_log()->error($term->get_error_message());
- return $values;
- }
- if (!empty($term['term_taxonomy_id'])) {
- // assign the new review to the category
- $values['assigned_terms'][] = $term['term_taxonomy_id'];
- }
- return $values;
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement