wpseek.com
Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren



wp_ajax_add_link_category › WordPress Function

Seit3.1.0
Veraltetn/v
wp_ajax_add_link_category ( $action )
Parameter:
  • (string) $action Action to perform.
    Erforderlich: Ja
Definiert in:
Codex:

Handles adding a link category via AJAX.



Quellcode

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();
}