wp_ajax_add_link_category( string $action )
- Since
- 3.1.0
- Source
wp-admin/includes/ajax-actions.php:1040
Compatibility
- WordPress
- since 3.1.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$actionstring- Action to perform.
Performance profile
How much work a call to wp_ajax_add_link_category() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Heavy
- Scaling
- Scales with input
- Instructions
- 36–41
- Plugin surface
- None
- Called by
- 0
Reaches the database via get_terms().
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 88.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- hookthird-party callbacks
do_action()one call below wp_ajax_add_link_category() - querycontent query
get_terms()one call below wp_ajax_add_link_category()
Further down the call graph this can also reach option, cache, serialize and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 2 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_ajax_add_link_category() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
current_user_can() | 36–38 | check_ajax_referer(), get_taxonomy(), current_user_can(), wp_unslash(), explode(), ->send() |
!current_user_can() | 39–41 | check_ajax_referer(), get_taxonomy(), current_user_can(), wp_die(), wp_unslash(), explode(), ->send() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 88 | 36–41 | 7 | |
| 8.5 | 88 | 36–41 | 7 | |
| 8.4 | 88 | 36–41 | 7 | 2 fewer instructions than PHP 8.3 |
| 8.3 | 90 | 36–41 | 7 | |
| 8.2 | 90 | 36–41 | 7 | |
| 8.1 | 90 | 36–41 | 7 | |
| 7.4 | 90 | 36–41 | 7 |
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Uses · 11
- check_ajax_referer()Verifies the Ajax request to prevent processing requests external of the blog.
- get_taxonomy()Retrieves the taxonomy object of $taxonomy.
- current_user_can()Returns whether the current user has the specified capability.
- wp_die()Kills WordPress execution and displays HTML page with an error message.
- wp_unslash()Removes slashes from a string or recursively removes slashes from strings within an array.
- sanitize_title()Sanitizes a string into a slug, which can be used in URLs or HTML attributes.
- wp_insert_term()Adds a new term to the database.
- is_wp_error()Checks whether the given variable is a WordPress Error.
- esc_html()Escaping for HTML blocks.
- esc_attr()Escaping for HTML attributes.
- WP_Ajax_Response::__construct()Constructor - Passes args to WP_Ajax_Response::add().
Source code
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'] ) ); $x = new WP_Ajax_Response(); foreach ( $names as $cat_name ) { $cat_name = trim( $cat_name ); $slug = sanitize_title( $cat_name ); if ( '' === $slug ) { continue; } $cat_id = wp_insert_term( $cat_name, 'link_category' ); if ( ! $cat_id || is_wp_error( $cat_id ) ) { continue; } else { $cat_id = $cat_id['term_id']; } $cat_name = esc_html( $cat_name ); $x->add( array( 'what' => 'link-category', 'id' => $cat_id, 'data' => "<li id='link-category-$cat_id'><label for='in-link-category-$cat_id' class='selectit'><input value='" . esc_attr( $cat_id ) . "' type='checkbox' checked='checked' name='link_category[]' id='in-link-category-$cat_id'/> $cat_name</label></li>", 'position' => -1, ) ); } $x->send();}Changelog
Introduced in 3.1.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.9.7 tag, from
src/wp-admin/includes/ajax-actions.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.