Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Automatically create categories for chatbots based on URL query
- *
- * Use like this: [site_reviews assigned_terms="chatbot_id"]
- *
- * @param int $ttid
- * @param string|int $term
- * @param string $taxonomy
- *
- * @return int
- */
- add_filter('site-reviews/assigned_terms/term_id', function ($ttid, $term, $taxonomy) {
- if (!empty($ttid) || 'chatbot_id' !== $term) {
- return $ttid;
- }
- $url = filter_input(INPUT_SERVER, 'REQUEST_URI');
- $path = wp_parse_url($url, PHP_URL_PATH);
- $query = wp_parse_args(wp_parse_url($url, PHP_URL_QUERY));
- if ('/chat/' !== $path) {
- return $ttid;
- }
- $chatbot = $query['id'] ?? '';
- if (!str_starts_with($chatbot, 'chatbot-') || 'chatbot-' === $chatbot) {
- return $ttid;
- }
- require_once ABSPATH.'wp-admin/includes/taxonomy.php';
- $term = wp_create_term($chatbot, $taxonomy);
- if (is_wp_error($term)) {
- return $ttid;
- }
- return $term['term_taxonomy_id'] ?? 0;
- }, 10, 3);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement