Add fictioneer logged-in cookie

This commit is contained in:
Tetrakern 2024-10-23 19:27:09 +02:00
parent cf8ef67497
commit 6788bfb5d2
5 changed files with 80 additions and 6 deletions

View File

@ -287,7 +287,7 @@ Fictioneer customizes WordPress by using as many standard action and filter hook
| `edit_user_profile_update` | `fictioneer_update_admin_user_profile` (10), `fictioneer_update_my_user_profile` (10), `fictioneer_update_admin_unlocked_posts` (10)
| `get_header` | `fictioneer_maintenance_mode` (10)
| `get_template_part` | `fictioneer_legacy_icon_menu_partial` (10)
| `init` | `fictioneer_add_character_taxonomy` (0), `fictioneer_add_content_warning_taxonomy` (0), `fictioneer_add_fandom_taxonomy` (0), `fictioneer_add_genre_taxonomy` (0), `fictioneer_add_logout_endpoint`, `fictioneer_fcn_chapter_post_type` (0), `fictioneer_fcn_collection_post_type` (0), `fictioneer_fcn_recommendation_post_type` (0), `fictioneer_fcn_story_post_type` (0), `fictioneer_add_epub_download_endpoint` (10), `fictioneer_add_oauth2_endpoint` (10), `fictioneer_restrict_admin_panel` (10), `fictioneer_disable_heartbeat` (1), `fictioneer_modify_allowed_tags` (20), `fictioneer_story_rss` (10), `fictioneer_remove_custom_fields_supports` (10), `fictioneer_add_sitemap_rewrite_rule` (10), `fictioneer_fast_ajax` (99999), `fictioneer_add_chapter_rewrite_tags` (10), `fictioneer_add_chapter_rewrite_rules` (10), `fictioneer_rewrite_chapter_permalink` (10), `fictioneer_disable_emojis` (10), `fictioneer_disable_page_optimize_plugin` (10)
| `init` | `fictioneer_add_character_taxonomy` (0), `fictioneer_add_content_warning_taxonomy` (0), `fictioneer_add_fandom_taxonomy` (0), `fictioneer_add_genre_taxonomy` (0), `fictioneer_add_logout_endpoint`, `fictioneer_fcn_chapter_post_type` (0), `fictioneer_fcn_collection_post_type` (0), `fictioneer_fcn_recommendation_post_type` (0), `fictioneer_fcn_story_post_type` (0), `fictioneer_add_epub_download_endpoint` (10), `fictioneer_add_oauth2_endpoint` (10), `fictioneer_restrict_admin_panel` (10), `fictioneer_disable_heartbeat` (1), `fictioneer_modify_allowed_tags` (20), `fictioneer_story_rss` (10), `fictioneer_remove_custom_fields_supports` (10), `fictioneer_add_sitemap_rewrite_rule` (10), `fictioneer_fast_ajax` (99999), `fictioneer_add_chapter_rewrite_tags` (10), `fictioneer_add_chapter_rewrite_rules` (10), `fictioneer_rewrite_chapter_permalink` (10), `fictioneer_disable_emojis` (10), `fictioneer_disable_page_optimize_plugin` (10), `fictioneer_fix_logged_in_cookie` (10)
| `login_form` | `fictioneer_after_logout_cleanup` (10)
| `login_head` | `fictioneer_wp_login_scripts` (10)
| `manage_comments_custom_column` | `fictioneer_add_comments_report_column_content` (10)
@ -301,6 +301,7 @@ Fictioneer customizes WordPress by using as many standard action and filter hook
| `restrict_manage_posts` | `fictioneer_add_chapter_story_filter_dropdown` (10)
| `save_post` | `fictioneer_refresh_chapters_schema` (20), `fictioneer_refresh_chapter_schema` (20), `fictioneer_refresh_collections_schema` (20), `fictioneer_refresh_post_caches` (20), `fictioneer_refresh_post_schema` (20), `fictioneer_refresh_recommendations_schema` (20), `fictioneer_refresh_recommendation_schema` (20), `fictioneer_refresh_stories_schema` (20), `fictioneer_refresh_story_schema` (20), `fictioneer_save_seo_metabox` (10), `fictioneer_save_word_count` (10), `fictioneer_track_chapter_and_story_updates` (10), `fictioneer_update_modified_date_on_story_for_chapter` (10), `fictioneer_update_shortcode_relationships` (10), `fictioneer_purge_transients_after_update` (10), `fictioneer_save_story_metaboxes` (10), `fictioneer_save_chapter_metaboxes` (10), `fictioneer_save_extra_metabox` (10), `fictioneer_save_support_links_metabox` (10), `fictioneer_save_collection_metaboxes` (10), `fictioneer_save_recommendation_metaboxes` (10), `fictioneer_save_post_metaboxes` (10), `fictioneer_delete_cached_story_card_after_update` (10), `fictioneer_rebuild_story_data_collection` (999), `fictioneer_post_chapter_to_discord` (99), `fictioneer_bulk_edit_save_patreon` (10), `fictioneer_bulk_edit_save_chapter_fields` (10)
| `send_headers` | `fictioneer_block_pages_from_indexing` (10)
| `set_logged_in_cookie` | `fictioneer_set_logged_in_cookie` (10)
| `show_user_profile` | `fictioneer_custom_profile_fields` (20)
| `shutdown` | `fictioneer_save_story_card_cache` (10)
| `switch_theme` | `fictioneer_theme_deactivation` (10)
@ -318,6 +319,7 @@ Fictioneer customizes WordPress by using as many standard action and filter hook
| `wp_footer` | `fictioneer_render_category_submenu` (10), `fictioneer_render_tag_submenu` (10), `fictioneer_render_genre_submenu` (10), `fictioneer_render_fandom_submenu` (10), `fictioneer_render_character_submenu` (10), `fictioneer_render_warning_submenu` (10)
| `wp_head` | `fictioneer_output_head_seo` (5), `fictioneer_output_rss` (10), `fictioneer_output_schemas` (10), `fictioneer_add_fiction_css` (10), `fictioneer_output_head_fonts` (5), `fictioneer_output_head_translations` (10), `fictioneer_remove_mu_registration_styles` (1), `fictioneer_output_mu_registration_style` (10), `fictioneer_output_head_meta` (1), `fictioneer_output_head_critical_scripts` (9999). `fictioneer_output_head_anti_flicker` (10), `fictioneer_cleanup_discord_meta` (10)
| `wp_insert_comment` | `fictioneer_delete_cached_story_card_by_comment` (10), `fictioneer_increment_story_comment_count` (10)
| `wp_logout` | `fictioneer_remove_logged_in_cookie` (10)
| `wp_update_nav_menu` | `fictioneer_purge_nav_menu_transients` (10)
<br>

