Skip to content

Commit fccd54d

Browse files
authored
Merge pull request #174 from imranhsayed/fix/purge-cache-post-status-change
Fix the purge caching issue when the post status is changed to draft or pending
2 parents 7bced91 + 668e793 commit fccd54d

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

admin/class-purger.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,29 @@ private function _purge_by_options( $post_id, $blog_id, $_purge_page, $_purge_ar
213213
$this->log( "Purging custom post type '" . $_post_type . "' ( id " . $post_id . ', blog id ' . $blog_id . ' )' );
214214
}
215215

216-
$url = get_permalink( $post_id );
216+
$post_status = get_post_status( $post_id );
217+
218+
if ( 'publish' !== $post_status ) {
219+
220+
if ( ! function_exists( 'get_sample_permalink' ) ) {
221+
require_once ABSPATH . '/wp-admin/includes/post.php';
222+
}
223+
224+
$url = get_sample_permalink( $post_id );
225+
226+
if ( ! empty( $url[0] ) && ! empty( $url[1] ) ) {
227+
$url = str_replace( '%postname%', $url[1], $url[0] );
228+
} else {
229+
$url = '';
230+
}
231+
232+
} else {
233+
$url = get_permalink( $post_id );
234+
}
235+
236+
if ( empty( $url ) && ! is_array( $url ) ) {
237+
return;
238+
}
217239

218240
if ( 'trash' === get_post_status( $post_id ) ) {
219241
$url = str_replace( '__trashed', '', $url );

0 commit comments

Comments
 (0)