Last active
July 6, 2023 12:16
-
-
Save dantetesta/053ab6b8ca35014dbfe78e490b961b13 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Author: Dante Testa | |
Date: 26/06/2023 | |
www.dantetesta.com.br | |
*/ | |
add_action( 'jet-form-builder/custom-action/add_tax', function( $request, $action_handler ) { | |
if (!isset($request['nome']) || !isset($request['taxonomia'])) { | |
return; | |
} | |
$terms = array_map('sanitize_text_field', explode(',', $request['nome'])); | |
$taxonomy = sanitize_text_field($request['taxonomia']); | |
if (!taxonomy_exists($taxonomy)) { | |
return; | |
} | |
foreach ($terms as $term) { | |
// Check if the term already exists | |
$existing_term = term_exists($term, $taxonomy); | |
// If the term doesn't exist and there was no error, create it | |
if ($existing_term === null) { | |
$result = wp_insert_term($term, $taxonomy); | |
if (is_wp_error($result)) { | |
// Handle the error here | |
} | |
} | |
} | |
}, 10, 2 ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment