wp_ajax_add_meta()
- Since
- 3.1.0
- Source
wp-admin/includes/ajax-actions.php:1635
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
- Scaling
- Constant
- Instructions
- 60–136
- Plugin surface
- None
- Called by
- 0
Reaches the database via get_post().
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 262.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- querycontent query
get_post()called directly - hookthird-party callbacks
do_action()one call below wp_ajax_add_meta() - serializeserialisation
maybe_unserialize()one call below wp_ajax_add_meta() - cacheobject cache
wp_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 · 95 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.
| When | Instructions | Calls it makes |
|---|---|---|
isset($value) | 60–70 | check_ajax_referer(), get_post(), wp_die(), add_meta(), get_metadata_by_mid(), get_object_vars(), _list_meta_row(), postid(), ->send() |
isset($value) && current_user_can() | 62–72 | check_ajax_referer(), get_post(), current_user_can(), add_meta(), get_metadata_by_mid(), get_object_vars(), _list_meta_row(), postid(), ->send() |
isset($value) | 65–75 | check_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) | 66–76 | check_ajax_referer(), get_post(), wp_die(), add_meta(), __(), wp_die(), get_metadata_by_mid(), get_object_vars(), _list_meta_row(), postid(), ->send() |
isset($value) && current_user_can() | 68–78 | check_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) && empty($value) | 70–73 | check_ajax_referer(), get_post(), wp_die(), wp_die(), add_meta(), get_metadata_by_mid(), get_object_vars(), _list_meta_row(), postid(), ->send() |
isset($value) | 71–81 | check_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) | 75–78 | check_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) && empty($value) | 76–79 | check_ajax_referer(), get_post(), wp_die(), 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) | 81–84 | check_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 === false | 89 | check_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 === false | 92 | check_ajax_referer(), get_post(), key(), wp_unslash(), wp_unslash(), get_metadata_by_mid(), wp_die(), is_protected_meta(), wp_die(), meta_key(), postid(), ->send() |
83 further outcomes, up to 136 instructions
!isset($value) && is_protected_meta() | 94–97 | check_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 === false | 94 | check_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 === false | 95 | check_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–100 | check_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() |
!isset($value) && is_protected_meta() | 97–100 | check_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 === false | 97 | check_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 === false | 98 | check_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) | 98–108 | check_ajax_referer(), get_post(), wp_die(), time(), __(), __(), gmdate(), __(), gmdate(), sprintf(), edit_post(), wp_die(), get_metadata_by_mid(), get_object_vars(), _list_meta_row(), postid(), ->send() |
!isset($value) | 99–102 | check_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) && is_protected_meta() | 100–103 | check_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–103 | check_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 === false | 100 | check_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) && current_user_can() | 100–110 | check_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) | 102–105 | check_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–105 | check_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) && is_protected_meta() | 103–106 | check_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–106 | check_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 === false | 103 | check_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_wp_error() | 103–113 | check_ajax_referer(), get_post(), 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) | 103–113 | check_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() && !current_user_can() && $value === false && $key === false | 104 | check_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) | 105–108 | check_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–108 | check_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) && current_user_can() && !is_wp_error() | 105–115 | check_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) && is_protected_meta() | 106–109 | check_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 === false | 107 | check_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) | 108–111 | check_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–111 | check_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) && empty($value) | 108–111 | check_ajax_referer(), get_post(), 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) && !is_wp_error() | 108–118 | check_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) && !is_protected_meta() && current_user_can() && $value === false && $key === false | 109 | check_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–112 | check_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 === false | 110 | check_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) && !is_wp_error() | 110–120 | check_ajax_referer(), get_post(), 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) | 111–114 | check_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) && is_wp_error() | 111–121 | check_ajax_referer(), get_post(), 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() && $value === false && $key === false | 112 | check_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 === false | 112 | check_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–115 | check_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–115 | check_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() && !is_wp_error() | 112–122 | check_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() && !current_user_can() && $value === false && $key === false | 113 | check_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) && empty($value) && !is_wp_error() | 113–116 | check_ajax_referer(), get_post(), 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) && !current_user_can() && empty($value) | 113–116 | check_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() | 113–123 | check_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() | 114–117 | check_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_protected_meta() && $value === false && $key === false | 115 | check_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 === false | 115 | check_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–118 | check_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–118 | check_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–125 | check_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_wp_error() | 116–126 | check_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–120 | check_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–120 | check_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–120 | check_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) && !is_protected_meta() && $value === false && $key === false | 118 | check_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 === false | 118 | check_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–121 | check_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–121 | check_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() && empty($value) && !is_wp_error() | 118–121 | check_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_wp_error() | 118–128 | check_ajax_referer(), get_post(), 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() | 120–123 | check_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–123 | check_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–123 | check_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–123 | check_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) && empty($value) && !is_wp_error() | 120–123 | check_ajax_referer(), get_post(), 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() && is_wp_error() | 120–130 | check_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() && $value === false && $key === false | 121 | check_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–124 | check_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) && empty($value) && is_wp_error() | 121–124 | check_ajax_referer(), get_post(), 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() | 123–126 | check_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–126 | check_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–126 | check_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–126 | check_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) && is_wp_error() | 123–133 | check_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) && !current_user_can() && empty($value) && !is_wp_error() | 125–128 | check_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) && !is_protected_meta() | 126–129 | check_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–129 | check_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–129 | check_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) && !current_user_can() && empty($value) && is_wp_error() | 126–129 | check_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) && empty($value) && is_wp_error() | 128–131 | check_ajax_referer(), get_post(), 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() |
!isset($value) && !is_protected_meta() | 129–132 | check_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() | 133–136 | check_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
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 262 | 60–136 | 21 | |
| 8.5 | 262 | 60–136 | 21 | |
| 8.4 | 262 | 60–136 | 21 | 2 fewer instructions than PHP 8.3 |
| 8.3 | 264 | 60–136 | 21 | |
| 8.2 | 264 | 60–136 | 21 | |
| 8.1 | 264 | 60–136 | 21 | |
| 7.4 | 264 | 60–136 | 21 |
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
- update_metadata_by_mid()Updates metadata by meta ID.
- WP_Ajax_Response::__construct()Constructor - Passes args to WP_Ajax_Response::add().
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 ( ! $post || ! 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.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 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.