diff --git src/wp-admin/includes/revision.php src/wp-admin/includes/revision.php
index 9e8b6e3..aa6481f 100644
|
|
|
function wp_get_revision_ui_diff( $post, $compare_from, $compare_to ) { |
| 111 | 111 | * |
| 112 | 112 | * @since 3.6.0 |
| 113 | 113 | * |
| 114 | | * @param object|int $post The post object. Also accepts a post ID. |
| 115 | | * @param int $selected_revision_id The selected revision ID. |
| 116 | | * @param int $from Optional. The revision ID to compare from. |
| | 114 | * @param array $args { |
| | 115 | * Options hash for preparing data. |
| | 116 | * |
| | 117 | * @type object|int $post The post object or post ID. |
| | 118 | * @type int $from Optional. The revision ID to compare from. Defaults to the |
| | 119 | * most recent revision. |
| | 120 | * @type int $to The revision ID to compare to. |
| | 121 | * @type array $revisions Optional. A group of revisions to prepare data for. |
| | 122 | * Defaults to all revisions of the post. |
| | 123 | * } |
| 117 | 124 | * |
| 118 | 125 | * @return array An associative array of revision data and related settings. |
| 119 | 126 | */ |
| 120 | | function wp_prepare_revisions_for_js( $post, $selected_revision_id, $from = null ) { |
| 121 | | $post = get_post( $post ); |
| | 127 | function wp_prepare_revisions_for_js( $args = array() ) { |
| | 128 | // Backwards compatibility for when this function was a string of arguments. |
| | 129 | if ( ! is_array( $args ) || func_num_args() > 1 ) { |
| | 130 | $old_args = array( 0 => 'post', 1 => 'to', 2 => 'from' ); |
| | 131 | $func_args = func_get_args(); |
| | 132 | foreach( $old_args as $arg_num => $arg_key ) { |
| | 133 | if ( isset( $func_args[$arg_num] ) ) { |
| | 134 | $new_args[$arg_key] = $func_args[$arg_num]; |
| | 135 | } |
| | 136 | } |
| | 137 | $args = $new_args; |
| | 138 | } |
| | 139 | |
| | 140 | $defaults = array( |
| | 141 | 'from' => null, |
| | 142 | 'revisions' => null |
| | 143 | ); |
| | 144 | $args = wp_parse_args( $args, $defaults ); |
| | 145 | |
| | 146 | if ( empty( $args['post'] ) ) { |
| | 147 | return new WP_Error( 'revisions_post_required', __( 'Post required.' ) ); |
| | 148 | } |
| | 149 | if ( empty( $args['to'] ) ) { |
| | 150 | return new WP_Error( 'revisions_to_required', __( 'To required.' ) ); |
| | 151 | } |
| | 152 | $post = get_post( $args['post'] ); |
| | 153 | $to = $args['to']; |
| | 154 | $from = $args['from']; |
| | 155 | |
| 122 | 156 | $authors = array(); |
| 123 | 157 | $now_gmt = time(); |
| 124 | 158 | |
| 125 | | $revisions = wp_get_post_revisions( $post->ID, array( 'order' => 'ASC', 'check_enabled' => false ) ); |
| | 159 | $revisions = $args['revisions']; |
| | 160 | if ( empty( $revisions ) ) { |
| | 161 | $revisions = wp_get_post_revisions( $post->ID, array( 'order' => 'ASC', 'check_enabled' => false ) ); |
| | 162 | } |
| | 163 | |
| 126 | 164 | // If revisions are disabled, we only want autosaves and the current post. |
| 127 | 165 | if ( ! wp_revisions_enabled( $post ) ) { |
| 128 | 166 | foreach ( $revisions as $revision_id => $revision ) { |
| … |
… |
function wp_prepare_revisions_for_js( $post, $selected_revision_id, $from = null |
| 209 | 247 | // Now, grab the initial diff. |
| 210 | 248 | $compare_two_mode = is_numeric( $from ); |
| 211 | 249 | if ( ! $compare_two_mode ) { |
| 212 | | $found = array_search( $selected_revision_id, array_keys( $revisions ) ); |
| | 250 | $found = array_search( $to, array_keys( $revisions ) ); |
| 213 | 251 | if ( $found ) { |
| 214 | 252 | $from = array_keys( array_slice( $revisions, $found - 1, 1, true ) ); |
| 215 | 253 | $from = reset( $from ); |
| … |
… |
function wp_prepare_revisions_for_js( $post, $selected_revision_id, $from = null |
| 219 | 257 | } |
| 220 | 258 | |
| 221 | 259 | $from = absint( $from ); |
| 222 | | |
| 223 | 260 | $diffs = array( array( |
| 224 | | 'id' => $from . ':' . $selected_revision_id, |
| 225 | | 'fields' => wp_get_revision_ui_diff( $post->ID, $from, $selected_revision_id ), |
| | 261 | 'id' => $from . ':' . $to, |
| | 262 | 'fields' => wp_get_revision_ui_diff( $post->ID, $from, $to ), |
| 226 | 263 | )); |
| 227 | 264 | |
| 228 | 265 | return array( |
| 229 | 266 | 'postId' => $post->ID, |
| 230 | 267 | 'nonce' => wp_create_nonce( 'revisions-ajax-nonce' ), |
| 231 | 268 | 'revisionData' => array_values( $revisions ), |
| 232 | | 'to' => $selected_revision_id, |
| | 269 | 'to' => $to, |
| 233 | 270 | 'from' => $from, |
| 234 | 271 | 'diffData' => $diffs, |
| 235 | 272 | 'baseUrl' => parse_url( admin_url( 'revision.php' ), PHP_URL_PATH ), |