diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php
index 98ad57f..dfeb89c 100644
a
|
b
|
function is_sticky( $post_id = 0 ) { |
2098 | 2098 | * |
2099 | 2099 | * @see sanitize_post_field() |
2100 | 2100 | * |
2101 | | * @param object|WP_Post|array $post The Post Object or Array |
| 2101 | * @param object|WP_Post|array $post The Post Object or Array. |
2102 | 2102 | * @param string $context Optional. How to sanitize post fields. |
2103 | 2103 | * Accepts 'raw', 'edit', 'db', or 'display'. |
2104 | 2104 | * Default 'display'. |
… |
… |
function is_sticky( $post_id = 0 ) { |
2106 | 2106 | * same type as $post). |
2107 | 2107 | */ |
2108 | 2108 | function sanitize_post( $post, $context = 'display' ) { |
| 2109 | |
| 2110 | $original_post = $post; |
| 2111 | |
2109 | 2112 | if ( is_object( $post ) ) { |
2110 | 2113 | // Check if post already filtered for this context. |
2111 | 2114 | if ( isset( $post->filter ) && $context == $post->filter ) { |
… |
… |
function sanitize_post( $post, $context = 'display' ) { |
2131 | 2134 | } |
2132 | 2135 | $post['filter'] = $context; |
2133 | 2136 | } |
2134 | | return $post; |
| 2137 | |
| 2138 | /** |
| 2139 | * Filters the sanitized post fields. |
| 2140 | * |
| 2141 | * @since 5.0.0 |
| 2142 | * |
| 2143 | * @param object|WP_Post|array $post The sanitized Post Object or Array. |
| 2144 | * @param object|WP_Post|array $original_post The Post Object or Array. |
| 2145 | * @param string $context Optional. How to sanitize post fields. |
| 2146 | * Accepts 'raw', 'edit', 'db', or 'display'. |
| 2147 | * Default 'display'. |
| 2148 | */ |
| 2149 | return apply_filters( 'sanitize_post', $post, $original_post, $context ); |
2135 | 2150 | } |
2136 | 2151 | |
2137 | 2152 | /** |
diff --git a/tests/phpunit/tests/post.php b/tests/phpunit/tests/post.php
index c0b20bb..4fa81a9 100644
a
|
b
|
class Tests_Post extends WP_UnitTestCase { |
1354 | 1354 | $this->assertEquals( $changeset_data, json_decode( get_post( $post_id )->post_content, true ) ); |
1355 | 1355 | } |
1356 | 1356 | |
| 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, 3 ); |
| 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, 3 ); |
| 1374 | } |
| 1375 | |
| 1376 | public function filter_sanitize_post( $post, $original_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 | |
1357 | 1391 | } |