wppaste
WordPress

wp_ajax_add_meta()

Since
3.1.0
Source
wp-admin/includes/ajax-actions.php:1617
Handles adding meta via AJAX.

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.

Performance profile

How much work a call to wp_ajax_add_meta() 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

Reaches the database via get_post().

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
61–135

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 261.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What it touches

  • querycontent queryget_post()called directly
  • hookthird-party callbacksdo_action()one call below wp_ajax_add_meta()
  • serializeserialisationmaybe_unserialize()one call below wp_ajax_add_meta()
  • cacheobject cachewp_cache_delete()one call below wp_ajax_add_meta()

Further down the call graph this can also reach option 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 · 81 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_ajax_add_meta() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
isset($value) && current_user_can()61–71check_ajax_referer(), get_post(), current_user_can(), add_meta(), get_metadata_by_mid(), get_object_vars(), _list_meta_row(), postid(), ->send()
isset($value)64–74check_ajax_referer(), get_post(), current_user_can(), wp_die(), add_meta(), get_metadata_by_mid(), get_object_vars(), _list_meta_row(), postid(), ->send()
isset($value) && current_user_can()67–77check_ajax_referer(), get_post(), current_user_can(), add_meta(), __(), wp_die(), get_metadata_by_mid(), get_object_vars(), _list_meta_row(), postid(), ->send()
isset($value)70–80check_ajax_referer(), get_post(), current_user_can(), wp_die(), add_meta(), __(), wp_die(), get_metadata_by_mid(), get_object_vars(), _list_meta_row(), postid(), ->send()
isset($value) && !current_user_can() && empty($value)74–77check_ajax_referer(), get_post(), current_user_can(), wp_die(), wp_die(), add_meta(), get_metadata_by_mid(), get_object_vars(), _list_meta_row(), postid(), ->send()
isset($value) && !current_user_can() && empty($value)80–83check_ajax_referer(), get_post(), current_user_can(), wp_die(), wp_die(), add_meta(), __(), wp_die(), get_metadata_by_mid(), get_object_vars(), _list_meta_row(), postid(), ->send()
!isset($value) && is_protected_meta() && $value === false && $key === false89check_ajax_referer(), get_post(), key(), wp_unslash(), wp_unslash(), get_metadata_by_mid(), is_protected_meta(), wp_die(), meta_key(), postid(), ->send()
!isset($value) && is_protected_meta() && $value === false && $key === false92check_ajax_referer(), get_post(), key(), wp_unslash(), wp_unslash(), get_metadata_by_mid(), wp_die(), is_protected_meta(), wp_die(), meta_key(), postid(), ->send()
!isset($value) && is_protected_meta()94–97check_ajax_referer(), get_post(), key(), wp_unslash(), wp_unslash(), get_metadata_by_mid(), is_protected_meta(), wp_die(), update_metadata_by_mid(), meta_key(), postid(), ->send()
!isset($value) && $value === false && $key === false94check_ajax_referer(), get_post(), key(), wp_unslash(), wp_unslash(), get_metadata_by_mid(), is_protected_meta(), is_protected_meta(), wp_die(), meta_key(), postid(), ->send()
!isset($value) && is_protected_meta() && $value === false && $key === false95check_ajax_referer(), get_post(), key(), wp_unslash(), wp_unslash(), __(), wp_die(), get_metadata_by_mid(), is_protected_meta(), wp_die(), meta_key(), postid(), ->send()
!isset($value) && is_protected_meta()97–100check_ajax_referer(), get_post(), key(), wp_unslash(), wp_unslash(), get_metadata_by_mid(), is_protected_meta(), wp_die(), update_metadata_by_mid(), wp_die(), meta_key(), postid(), ->send()
69 further outcomes, up to 135 instructions
!isset($value) && is_protected_meta()97–100check_ajax_referer(), get_post(), key(), wp_unslash(), wp_unslash(), get_metadata_by_mid(), wp_die(), is_protected_meta(), wp_die(), update_metadata_by_mid(), meta_key(), postid(), ->send()
!isset($value) && $value === false && $key === false97check_ajax_referer(), get_post(), key(), wp_unslash(), wp_unslash(), get_metadata_by_mid(), wp_die(), is_protected_meta(), is_protected_meta(), wp_die(), meta_key(), postid(), ->send()
!isset($value) && is_protected_meta() && $value === false && $key === false98check_ajax_referer(), get_post(), key(), wp_unslash(), wp_unslash(), __(), wp_die(), get_metadata_by_mid(), wp_die(), is_protected_meta(), wp_die(), meta_key(), postid(), ->send()
!isset($value)99–102check_ajax_referer(), get_post(), key(), wp_unslash(), wp_unslash(), get_metadata_by_mid(), is_protected_meta(), is_protected_meta(), wp_die(), update_metadata_by_mid(), meta_key(), postid(), ->send()
isset($value) && current_user_can()99–109check_ajax_referer(), get_post(), current_user_can(), time(), __(), __(), gmdate(), __(), gmdate(), sprintf(), edit_post(), wp_die(), get_metadata_by_mid(), get_object_vars(), _list_meta_row(), postid(), ->send()
!isset($value) && is_protected_meta()100–103check_ajax_referer(), get_post(), key(), wp_unslash(), wp_unslash(), get_metadata_by_mid(), wp_die(), is_protected_meta(), wp_die(), update_metadata_by_mid(), wp_die(), meta_key(), postid(), ->send()
!isset($value) && is_protected_meta()100–103check_ajax_referer(), get_post(), key(), wp_unslash(), wp_unslash(), __(), wp_die(), get_metadata_by_mid(), is_protected_meta(), wp_die(), update_metadata_by_mid(), meta_key(), postid(), ->send()
!isset($value) && $value === false && $key === false100check_ajax_referer(), get_post(), key(), wp_unslash(), wp_unslash(), __(), wp_die(), get_metadata_by_mid(), is_protected_meta(), is_protected_meta(), wp_die(), meta_key(), postid(), ->send()
!isset($value)102–105check_ajax_referer(), get_post(), key(), wp_unslash(), wp_unslash(), get_metadata_by_mid(), is_protected_meta(), is_protected_meta(), wp_die(), update_metadata_by_mid(), wp_die(), meta_key(), postid(), ->send()
!isset($value)102–105check_ajax_referer(), get_post(), key(), wp_unslash(), wp_unslash(), get_metadata_by_mid(), wp_die(), is_protected_meta(), is_protected_meta(), wp_die(), update_metadata_by_mid(), meta_key(), postid(), ->send()
isset($value)102–112check_ajax_referer(), get_post(), current_user_can(), wp_die(), time(), __(), __(), gmdate(), __(), gmdate(), sprintf(), edit_post(), wp_die(), get_metadata_by_mid(), get_object_vars(), _list_meta_row(), postid(), ->send()
!isset($value) && is_protected_meta()103–106check_ajax_referer(), get_post(), key(), wp_unslash(), wp_unslash(), __(), wp_die(), get_metadata_by_mid(), is_protected_meta(), wp_die(), update_metadata_by_mid(), wp_die(), meta_key(), postid(), ->send()
!isset($value) && is_protected_meta()103–106check_ajax_referer(), get_post(), key(), wp_unslash(), wp_unslash(), __(), wp_die(), get_metadata_by_mid(), wp_die(), is_protected_meta(), wp_die(), update_metadata_by_mid(), meta_key(), postid(), ->send()
!isset($value) && $value === false && $key === false103check_ajax_referer(), get_post(), key(), wp_unslash(), wp_unslash(), __(), wp_die(), get_metadata_by_mid(), wp_die(), is_protected_meta(), is_protected_meta(), wp_die(), meta_key(), postid(), ->send()
!isset($value) && !is_protected_meta() && !current_user_can() && $value === false && $key === false104check_ajax_referer(), get_post(), key(), wp_unslash(), wp_unslash(), get_metadata_by_mid(), is_protected_meta(), is_protected_meta(), current_user_can(), wp_die(), meta_key(), postid(), ->send()
isset($value) && current_user_can() && !is_wp_error()104–114check_ajax_referer(), get_post(), current_user_can(), time(), __(), __(), gmdate(), __(), gmdate(), sprintf(), edit_post(), is_wp_error(), add_meta(), get_metadata_by_mid(), get_object_vars(), _list_meta_row(), postid(), ->send()
!isset($value)105–108check_ajax_referer(), get_post(), key(), wp_unslash(), wp_unslash(), get_metadata_by_mid(), wp_die(), is_protected_meta(), is_protected_meta(), wp_die(), update_metadata_by_mid(), wp_die(), meta_key(), postid(), ->send()
!isset($value)105–108check_ajax_referer(), get_post(), key(), wp_unslash(), wp_unslash(), __(), wp_die(), get_metadata_by_mid(), is_protected_meta(), is_protected_meta(), wp_die(), update_metadata_by_mid(), meta_key(), postid(), ->send()
!isset($value) && is_protected_meta()106–109check_ajax_referer(), get_post(), key(), wp_unslash(), wp_unslash(), __(), wp_die(), get_metadata_by_mid(), wp_die(), is_protected_meta(), wp_die(), update_metadata_by_mid(), wp_die(), meta_key(), postid(), ->send()
!isset($value) && !is_protected_meta() && !current_user_can() && $value === false && $key === false107check_ajax_referer(), get_post(), key(), wp_unslash(), wp_unslash(), get_metadata_by_mid(), wp_die(), is_protected_meta(), is_protected_meta(), current_user_can(), wp_die(), meta_key(), postid(), ->send()
isset($value) && !is_wp_error()107–117check_ajax_referer(), get_post(), current_user_can(), wp_die(), time(), __(), __(), gmdate(), __(), gmdate(), sprintf(), edit_post(), is_wp_error(), add_meta(), get_metadata_by_mid(), get_object_vars(), _list_meta_row(), postid(), ->send()
!isset($value)108–111check_ajax_referer(), get_post(), key(), wp_unslash(), wp_unslash(), __(), wp_die(), get_metadata_by_mid(), is_protected_meta(), is_protected_meta(), wp_die(), update_metadata_by_mid(), wp_die(), meta_key(), postid(), ->send()
!isset($value)108–111check_ajax_referer(), get_post(), key(), wp_unslash(), wp_unslash(), __(), wp_die(), get_metadata_by_mid(), wp_die(), is_protected_meta(), is_protected_meta(), wp_die(), update_metadata_by_mid(), meta_key(), postid(), ->send()
!isset($value) && !is_protected_meta() && current_user_can() && $value === false && $key === false109check_ajax_referer(), get_post(), key(), wp_unslash(), wp_unslash(), get_metadata_by_mid(), is_protected_meta(), is_protected_meta(), current_user_can(), current_user_can(), meta_key(), postid(), ->send()
!isset($value) && !is_protected_meta() && !current_user_can()109–112check_ajax_referer(), get_post(), key(), wp_unslash(), wp_unslash(), get_metadata_by_mid(), is_protected_meta(), is_protected_meta(), current_user_can(), wp_die(), update_metadata_by_mid(), meta_key(), postid(), ->send()
!isset($value) && !is_protected_meta() && !current_user_can() && $value === false && $key === false110check_ajax_referer(), get_post(), key(), wp_unslash(), wp_unslash(), __(), wp_die(), get_metadata_by_mid(), is_protected_meta(), is_protected_meta(), current_user_can(), wp_die(), meta_key(), postid(), ->send()
!isset($value)111–114check_ajax_referer(), get_post(), key(), wp_unslash(), wp_unslash(), __(), wp_die(), get_metadata_by_mid(), wp_die(), is_protected_meta(), is_protected_meta(), wp_die(), update_metadata_by_mid(), wp_die(), meta_key(), postid(), ->send()
isset($value) && current_user_can() && !is_wp_error()111–121check_ajax_referer(), get_post(), current_user_can(), time(), __(), __(), gmdate(), __(), gmdate(), sprintf(), edit_post(), is_wp_error(), add_meta(), __(), wp_die(), get_metadata_by_mid(), get_object_vars(), _list_meta_row(), postid(), ->send()
!isset($value) && !is_protected_meta() && $value === false && $key === false112check_ajax_referer(), get_post(), key(), wp_unslash(), wp_unslash(), get_metadata_by_mid(), is_protected_meta(), is_protected_meta(), current_user_can(), current_user_can(), wp_die(), meta_key(), postid(), ->send()
!isset($value) && !is_protected_meta() && current_user_can() && $value === false && $key === false112check_ajax_referer(), get_post(), key(), wp_unslash(), wp_unslash(), get_metadata_by_mid(), wp_die(), is_protected_meta(), is_protected_meta(), current_user_can(), current_user_can(), meta_key(), postid(), ->send()
!isset($value) && !is_protected_meta() && !current_user_can()112–115check_ajax_referer(), get_post(), key(), wp_unslash(), wp_unslash(), get_metadata_by_mid(), is_protected_meta(), is_protected_meta(), current_user_can(), wp_die(), update_metadata_by_mid(), wp_die(), meta_key(), postid(), ->send()
!isset($value) && !is_protected_meta() && !current_user_can()112–115check_ajax_referer(), get_post(), key(), wp_unslash(), wp_unslash(), get_metadata_by_mid(), wp_die(), is_protected_meta(), is_protected_meta(), current_user_can(), wp_die(), update_metadata_by_mid(), meta_key(), postid(), ->send()
isset($value) && !current_user_can() && empty($value)112–115check_ajax_referer(), get_post(), current_user_can(), wp_die(), wp_die(), time(), __(), __(), gmdate(), __(), gmdate(), sprintf(), edit_post(), wp_die(), get_metadata_by_mid(), get_object_vars(), _list_meta_row(), postid(), ->send()
isset($value) && current_user_can() && is_wp_error()112–122check_ajax_referer(), get_post(), current_user_can(), time(), __(), __(), gmdate(), __(), gmdate(), sprintf(), edit_post(), is_wp_error(), meta(), ->send(), add_meta(), get_metadata_by_mid(), get_object_vars(), _list_meta_row(), postid(), ->send()
!isset($value) && !is_protected_meta() && !current_user_can() && $value === false && $key === false113check_ajax_referer(), get_post(), key(), wp_unslash(), wp_unslash(), __(), wp_die(), get_metadata_by_mid(), wp_die(), is_protected_meta(), is_protected_meta(), current_user_can(), wp_die(), meta_key(), postid(), ->send()
!isset($value) && !is_protected_meta() && current_user_can()114–117check_ajax_referer(), get_post(), key(), wp_unslash(), wp_unslash(), get_metadata_by_mid(), is_protected_meta(), is_protected_meta(), current_user_can(), current_user_can(), update_metadata_by_mid(), meta_key(), postid(), ->send()
isset($value) && !is_wp_error()114–124check_ajax_referer(), get_post(), current_user_can(), wp_die(), time(), __(), __(), gmdate(), __(), gmdate(), sprintf(), edit_post(), is_wp_error(), add_meta(), __(), wp_die(), get_metadata_by_mid(), get_object_vars(), _list_meta_row(), postid(), ->send()
!isset($value) && !is_protected_meta() && $value === false && $key === false115check_ajax_referer(), get_post(), key(), wp_unslash(), wp_unslash(), get_metadata_by_mid(), wp_die(), is_protected_meta(), is_protected_meta(), current_user_can(), current_user_can(), wp_die(), meta_key(), postid(), ->send()
!isset($value) && !is_protected_meta() && current_user_can() && $value === false && $key === false115check_ajax_referer(), get_post(), key(), wp_unslash(), wp_unslash(), __(), wp_die(), get_metadata_by_mid(), is_protected_meta(), is_protected_meta(), current_user_can(), current_user_can(), meta_key(), postid(), ->send()
!isset($value) && !is_protected_meta() && !current_user_can()115–118check_ajax_referer(), get_post(), key(), wp_unslash(), wp_unslash(), get_metadata_by_mid(), wp_die(), is_protected_meta(), is_protected_meta(), current_user_can(), wp_die(), update_metadata_by_mid(), wp_die(), meta_key(), postid(), ->send()
!isset($value) && !is_protected_meta() && !current_user_can()115–118check_ajax_referer(), get_post(), key(), wp_unslash(), wp_unslash(), __(), wp_die(), get_metadata_by_mid(), is_protected_meta(), is_protected_meta(), current_user_can(), wp_die(), update_metadata_by_mid(), meta_key(), postid(), ->send()
isset($value) && is_wp_error()115–125check_ajax_referer(), get_post(), current_user_can(), wp_die(), time(), __(), __(), gmdate(), __(), gmdate(), sprintf(), edit_post(), is_wp_error(), meta(), ->send(), add_meta(), get_metadata_by_mid(), get_object_vars(), _list_meta_row(), postid(), ->send()
!isset($value) && !is_protected_meta() && current_user_can()117–120check_ajax_referer(), get_post(), key(), wp_unslash(), wp_unslash(), get_metadata_by_mid(), is_protected_meta(), is_protected_meta(), current_user_can(), current_user_can(), update_metadata_by_mid(), wp_die(), meta_key(), postid(), ->send()
!isset($value) && !is_protected_meta()117–120check_ajax_referer(), get_post(), key(), wp_unslash(), wp_unslash(), get_metadata_by_mid(), is_protected_meta(), is_protected_meta(), current_user_can(), current_user_can(), wp_die(), update_metadata_by_mid(), meta_key(), postid(), ->send()
!isset($value) && !is_protected_meta() && current_user_can()117–120check_ajax_referer(), get_post(), key(), wp_unslash(), wp_unslash(), get_metadata_by_mid(), wp_die(), is_protected_meta(), is_protected_meta(), current_user_can(), current_user_can(), update_metadata_by_mid(), meta_key(), postid(), ->send()
isset($value) && !current_user_can() && empty($value) && !is_wp_error()117–120check_ajax_referer(), get_post(), current_user_can(), wp_die(), wp_die(), time(), __(), __(), gmdate(), __(), gmdate(), sprintf(), edit_post(), is_wp_error(), add_meta(), get_metadata_by_mid(), get_object_vars(), _list_meta_row(), postid(), ->send()
!isset($value) && !is_protected_meta() && $value === false && $key === false118check_ajax_referer(), get_post(), key(), wp_unslash(), wp_unslash(), __(), wp_die(), get_metadata_by_mid(), is_protected_meta(), is_protected_meta(), current_user_can(), current_user_can(), wp_die(), meta_key(), postid(), ->send()
!isset($value) && !is_protected_meta() && current_user_can() && $value === false && $key === false118check_ajax_referer(), get_post(), key(), wp_unslash(), wp_unslash(), __(), wp_die(), get_metadata_by_mid(), wp_die(), is_protected_meta(), is_protected_meta(), current_user_can(), current_user_can(), meta_key(), postid(), ->send()
!isset($value) && !is_protected_meta() && !current_user_can()118–121check_ajax_referer(), get_post(), key(), wp_unslash(), wp_unslash(), __(), wp_die(), get_metadata_by_mid(), is_protected_meta(), is_protected_meta(), current_user_can(), wp_die(), update_metadata_by_mid(), wp_die(), meta_key(), postid(), ->send()
!isset($value) && !is_protected_meta() && !current_user_can()118–121check_ajax_referer(), get_post(), key(), wp_unslash(), wp_unslash(), __(), wp_die(), get_metadata_by_mid(), wp_die(), is_protected_meta(), is_protected_meta(), current_user_can(), wp_die(), update_metadata_by_mid(), meta_key(), postid(), ->send()
isset($value) && current_user_can() && is_wp_error()119–129check_ajax_referer(), get_post(), current_user_can(), time(), __(), __(), gmdate(), __(), gmdate(), sprintf(), edit_post(), is_wp_error(), meta(), ->send(), add_meta(), __(), wp_die(), get_metadata_by_mid(), get_object_vars(), _list_meta_row(), postid(), ->send()
!isset($value) && !is_protected_meta()120–123check_ajax_referer(), get_post(), key(), wp_unslash(), wp_unslash(), get_metadata_by_mid(), is_protected_meta(), is_protected_meta(), current_user_can(), current_user_can(), wp_die(), update_metadata_by_mid(), wp_die(), meta_key(), postid(), ->send()
!isset($value) && !is_protected_meta() && current_user_can()120–123check_ajax_referer(), get_post(), key(), wp_unslash(), wp_unslash(), get_metadata_by_mid(), wp_die(), is_protected_meta(), is_protected_meta(), current_user_can(), current_user_can(), update_metadata_by_mid(), wp_die(), meta_key(), postid(), ->send()
!isset($value) && !is_protected_meta()120–123check_ajax_referer(), get_post(), key(), wp_unslash(), wp_unslash(), get_metadata_by_mid(), wp_die(), is_protected_meta(), is_protected_meta(), current_user_can(), current_user_can(), wp_die(), update_metadata_by_mid(), meta_key(), postid(), ->send()
!isset($value) && !is_protected_meta() && current_user_can()120–123check_ajax_referer(), get_post(), key(), wp_unslash(), wp_unslash(), __(), wp_die(), get_metadata_by_mid(), is_protected_meta(), is_protected_meta(), current_user_can(), current_user_can(), update_metadata_by_mid(), meta_key(), postid(), ->send()
!isset($value) && !is_protected_meta() && $value === false && $key === false121check_ajax_referer(), get_post(), key(), wp_unslash(), wp_unslash(), __(), wp_die(), get_metadata_by_mid(), wp_die(), is_protected_meta(), is_protected_meta(), current_user_can(), current_user_can(), wp_die(), meta_key(), postid(), ->send()
!isset($value) && !is_protected_meta() && !current_user_can()121–124check_ajax_referer(), get_post(), key(), wp_unslash(), wp_unslash(), __(), wp_die(), get_metadata_by_mid(), wp_die(), is_protected_meta(), is_protected_meta(), current_user_can(), wp_die(), update_metadata_by_mid(), wp_die(), meta_key(), postid(), ->send()
isset($value) && is_wp_error()122–132check_ajax_referer(), get_post(), current_user_can(), wp_die(), time(), __(), __(), gmdate(), __(), gmdate(), sprintf(), edit_post(), is_wp_error(), meta(), ->send(), add_meta(), __(), wp_die(), get_metadata_by_mid(), get_object_vars(), _list_meta_row(), postid(), ->send()
!isset($value) && !is_protected_meta()123–126check_ajax_referer(), get_post(), key(), wp_unslash(), wp_unslash(), get_metadata_by_mid(), wp_die(), is_protected_meta(), is_protected_meta(), current_user_can(), current_user_can(), wp_die(), update_metadata_by_mid(), wp_die(), meta_key(), postid(), ->send()
!isset($value) && !is_protected_meta() && current_user_can()123–126check_ajax_referer(), get_post(), key(), wp_unslash(), wp_unslash(), __(), wp_die(), get_metadata_by_mid(), is_protected_meta(), is_protected_meta(), current_user_can(), current_user_can(), update_metadata_by_mid(), wp_die(), meta_key(), postid(), ->send()
!isset($value) && !is_protected_meta()123–126check_ajax_referer(), get_post(), key(), wp_unslash(), wp_unslash(), __(), wp_die(), get_metadata_by_mid(), is_protected_meta(), is_protected_meta(), current_user_can(), current_user_can(), wp_die(), update_metadata_by_mid(), meta_key(), postid(), ->send()
!isset($value) && !is_protected_meta() && current_user_can()123–126check_ajax_referer(), get_post(), key(), wp_unslash(), wp_unslash(), __(), wp_die(), get_metadata_by_mid(), wp_die(), is_protected_meta(), is_protected_meta(), current_user_can(), current_user_can(), update_metadata_by_mid(), meta_key(), postid(), ->send()
isset($value) && !current_user_can() && empty($value) && !is_wp_error()124–127check_ajax_referer(), get_post(), current_user_can(), wp_die(), wp_die(), time(), __(), __(), gmdate(), __(), gmdate(), sprintf(), edit_post(), is_wp_error(), add_meta(), __(), wp_die(), get_metadata_by_mid(), get_object_vars(), _list_meta_row(), postid(), ->send()
isset($value) && !current_user_can() && empty($value) && is_wp_error()125–128check_ajax_referer(), get_post(), current_user_can(), wp_die(), wp_die(), time(), __(), __(), gmdate(), __(), gmdate(), sprintf(), edit_post(), is_wp_error(), meta(), ->send(), add_meta(), get_metadata_by_mid(), get_object_vars(), _list_meta_row(), postid(), ->send()
!isset($value) && !is_protected_meta()126–129check_ajax_referer(), get_post(), key(), wp_unslash(), wp_unslash(), __(), wp_die(), get_metadata_by_mid(), is_protected_meta(), is_protected_meta(), current_user_can(), current_user_can(), wp_die(), update_metadata_by_mid(), wp_die(), meta_key(), postid(), ->send()
!isset($value) && !is_protected_meta() && current_user_can()126–129check_ajax_referer(), get_post(), key(), wp_unslash(), wp_unslash(), __(), wp_die(), get_metadata_by_mid(), wp_die(), is_protected_meta(), is_protected_meta(), current_user_can(), current_user_can(), update_metadata_by_mid(), wp_die(), meta_key(), postid(), ->send()
!isset($value) && !is_protected_meta()126–129check_ajax_referer(), get_post(), key(), wp_unslash(), wp_unslash(), __(), wp_die(), get_metadata_by_mid(), wp_die(), is_protected_meta(), is_protected_meta(), current_user_can(), current_user_can(), wp_die(), update_metadata_by_mid(), meta_key(), postid(), ->send()
!isset($value) && !is_protected_meta()129–132check_ajax_referer(), get_post(), key(), wp_unslash(), wp_unslash(), __(), wp_die(), get_metadata_by_mid(), wp_die(), is_protected_meta(), is_protected_meta(), current_user_can(), current_user_can(), wp_die(), update_metadata_by_mid(), wp_die(), meta_key(), postid(), ->send()
isset($value) && !current_user_can() && empty($value) && is_wp_error()132–135check_ajax_referer(), get_post(), current_user_can(), wp_die(), wp_die(), time(), __(), __(), gmdate(), __(), gmdate(), sprintf(), edit_post(), is_wp_error(), meta(), ->send(), add_meta(), __(), wp_die(), get_metadata_by_mid(), get_object_vars(), _list_meta_row(), postid(), ->send()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev26161–13520
8.526161–13520
8.426161–135202 fewer instructions than PHP 8.3
8.326361–13520
8.226361–13520
8.126361–13520
7.426361–13520

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 · 14

  • check_ajax_referer()Verifies the Ajax request to prevent processing requests external of the blog.
  • get_post()Retrieves post data given a post ID or post object.
  • 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.
  • __()Retrieves the translation of $text.
  • edit_post()Updates an existing post with values provided in `$_POST`.
  • is_wp_error()Checks whether the given variable is a WordPress Error.
  • add_meta()Adds post meta data defined in the `$_POST` superglobal for a post with given ID.
  • get_metadata_by_mid()Retrieves metadata by meta ID.
  • _list_meta_row()Outputs a single row of public meta data in the Custom Fields meta box.
  • wp_unslash()Removes slashes from a string or recursively removes slashes from strings within an array.
  • is_protected_meta()Determines whether a meta key is considered protected.
