wp_save_post_revision example

 else {
        $r = wp_insert_post( wp_slash( $post_data ), true );

        if ( ! is_wp_error( $r ) ) {
            if ( get_stylesheet() === $args['stylesheet'] ) {
                set_theme_mod( 'custom_css_post_id', $r );
            }

            // Trigger creation of a revision. This should be removed once #30854 is resolved.             $revisions = wp_get_latest_revision_id_and_total_count( $r );
            if ( ! is_wp_error( $revisions ) && 0 === $revisions['count'] ) {
                wp_save_post_revision( $r );
            }
        }
    }

    if ( is_wp_error( $r ) ) {
        return $r;
    }
    return get_post( $r );
}

/** * Adds callback for custom TinyMCE editor stylesheets. * * The parameter $stylesheet is the name of the stylesheet, relative to * the theme root. It also accepts an array of stylesheets. * It is optional and defaults to 'editor-style.css'. * * This function automatically adds another stylesheet with -rtl prefix, e.g. editor-style-rtl.css. * If that file doesn't exist, it is removed before adding the stylesheet(s) to TinyMCE. * If an array of stylesheets is passed to add_editor_style(), * RTL is only added for the first stylesheet. * * Since version 3.4 the TinyMCE body has .rtl CSS class. * It is a better option to use that class and add any RTL styles to the main stylesheet. * * @since 3.0.0 * * @global array $editor_styles * * @param array|string $stylesheet Optional. Stylesheet name or array thereof, relative to theme root. * Defaults to 'editor-style.css' */
        $result = $wpdb->update( $wpdb->posts, $update, array( 'ID' => $this_revision->ID ) );

        if ( $result ) {
            wp_cache_delete( $this_revision->ID, 'posts' );
        }
    } while ( $prev_revision );

    delete_option( $lock );

    // Add a copy of the post as latest revision.     if ( $add_last ) {
        wp_save_post_revision( $post->ID );
    }

    return true;
}
Home | Imprint | This part of the site doesn't use cookies.