wpseek.com
A WordPress-centric search engine for devs and theme authors
wp_autosave_post_revisioned_meta_fields › WordPress Function
Since6.4.0
Deprecatedn/a
› wp_autosave_post_revisioned_meta_fields ( $new_autosave )
Parameters: |
|
Defined at: |
|
Codex: |
Autosaves the revisioned meta fields.
Iterates through the revisioned meta fields and checks each to see if they are set, and have a changed value. If so, the meta value is saved and attached to the autosave.Source
function wp_autosave_post_revisioned_meta_fields( $new_autosave ) { /* * The post data arrives as either $_POST['data']['wp_autosave'] or the $_POST * itself. This sets $posted_data to the correct variable. * * Ignoring sanitization to avoid altering meta. Ignoring the nonce check because * this is hooked on inner core hooks where a valid nonce was already checked. */ $posted_data = isset( $_POST['data']['wp_autosave'] ) ? $_POST['data']['wp_autosave'] : $_POST; $post_type = get_post_type( $new_autosave['post_parent'] ); /* * Go through the revisioned meta keys and save them as part of the autosave, * if the meta key is part of the posted data, the meta value is not blank, * and the meta value has changes from the last autosaved value. */ foreach ( wp_post_revision_meta_keys( $post_type ) as $meta_key ) { if ( isset( $posted_data[ $meta_key ] ) && get_post_meta( $new_autosave['ID'], $meta_key, true ) !== wp_unslash( $posted_data[ $meta_key ] ) ) { /* * Use the underlying delete_metadata() and add_metadata() functions * vs delete_post_meta() and add_post_meta() to make sure we're working * with the actual revision meta. */ delete_metadata( 'post', $new_autosave['ID'], $meta_key ); // One last check to ensure meta value is not empty. if ( ! empty( $posted_data[ $meta_key ] ) ) { // Add the revisions meta data to the autosave. add_metadata( 'post', $new_autosave['ID'], $meta_key, $posted_data[ $meta_key ] ); } } } }