Restrict chapters of unpublished stories
This commit is contained in:
parent
b4917ec34e
commit
3377ed7c55
@ -1800,6 +1800,7 @@ function fictioneer_save_array_zero( $array ) {
|
|||||||
// REDIRECT TO 404
|
// REDIRECT TO 404
|
||||||
// =============================================================================
|
// =============================================================================
|
||||||
|
|
||||||
|
if ( ! function_exists( 'fictioneer_redirect_to_404' ) ) {
|
||||||
/**
|
/**
|
||||||
* Redirects the current request to the WordPress 404 page
|
* Redirects the current request to the WordPress 404 page
|
||||||
*
|
*
|
||||||
@ -1815,18 +1816,21 @@ function fictioneer_redirect_to_404() {
|
|||||||
|
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// =============================================================================
|
// =============================================================================
|
||||||
// UNPUBLISHED ACCESS
|
// UNPUBLISHED ACCESS
|
||||||
// =============================================================================
|
// =============================================================================
|
||||||
|
|
||||||
|
if ( ! function_exists( 'fictioneer_gate_unpublished_posts' ) ) {
|
||||||
/**
|
/**
|
||||||
* Restrict access to unpublished posts
|
* Restrict access to unpublished posts
|
||||||
*
|
*
|
||||||
* This is meant for sites with public caching, which could otherwise
|
* This is meant for sites with public caching, which could otherwise
|
||||||
* accidentally expose private posts or drafts.
|
* accidentally expose private posts or drafts. It ignored the current
|
||||||
|
* user in favor of preview query vars via `fictioneer_verify_preview_access()`.
|
||||||
*
|
*
|
||||||
* @global int|null $post_id Optional. The current post ID. Defaults to the
|
* @param int|null $post_id Optional. The current post ID. Defaults to the
|
||||||
* currently queried object ID.
|
* currently queried object ID.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -1844,5 +1848,28 @@ function fictioneer_gate_unpublished_posts( $post_id = null ) {
|
|||||||
fictioneer_redirect_to_404();
|
fictioneer_redirect_to_404();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// =============================================================================
|
||||||
|
// PREVIEW ACCESS VERIFICATION
|
||||||
|
// =============================================================================
|
||||||
|
|
||||||
|
if ( ! function_exists( 'fictioneer_verify_preview_access' ) ) {
|
||||||
|
/**
|
||||||
|
* Verifies preview query vars
|
||||||
|
*
|
||||||
|
* @return boolean True if access granted, false otherwise.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function fictioneer_verify_preview_access() {
|
||||||
|
if ( isset( $_GET['preview'], $_GET['preview_nonce'] ) && $_GET['preview'] === 'true' ) {
|
||||||
|
if ( wp_verify_nonce( $_GET['preview_nonce'], 'post_preview_' . $_GET['preview_id'] ) ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
@ -33,17 +33,13 @@ $story_id = fictioneer_get_field( 'fictioneer_chapter_story', get_queried_object
|
|||||||
$story_data = null;
|
$story_data = null;
|
||||||
$story_post = null;
|
$story_post = null;
|
||||||
|
|
||||||
// 404 if story set but not published
|
// Gate if story is unpublished
|
||||||
// if ( ! empty( $story_id ) && get_post_status( $story_id ) === 'publish' ) {
|
if ( ! empty( $story_id ) && get_post_status( $story_id ) === 'publish' ) {
|
||||||
// $story_post = empty( $story_id ) ? null : get_post( $story_id );
|
$story_post = empty( $story_id ) ? null : get_post( $story_id );
|
||||||
// }
|
} elseif ( ! empty( $story_id ) && ! fictioneer_verify_preview_access() ) {
|
||||||
|
|
||||||
if ( ! empty( $story_id ) && get_post_status( $story_id ) !== 'publish' ) {
|
|
||||||
fictioneer_redirect_to_404();
|
fictioneer_redirect_to_404();
|
||||||
}
|
}
|
||||||
|
|
||||||
$story_post = empty( $story_id ) ? null : get_post( $story_id );
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<div class="progress">
|
<div class="progress">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user