true,
]
);
$public = get_taxonomies(
[
'_builtin' => false,
'public' => true,
]
);
$private = get_taxonomies(
[
'_builtin' => false,
'public' => false,
]
);
$registered_taxonomies = array_merge( $core, $public, $private );
wp_localize_script(
'cptui',
'cptui_tax_data',
[
'confirm' => esc_html__( 'Are you sure you want to delete this? Deleting will NOT remove created content.', 'custom-post-type-ui' ),
'no_associated_type' => esc_html__( 'Please select a post type to associate with.', 'custom-post-type-ui' ),
'existing_taxonomies' => $registered_taxonomies,
]
);
}
add_action( 'admin_enqueue_scripts', 'cptui_taxonomies_enqueue_scripts' );
/**
* Register our tabs for the Taxonomy screen.
*
* @since 1.3.0
*
* @internal
*
* @param array $tabs Array of tabs to display. Optional.
* @param string $current_page Current page being shown. Optional. Default empty string.
* @return array Amended array of tabs to show.
*/
function cptui_taxonomy_tabs( $tabs = [], $current_page = '' ) {
if ( 'taxonomies' === $current_page ) {
$taxonomies = cptui_get_taxonomy_data();
$classes = [ 'nav-tab' ];
$tabs['page_title'] = get_admin_page_title();
$tabs['tabs'] = [];
$tabs['tabs']['add'] = [ // Start out with our basic "Add new" tab.
'text' => esc_html__( 'Add New Taxonomy', 'custom-post-type-ui' ),
'classes' => $classes,
'url' => cptui_admin_url( 'admin.php?page=cptui_manage_' . $current_page ),
'aria-selected' => 'false',
];
$action = cptui_get_current_action();
if ( empty( $action ) ) {
$tabs['tabs']['add']['classes'][] = 'nav-tab-active';
$tabs['tabs']['add']['aria-selected'] = 'true';
}
if ( ! empty( $taxonomies ) ) {
if ( ! empty( $action ) ) {
$classes[] = 'nav-tab-active';
}
$tabs['tabs']['edit'] = [
'text' => esc_html__( 'Edit Taxonomies', 'custom-post-type-ui' ),
'classes' => $classes,
'url' => esc_url( add_query_arg( [ 'action' => 'edit' ], cptui_admin_url( 'admin.php?page=cptui_manage_' . $current_page ) ) ),
'aria-selected' => ! empty( $action ) ? 'true' : 'false',
];
$tabs['tabs']['view'] = [
'text' => esc_html__( 'View Taxonomies', 'custom-post-type-ui' ),
'classes' => [ 'nav-tab' ], // Prevent notices.
'url' => esc_url( cptui_admin_url( 'admin.php?page=cptui_listings#taxonomies' ) ),
'aria-selected' => 'false',
];
$tabs['tabs']['export'] = [
'text' => esc_html__( 'Import/Export Taxonomies', 'custom-post-type-ui' ),
'classes' => [ 'nav-tab' ], // Prevent notices.
'url' => esc_url( cptui_admin_url( 'admin.php?page=cptui_tools&action=taxonomies' ) ),
'aria-selected' => 'false',
];
}
}
return $tabs;
}
add_filter( 'cptui_get_tabs', 'cptui_taxonomy_tabs', 10, 2 );
/**
* Create our settings page output.
*
* @since 1.0.0
*
* @internal
*/
function cptui_manage_taxonomies() {
$tab = ( ! empty( $_GET ) && ! empty( $_GET['action'] ) && 'edit' == $_GET['action'] ) ? 'edit' : 'new'; // phpcs:ignore.
$tab_class = 'cptui-' . $tab;
$current = null;
?>
$tax['name'],
'text' => $text,
];
}
$current = cptui_get_current_taxonomy();
$select['selected'] = $current;
/**
* Filters the taxonomy dropdown options before rendering.
*
* @since 1.6.0
*
* @param array $select Array of options for the dropdown.
* @param array $taxonomies Array of original passed in post types.
*/
$select = apply_filters( 'cptui_taxonomies_dropdown_options', $select, $taxonomies );
echo $ui->get_select_input( // phpcs:ignore.
[
'namearray' => 'cptui_selected_taxonomy',
'name' => 'taxonomy',
'selections' => $select, // phpcs:ignore.
'wrap' => false,
]
);
}
}
/**
* Get the selected taxonomy from the $_POST global.
*
* @since 1.0.0
*
* @internal
*
* @param bool $taxonomy_deleted Whether or not a taxonomy was recently deleted. Optional. Default false.
* @return bool|string False on no result, sanitized taxonomy if set.
*/
function cptui_get_current_taxonomy( $taxonomy_deleted = false ) {
$tax = false;
if ( ! empty( $_POST ) ) {
if ( ! empty( $_POST['cptui_select_taxonomy_nonce_field'] ) ) {
check_admin_referer( 'cptui_select_taxonomy_nonce_action', 'cptui_select_taxonomy_nonce_field' );
}
if ( isset( $_POST['cptui_selected_taxonomy']['taxonomy'] ) ) {
$tax = sanitize_text_field( wp_unslash( $_POST['cptui_selected_taxonomy']['taxonomy'] ) );
} elseif ( $taxonomy_deleted ) {
$taxonomies = cptui_get_taxonomy_data();
$tax = key( $taxonomies );
} elseif ( isset( $_POST['cpt_custom_tax']['name'] ) ) {
// Return the submitted value.
if ( ! in_array( $_POST['cpt_custom_tax']['name'], cptui_reserved_taxonomies(), true ) ) {
$tax = sanitize_text_field( wp_unslash( $_POST['cpt_custom_tax']['name'] ) );
} else {
// Return the original value since user tried to submit a reserved term.
$tax = sanitize_text_field( wp_unslash( $_POST['tax_original'] ) ); // phpcs:ignore.
}
}
} elseif ( ! empty( $_GET ) && isset( $_GET['cptui_taxonomy'] ) ) {
$tax = sanitize_text_field( wp_unslash( $_GET['cptui_taxonomy'] ) );
} else {
$taxonomies = cptui_get_taxonomy_data();
if ( ! empty( $taxonomies ) ) {
// Will return the first array key.
$tax = key( $taxonomies );
}
}
/**
* Filters the current taxonomy to edit.
*
* @since 1.3.0
*
* @param string $tax Taxonomy slug.
*/
return apply_filters( 'cptui_current_taxonomy', $tax );
}
/**
* Delete our custom taxonomy from the array of taxonomies.
*
* @since 1.0.0
*
* @internal
*
* @param array $data The $_POST values. Optional.
* @return bool|string False on failure, string on success.
*/
function cptui_delete_taxonomy( $data = [] ) {
if ( is_string( $data ) && taxonomy_exists( $data ) ) {
$slug = $data;
$data = [];
$data['name'] = $slug;
}
// Check if they selected one to delete.
if ( empty( $data['name'] ) ) {
return cptui_admin_notices( 'error', '', false, esc_html__( 'Please provide a taxonomy to delete', 'custom-post-type-ui' ) );
}
/**
* Fires before a taxonomy is deleted from our saved options.
*
* @since 1.0.0
*
* @param array $data Array of taxonomy data we are deleting.
*/
do_action( 'cptui_before_delete_taxonomy', $data );
$taxonomies = cptui_get_taxonomy_data();
if ( array_key_exists( strtolower( $data['name'] ), $taxonomies ) ) {
unset( $taxonomies[ $data['name'] ] );
/**
* Filters whether or not 3rd party options were saved successfully within taxonomy deletion.
*
* @since 1.3.0
*
* @param bool $value Whether or not someone else saved successfully. Default false.
* @param array $taxonomies Array of our updated taxonomies data.
* @param array $data Array of submitted taxonomy to update.
*/
if ( false === ( $success = apply_filters( 'cptui_taxonomy_delete_tax', false, $taxonomies, $data ) ) ) { // phpcs:ignore.
$success = update_option( 'cptui_taxonomies', $taxonomies );
}
}
delete_option( "default_term_{$data['name']}" );
/**
* Fires after a taxonomy is deleted from our saved options.
*
* @since 1.0.0
*
* @param array $data Array of taxonomy data that was deleted.
*/
do_action( 'cptui_after_delete_taxonomy', $data );
// Used to help flush rewrite rules on init.
set_transient( 'cptui_flush_rewrite_rules', 'true', 5 * 60 );
if ( isset( $success ) ) {
return 'delete_success';
}
return 'delete_fail';
}
/**
* Add to or update our CPTUI option with new data.
*
* @since 1.0.0
*
* @internal
*
* @param array $data Array of taxonomy data to update. Optional.
* @return bool|string False on failure, string on success.
*/
function cptui_update_taxonomy( $data = [] ) {
/**
* Fires before a taxonomy is updated to our saved options.
*
* @since 1.0.0
*
* @param array $data Array of taxonomy data we are updating.
*/
do_action( 'cptui_before_update_taxonomy', $data );
// They need to provide a name.
if ( empty( $data['cpt_custom_tax']['name'] ) ) {
return cptui_admin_notices( 'error', '', false, esc_html__( 'Please provide a taxonomy name', 'custom-post-type-ui' ) );
}
// Maybe a little harsh, but we shouldn't be saving THAT frequently.
delete_option( "default_term_{$data['cpt_custom_tax']['name']}" );
if ( empty( $data['cpt_post_types'] ) ) {
add_filter( 'cptui_custom_error_message', 'cptui_empty_cpt_on_taxonomy' );
return 'error';
}
if ( ! empty( $data['tax_original'] ) && $data['tax_original'] !== $data['cpt_custom_tax']['name'] ) {
if ( ! empty( $data['update_taxonomy'] ) ) {
add_filter( 'cptui_convert_taxonomy_terms', '__return_true' );
}
}
foreach ( $data as $key => $value ) {
if ( is_string( $value ) ) {
$data[ $key ] = sanitize_text_field( $value );
} else {
array_map( 'sanitize_text_field', $data[ $key ] );
}
}
if ( false !== strpos( $data['cpt_custom_tax']['name'], '\'' ) ||
false !== strpos( $data['cpt_custom_tax']['name'], '\"' ) ||
false !== strpos( $data['cpt_custom_tax']['rewrite_slug'], '\'' ) ||
false !== strpos( $data['cpt_custom_tax']['rewrite_slug'], '\"' ) ) {
add_filter( 'cptui_custom_error_message', 'cptui_slug_has_quotes' );
return 'error';
}
$taxonomies = cptui_get_taxonomy_data();
/**
* Check if we already have a post type of that name.
*
* @since 1.3.0
*
* @param bool $value Assume we have no conflict by default.
* @param string $value Post type slug being saved.
* @param array $post_types Array of existing post types from CPTUI.
*/
$slug_exists = apply_filters( 'cptui_taxonomy_slug_exists', false, $data['cpt_custom_tax']['name'], $taxonomies );
if ( true === $slug_exists ) {
add_filter( 'cptui_custom_error_message', 'cptui_slug_matches_taxonomy' );
return 'error';
}
if ( empty( $data['cpt_tax_labels'] ) || ! is_array( $data['cpt_tax_labels'] ) ) {
$data['cpt_tax_labels'] = [];
}
foreach ( $data['cpt_tax_labels'] as $key => $label ) {
if ( empty( $label ) ) {
unset( $data['cpt_tax_labels'][ $key ] );
}
$label = str_replace( '"', '', htmlspecialchars_decode( $label ) );
$label = htmlspecialchars( $label, ENT_QUOTES );
$label = trim( $label );
$data['cpt_tax_labels'][ $key ] = stripslashes_deep( $label );
}
$label = ucwords( str_replace( '_', ' ', $data['cpt_custom_tax']['name'] ) );
if ( ! empty( $data['cpt_custom_tax']['label'] ) ) {
$label = str_replace( '"', '', htmlspecialchars_decode( $data['cpt_custom_tax']['label'] ) );
$label = htmlspecialchars( stripslashes( $label ), ENT_QUOTES );
}
$name = trim( $data['cpt_custom_tax']['name'] );
$singular_label = ucwords( str_replace( '_', ' ', $data['cpt_custom_tax']['name'] ) );
if ( ! empty( $data['cpt_custom_tax']['singular_label'] ) ) {
$singular_label = str_replace( '"', '', htmlspecialchars_decode( $data['cpt_custom_tax']['singular_label'] ) );
$singular_label = htmlspecialchars( stripslashes( $singular_label ) );
}
$description = stripslashes_deep( $data['cpt_custom_tax']['description'] );
$query_var_slug = trim( $data['cpt_custom_tax']['query_var_slug'] );
$rewrite_slug = trim( $data['cpt_custom_tax']['rewrite_slug'] );
$rest_base = trim( $data['cpt_custom_tax']['rest_base'] );
$rest_controller_class = trim( $data['cpt_custom_tax']['rest_controller_class'] );
$rest_namespace = trim( $data['cpt_custom_tax']['rest_namespace'] );
$show_quickpanel_bulk = ! empty( $data['cpt_custom_tax']['show_in_quick_edit'] ) ? disp_boolean( $data['cpt_custom_tax']['show_in_quick_edit'] ) : '';
$default_term = trim( $data['cpt_custom_tax']['default_term'] );
$meta_box_cb = trim( $data['cpt_custom_tax']['meta_box_cb'] );
// We may or may not need to force a boolean false keyword.
$maybe_false = strtolower( trim( $data['cpt_custom_tax']['meta_box_cb'] ) );
if ( 'false' === $maybe_false ) {
$meta_box_cb = $maybe_false;
}
$taxonomies[ $data['cpt_custom_tax']['name'] ] = [
'name' => $name,
'label' => $label,
'singular_label' => $singular_label,
'description' => $description,
'public' => disp_boolean( $data['cpt_custom_tax']['public'] ),
'publicly_queryable' => disp_boolean( $data['cpt_custom_tax']['publicly_queryable'] ),
'hierarchical' => disp_boolean( $data['cpt_custom_tax']['hierarchical'] ),
'show_ui' => disp_boolean( $data['cpt_custom_tax']['show_ui'] ),
'show_in_menu' => disp_boolean( $data['cpt_custom_tax']['show_in_menu'] ),
'show_in_nav_menus' => disp_boolean( $data['cpt_custom_tax']['show_in_nav_menus'] ),
'query_var' => disp_boolean( $data['cpt_custom_tax']['query_var'] ),
'query_var_slug' => $query_var_slug,
'rewrite' => disp_boolean( $data['cpt_custom_tax']['rewrite'] ),
'rewrite_slug' => $rewrite_slug,
'rewrite_withfront' => $data['cpt_custom_tax']['rewrite_withfront'],
'rewrite_hierarchical' => $data['cpt_custom_tax']['rewrite_hierarchical'],
'show_admin_column' => disp_boolean( $data['cpt_custom_tax']['show_admin_column'] ),
'show_in_rest' => disp_boolean( $data['cpt_custom_tax']['show_in_rest'] ),
'show_tagcloud' => disp_boolean( $data['cpt_custom_tax']['show_tagcloud'] ),
'sort' => disp_boolean( $data['cpt_custom_tax']['sort'] ),
'show_in_quick_edit' => $show_quickpanel_bulk,
'rest_base' => $rest_base,
'rest_controller_class' => $rest_controller_class,
'rest_namespace' => $rest_namespace,
'labels' => $data['cpt_tax_labels'],
'meta_box_cb' => $meta_box_cb,
'default_term' => $default_term,
];
$taxonomies[ $data['cpt_custom_tax']['name'] ]['object_types'] = $data['cpt_post_types'];
/**
* Filters final data to be saved right before saving taxoomy data.
*
* @since 1.6.0
*
* @param array $taxonomies Array of final taxonomy data to save.
* @param string $name Taxonomy slug for taxonomy being saved.
*/
$taxonomies = apply_filters( 'cptui_pre_save_taxonomy', $taxonomies, $name );
/**
* Filters whether or not 3rd party options were saved successfully within taxonomy add/update.
*
* @since 1.3.0
*
* @param bool $value Whether or not someone else saved successfully. Default false.
* @param array $taxonomies Array of our updated taxonomies data.
* @param array $data Array of submitted taxonomy to update.
*/
if ( false === ( $success = apply_filters( 'cptui_taxonomy_update_save', false, $taxonomies, $data ) ) ) { // phpcs:ignore.
$success = update_option( 'cptui_taxonomies', $taxonomies );
}
/**
* Fires after a taxonomy is updated to our saved options.
*
* @since 1.0.0
*
* @param array $data Array of taxonomy data that was updated.
*/
do_action( 'cptui_after_update_taxonomy', $data );
// Used to help flush rewrite rules on init.
set_transient( 'cptui_flush_rewrite_rules', 'true', 5 * 60 );
if ( isset( $success ) && 'new' === $data['cpt_tax_status'] ) {
return 'add_success';
}
return 'update_success';
}
/**
* Return an array of names that users should not or can not use for taxonomy names.
*
* @since 1.3.0
*
* @return array $value Array of names that are recommended against.
*/
function cptui_reserved_taxonomies() {
$reserved = [
'action',
'attachment',
'attachment_id',
'author',
'author_name',
'calendar',
'cat',
'category',
'category__and',
'category__in',
'category__not_in',
'category_name',
'comments_per_page',
'comments_popup',
'cpage',
'custom',
'customize_messenger_channel',
'customized',
'date',
'day',
'debug',
'embed',
'error',
'exact',
'feed',
'fields',
'hour',
'include',
'link_category',
'm',
'minute',
'monthnum',
'more',
'name',
'nav_menu',
'nonce',
'nopaging',
'offset',
'order',
'orderby',
'output',
'p',
'page',
'page_id',
'paged',
'pagename',
'pb',
'perm',
'post',
'post__in',
'post__not_in',
'post_format',
'post_mime_type',
'post_status',
'post_tag',
'post_type',
'posts',
'posts_per_archive_page',
'posts_per_page',
'preview',
'robots',
's',
'search',
'search_terms',
'second',
'sentence',
'showposts',
'static',
'status',
'subpost',
'subpost_id',
'tag',
'tag__and',
'tag__in',
'tag__not_in',
'tag_id',
'tag_slug__and',
'tag_slug__in',
'taxonomy',
'tb',
'term',
'terms',
'theme',
'themes',
'title',
'type',
'types',
'w',
'withcomments',
'withoutcomments',
'year',
];
/**
* Filters the list of reserved post types to check against.
* 3rd party plugin authors could use this to prevent duplicate post types.
*
* @since 1.0.0
*
* @param array $value Array of post type slugs to forbid.
*/
$custom_reserved = apply_filters( 'cptui_reserved_taxonomies', [] );
if ( is_string( $custom_reserved ) && ! empty( $custom_reserved ) ) {
$reserved[] = $custom_reserved;
} elseif ( is_array( $custom_reserved ) && ! empty( $custom_reserved ) ) {
foreach ( $custom_reserved as $slug ) {
$reserved[] = $slug;
}
}
return $reserved;
}
/**
* Convert taxonomies.
*
* @since 1.3.0
*
* @internal
*
* @param string $original_slug Original taxonomy slug. Optional. Default empty string.
* @param string $new_slug New taxonomy slug. Optional. Default empty string.
*/
function cptui_convert_taxonomy_terms( $original_slug = '', $new_slug = '' ) {
global $wpdb;
$args = [
'taxonomy' => $original_slug,
'hide_empty' => false,
'fields' => 'ids',
];
$term_ids = get_terms( $args );
if ( is_int( $term_ids ) ) {
$term_ids = (array) $term_ids;
}
if ( is_array( $term_ids ) && ! empty( $term_ids ) ) {
$term_ids = implode( ',', $term_ids );
$query = "UPDATE `{$wpdb->term_taxonomy}` SET `taxonomy` = %s WHERE `taxonomy` = %s AND `term_id` IN ( {$term_ids} )";
$wpdb->query( // phpcs:ignore.
$wpdb->prepare( $query, $new_slug, $original_slug ) // phpcs:ignore.
);
}
cptui_delete_taxonomy( $original_slug );
}
/**
* Checks if we are trying to register an already registered taxonomy slug.
*
* @since 1.3.0
*
* @param bool $slug_exists Whether or not the post type slug exists. Optional. Default false.
* @param string $taxonomy_slug The post type slug being saved. Optional. Default empty string.
* @param array $taxonomies Array of CPTUI-registered post types. Optional.
*
* @return bool
*/
function cptui_check_existing_taxonomy_slugs( $slug_exists = false, $taxonomy_slug = '', $taxonomies = [] ) {
// If true, then we'll already have a conflict, let's not re-process.
if ( true === $slug_exists ) {
return $slug_exists;
}
if ( ! is_array( $taxonomies ) ) {
return $slug_exists;
}
// Check if CPTUI has already registered this slug.
if ( array_key_exists( strtolower( $taxonomy_slug ), $taxonomies ) ) { // phpcs:ignore.
return true;
}
// Check if we're registering a reserved post type slug.
if ( in_array( $taxonomy_slug, cptui_reserved_taxonomies() ) ) { // phpcs:ignore.
return true;
}
// Check if other plugins have registered this same slug.
$public = get_taxonomies(
[
'_builtin' => false,
'public' => true,
]
);
$private = get_taxonomies(
[
'_builtin' => false,
'public' => false,
]
);
$registered_taxonomies = array_merge( $public, $private );
if ( in_array( $taxonomy_slug, $registered_taxonomies, true ) ) {
return true;
}
// If we're this far, it's false.
return $slug_exists;
}
add_filter( 'cptui_taxonomy_slug_exists', 'cptui_check_existing_taxonomy_slugs', 10, 3 );
/**
* Handle the save and deletion of taxonomy data.
*
* @since 1.4.0
*/
function cptui_process_taxonomy() {
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
if ( wp_doing_ajax() ) {
return;
}
if ( ! is_admin() ) {
return;
}
if ( ! empty( $_GET ) && isset( $_GET['page'] ) && 'cptui_manage_taxonomies' !== $_GET['page'] ) {
return;
}
if ( ! empty( $_POST ) ) {
$result = '';
if ( isset( $_POST['cpt_submit'] ) ) {
check_admin_referer( 'cptui_addedit_taxonomy_nonce_action', 'cptui_addedit_taxonomy_nonce_field' );
$data = cptui_filtered_taxonomy_post_global();
$result = cptui_update_taxonomy( $data );
} elseif ( isset( $_POST['cpt_delete'] ) ) {
check_admin_referer( 'cptui_addedit_taxonomy_nonce_action', 'cptui_addedit_taxonomy_nonce_field' );
$filtered_data = filter_input( INPUT_POST, 'cpt_custom_tax', FILTER_SANITIZE_SPECIAL_CHARS, FILTER_REQUIRE_ARRAY );
$result = cptui_delete_taxonomy( $filtered_data );
add_filter( 'cptui_taxonomy_deleted', '__return_true' );
}
if ( $result && is_callable( "cptui_{$result}_admin_notice" ) ) {
add_action( 'admin_notices', "cptui_{$result}_admin_notice" );
}
if ( isset( $_POST['cpt_delete'] ) && empty( cptui_get_taxonomy_slugs() ) ) {
wp_safe_redirect(
add_query_arg(
[ 'page' => 'cptui_manage_taxonomies' ],
cptui_admin_url( 'admin.php?page=cptui_manage_taxonomies' )
)
);
}
}
}
add_action( 'init', 'cptui_process_taxonomy', 8 );
/**
* Handle the conversion of taxonomy terms.
*
* This function came to be because we needed to convert AFTER registration.
*
* @since 1.4.3
*/
function cptui_do_convert_taxonomy_terms() {
/**
* Whether or not to convert taxonomy terms.
*
* @since 1.4.3
*
* @param bool $value Whether or not to convert.
*/
if ( apply_filters( 'cptui_convert_taxonomy_terms', false ) ) {
check_admin_referer( 'cptui_addedit_taxonomy_nonce_action', 'cptui_addedit_taxonomy_nonce_field' );
$original = filter_input( INPUT_POST, 'tax_original', FILTER_SANITIZE_SPECIAL_CHARS );
$new = filter_input( INPUT_POST, 'cpt_custom_tax', FILTER_SANITIZE_SPECIAL_CHARS, FILTER_REQUIRE_ARRAY );
// Return early if either fails to successfully validate.
if ( ! $original || ! $new ) {
return;
}
cptui_convert_taxonomy_terms( sanitize_text_field( $original ), sanitize_text_field( $new['name'] ) );
}
}
add_action( 'init', 'cptui_do_convert_taxonomy_terms' );
/**
* Handles slug_exist checks for cases of editing an existing taxonomy.
*
* @since 1.5.3
*
* @param bool $slug_exists Current status for exist checks.
* @param string $taxonomy_slug Taxonomy slug being processed.
* @param array $taxonomies CPTUI taxonomies.
* @return bool
*/
function cptui_updated_taxonomy_slug_exists( $slug_exists, $taxonomy_slug = '', $taxonomies = [] ) {
if (
( ! empty( $_POST['cpt_tax_status'] ) && 'edit' === $_POST['cpt_tax_status'] ) && // phpcs:ignore WordPress.Security.NonceVerification
! in_array( $taxonomy_slug, cptui_reserved_taxonomies(), true ) && // phpcs:ignore WordPress.Security.NonceVerification
( ! empty( $_POST['tax_original'] ) && $taxonomy_slug === $_POST['tax_original'] ) // phpcs:ignore WordPress.Security.NonceVerification
) {
$slug_exists = false;
}
return $slug_exists;
}
add_filter( 'cptui_taxonomy_slug_exists', 'cptui_updated_taxonomy_slug_exists', 11, 3 );
/**
* Sanitize and filter the $_POST global and return a reconstructed array of the parts we need.
*
* Used for when managing taxonomies.
*
* @since 1.10.0
* @return array
*/
function cptui_filtered_taxonomy_post_global() {
$filtered_data = [];
$default_arrays = [
'cpt_custom_tax',
'cpt_tax_labels',
'cpt_post_types',
'update_taxonomy',
];
$third_party_items_arrays = apply_filters(
'cptui_filtered_taxonomy_post_global_arrays',
(array) [] // phpcs:ignore.
);
$items_arrays = array_merge( $default_arrays, $third_party_items_arrays );
foreach ( $items_arrays as $item ) {
$first_result = filter_input( INPUT_POST, $item, FILTER_SANITIZE_SPECIAL_CHARS, FILTER_REQUIRE_ARRAY );
if ( $first_result ) {
$filtered_data[ $item ] = $first_result;
}
}
$default_strings = [
'tax_original',
'cpt_tax_status',
];
$third_party_items_strings = apply_filters(
'cptui_filtered_taxonomy_post_global_strings',
(array) [] // phpcs:ignore.
);
$items_strings = array_merge( $default_strings, $third_party_items_strings );
foreach ( $items_strings as $item ) {
$second_result = filter_input( INPUT_POST, $item, FILTER_SANITIZE_SPECIAL_CHARS );
if ( $second_result ) {
$filtered_data[ $item ] = $second_result;
}
}
return $filtered_data;
}