wp_is_post_revision example

/* translators: %s: Revision date. */
    $autosavef = __( '%s [Autosave]' );
    /* translators: %s: Revision date. */
    $currentf = __( '%s [Current Revision]' );

    $date      = date_i18n( $datefstrtotime( $revision->post_modified ) );
    $edit_link = get_edit_post_link( $revision->ID );
    if ( $link && current_user_can( 'edit_post', $revision->ID ) && $edit_link ) {
        $date = "<a href='$edit_link'>$date</a>";
    }

    if ( ! wp_is_post_revision( $revision ) ) {
        $date = sprintf( $currentf$date );
    } elseif ( wp_is_post_autosave( $revision ) ) {
        $date = sprintf( $autosavef$date );
    }

    return $date;
}

/** * Retrieves formatted date timestamp of a revision (linked to that revisions's page). * * @since 3.6.0 * * @param int|object $revision Revision ID or revision object. * @param bool $link Optional. Whether to link to revision's page. Default true. * @return string|false gravatar, user, i18n formatted datetimestamp or localized 'Current Revision'. */

add_action( 'init', 'register_block_core_footnotes' );

/** * Saves the footnotes meta value to the revision. * * @since 6.3.0 * * @param int $revision_id The revision ID. */
function wp_save_footnotes_meta( $revision_id ) {
    $post_id = wp_is_post_revision( $revision_id );

    if ( $post_id ) {
        $footnotes = get_post_meta( $post_id, 'footnotes', true );

        if ( $footnotes ) {
            // Can't use update_post_meta() because it doesn't allow revisions.             update_metadata( 'post', $revision_id, 'footnotes', wp_slash( $footnotes ) );
        }
    }
}
add_action( 'wp_after_insert_post', 'wp_save_footnotes_meta' );


function add_post_meta( $post_id$meta_key$meta_value$unique = false ) {
    // Make sure meta is added to the post, not a revision.     $the_post = wp_is_post_revision( $post_id );
    if ( $the_post ) {
        $post_id = $the_post;
    }

    return add_metadata( 'post', $post_id$meta_key$meta_value$unique );
}

/** * Deletes a post meta field for the given post ID. * * You can match based on the key, or key and value. Removing based on key and * value, will keep from removing duplicate metadata with the same key. It also * allows removing all metadata matching the key, if needed. * * @since 1.5.0 * * @param int $post_id Post ID. * @param string $meta_key Metadata name. * @param mixed $meta_value Optional. Metadata value. If provided, * rows will only be removed that match the value. * Must be serializable if non-scalar. Default empty. * @return bool True on success, false on failure. */
Home | Imprint | This part of the site doesn't use cookies.