Show all 14

Source code

function wp_ajax_add_meta() {	check_ajax_referer( 'add-meta', '_ajax_nonce-add-meta' );	$count   = 0;	$post_id = (int) $_POST['post_id'];	$post    = get_post( $post_id ); 	if ( isset( $_POST['metakeyselect'] ) || isset( $_POST['metakeyinput'] ) ) {		if ( ! current_user_can( 'edit_post', $post_id ) ) {			wp_die( -1 );		} 		if ( isset( $_POST['metakeyselect'] ) && '#NONE#' === $_POST['metakeyselect'] && empty( $_POST['metakeyinput'] ) ) {			wp_die( 1 );		} 		// If the post is an autodraft, save the post as a draft and then attempt to save the meta.		if ( 'auto-draft' === $post->post_status ) {			$post_data                = array();			$post_data['action']      = 'draft'; // Warning fix.			$post_data['post_ID']     = $post_id;			$post_data['post_type']   = $post->post_type;			$post_data['post_status'] = 'draft';			$now                      = time(); 			$post_data['post_title'] = sprintf(				/* translators: 1: Post creation date, 2: Post creation time. */				__( 'Draft created on %1$s at %2$s' ),				gmdate( __( 'F j, Y' ), $now ),				gmdate( __( 'g:i a' ), $now )			); 			$post_id = edit_post( $post_data ); 			if ( $post_id ) {				if ( is_wp_error( $post_id ) ) {					$response = new WP_Ajax_Response(						array(							'what' => 'meta',							'data' => $post_id,						)					);					$response->send();				} 				$meta_id = add_meta( $post_id ); 				if ( ! $meta_id ) {					wp_die( __( 'Please provide a custom field value.' ) );				}			} else {				wp_die( 0 );			}		} else {			$meta_id = add_meta( $post_id ); 			if ( ! $meta_id ) {				wp_die( __( 'Please provide a custom field value.' ) );			}		} 		$meta    = get_metadata_by_mid( 'post', $meta_id );		$post_id = (int) $meta->post_id;		$meta    = get_object_vars( $meta ); 		$response = new WP_Ajax_Response(			array(				'what'         => 'meta',				'id'           => $meta_id,				'data'         => _list_meta_row( $meta, $count ),				'position'     => 1,				'supplemental' => array( 'postid' => $post_id ),			)		);	} else { // Update?		$meta_id = (int) key( $_POST['meta'] );		$key     = wp_unslash( $_POST['meta'][ $meta_id ]['key'] );		$value   = wp_unslash( $_POST['meta'][ $meta_id ]['value'] ); 		if ( '' === trim( $key ) ) {			wp_die( __( 'Please provide a custom field name.' ) );

Changelog

Introduced in 3.1.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.0.4 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.