taxonomy_meta_box_sanitize_cb_input

函数
taxonomy_meta_box_sanitize_cb_input ( $taxonomy, $terms )
参数
  • (string) $taxonomy The taxonomy name.
    Required:
  • (array|string) $terms Raw term data from the 'tax_input' field.
    Required:
返回值
  • (array)
定义位置
相关方法
taxonomy_meta_box_sanitize_cb_checkboxeswp_nav_menu_taxonomy_meta_boxestaxonomy_existsrest_sanitize_objectrest_sanitize_boolean
引入
5.1.0
弃用
-

taxonomy_meta_box_sanitize_cb_input: 此函数用于对带有输入字段的分类元框的输入进行净化。

从输入分类metabox中清理POST值。

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, " ntrx0B," ) );
	}

	$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;
}

常见问题

FAQs
查看更多 >
闪电侠

(工作日 10:00 - 18:30 为您服务)

2025-12-05 15:32:55

您好,无论是售前、售后、意见建议……均可通过联系工单与我们取得联系。

您也可选择聊天工具与我们即时沟通或点击查看:

您的工单我们已经收到,我们将会尽快跟您联系!
取消
选择聊天工具: