~canonical-sysadmins/wordpress/4.8.1

« back to all changes in this revision

Viewing changes to wp-includes/revision.php

  • Committer: Barry Price
  • Date: 2016-08-17 04:50:12 UTC
  • mfrom: (1.1.18 upstream)
  • Revision ID: barry.price@canonical.com-20160817045012-qfui81zhqnqv2ba9
Merge WP4.6 from upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
        }
39
39
 
40
40
        /**
41
 
         * Filter the list of fields saved in post revisions.
 
41
         * Filters the list of fields saved in post revisions.
42
42
         *
43
43
         * Included by default: 'post_title', 'post_content' and 'post_excerpt'.
44
44
         *
138
138
                }
139
139
 
140
140
                /**
141
 
                 * Filter whether the post has changed since the last revision.
 
141
                 * Filters whether the post has changed since the last revision.
142
142
                 *
143
143
                 * By default a revision is saved only if one of the revisioned fields has changed.
144
144
                 * This filter can override that so a revision is saved even if nothing has changed.
162
162
                        }
163
163
 
164
164
                        /**
165
 
                         * Filter whether a post has changed.
 
165
                         * Filters whether a post has changed.
166
166
                         *
167
167
                         * By default a revision is saved only if one of the revisioned fields has changed.
168
168
                         * This filter allows for additional checks to determine if there were changes.
322
322
 *
323
323
 * @param int|WP_Post $post   The post ID or object.
324
324
 * @param string      $output Optional. OBJECT, ARRAY_A, or ARRAY_N.
325
 
 * @param string      $filter Optional sanitation filter. @see sanitize_post().
 
325
 * @param string      $filter Optional sanitation filter. See sanitize_post().
326
326
 * @return WP_Post|array|null Null if error or post object if success.
327
327
 */
328
328
function wp_get_post_revision(&$post, $output = OBJECT, $filter = 'raw') {
378
378
        if ( ! $post_id || is_wp_error( $post_id ) )
379
379
                return $post_id;
380
380
 
381
 
        // Add restore from details
382
 
        $restore_details = array(
383
 
                'restored_revision_id' => $revision_id,
384
 
                'restored_by_user'     => get_current_user_id(),
385
 
                'restored_time'        => time()
386
 
        );
387
 
        update_post_meta( $post_id, '_post_restored_from', $restore_details );
388
 
 
389
381
        // Update last edit user
390
382
        update_post_meta( $post_id, '_edit_last', get_current_user_id() );
391
383
 
500
492
                $num = 0;
501
493
 
502
494
        /**
503
 
         * Filter the number of revisions to save for the given post.
 
495
         * Filters the number of revisions to save for the given post.
504
496
         *
505
497
         * Overrides the value of WP_POST_REVISIONS.
506
498
         *
538
530
        $post->post_excerpt = $preview->post_excerpt;
539
531
 
540
532
        add_filter( 'get_the_terms', '_wp_preview_terms_filter', 10, 3 );
 
533
        add_filter( 'get_post_metadata', '_wp_preview_post_thumbnail_filter', 10, 3 );
541
534
 
542
535
        return $post;
543
536
}
553
546
                $id = (int) $_GET['preview_id'];
554
547
 
555
548
                if ( false === wp_verify_nonce( $_GET['preview_nonce'], 'post_preview_' . $id ) )
556
 
                        wp_die( __('You do not have permission to preview drafts.') );
 
549
                        wp_die( __('Sorry, you are not allowed to preview drafts.') );
557
550
 
558
551
                add_filter('the_preview', '_set_preview');
559
552
        }
586
579
}
587
580
 
588
581
/**
 
582
 * Filters post thumbnail lookup to set the post thumbnail.
 
583
 *
 
584
 * @since 4.6.0
 
585
 * @access private
 
586
 *
 
587
 * @param null|array|string $value    The value to return - a single metadata value, or an array of values.
 
588
 * @param int               $post_id  Post ID.
 
589
 * @param string            $meta_key Meta key.
 
590
 * @return null|array The default return value or the post thumbnail meta array.
 
591
 */
 
592
function _wp_preview_post_thumbnail_filter( $value, $post_id, $meta_key ) {
 
593
        if ( ! $post = get_post() ) {
 
594
                return $value;
 
595
        }
 
596
 
 
597
        if ( empty( $_REQUEST['_thumbnail_id'] ) || $post->ID != $post_id || '_thumbnail_id' != $meta_key || 'revision' == $post->post_type ) {
 
598
                return $value;
 
599
        }
 
600
 
 
601
        $thumbnail_id = intval( $_REQUEST['_thumbnail_id'] );
 
602
        if ( $thumbnail_id <= 0 ) {
 
603
                return '';
 
604
        }
 
605
 
 
606
        return strval( $thumbnail_id );
 
607
}
 
608
 
 
609
/**
589
610
 * Gets the post revision version.
590
611
 *
591
612
 * @since 3.6.0