WordPress.org

Make WordPress Core

Ticket #22072: 22072-test.php

File 22072-test.php, 1.7 KB (added by mdawaffe, 19 months ago)
Line 
1<?php
2
3require 'wp-load.php';
4
5$post_id_with_title    = 10577;
6$post_id_without_title = 10558; // Must be post immediately preceding the $post_id_with_title post.
7
8// Initial State
9$post_with_title    = get_post( $post_id_with_title );
10$post_without_title = get_post( $post_id_without_title );
11
12echo "Initial State\n";
13var_dump( $post_with_title->post_title );
14// Expected: "This Post Has A Title"
15// Actual  : "This Post Has A Title"
16var_dump( $post_without_title->post_title );
17// Expected: ""
18// Actual  : ""
19
20echo "\n";
21
22
23echo "Trial 1: Do not clear the cache within get_adjacent_post_rel_link()\n";
24
25// Setup global post
26$GLOBALS['post'] = $post_with_title;
27setup_postdata( $post_with_title );
28
29get_adjacent_post_rel_link();
30
31// Trial 1 Results
32$post_with_title    = get_post( $post_id_with_title );
33$post_without_title = get_post( $post_id_without_title );
34
35var_dump( $post_with_title->post_title );
36// Expected: "This Post Has A Title"
37// Actual  : "This Post Has A Title"
38var_dump( $post_without_title->post_title );
39// Expected: ""
40// Actual  : ""
41
42echo "\n";
43
44
45echo "Trial 2: Clear the cache within get_adjacent_post_rel_link()\n";
46
47// Setup global post
48$GLOBALS['post'] = $post_with_title;
49setup_postdata( $post_with_title );
50
51// Clear cache within get_adjacent_post_rel_link()
52add_filter( 'the_title', function( $title, $post_id ) {
53        clean_post_cache( $post_id );
54        return $title;
55}, 10, 2 );
56
57get_adjacent_post_rel_link();
58
59// Trial 2 Results
60$post_with_title    = get_post( $post_id_with_title );
61$post_without_title = get_post( $post_id_without_title );
62
63var_dump( $post_with_title->post_title );
64// Expected: "This Post Has A Title"
65// Actual  : "This Post Has A Title"
66var_dump( $post_without_title->post_title );
67// Expected: ""
68// Actual  : "Previous Post"