wpseek.com
A WordPress-centric search engine for devs and theme authors
wp_ajax_add_link_category › WordPress Function
Since3.1.0
Deprecatedn/a
› wp_ajax_add_link_category ( $action )
| Parameters: |
|
| Defined at: |
|
| Codex: |
Handles adding a link category via AJAX.
Source
function wp_ajax_add_link_category( $action ) {
if ( empty( $action ) ) {
$action = 'add-link-category';
}
check_ajax_referer( $action );
$taxonomy_object = get_taxonomy( 'link_category' );
if ( ! current_user_can( $taxonomy_object->cap->manage_terms ) ) {
wp_die( -1 );
}
$names = explode( ',', wp_unslash( $_POST['newcat'] ) );
$response = new WP_Ajax_Response();
foreach ( $names as $category_name ) {
$category_name = trim( $category_name );
$slug = sanitize_title( $category_name );
if ( '' === $slug ) {
continue;
}
$category_id = wp_insert_term( $category_name, 'link_category' );
if ( ! $category_id || is_wp_error( $category_id ) ) {
continue;
} else {
$category_id = $category_id['term_id'];
}
$category_name = esc_html( $category_name );
$response->add(
array(
'what' => 'link-category',
'id' => $category_id,
'data' => "<li id='link-category-$category_id'><label for='in-link-category-$category_id' class='selectit'><input value='" . esc_attr( $category_id ) . "' type='checkbox' checked='checked' name='link_category[]' id='in-link-category-$category_id'/> $category_name</label></li>",
'position' => -1,
)
);
}
$response->send();
}