View File

@ -2464,3 +2464,51 @@ function show_page_optimize_deactivated_notice() {
)
);
}
// =============================================================================
// LOGIN CHECK COOKIE
// =============================================================================
/**
* Sets the fictioneer login check cookie
*
* @since 5.26.0
* @link https://developer.wordpress.org/reference/functions/wp_set_auth_cookie/
*
* @param string $logged_in_cookie The logged-in cookie value.
* @param int $expire The time the login grace period expires as a UNIX timestamp.
* Default is 12 hours past the cookie's expiration time.
*/
function fictioneer_set_logged_in_cookie( $logged_in_cookie, $expire ) {
$cookie_domain = defined( 'COOKIE_DOMAIN' ) ? COOKIE_DOMAIN : $_SERVER['HTTP_HOST'];
setcookie( 'fcnLoggedIn', '1', $expire, COOKIEPATH, $cookie_domain, is_ssl(), false );
}
add_action( 'set_logged_in_cookie', 'fictioneer_set_logged_in_cookie', 10, 2 );
/**
* Removes the fictioneer login check cookie
*
* @since 5.26.0
*/
function fictioneer_remove_logged_in_cookie() {
$cookie_domain = defined( 'COOKIE_DOMAIN' ) ? COOKIE_DOMAIN : $_SERVER['HTTP_HOST'];
setcookie( 'fcnLoggedIn', '', time() - 3600, COOKIEPATH, $cookie_domain, is_ssl(), false );
}
add_action( 'wp_logout', 'fictioneer_remove_logged_in_cookie' );
/**
* Cleans up the fictioneer login check cookie
*
* @since 5.26.0
*/
function fictioneer_fix_logged_in_cookie() {
if ( ! get_current_user_id() && isset( $_COOKIE['fcnLoggedIn'] ) ) {
fictioneer_remove_logged_in_cookie();
}
}
add_action( 'init', 'fictioneer_fix_logged_in_cookie' );

8
js/complete.min.js vendored

File diff suppressed because one or more lines are too long

2
js/utility.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -949,3 +949,27 @@ function fcn_isSearchEngineCrawler() {
return crawlers.some(crawler => userAgent.includes(crawler));
}
// =============================================================================
// CHECK LOGIN STATUS
// =============================================================================
/**
* Checks whether to user is logged-in via special theme cookie.
*
* @since 5.26.0
*/
function fcn_isUserLoggedIn() {
const cookies = document.cookie.split(';');
for (let i = 0; i < cookies.length; i++) {
let cookie = cookies[i].trim();
if (cookie.indexOf('fcnLoggedIn=1') !== -1) {
return true;
}
}
return false;
}