Make WordPress Core

Ticket #22289: 22289.patch

File 22289.patch, 6.1 KB (added by ethitter, 10 years ago)
  • wp-admin/revision.php

     
    2828        if ( !$post = get_post( $revision->post_parent ) )
    2929                break;
    3030
     31        // Revision context to aid wp_post_revisions filter
     32        $context = 'admin-' . $action;
     33
    3134        // Revisions disabled and we're not looking at an autosave
    32         if ( ( ! WP_POST_REVISIONS || !post_type_supports($post->post_type, 'revisions') ) && !wp_is_post_autosave( $revision ) ) {
     35        if ( ( ! apply_filters( 'wp_post_revisions', WP_POST_REVISIONS, compact( 'context', 'post', 'revision' ) ) || !post_type_supports($post->post_type, 'revisions') ) && !wp_is_post_autosave( $revision ) ) {
    3336                $redirect = 'edit.php?post_type=' . $post->post_type;
    3437                break;
    3538        }
     
    7073        else
    7174                break; // Don't diff two unrelated revisions
    7275
    73         if ( ! WP_POST_REVISIONS || !post_type_supports($post->post_type, 'revisions') ) { // Revisions disabled
     76        // Revision context to aid wp_post_revisions filter
     77        $context = 'admin-' . $action;
     78
     79        if ( ! apply_filters( 'wp_post_revisions', WP_POST_REVISIONS, compact( 'context', 'post', 'left_revision', 'right_revision' ) ) || !post_type_supports($post->post_type, 'revisions') ) { // Revisions disabled
    7480                if (
    7581                        // we're not looking at an autosave
    7682                        ( !wp_is_post_autosave( $left_revision ) && !wp_is_post_autosave( $right_revision ) )
     
    111117        if ( !current_user_can( 'read_post', $revision->ID ) || !current_user_can( 'read_post', $post->ID ) )
    112118                break;
    113119
     120        // Revision context to aid wp_post_revisions filter
     121        $context = 'admin-' . $action;
     122
    114123        // Revisions disabled and we're not looking at an autosave
    115         if ( ( ! WP_POST_REVISIONS || !post_type_supports($post->post_type, 'revisions') ) && !wp_is_post_autosave( $revision ) ) {
     124        if ( ( ! apply_filters( 'wp_post_revisions', WP_POST_REVISIONS, compact( 'context', 'post', 'revision' ) ) || !post_type_supports($post->post_type, 'revisions') ) && !wp_is_post_autosave( $revision ) ) {
    116125                $redirect = 'edit.php?post_type=' . $post->post_type;
    117126                break;
    118127        }
     
    209218
    210219<?php
    211220
     221// Revision context to aid wp_post_revisions filter
     222$context = 'admin';
     223
    212224$args = array( 'format' => 'form-table', 'parent' => true, 'right' => $right, 'left' => $left );
    213 if ( ! WP_POST_REVISIONS || !post_type_supports($post->post_type, 'revisions') )
     225if ( ! apply_filters( 'wp_post_revisions', WP_POST_REVISIONS, compact( 'context', 'post', 'left', 'right' ) ) || !post_type_supports($post->post_type, 'revisions') )
    214226        $args['type'] = 'autosave';
    215227
    216228wp_list_post_revisions( $post, $args );
  • wp-includes/class-wp-xmlrpc-server.php

     
    35353535                        return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts.' ) );
    35363536
    35373537                // Check if revisions are enabled.
    3538                 if ( ! WP_POST_REVISIONS || ! post_type_supports( $post->post_type, 'revisions' ) )
     3538                $context = 'xmlrpc-get';
     3539                if ( ! apply_filters( 'wp_post_revisions', WP_POST_REVISIONS, compact( 'context', 'post', 'blog_id', 'username' ) ) || ! post_type_supports( $post->post_type, 'revisions' ) )
    35393540                        return new IXR_Error( 401, __( 'Sorry, revisions are disabled.' ) );
    35403541
    35413542                $revisions = wp_get_post_revisions( $post_id );
     
    35643565         *
    35653566         * @since 3.5.0
    35663567         *
     3568         * @uses apply_filters
    35673569         * @uses wp_restore_post_revision()
    35683570         *
    35693571         * @param array $args Method parameters. Contains:
     
    36023604                        return new IXR_Error( 401, __( 'Sorry, you cannot edit this post.' ) );
    36033605
    36043606                // Check if revisions are disabled.
    3605                 if ( ! WP_POST_REVISIONS || ! post_type_supports( $post->post_type, 'revisions' ) )
     3607                $context = 'xmlrpc-restore';
     3608                if ( ! apply_filters( 'wp_post_revisions', WP_POST_REVISIONS, compact( 'context', 'post', 'revision', 'blog_id', 'username' ) ) || ! post_type_supports( $post->post_type, 'revisions' ) )
    36063609                        return new IXR_Error( 401, __( 'Sorry, revisions are disabled.' ) );
    36073610
    36083611                $post = wp_restore_post_revision( $revision_id );
  • wp-includes/post.php

     
    49324932 * @subpackage Post_Revisions
    49334933 * @since 2.6.0
    49344934 *
     4935 * @uses apply_filters()
    49354936 * @uses _wp_put_post_revision()
    49364937 *
    49374938 * @param int $post_id The ID of the post to save as a revision.
     
    49424943        if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
    49434944                return;
    49444945
    4945         // WP_POST_REVISIONS = 0, false
    4946         if ( ! WP_POST_REVISIONS )
     4946        // Revision quantity
     4947        $context = 'save';
     4948        $revision_qty = apply_filters( 'wp_post_revisions', WP_POST_REVISIONS, compact( 'context', 'post_id' ) );
     4949
     4950        // $revision_qty = 0, false
     4951        if ( ! $revision_qty )
    49474952                return;
    49484953
    49494954        if ( !$post = get_post( $post_id, ARRAY_A ) )
     
    49574962
    49584963        $return = _wp_put_post_revision( $post );
    49594964
    4960         // WP_POST_REVISIONS = true (default), -1
    4961         if ( !is_numeric( WP_POST_REVISIONS ) || WP_POST_REVISIONS < 0 )
     4965        // $revision_qty = true (default), -1
     4966        if ( !is_numeric( $revision_qty ) || $revision_qty < 0 )
    49624967                return $return;
    49634968
    49644969        // all revisions and (possibly) one autosave
    49654970        $revisions = wp_get_post_revisions( $post_id, array( 'order' => 'ASC' ) );
    49664971
    4967         // WP_POST_REVISIONS = (int) (# of autosaves to save)
    4968         $delete = count($revisions) - WP_POST_REVISIONS;
     4972        // $revision_qty = (int) (# of autosaves to save)
     4973        $delete = count($revisions) - $revision_qty;
    49694974
    49704975        if ( $delete < 1 )
    49714976                return $return;
     
    52185223 * @subpackage Post_Revisions
    52195224 * @since 2.6.0
    52205225 *
     5226 * @uses apply_filters()
    52215227 * @uses get_children()
    52225228 *
    52235229 * @param int|object $post_id Post ID or post object
    52245230 * @return array empty if no revisions
    52255231 */
    52265232function wp_get_post_revisions( $post_id = 0, $args = null ) {
    5227         if ( ! WP_POST_REVISIONS )
     5233        $context = 'get';
     5234        $revision_qty = apply_filters( 'wp_post_revisions', WP_POST_REVISIONS, compact( 'context', 'post_id', 'args' ) );
     5235
     5236        if ( ! $revision_qty )
    52285237                return array();
     5238
    52295239        if ( ( !$post = get_post( $post_id ) ) || empty( $post->ID ) )
    52305240                return array();
    52315241