taxonomy_meta_box_sanitize_cb_input

The timeline below displays how wordpress function taxonomy_meta_box_sanitize_cb_input has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 5.6

/**
 * Sanitizes POST values from an input taxonomy metabox.
 *
 * @since 5.1.0
 *
 * @param string       $taxonomy The taxonomy name.
 * @param array|string $terms    Raw term data from the 'tax_input' field.
 * @return array
 */
function taxonomy_meta_box_sanitize_cb_input($taxonomy, $terms)
{
    /*
     * Assume that a 'tax_input' string is a comma-separated list of term names.
     * Some languages may use a character other than a comma as a delimiter, so we standardize on
     * commas before parsing the list.
     */
    if (!is_array($terms)) {
        $comma = _x(',', 'tag delimiter');
        if (',' !== $comma) {
            $terms = str_replace($comma, ',', $terms);
        }
        $terms = explode(',', trim($terms, " \n\t\r\x00\v,"));
    }
    $clean_terms = array();
    foreach ($terms as $term) {
        // Empty terms are invalid input.
        if (empty($term)) {
            continue;
        }
        $_term = get_terms(array('taxonomy' => $taxonomy, 'name' => $term, 'fields' => 'ids', 'hide_empty' => false));
        if (!empty($_term)) {
            $clean_terms[] = (int) $_term[0];
        } else {
            // No existing term was found, so pass the string. A new term will be created.
            $clean_terms[] = $term;
        }
    }
    return $clean_terms;
}

WordPress Version: 5.4

/**
 * Sanitizes POST values from an input taxonomy metabox.
 *
 * @since 5.1.0
 *
 * @param string       $taxonomy The taxonomy name.
 * @param array|string $terms    Raw term data from the 'tax_input' field.
 * @return array
 */
function taxonomy_meta_box_sanitize_cb_input($taxonomy, $terms)
{
    /*
     * Assume that a 'tax_input' string is a comma-separated list of term names.
     * Some languages may use a character other than a comma as a delimiter, so we standardize on
     * commas before parsing the list.
     */
    if (!is_array($terms)) {
        $comma = _x(',', 'tag delimiter');
        if (',' !== $comma) {
            $terms = str_replace($comma, ',', $terms);
        }
        $terms = explode(',', trim($terms, " \n\t\r\x00\v,"));
    }
    $clean_terms = array();
    foreach ($terms as $term) {
        // Empty terms are invalid input.
        if (empty($term)) {
            continue;
        }
        $_term = get_terms(array('taxonomy' => $taxonomy, 'name' => $term, 'fields' => 'ids', 'hide_empty' => false));
        if (!empty($_term)) {
            $clean_terms[] = intval($_term[0]);
        } else {
            // No existing term was found, so pass the string. A new term will be created.
            $clean_terms[] = $term;
        }
    }
    return $clean_terms;
}

WordPress Version: 5.3

/**
 * Sanitizes POST values from an input taxonomy metabox.
 *
 * @since 5.1.0
 *
 * @param mixed $terms Raw term data from the 'tax_input' field.
 * @return array
 */
function taxonomy_meta_box_sanitize_cb_input($taxonomy, $terms)
{
    /*
     * Assume that a 'tax_input' string is a comma-separated list of term names.
     * Some languages may use a character other than a comma as a delimiter, so we standardize on
     * commas before parsing the list.
     */
    if (!is_array($terms)) {
        $comma = _x(',', 'tag delimiter');
        if (',' !== $comma) {
            $terms = str_replace($comma, ',', $terms);
        }
        $terms = explode(',', trim($terms, " \n\t\r\x00\v,"));
    }
    $clean_terms = array();
    foreach ($terms as $term) {
        // Empty terms are invalid input.
        if (empty($term)) {
            continue;
        }
        $_term = get_terms(array('taxonomy' => $taxonomy, 'name' => $term, 'fields' => 'ids', 'hide_empty' => false));
        if (!empty($_term)) {
            $clean_terms[] = intval($_term[0]);
        } else {
            // No existing term was found, so pass the string. A new term will be created.
            $clean_terms[] = $term;
        }
    }
    return $clean_terms;
}

WordPress Version: 5.1

/**
 * Sanitizes POST values from an input taxonomy metabox.
 *
 * @since 5.1.0
 *
 * @param mixed $terms Raw term data from the 'tax_input' field.
 * @return array
 */
function taxonomy_meta_box_sanitize_cb_input($taxonomy, $terms)
{
    /*
     * Assume that a 'tax_input' string is a comma-separated list of term names.
     * Some languages may use a character other than a comma as a delimiter, so we standardize on
     * commas before parsing the list.
     */
    if (!is_array($terms)) {
        $comma = _x(',', 'tag delimiter');
        if (',' !== $comma) {
            $terms = str_replace($comma, ',', $terms);
        }
        $terms = explode(',', trim($terms, " \n\t\r\x00\v,"));
    }
    $clean_terms = array();
    foreach ($terms as $term) {
        // Empty terms are invalid input.
        if (empty($term)) {
            continue;
        }
        $_term = get_terms($taxonomy, array('name' => $term, 'fields' => 'ids', 'hide_empty' => false));
        if (!empty($_term)) {
            $clean_terms[] = intval($_term[0]);
        } else {
            // No existing term was found, so pass the string. A new term will be created.
            $clean_terms[] = $term;
        }
    }
    return $clean_terms;
}