wp-admin/includes/ajax-actions.php:1635Handles adding meta via AJAX.
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.' ) );Introduced in 3.1.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
src/wp-admin/includes/ajax-actions.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.