Make WordPress Core

Ticket #43638: 43638.patch

File 43638.patch, 2.5 KB (added by enrico.sorcinelli, 8 years ago)
  • src/wp-includes/post.php

    diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php
    index e46f949..b601963 100644
    a b function is_sticky( $post_id = 0 ) { 
    20292029 *
    20302030 * @see sanitize_post_field()
    20312031 *
    2032  * @param object|WP_Post|array $post    The Post Object or Array
     2032 * @param object|WP_Post|array $post    The Post Object or Array.
    20332033 * @param string               $context Optional. How to sanitize post fields.
    20342034 *                                      Accepts 'raw', 'edit', 'db', or 'display'.
    20352035 *                                      Default 'display'.
    function is_sticky( $post_id = 0 ) { 
    20372037 *                              same type as $post).
    20382038 */
    20392039function sanitize_post( $post, $context = 'display' ) {
     2040
     2041        /**
     2042         * Filters the post fields.
     2043         *
     2044         * @since 5.0.0
     2045         *
     2046         * @param object|WP_Post|array $post    The Post Object or Array.
     2047         * @param string               $context Optional. How to sanitize post fields.
     2048         *                                      Accepts 'raw', 'edit', 'db', or 'display'.
     2049         *                                      Default 'display'.
     2050         */
     2051        $post = apply_filters( 'sanitize_post', $post, $context );
     2052
    20402053        if ( is_object( $post ) ) {
    20412054                // Check if post already filtered for this context.
    20422055                if ( isset( $post->filter ) && $context == $post->filter ) {
  • tests/phpunit/tests/post.php

    diff --git a/tests/phpunit/tests/post.php b/tests/phpunit/tests/post.php
    index c0b20bb..ff1ee07 100644
    a b class Tests_Post extends WP_UnitTestCase { 
    13541354                $this->assertEquals( $changeset_data, json_decode( get_post( $post_id )->post_content, true ) );
    13551355        }
    13561356
     1357        /**
     1358         * Test 'sanitize_post' filter.
     1359         *
     1360         * @ticket 43638
     1361         */
     1362        public function test_sanitize_post_filter() {
     1363                add_filter( 'sanitize_post', array( $this, 'filter_sanitize_post' ), 10, 2 );
     1364                $post_id = wp_insert_post(
     1365                        array(
     1366                                'post_type' => 'post',
     1367                                'post_title' => 'Stuff and Things',
     1368                                'post_status' => 'draft'
     1369                        )
     1370                );
     1371                $post = get_post( $post_id );
     1372                $this->assertEquals( $post->post_title, 'Stuff and Things - draft' );
     1373                remove_filter( 'sanitize_post', array( $this, 'filter_sanitize_post' ), 10, 2 );
     1374        }
     1375
     1376        public function filter_sanitize_post( $post, $context ) {
     1377                if ( 'raw' === $context ) {
     1378                        return $post;
     1379                }
     1380                if ( $context === 'db' ) {
     1381                        if ( is_object( $post ) ) {
     1382                                $post->post_title .= ' - ' . $post->post_status;
     1383                        }
     1384                        else {
     1385                                $post['post_title'] .= ' - ' . $post['post_status'];
     1386                        }
     1387                }
     1388                return $post;
     1389        }
     1390
    13571391}