Handle story redirect

This commit is contained in:
Tetrakern 2024-04-14 22:56:40 +02:00
parent 698fe3d313
commit b58a46781b
2 changed files with 29 additions and 1 deletions

View File

@ -237,7 +237,7 @@ Fictioneer customizes WordPress by using as many standard action and filter hook
| `save_post` | `fictioneer_refresh_chapters_schema`, `fictioneer_refresh_chapter_schema`, `fictioneer_refresh_collections_schema`, `fictioneer_refresh_post_caches`, `fictioneer_refresh_post_schema`, `fictioneer_refresh_recommendations_schema`, `fictioneer_refresh_recommendation_schema`, `fictioneer_refresh_stories_schema`, `fictioneer_refresh_story_schema`, `fictioneer_save_seo_metabox`, `fictioneer_save_word_count`, `fictioneer_track_chapter_and_story_updates`, `fictioneer_update_modified_date_on_story_for_chapter`, `fictioneer_update_shortcode_relationships`, `fictioneer_purge_transients`, `fictioneer_post_story_to_discord`, `fictioneer_post_chapter_to_discord`, `fictioneer_save_story_metaboxes`, `fictioneer_save_chapter_metaboxes`, `fictioneer_save_advanced_metabox`, `fictioneer_save_support_links_metabox`, `fictioneer_save_collection_metaboxes`, `fictioneer_save_recommendation_metaboxes`, `fictioneer_save_post_metaboxes`
| `show_user_profile` | `fictioneer_custom_profile_fields`
| `switch_theme` | `fictioneer_theme_deactivation`
| `template_redirect` | `fictioneer_disable_date_archives`, `fictioneer_generate_epub`, `fictioneer_handle_oauth`, `fictioneer_logout`, `fictioneer_disable_attachment_pages`, `fictioneer_gate_unpublished_content`, `fictioneer_serve_sitemap`
| `template_redirect` | `fictioneer_disable_date_archives`, `fictioneer_generate_epub`, `fictioneer_handle_oauth`, `fictioneer_logout`, `fictioneer_disable_attachment_pages`, `fictioneer_gate_unpublished_content`, `fictioneer_serve_sitemap`, `fictioneer_redirect_story`
| `transition_post_status` | `fictioneer_log_story_chapter_status_changes`
| `trashed_post` | `fictioneer_refresh_post_caches`, `fictioneer_track_chapter_and_story_updates`, `fictioneer_update_modified_date_on_story_for_chapter`, `fictioneer_purge_transients`, `fictioneer_remove_chapter_from_story`
| `untrash_post` | `fictioneer_refresh_post_caches`, `fictioneer_track_chapter_and_story_updates`, `fictioneer_update_modified_date_on_story_for_chapter`, `fictioneer_purge_transients`

View File

@ -1532,3 +1532,31 @@ function fictioneer_output_head_translations() {
echo "<script id='fictioneer-translations' type='text/javascript' data-no-optimize='1' data-no-defer='1' data-no-minify='1'>const fictioneer_tl = " . json_encode( fictioneer_get_js_translations() ) . ";</script>";
}
add_action( 'wp_head', 'fictioneer_output_head_translations' );
// =============================================================================
// STORY REDIRECT
// =============================================================================
/**
* Directs story if a redirect link is set
*
* @since 5.14.0
*/
function fictioneer_redirect_story() {
global $post;
// Abort if...
if ( ! is_single() || get_post_type( $post ) !== 'fcn_story' ) {
return;
}
// Setup
$redirect = get_post_meta( $post->ID ?? 0, 'fictioneer_story_redirect_link', true );
if ( $redirect ) {
wp_redirect( $redirect, 301 );
exit;
}
}
add_action( 'template_redirect', 'fictioneer_redirect_story' );