2023-01-21 01:31:34 +01:00
|
|
|
<?php
|
|
|
|
|
2023-08-11 22:33:41 +02:00
|
|
|
// =============================================================================
|
|
|
|
// LEGACY CLEANUP
|
|
|
|
// =============================================================================
|
|
|
|
|
2023-08-11 23:51:30 +02:00
|
|
|
/**
|
|
|
|
* Clean up obsolete database entries
|
|
|
|
*
|
|
|
|
* @since 5.6.0
|
|
|
|
*/
|
|
|
|
|
2023-08-11 22:33:41 +02:00
|
|
|
function fictioneer_bring_out_legacy_trash() {
|
|
|
|
// Setup
|
|
|
|
$options = wp_cache_get( 'alloptions', 'options' );
|
2023-09-03 14:07:13 +02:00
|
|
|
$obsolete = ['fictioneer_disable_html_in_comments', 'fictioneer_block_subscribers_from_admin', 'fictioneer_admin_restrict_menus', 'fictioneer_admin_restrict_private_data', 'fictioneer_admin_reduce_subscriber_profile', 'fictioneer_enable_subscriber_self_delete', 'fictioneer_strip_shortcodes_for_non_administrators', 'fictioneer_restrict_media_access', 'fictioneer_subscription_enabled', 'fictioneer_patreon_badge_map', 'fictioneer_patreon_tier_as_badge', 'fictioneer_patreon_campaign_ids', 'fictioneer_patreon_campaign_id', 'fictioneer_mount_wpdiscuz_theme_styles', 'fictioneer_base_site_width', 'fictioneer_comment_form_selector', 'fictioneer_featherlight_enabled', 'fictioneer_tts_enabled', 'fictioneer_log', 'fictioneer_enable_ajax_nonce', 'fictioneer_flush_object_cache'];
|
2023-08-11 22:33:41 +02:00
|
|
|
|
2023-08-19 13:33:25 +02:00
|
|
|
// Check for most recent obsolete option...
|
2023-09-03 14:07:13 +02:00
|
|
|
if ( isset( $options['fictioneer_flush_object_cache'] ) ) {
|
2023-08-19 13:33:25 +02:00
|
|
|
// Looping everything is not great but it only happens once!
|
2023-08-11 22:37:53 +02:00
|
|
|
foreach ( $obsolete as $trash ) {
|
|
|
|
delete_option( $trash );
|
|
|
|
}
|
|
|
|
}
|
2023-08-11 22:33:41 +02:00
|
|
|
}
|
2023-08-19 13:33:25 +02:00
|
|
|
add_action( 'admin_init', 'fictioneer_bring_out_legacy_trash' );
|
2023-08-11 22:33:41 +02:00
|
|
|
|
2023-01-21 01:31:34 +01:00
|
|
|
// =============================================================================
|
|
|
|
// THEME SETUP
|
|
|
|
// =============================================================================
|
|
|
|
|
|
|
|
/**
|
2023-08-11 23:51:30 +02:00
|
|
|
* Sets up theme defaults and registers support for various WordPress features
|
2023-01-21 01:31:34 +01:00
|
|
|
*
|
2024-01-27 13:46:03 +01:00
|
|
|
* @since 1.0.0
|
2023-01-21 01:31:34 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
function fictioneer_theme_setup() {
|
|
|
|
// Load translations (if any)
|
|
|
|
load_theme_textdomain( 'fictioneer', get_template_directory() . '/languages' );
|
|
|
|
|
|
|
|
// Let WordPress handle the title tag
|
|
|
|
add_theme_support( 'title-tag' );
|
|
|
|
|
|
|
|
// Activate support for featured images (thumbnails)
|
|
|
|
add_theme_support(
|
|
|
|
'post-thumbnails',
|
|
|
|
array(
|
|
|
|
'post',
|
|
|
|
'page',
|
|
|
|
'fcn_story',
|
|
|
|
'fcn_chapter',
|
|
|
|
'fcn_recommendation',
|
|
|
|
'fcn_collection'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
// Register navigation menus
|
|
|
|
register_nav_menu( 'nav_menu', __( 'Navigation' ) );
|
|
|
|
register_nav_menu( 'footer_menu', __( 'Footer Menu' ) );
|
|
|
|
|
|
|
|
// Switch core markup to valid HTML5 (except 'comment-form' because WP adds novalidate for some reason)
|
|
|
|
add_theme_support(
|
|
|
|
'html5',
|
|
|
|
array(
|
|
|
|
'comment-list',
|
|
|
|
'search-form',
|
|
|
|
'gallery',
|
|
|
|
'caption',
|
|
|
|
'style',
|
|
|
|
'script'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
// Add support for custom backgrounds (with custom callback)
|
2023-08-19 13:33:25 +02:00
|
|
|
add_theme_support( 'custom-background', array( 'wp-head-callback' => 'fictioneer_custom_background' ) );
|
2023-01-21 01:31:34 +01:00
|
|
|
|
|
|
|
// Add support for custom header images
|
|
|
|
add_theme_support(
|
|
|
|
'custom-header',
|
|
|
|
array(
|
|
|
|
'flex-width' => true,
|
|
|
|
'flex-height' => true,
|
|
|
|
'height' => get_theme_mod( 'header_image_height_max', 480 )
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
// Add support for editor styles
|
|
|
|
add_theme_support( 'editor-styles' );
|
2023-08-18 23:48:02 +02:00
|
|
|
add_editor_style( '/css/editor.css' );
|
2023-01-21 01:31:34 +01:00
|
|
|
|
|
|
|
// Add support for custom logo
|
|
|
|
add_theme_support(
|
|
|
|
'custom-logo',
|
|
|
|
array(
|
|
|
|
'flex-width' => true,
|
|
|
|
'width' => (int) get_theme_mod( 'header_image_height_max', 210 ) * 1.5,
|
|
|
|
'flex-height' => true,
|
|
|
|
'height' => get_theme_mod( 'header_image_height_max', 210 ),
|
2023-08-19 13:33:25 +02:00
|
|
|
'header-text' => ['site-title', 'site-description'],
|
2023-01-21 01:31:34 +01:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2023-08-15 18:14:24 +02:00
|
|
|
// Remove block patterns
|
|
|
|
remove_theme_support( 'core-block-patterns' );
|
|
|
|
|
2023-08-19 13:33:25 +02:00
|
|
|
// Disable template editor (automatically added due to theme.json!)
|
2023-08-19 03:50:57 +02:00
|
|
|
remove_theme_support( 'block-templates' );
|
|
|
|
|
2023-08-15 18:24:14 +02:00
|
|
|
// Remove widget support...
|
|
|
|
if ( get_option( 'fictioneer_disable_all_widgets' ) ) {
|
|
|
|
remove_theme_support( 'widgets' );
|
|
|
|
remove_theme_support( 'widgets-block-editor' );
|
|
|
|
}
|
|
|
|
|
2023-01-21 01:31:34 +01:00
|
|
|
// Add new size for cover images used on story pages
|
|
|
|
add_image_size( 'cover', 400 );
|
|
|
|
|
|
|
|
// Add new size for cover snippets used in cards
|
|
|
|
add_image_size( 'snippet', 0, 200 );
|
|
|
|
}
|
|
|
|
add_action( 'after_setup_theme', 'fictioneer_theme_setup' );
|
|
|
|
|
|
|
|
// =============================================================================
|
2023-11-20 16:14:37 +01:00
|
|
|
// PROTECT META FIELDS
|
2023-11-20 14:16:05 +01:00
|
|
|
// =============================================================================
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes default custom fields meta box
|
|
|
|
*
|
|
|
|
* @since 5.8.0
|
|
|
|
*
|
|
|
|
* @param string $post_type Post type of the post on Edit Post screen, 'link'
|
|
|
|
* on Edit Link screen, 'dashboard' on Dashboard screen.
|
|
|
|
* @param string $context Meta box context. Possible values include 'normal',
|
|
|
|
* 'advanced', 'side'.
|
|
|
|
*/
|
|
|
|
|
2023-11-20 16:14:37 +01:00
|
|
|
function fictioneer_remove_custom_fields_meta_boxes( $post_type, $context ) {
|
2023-11-20 14:16:05 +01:00
|
|
|
remove_meta_box( 'postcustom', $post_type, $context );
|
|
|
|
}
|
2023-11-20 16:14:37 +01:00
|
|
|
add_action( 'do_meta_boxes', 'fictioneer_remove_custom_fields_meta_boxes', 1, 2 );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes 'custom-fields' support for posts and pages
|
|
|
|
*
|
|
|
|
* @since 5.8.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
function fictioneer_remove_custom_fields_supports() {
|
|
|
|
remove_post_type_support( 'post', 'custom-fields' );
|
|
|
|
remove_post_type_support( 'page', 'custom-fields' );
|
|
|
|
}
|
|
|
|
add_action( 'init', 'fictioneer_remove_custom_fields_supports' );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Makes theme meta fields protected
|
|
|
|
*
|
|
|
|
* @since 5.8.0
|
|
|
|
*
|
|
|
|
* @param bool $protected Whether the meta key is considered protected.
|
|
|
|
* @param string $meta_key The meta key to check.
|
|
|
|
*
|
|
|
|
* @return bool True if the meta key is protected, false otherwise.
|
|
|
|
*/
|
|
|
|
|
|
|
|
function fictioneer_make_theme_meta_protected( $protected, $meta_key ) {
|
|
|
|
if ( strpos( $meta_key, 'fictioneer_' ) === 0 ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $protected;
|
|
|
|
}
|
|
|
|
add_filter( 'is_protected_meta', 'fictioneer_make_theme_meta_protected', 10, 2 );
|
2023-11-20 14:16:05 +01:00
|
|
|
|
|
|
|
// =============================================================================
|
2023-11-21 17:59:02 +01:00
|
|
|
// PROTECT PERMALINKS
|
|
|
|
// =============================================================================
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prevents reserved slugs from being used in permalinks
|
|
|
|
*
|
|
|
|
* @since 5.8.0
|
|
|
|
*
|
|
|
|
* @param string $slug The prospective slug.
|
|
|
|
*
|
|
|
|
* @return string The filtered slug.
|
|
|
|
*/
|
|
|
|
|
|
|
|
function fictioneer_protect_reserved_post_slugs( $slug ) {
|
2024-01-13 02:59:24 +01:00
|
|
|
$protected = [FICTIONEER_OAUTH_ENDPOINT, FICTIONEER_EPUB_ENDPOINT, FICTIONEER_LOGOUT_ENDPOINT, 'fictioneer_sitemap'];
|
2023-11-21 17:59:02 +01:00
|
|
|
|
|
|
|
// Prevent slugs from being applied to posts
|
|
|
|
if ( in_array( $slug, $protected ) ) {
|
|
|
|
return $slug . '-2';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Continue filter
|
|
|
|
return $slug;
|
|
|
|
}
|
|
|
|
add_filter( 'wp_unique_post_slug', 'fictioneer_protect_reserved_post_slugs' );
|
|
|
|
|
|
|
|
// =============================================================================
|
2023-01-21 01:31:34 +01:00
|
|
|
// CUSTOM BACKGROUND CALLBACK
|
|
|
|
// =============================================================================
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fictioneer version of _custom_background_cb() for custom backgrounds
|
|
|
|
*
|
2024-01-26 17:45:59 +01:00
|
|
|
* @since 4.7.0
|
2023-01-21 01:31:34 +01:00
|
|
|
* @link https://developer.wordpress.org/reference/functions/_custom_background_cb/
|
|
|
|
*/
|
|
|
|
|
|
|
|
function fictioneer_custom_background() {
|
|
|
|
// Get background image
|
|
|
|
$background = set_url_scheme( get_background_image() );
|
|
|
|
|
|
|
|
// Abort if no background image
|
|
|
|
if ( ! $background ) {
|
|
|
|
echo '';
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Assign background image to property
|
|
|
|
$image = 'background-image: url("' . esc_url_raw( $background ) . '");';
|
|
|
|
|
|
|
|
// Background position
|
|
|
|
$position_x = get_theme_mod( 'background_position_x' );
|
|
|
|
$position_y = get_theme_mod( 'background_position_y' );
|
2023-08-19 13:33:25 +02:00
|
|
|
|
|
|
|
if ( ! in_array( $position_x, ['left', 'center', 'right'], true ) ) {
|
|
|
|
$position_x = 'left';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! in_array( $position_y, ['top', 'center', 'bottom'], true ) ) {
|
|
|
|
$position_y = 'top';
|
|
|
|
}
|
|
|
|
|
|
|
|
$position = "background-position: {$position_x} {$position_y};";
|
2023-01-21 01:31:34 +01:00
|
|
|
|
|
|
|
// Background size
|
|
|
|
$size = get_theme_mod( 'background_size' );
|
2023-08-19 13:33:25 +02:00
|
|
|
|
|
|
|
if ( ! in_array( $size, ['auto', 'contain', 'cover'], true ) ) {
|
|
|
|
$size = 'auto';
|
|
|
|
}
|
|
|
|
|
|
|
|
$size = "background-size: {$size};";
|
2023-01-21 01:31:34 +01:00
|
|
|
|
|
|
|
// Background repeat
|
|
|
|
$repeat = get_theme_mod( 'background_repeat' );
|
2023-08-19 13:33:25 +02:00
|
|
|
|
|
|
|
if ( ! in_array( $repeat, ['repeat-x', 'repeat-y', 'repeat', 'no-repeat'], true ) ) {
|
|
|
|
$repeat = 'repeat';
|
|
|
|
}
|
|
|
|
|
|
|
|
$repeat = "background-repeat: {$repeat};";
|
2023-01-21 01:31:34 +01:00
|
|
|
|
|
|
|
// Background scroll
|
|
|
|
$attachment = get_theme_mod( 'background_attachment' );
|
2023-08-19 13:33:25 +02:00
|
|
|
|
2023-08-27 23:53:01 +02:00
|
|
|
if ( $attachment !== 'fixed' ) {
|
2023-08-19 13:33:25 +02:00
|
|
|
$attachment = 'scroll';
|
|
|
|
}
|
|
|
|
|
|
|
|
$attachment = "background-attachment: {$attachment};";
|
2023-01-21 01:31:34 +01:00
|
|
|
|
|
|
|
// Build
|
|
|
|
$style = $image . $position . $size . $repeat . $attachment;
|
|
|
|
|
|
|
|
// Output
|
2023-08-27 23:53:01 +02:00
|
|
|
echo '<style id="custom-background-css" type="text/css">.custom-background {' . trim( $style ) . '}</style>';
|
2023-01-21 01:31:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// =============================================================================
|
|
|
|
// MODIFY ALLOWED TAGS
|
|
|
|
// =============================================================================
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update list of allowed tags
|
|
|
|
*
|
2024-01-26 17:45:59 +01:00
|
|
|
* @since 4.7.0
|
2023-01-21 01:31:34 +01:00
|
|
|
*
|
2023-08-11 22:23:54 +02:00
|
|
|
* @global array $allowedtags Array of allowed tags.
|
2023-01-21 01:31:34 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
function fictioneer_modify_allowed_tags() {
|
|
|
|
global $allowedtags;
|
|
|
|
|
|
|
|
$allowedtags['ins'] = array(
|
|
|
|
'datetime' => []
|
|
|
|
);
|
|
|
|
|
2023-08-19 13:33:25 +02:00
|
|
|
$allowedtags['p'] = [];
|
|
|
|
$allowedtags['span'] = [];
|
|
|
|
$allowedtags['br'] = [];
|
2023-01-21 01:31:34 +01:00
|
|
|
}
|
|
|
|
add_action( 'init', 'fictioneer_modify_allowed_tags', 20 );
|
|
|
|
|
|
|
|
// =============================================================================
|
|
|
|
// HTML ROOT INJECTION
|
|
|
|
// =============================================================================
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Injects attributes and classes into the <html> root
|
|
|
|
*
|
2024-01-26 17:45:59 +01:00
|
|
|
* @since 4.7.0
|
2023-01-21 01:31:34 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
function fictioneer_root_attributes() {
|
2023-09-17 21:17:36 +02:00
|
|
|
global $post;
|
|
|
|
|
|
|
|
// Setup
|
|
|
|
$post_author_id = ( $post instanceof WP_Post ) ? $post->post_author : 0;
|
2023-01-21 01:31:34 +01:00
|
|
|
$output = [];
|
|
|
|
$header_classes = [];
|
|
|
|
|
2023-09-17 21:17:36 +02:00
|
|
|
if ( is_archive() || is_search() || is_404() ) {
|
|
|
|
$post_author_id = 0;
|
|
|
|
}
|
|
|
|
|
2023-01-21 01:31:34 +01:00
|
|
|
// Add configuration classes
|
2023-08-19 13:33:25 +02:00
|
|
|
if ( get_theme_mod( 'inset_header_image', false ) ) {
|
|
|
|
$header_classes[] = 'inset-header-image';
|
|
|
|
}
|
2023-01-21 01:31:34 +01:00
|
|
|
|
2023-11-24 23:34:57 +01:00
|
|
|
// Header style
|
|
|
|
$header_classes[] = 'header-style-' . get_theme_mod( 'header_style', 'default' );
|
|
|
|
|
2023-01-21 01:31:34 +01:00
|
|
|
// Prepare
|
|
|
|
$output['class'] = implode( ' ', $header_classes );
|
2023-08-19 13:33:25 +02:00
|
|
|
$output['data-mode-default'] = get_option( 'fictioneer_light_mode_as_default', false ) ? 'light' : 'dark';
|
|
|
|
$output['data-site-width-default'] = get_theme_mod( 'site_width', 960 );
|
2023-01-21 01:31:34 +01:00
|
|
|
$output['data-theme'] = 'default';
|
2023-11-25 16:36:45 +01:00
|
|
|
$output['data-mode'] = $output['data-mode-default'];
|
2023-01-21 01:31:34 +01:00
|
|
|
$output['data-font-weight'] = 'default';
|
2023-02-08 20:54:54 +01:00
|
|
|
$output['data-primary-font'] = FICTIONEER_PRIMARY_FONT_CSS;
|
2023-08-19 13:33:25 +02:00
|
|
|
|
|
|
|
$conditions = array(
|
2024-01-20 15:27:46 +01:00
|
|
|
'data-age-confirmation' => get_option( 'fictioneer_enable_site_age_confirmation' ),
|
2023-08-30 19:18:23 +02:00
|
|
|
'data-caching-active' => fictioneer_caching_active(),
|
2023-08-19 13:33:25 +02:00
|
|
|
'data-ajax-submit' => get_option( 'fictioneer_enable_ajax_comment_submit', false ),
|
|
|
|
'data-force-child-theme' => ! FICTIONEER_THEME_SWITCH,
|
|
|
|
'data-public-caching' => get_option( 'fictioneer_enable_public_cache_compatibility', false ),
|
|
|
|
'data-ajax-auth' => get_option( 'fictioneer_enable_ajax_authentication', false ),
|
|
|
|
'data-edit-time' => get_option( 'fictioneer_enable_user_comment_editing', false ) ?
|
|
|
|
get_option( 'fictioneer_user_comment_edit_time', 15 ) : false,
|
|
|
|
);
|
|
|
|
|
|
|
|
// Iterate conditions and add the truthy to the output
|
|
|
|
foreach ( $conditions as $key => $condition ) {
|
|
|
|
if ( $condition ) {
|
|
|
|
$output[ $key ] = is_bool( $condition ) ? '1' : $condition;
|
|
|
|
}
|
|
|
|
}
|
2023-01-21 01:31:34 +01:00
|
|
|
|
2023-09-17 21:17:36 +02:00
|
|
|
// Fingerprint
|
|
|
|
if ( $post_author_id ) {
|
|
|
|
$output['data-author-fingerprint'] = fictioneer_get_user_fingerprint( $post_author_id );
|
|
|
|
}
|
|
|
|
|
2023-01-21 01:31:34 +01:00
|
|
|
// Filter output
|
|
|
|
$output = apply_filters( 'fictioneer_filter_root_attributes', $output );
|
|
|
|
|
|
|
|
// Output
|
|
|
|
foreach ( $output as $key => $value ) {
|
2023-08-19 13:33:25 +02:00
|
|
|
echo "{$key}='{$value}' ";
|
2023-01-21 01:31:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-11 12:14:16 +01:00
|
|
|
// =============================================================================
|
|
|
|
// ADD BODY CLASSES
|
|
|
|
// =============================================================================
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add additional classes to the frontend <body>
|
|
|
|
*
|
2024-01-26 17:45:59 +01:00
|
|
|
* @since 5.0.0
|
2024-01-11 12:14:16 +01:00
|
|
|
*
|
|
|
|
* @param array $classes Current body classes.
|
|
|
|
*
|
|
|
|
* @return array The updated body classes.
|
|
|
|
*/
|
|
|
|
|
|
|
|
function fictioneer_add_classes_to_body( $classes ) {
|
|
|
|
// Setup
|
|
|
|
$user = wp_get_current_user();
|
|
|
|
$includes = [];
|
|
|
|
|
2024-01-11 14:18:17 +01:00
|
|
|
// Mobile menu
|
|
|
|
if ( get_theme_mod( 'mobile_menu_style', 'minimize_to_right' ) === 'minimize_to_right' ) {
|
|
|
|
$classes[] = 'advanced-mobile-menu';
|
|
|
|
}
|
|
|
|
|
2024-01-11 12:14:16 +01:00
|
|
|
// Roles
|
|
|
|
if ( $user->ID > 0 && ! get_option( 'fictioneer_enable_public_cache_compatibility' ) ) {
|
|
|
|
$includes['is-admin'] = fictioneer_is_admin( $user->ID );
|
|
|
|
$includes['is-moderator'] = fictioneer_is_moderator( $user->ID );
|
|
|
|
$includes['is-author'] = fictioneer_is_author( $user->ID );
|
|
|
|
$includes['is-editor'] = fictioneer_is_editor( $user->ID );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Browsers
|
|
|
|
if ( ! fictioneer_caching_active() ) {
|
|
|
|
$includes['is-iphone'] = $GLOBALS['is_iphone'];
|
|
|
|
$includes['is-chrome'] = $GLOBALS['is_chrome'];
|
|
|
|
$includes['is-safari'] = $GLOBALS['is_safari'];
|
|
|
|
$includes['is-opera'] = $GLOBALS['is_opera'];
|
|
|
|
$includes['is-gecko'] = $GLOBALS['is_gecko'];
|
|
|
|
$includes['is-lynx'] = $GLOBALS['is_lynx'];
|
|
|
|
$includes['is-ie'] = $GLOBALS['is_IE'];
|
|
|
|
$includes['is-edge'] = $GLOBALS['is_edge'];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add classes to defaults
|
|
|
|
foreach ( $includes as $class => $test ) {
|
2024-01-27 21:00:00 +01:00
|
|
|
if ( $test ) {
|
2024-01-11 12:14:16 +01:00
|
|
|
$classes[ $class ] = $class;
|
|
|
|
}
|
2024-01-27 21:00:00 +01:00
|
|
|
}
|
2024-01-11 12:14:16 +01:00
|
|
|
|
|
|
|
// Continue filter
|
|
|
|
return $classes;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! is_admin() ) {
|
|
|
|
add_filter( 'body_class', 'fictioneer_add_classes_to_body' );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add additional classes to the admin <body>
|
|
|
|
*
|
2024-01-26 17:45:59 +01:00
|
|
|
* @since 5.0.0
|
2024-01-11 12:14:16 +01:00
|
|
|
*
|
2024-01-11 14:18:17 +01:00
|
|
|
* @param string $classes Current body classes separated by whitespace.
|
2024-01-11 12:14:16 +01:00
|
|
|
*
|
2024-01-11 14:18:17 +01:00
|
|
|
* @return string The updated body classes.
|
2024-01-11 12:14:16 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
function fictioneer_add_classes_to_admin_body( $classes ) {
|
|
|
|
// Setup
|
|
|
|
$user = wp_get_current_user();
|
|
|
|
$includes = [];
|
|
|
|
|
|
|
|
// Classes
|
|
|
|
$includes['is-admin'] = fictioneer_is_admin( $user->ID );
|
|
|
|
$includes['is-moderator'] = fictioneer_is_moderator( $user->ID );
|
|
|
|
$includes['is-author'] = fictioneer_is_author( $user->ID );
|
|
|
|
$includes['is-editor'] = fictioneer_is_editor( $user->ID );
|
|
|
|
|
|
|
|
// Add classes to defaults
|
|
|
|
if ( array_intersect( ['subscriber'], $user->roles ) ) {
|
|
|
|
$classes .= ' is-subscriber';
|
|
|
|
} else {
|
|
|
|
foreach ( $includes as $class => $test ) {
|
|
|
|
if ( $test ) {
|
|
|
|
$classes .= " $class";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Continue filter
|
|
|
|
return $classes;
|
|
|
|
}
|
|
|
|
add_filter( 'admin_body_class', 'fictioneer_add_classes_to_admin_body' );
|
|
|
|
|
2023-01-21 01:31:34 +01:00
|
|
|
// =============================================================================
|
|
|
|
// ENQUEUE STYLESHEETS
|
|
|
|
// =============================================================================
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enqueues stylesheets
|
|
|
|
*
|
2024-01-27 13:46:03 +01:00
|
|
|
* @since 1.0.0
|
|
|
|
* @since 4.7.0 - Split stylesheets into separate concerns.
|
2023-01-21 01:31:34 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
function fictioneer_style_queue() {
|
|
|
|
// Either load separate small style files on demand or the complete one
|
|
|
|
if ( ! get_option( 'fictioneer_bundle_stylesheets' ) ) {
|
|
|
|
// Setup
|
|
|
|
$post_type = get_post_type();
|
|
|
|
$application_dependencies = [];
|
|
|
|
|
|
|
|
// Properties
|
|
|
|
if ( ! get_option( 'fictioneer_disable_properties' ) ) {
|
|
|
|
wp_enqueue_style(
|
|
|
|
'fictioneer-properties',
|
|
|
|
get_template_directory_uri() . '/css/properties.css',
|
|
|
|
[],
|
2023-08-14 23:40:52 +02:00
|
|
|
FICTIONEER_VERSION
|
2023-01-21 01:31:34 +01:00
|
|
|
);
|
|
|
|
$application_dependencies[] = 'fictioneer-properties';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Application
|
|
|
|
wp_enqueue_style(
|
|
|
|
'fictioneer-application',
|
|
|
|
get_template_directory_uri() . '/css/application.css',
|
|
|
|
$application_dependencies,
|
2023-08-14 23:40:52 +02:00
|
|
|
FICTIONEER_VERSION
|
2023-01-21 01:31:34 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
// If NOT an archive or search page...
|
|
|
|
if ( ! is_search() && ! is_archive() ) {
|
|
|
|
// Collections
|
|
|
|
if ( is_page_template( 'stories.php' ) || $post_type == 'fcn_collection' ) {
|
|
|
|
wp_enqueue_style(
|
|
|
|
'fictioneer-collections',
|
|
|
|
get_template_directory_uri() . '/css/collections.css',
|
|
|
|
['fictioneer-application'],
|
2023-08-14 23:40:52 +02:00
|
|
|
FICTIONEER_VERSION
|
2023-01-21 01:31:34 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Chapter
|
|
|
|
if ( $post_type == 'fcn_chapter' ) {
|
|
|
|
wp_enqueue_style(
|
|
|
|
'fictioneer-chapter',
|
|
|
|
get_template_directory_uri() . '/css/chapter.css',
|
|
|
|
['fictioneer-application'],
|
2023-08-14 23:40:52 +02:00
|
|
|
FICTIONEER_VERSION
|
2023-01-21 01:31:34 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Story
|
|
|
|
if ( $post_type == 'fcn_story' ) {
|
|
|
|
wp_enqueue_style(
|
|
|
|
'fictioneer-story',
|
|
|
|
get_template_directory_uri() . '/css/story.css',
|
|
|
|
['fictioneer-application'],
|
2023-08-14 23:40:52 +02:00
|
|
|
FICTIONEER_VERSION
|
2023-01-21 01:31:34 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Recommendation
|
|
|
|
if ( $post_type == 'fcn_recommendation' ) {
|
|
|
|
wp_enqueue_style(
|
|
|
|
'fictioneer-recommendation',
|
|
|
|
get_template_directory_uri() . '/css/recommendation.css',
|
|
|
|
['fictioneer-application'],
|
2023-08-14 23:40:52 +02:00
|
|
|
FICTIONEER_VERSION
|
2023-01-21 01:31:34 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Comments
|
|
|
|
if ( $post_type == 'fcn_story' || comments_open() ) {
|
|
|
|
wp_enqueue_style(
|
|
|
|
'fictioneer-comments',
|
|
|
|
get_template_directory_uri() . '/css/comments.css',
|
|
|
|
['fictioneer-application'],
|
2023-08-14 23:40:52 +02:00
|
|
|
FICTIONEER_VERSION
|
2023-01-21 01:31:34 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Archive
|
|
|
|
if ( is_archive() ) {
|
|
|
|
wp_enqueue_style(
|
|
|
|
'fictioneer-archive',
|
|
|
|
get_template_directory_uri() . '/css/taxonomies.css',
|
|
|
|
['fictioneer-application'],
|
2023-08-14 23:40:52 +02:00
|
|
|
FICTIONEER_VERSION
|
2023-01-21 01:31:34 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Complete
|
|
|
|
wp_enqueue_style(
|
|
|
|
'fictioneer-complete',
|
|
|
|
get_template_directory_uri() . '/css/complete.css',
|
|
|
|
[],
|
2023-08-14 23:40:52 +02:00
|
|
|
FICTIONEER_VERSION
|
2023-01-21 01:31:34 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove Gutenberg default styles
|
|
|
|
if ( ! get_option( 'fictioneer_enable_all_block_styles' ) ) {
|
|
|
|
wp_dequeue_style( 'wp-block-library' );
|
|
|
|
wp_dequeue_style( 'wp-block-library-theme' );
|
|
|
|
wp_dequeue_style( 'wc-blocks-style' );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
add_action( 'wp_enqueue_scripts', 'fictioneer_style_queue' );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enqueues customizer stylesheets
|
|
|
|
*
|
2024-01-26 17:45:59 +01:00
|
|
|
* @since 5.0.0
|
2023-01-21 01:31:34 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
function fictioneer_customizer_queue() {
|
|
|
|
fictioneer_add_customized_layout_css();
|
|
|
|
fictioneer_add_customized_light_mode_css();
|
|
|
|
fictioneer_add_customized_dark_mode_css();
|
|
|
|
}
|
|
|
|
add_action( 'wp_enqueue_scripts', 'fictioneer_customizer_queue', 999 ); // Make sure this is added last!
|
|
|
|
|
|
|
|
// =============================================================================
|
|
|
|
// ENQUEUE OVERRIDE STYLESHEETS
|
|
|
|
// =============================================================================
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enqueues an "override" stylesheet that supersedes all others
|
|
|
|
*
|
2024-01-27 13:46:03 +01:00
|
|
|
* @since 2.0.0
|
2023-01-21 01:31:34 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
function fictioneer_style_footer_queue() {
|
|
|
|
wp_enqueue_style( 'override', get_template_directory_uri() . '/css/override.css' );
|
|
|
|
}
|
|
|
|
add_action( 'get_footer', 'fictioneer_style_footer_queue' );
|
|
|
|
|
|
|
|
// =============================================================================
|
2023-11-10 17:22:35 +01:00
|
|
|
// FONT AWESOME
|
2023-01-21 01:31:34 +01:00
|
|
|
// =============================================================================
|
|
|
|
|
2023-11-10 17:22:35 +01:00
|
|
|
if ( ! function_exists( 'fictioneer_add_font_awesome_integrity' ) ) {
|
2023-08-08 22:45:55 +02:00
|
|
|
/**
|
2023-11-10 17:22:35 +01:00
|
|
|
* Enqueue Font Awesome
|
2023-08-08 22:45:55 +02:00
|
|
|
*
|
2023-11-10 17:22:35 +01:00
|
|
|
* @since 5.7.6
|
2023-08-08 22:45:55 +02:00
|
|
|
* @link https://fontawesome.com/docs/web/use-with/wordpress/install-manually
|
2023-11-10 17:22:35 +01:00
|
|
|
*
|
|
|
|
* @param string $tag The link tag for the enqueued style.
|
|
|
|
* @param string $handle The style's registered handle.
|
|
|
|
*
|
|
|
|
* @return string The modified link tag.
|
2023-08-08 22:45:55 +02:00
|
|
|
*/
|
|
|
|
|
2023-11-10 17:22:35 +01:00
|
|
|
function fictioneer_add_font_awesome_integrity( $tag, $handle ) {
|
|
|
|
// Abort conditions...
|
|
|
|
if ( empty( FICTIONEER_FA_INTEGRITY ) ) {
|
|
|
|
return $tag;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Modify HTML
|
|
|
|
if ( $handle === 'font-awesome-cdn-webfont-fictioneer' ) {
|
|
|
|
$tag = preg_replace( '/\/>$/', 'integrity="' . FICTIONEER_FA_INTEGRITY . '" crossorigin="anonymous" />', $tag, 1 );
|
|
|
|
}
|
2023-01-21 01:31:34 +01:00
|
|
|
|
2023-11-10 17:22:35 +01:00
|
|
|
// Continue filter
|
|
|
|
return $tag;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! function_exists( 'fictioneer_add_font_awesome' ) ) {
|
|
|
|
/**
|
|
|
|
* Enqueue Font Awesome
|
|
|
|
*
|
|
|
|
* @since 5.7.6
|
|
|
|
* @link https://fontawesome.com/docs/web/use-with/wordpress/install-manually
|
|
|
|
*/
|
|
|
|
|
|
|
|
function fictioneer_add_font_awesome() {
|
|
|
|
// Abort conditions...
|
|
|
|
if ( empty( FICTIONEER_FA_CDN ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Setup
|
|
|
|
$actions = ['wp_enqueue_scripts', 'admin_enqueue_scripts', 'login_enqueue_scripts'];
|
|
|
|
|
|
|
|
// Actions
|
|
|
|
foreach ( $actions as $action ) {
|
2023-01-21 01:31:34 +01:00
|
|
|
add_action(
|
|
|
|
$action,
|
2023-11-10 20:23:23 +01:00
|
|
|
function() {
|
2023-11-10 17:22:35 +01:00
|
|
|
wp_enqueue_style( 'font-awesome-cdn-webfont-fictioneer', FICTIONEER_FA_CDN, [], null );
|
2023-01-21 01:31:34 +01:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-11-10 17:22:35 +01:00
|
|
|
// Filters
|
|
|
|
add_filter( 'style_loader_tag', 'fictioneer_add_font_awesome_integrity', 10, 2 );
|
2023-01-21 01:31:34 +01:00
|
|
|
}
|
|
|
|
|
2023-11-10 17:22:35 +01:00
|
|
|
// Initialize
|
|
|
|
if ( ! get_option( 'fictioneer_disable_font_awesome' ) ) {
|
|
|
|
fictioneer_add_font_awesome();
|
|
|
|
}
|
2023-01-21 01:31:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// =============================================================================
|
|
|
|
// ENQUEUE SCRIPTS
|
|
|
|
// =============================================================================
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enqueue scripts
|
|
|
|
*
|
2024-01-27 13:46:03 +01:00
|
|
|
* @since 1.0.0
|
|
|
|
* @since 4.7.0 - Split scripts and made enqueuing depending on options.
|
2023-01-21 01:31:34 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
function fictioneer_add_custom_scripts() {
|
|
|
|
// Setup
|
|
|
|
$post_type = get_post_type();
|
|
|
|
|
|
|
|
// Utility
|
2023-08-14 23:40:52 +02:00
|
|
|
wp_register_script( 'fictioneer-utility-scripts', get_template_directory_uri() . '/js/utility.min.js', [], FICTIONEER_VERSION, true );
|
2023-01-21 01:31:34 +01:00
|
|
|
|
|
|
|
// Application
|
2023-08-14 23:40:52 +02:00
|
|
|
wp_register_script( 'fictioneer-application-scripts', get_template_directory_uri() . '/js/application.min.js', [ 'fictioneer-utility-scripts', 'wp-i18n'], FICTIONEER_VERSION, true );
|
2023-01-21 01:31:34 +01:00
|
|
|
|
|
|
|
// Lightbox
|
|
|
|
if ( get_option( 'fictioneer_enable_lightbox' ) ) {
|
2023-08-14 23:40:52 +02:00
|
|
|
wp_enqueue_script( 'fictioneer-lightbox', get_template_directory_uri() . '/js/lightbox.min.js', ['fictioneer-application-scripts'], FICTIONEER_VERSION, true );
|
2023-01-21 01:31:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Mobile menu
|
2023-08-14 23:40:52 +02:00
|
|
|
wp_register_script( 'fictioneer-mobile-menu-scripts', get_template_directory_uri() . '/js/mobile-menu.min.js', [ 'fictioneer-application-scripts'], FICTIONEER_VERSION, true );
|
2023-01-21 01:31:34 +01:00
|
|
|
|
|
|
|
// Consent
|
2024-01-08 02:48:39 +01:00
|
|
|
wp_register_script( 'fictioneer-consent-scripts', get_template_directory_uri() . '/js/laws.min.js', [ 'fictioneer-application-scripts'], FICTIONEER_VERSION, true );
|
2023-01-21 01:31:34 +01:00
|
|
|
|
|
|
|
// Chapter
|
2023-08-14 23:40:52 +02:00
|
|
|
wp_register_script( 'fictioneer-chapter-scripts', get_template_directory_uri() . '/js/chapter.min.js', [ 'fictioneer-application-scripts'], FICTIONEER_VERSION, true );
|
2023-01-21 01:31:34 +01:00
|
|
|
|
|
|
|
// Suggestions
|
2023-08-14 23:40:52 +02:00
|
|
|
wp_register_script( 'fictioneer-suggestion-scripts', get_template_directory_uri() . '/js/suggestion.min.js', [ 'fictioneer-chapter-scripts'], FICTIONEER_VERSION, true );
|
2023-01-21 01:31:34 +01:00
|
|
|
|
|
|
|
// Text-To-Speech
|
2023-08-14 23:40:52 +02:00
|
|
|
wp_register_script( 'fictioneer-tts-scripts', get_template_directory_uri() . '/js/tts.min.js', [ 'fictioneer-chapter-scripts'], FICTIONEER_VERSION, true );
|
2023-01-21 01:31:34 +01:00
|
|
|
|
|
|
|
// Story
|
2023-08-14 23:40:52 +02:00
|
|
|
wp_register_script( 'fictioneer-story-scripts', get_template_directory_uri() . '/js/story.min.js', [ 'fictioneer-application-scripts'], FICTIONEER_VERSION, true );
|
2023-01-21 01:31:34 +01:00
|
|
|
|
|
|
|
// User
|
2023-08-14 23:40:52 +02:00
|
|
|
wp_register_script( 'fictioneer-user-scripts', get_template_directory_uri() . '/js/user.min.js', [ 'fictioneer-application-scripts'], FICTIONEER_VERSION, true );
|
2023-01-21 01:31:34 +01:00
|
|
|
|
|
|
|
// User Profile
|
2023-08-27 17:14:56 +02:00
|
|
|
wp_register_script( 'fictioneer-user-profile-scripts', get_template_directory_uri() . '/js/user-profile.min.js', [ 'fictioneer-application-scripts', 'fictioneer-user-scripts'], FICTIONEER_VERSION, true );
|
|
|
|
|
|
|
|
// Bookmarks
|
|
|
|
wp_register_script( 'fictioneer-bookmarks-scripts', get_template_directory_uri() . '/js/bookmarks.min.js', [ 'fictioneer-application-scripts', 'fictioneer-user-scripts'], FICTIONEER_VERSION, true );
|
2023-01-21 01:31:34 +01:00
|
|
|
|
|
|
|
// Follows
|
2023-08-27 17:14:56 +02:00
|
|
|
wp_register_script( 'fictioneer-follows-scripts', get_template_directory_uri() . '/js/follows.min.js', [ 'fictioneer-application-scripts', 'fictioneer-user-scripts'], FICTIONEER_VERSION, true );
|
2023-01-21 01:31:34 +01:00
|
|
|
|
|
|
|
// Checkmarks
|
2023-08-27 17:14:56 +02:00
|
|
|
wp_register_script( 'fictioneer-checkmarks-scripts', get_template_directory_uri() . '/js/checkmarks.min.js', [ 'fictioneer-application-scripts', 'fictioneer-user-scripts'], FICTIONEER_VERSION, true );
|
2023-01-21 01:31:34 +01:00
|
|
|
|
|
|
|
// Reminders
|
2023-08-27 17:14:56 +02:00
|
|
|
wp_register_script( 'fictioneer-reminders-scripts', get_template_directory_uri() . '/js/reminders.min.js', [ 'fictioneer-application-scripts', 'fictioneer-user-scripts'], FICTIONEER_VERSION, true );
|
2023-01-21 01:31:34 +01:00
|
|
|
|
|
|
|
// Comments
|
2023-08-14 23:40:52 +02:00
|
|
|
wp_register_script( 'fictioneer-comments-scripts', get_template_directory_uri() . '/js/comments.min.js', [ 'fictioneer-application-scripts'], FICTIONEER_VERSION, true );
|
2023-01-21 01:31:34 +01:00
|
|
|
|
|
|
|
// AJAX Comments
|
2023-08-14 23:40:52 +02:00
|
|
|
wp_register_script( 'fictioneer-ajax-comments-scripts', get_template_directory_uri() . '/js/ajax-comments.min.js', [ 'fictioneer-comments-scripts'], FICTIONEER_VERSION, true );
|
2023-01-21 01:31:34 +01:00
|
|
|
|
|
|
|
// AJAX Bookshelf
|
2023-08-14 23:40:52 +02:00
|
|
|
wp_register_script( 'fictioneer-ajax-bookshelf-scripts', get_template_directory_uri() . '/js/ajax-bookshelf.min.js', [ 'fictioneer-application-scripts'], FICTIONEER_VERSION, true );
|
2023-01-21 01:31:34 +01:00
|
|
|
|
|
|
|
// Enqueue utility
|
|
|
|
wp_enqueue_script( 'fictioneer-utility-scripts' );
|
|
|
|
|
|
|
|
// Enqueue application
|
|
|
|
wp_enqueue_script( 'fictioneer-application-scripts' );
|
2023-02-23 17:03:41 +01:00
|
|
|
|
2023-02-23 18:41:14 +01:00
|
|
|
// Localize application
|
2023-01-21 01:31:34 +01:00
|
|
|
wp_localize_script( 'fictioneer-application-scripts', 'fictioneer_ajax', array(
|
|
|
|
'ajax_url' => admin_url( 'admin-ajax.php' ),
|
2023-08-21 21:32:52 +02:00
|
|
|
'rest_url' => get_rest_url( null, 'fictioneer/v1/' ),
|
2023-01-21 01:31:34 +01:00
|
|
|
'ttl' => FICTIONEER_AJAX_TTL,
|
|
|
|
'login_ttl' => FICTIONEER_AJAX_LOGIN_TTL,
|
|
|
|
'post_debounce_rate' => FICTIONEER_AJAX_POST_DEBOUNCE_RATE
|
|
|
|
));
|
2023-02-23 17:03:41 +01:00
|
|
|
wp_localize_script( 'fictioneer-application-scripts', 'fictioneer_fonts', fictioneer_get_fonts() );
|
2023-02-23 18:41:14 +01:00
|
|
|
wp_localize_script( 'fictioneer-application-scripts', 'fictioneer_font_colors', fictioneer_get_font_colors() );
|
2023-02-23 17:03:41 +01:00
|
|
|
|
2023-05-23 00:57:30 +02:00
|
|
|
// Append JS snippets
|
2023-06-02 03:29:57 +02:00
|
|
|
$removable_query_args = ['success', 'failure', 'fictioneer_nonce', 'fictioneer-notice'];
|
2023-05-23 00:57:30 +02:00
|
|
|
$removable_query_args = apply_filters( 'fictioneer_filter_removable_query_args', $removable_query_args );
|
|
|
|
|
|
|
|
$extra_scripts = "
|
|
|
|
function fcn_removeQueryArgs() {
|
|
|
|
history.replaceState && history.replaceState(null, '', location.pathname + location.search.replace(/[?&](" . implode( '|', $removable_query_args ) . ")=[^&]+/g, '').replace(/^[?&]/, '?') + location.hash);
|
|
|
|
}
|
|
|
|
";
|
|
|
|
|
|
|
|
// Localize the script
|
|
|
|
wp_add_inline_script( 'fictioneer-application-scripts', $extra_scripts );
|
|
|
|
|
2023-01-21 01:31:34 +01:00
|
|
|
// Enqueue mobile menu
|
|
|
|
wp_enqueue_script( 'fictioneer-mobile-menu-scripts' );
|
|
|
|
|
|
|
|
// Enqueue consent
|
|
|
|
if ( get_option( 'fictioneer_cookie_banner' ) ) {
|
|
|
|
wp_enqueue_script( 'fictioneer-consent-scripts' );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Enqueue chapter
|
|
|
|
if ( $post_type == 'fcn_chapter' && ! is_archive() && ! is_search() ) {
|
|
|
|
wp_enqueue_script( 'fictioneer-chapter-scripts' );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Enqueue Diff-Match-Patch + suggestions
|
|
|
|
if (
|
|
|
|
$post_type == 'fcn_chapter' &&
|
|
|
|
get_option( 'fictioneer_enable_suggestions' ) &&
|
|
|
|
! is_archive() &&
|
|
|
|
! is_search() &&
|
|
|
|
! post_password_required() &&
|
2023-11-30 16:03:53 +01:00
|
|
|
! get_post_meta( get_the_ID(), 'fictioneer_disable_commenting', true ) &&
|
2023-01-21 01:31:34 +01:00
|
|
|
comments_open()
|
|
|
|
) {
|
|
|
|
wp_enqueue_script( 'dmp', get_template_directory_uri() . '/js/diff-match-patch.js', array(), null, true );
|
|
|
|
wp_enqueue_script( 'fictioneer-suggestion-scripts' );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Enqueue TTS
|
|
|
|
if (
|
|
|
|
$post_type == 'fcn_chapter' &&
|
|
|
|
get_option( 'fictioneer_enable_tts' ) &&
|
|
|
|
! is_archive() &&
|
|
|
|
! is_search() &&
|
|
|
|
! post_password_required()
|
|
|
|
) {
|
|
|
|
wp_enqueue_script( 'fictioneer-tts-scripts' );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Enqueue story
|
|
|
|
if ( $post_type == 'fcn_story' && ! is_archive() && ! is_search() ) {
|
|
|
|
wp_enqueue_script( 'fictioneer-story-scripts' );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Enqueue users + user profile + follows + checkmarks + reminders
|
2023-08-27 17:14:56 +02:00
|
|
|
if ( is_user_logged_in() || get_option( 'fictioneer_enable_ajax_authentication' ) ) {
|
2023-01-21 01:31:34 +01:00
|
|
|
wp_enqueue_script( 'fictioneer-user-scripts' );
|
|
|
|
|
|
|
|
if ( get_option( 'fictioneer_enable_checkmarks' ) ) {
|
|
|
|
wp_enqueue_script( 'fictioneer-checkmarks-scripts' );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( get_option( 'fictioneer_enable_reminders' ) ) {
|
|
|
|
wp_enqueue_script( 'fictioneer-reminders-scripts' );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( get_option( 'fictioneer_enable_follows' ) ) {
|
|
|
|
wp_enqueue_script( 'fictioneer-follows-scripts' );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( is_page_template( 'user-profile.php' ) ) {
|
|
|
|
wp_enqueue_script( 'fictioneer-user-profile-scripts' );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-27 17:14:56 +02:00
|
|
|
// Enqueue bookmarks
|
|
|
|
if ( get_option( 'fictioneer_enable_bookmarks' ) ) {
|
|
|
|
wp_enqueue_script( 'fictioneer-bookmarks-scripts' );
|
|
|
|
}
|
|
|
|
|
2023-01-21 01:31:34 +01:00
|
|
|
// Enqueue WordPress comment-reply
|
|
|
|
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
|
|
|
|
wp_enqueue_script( 'comment-reply' );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Enqueue comments
|
|
|
|
if ( is_singular() && comments_open() ) {
|
|
|
|
wp_enqueue_script( 'fictioneer-comments-scripts' );
|
|
|
|
|
|
|
|
if ( get_option( 'fictioneer_enable_ajax_comments' ) ) {
|
|
|
|
wp_enqueue_script( 'fictioneer-ajax-comments-scripts' );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Enqueue bookshelf
|
|
|
|
if ( is_page_template( 'singular-bookshelf-ajax.php' ) ) {
|
|
|
|
wp_enqueue_script( 'fictioneer-ajax-bookshelf-scripts' );
|
|
|
|
}
|
2023-08-27 22:03:18 +02:00
|
|
|
|
|
|
|
// DEV Utilities
|
|
|
|
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
|
|
|
|
wp_register_script( 'fictioneer-dev-scripts', get_template_directory_uri() . '/js/dev-tools.min.js', [ 'fictioneer-application-scripts'], FICTIONEER_VERSION, true );
|
|
|
|
wp_enqueue_script( 'fictioneer-dev-scripts' );
|
|
|
|
}
|
2023-01-21 01:31:34 +01:00
|
|
|
}
|
|
|
|
add_action( 'wp_enqueue_scripts', 'fictioneer_add_custom_scripts' );
|
|
|
|
|
2023-08-14 23:40:52 +02:00
|
|
|
/**
|
|
|
|
* Enqueue block editor scripts
|
|
|
|
*
|
|
|
|
* @since 5.6.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
function fictioneer_enqueue_block_editor_scripts() {
|
|
|
|
$current_user = wp_get_current_user();
|
|
|
|
|
|
|
|
wp_register_script(
|
|
|
|
'fictioneer-block-editor-scripts',
|
|
|
|
get_template_directory_uri() . '/js/block-editor.min.js',
|
2023-08-15 19:03:43 +02:00
|
|
|
['wp-dom-ready', 'wp-edit-post', 'wp-blocks', 'wp-element', 'wp-components', 'wp-editor', 'wp-data', 'jquery'],
|
2023-08-14 23:40:52 +02:00
|
|
|
FICTIONEER_VERSION,
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
wp_enqueue_script( 'fictioneer-block-editor-scripts' );
|
|
|
|
|
|
|
|
wp_localize_script( 'fictioneer-block-editor-scripts', 'fictioneerData', array(
|
|
|
|
'userCapabilities' => $current_user->allcaps
|
|
|
|
));
|
|
|
|
}
|
|
|
|
add_action( 'enqueue_block_editor_assets', 'fictioneer_enqueue_block_editor_scripts' );
|
|
|
|
|
2023-09-17 16:43:46 +02:00
|
|
|
// =============================================================================
|
|
|
|
// ADD SCRIPTS TO LOGIN HEAD
|
|
|
|
// =============================================================================
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Print scripts to the wp-login-php
|
|
|
|
*
|
|
|
|
* @since 5.7.3
|
|
|
|
*/
|
|
|
|
|
|
|
|
function fictioneer_wp_login_scripts() {
|
|
|
|
// Clear web storage in preparation of login
|
|
|
|
echo "<script type='text/javascript'>localStorage.removeItem('fcnUserData'); localStorage.removeItem('fcnAuth');</script>";
|
|
|
|
}
|
|
|
|
add_action( 'login_head', 'fictioneer_wp_login_scripts' );
|
|
|
|
|
2023-01-21 01:31:34 +01:00
|
|
|
// =============================================================================
|
|
|
|
// LOAD TRANSLATIONS FOR JAVASCRIPT
|
|
|
|
// =============================================================================
|
|
|
|
|
|
|
|
function fictioneer_load_script_translations() {
|
|
|
|
wp_set_script_translations(
|
|
|
|
'fictioneer-application-scripts',
|
|
|
|
'fictioneer',
|
|
|
|
get_template_directory() . '/languages'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
add_action( 'wp_enqueue_scripts', 'fictioneer_load_script_translations', 99 );
|
|
|
|
|
|
|
|
// =============================================================================
|
|
|
|
// DISABLE JQUERY MIGRATE
|
|
|
|
// =============================================================================
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removed the jQuery migrate script
|
|
|
|
*
|
2024-01-26 17:45:59 +01:00
|
|
|
* @since 5.0.0
|
2023-01-21 01:31:34 +01:00
|
|
|
*
|
2024-01-27 13:46:03 +01:00
|
|
|
* @param object $scripts The loaded scripts.
|
2023-01-21 01:31:34 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
function fictioneer_remove_jquery_migrate( $scripts ) {
|
|
|
|
// Abort if...
|
2023-08-28 10:43:04 +02:00
|
|
|
if ( ! isset( $scripts->registered['jquery'] ) ) {
|
|
|
|
return;
|
|
|
|
}
|
2023-01-21 01:31:34 +01:00
|
|
|
|
|
|
|
// Setup
|
|
|
|
$script = $scripts->registered['jquery'];
|
|
|
|
|
|
|
|
// Remove migrate script
|
|
|
|
if ( $script->deps ) {
|
|
|
|
$script->deps = array_diff( $script->deps, array( 'jquery-migrate' ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! is_admin() && ! get_option( 'fictioneer_enable_jquery_migrate' ) ) {
|
|
|
|
add_action( 'wp_default_scripts', 'fictioneer_remove_jquery_migrate' );
|
|
|
|
}
|
|
|
|
|
|
|
|
// =============================================================================
|
|
|
|
// AUTOPTIMIZE CONFIGURATION
|
|
|
|
// =============================================================================
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Change replace tag for Autoptimize (if installed)
|
|
|
|
*
|
2024-01-26 17:45:59 +01:00
|
|
|
* @since 4.0.0
|
2023-01-21 01:31:34 +01:00
|
|
|
* @link https://github.com/wp-plugins/autoptimize
|
|
|
|
*
|
2024-01-27 13:46:03 +01:00
|
|
|
* @param string $replacetag The original replace tag.
|
2023-01-21 01:31:34 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
function fictioneer_replace_ao_insert_position( $replacetag ) {
|
|
|
|
return array( '<injectjs />', 'replace' );
|
|
|
|
}
|
|
|
|
add_filter( 'autoptimize_filter_js_replacetag', 'fictioneer_replace_ao_insert_position', 10, 1 );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Exclude scripts from Autoptimize (if installed)
|
|
|
|
*
|
2024-01-26 17:45:59 +01:00
|
|
|
* @since 4.0.0
|
2023-01-21 01:31:34 +01:00
|
|
|
* @link https://github.com/wp-plugins/autoptimize
|
|
|
|
*
|
2024-01-27 13:46:03 +01:00
|
|
|
* @param string $exclude List of default excludes.
|
2023-01-21 01:31:34 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
function fictioneer_ao_exclude_scripts( $exclude ) {
|
2024-01-27 21:00:00 +01:00
|
|
|
return $exclude . '';
|
2023-01-21 01:31:34 +01:00
|
|
|
}
|
|
|
|
add_filter( 'autoptimize_filter_js_exclude', 'fictioneer_ao_exclude_scripts', 10, 1 );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Exclude stylesheets from Autoptimize (if installed)
|
|
|
|
*
|
2024-01-26 17:45:59 +01:00
|
|
|
* @since 4.0.0
|
2023-01-21 01:31:34 +01:00
|
|
|
* @link https://github.com/wp-plugins/autoptimize
|
|
|
|
*
|
|
|
|
* @param string $exclude List of default excludes.
|
|
|
|
*/
|
|
|
|
|
|
|
|
function fictioneer_ao_exclude_css( $exclude ) {
|
2024-01-27 21:00:00 +01:00
|
|
|
return $exclude . ', fonts.css';
|
2023-01-21 01:31:34 +01:00
|
|
|
}
|
|
|
|
add_filter( 'autoptimize_filter_css_exclude', 'fictioneer_ao_exclude_css', 10, 1 );
|
|
|
|
|
|
|
|
// =============================================================================
|
|
|
|
// OUTPUT HEAD FONTS
|
|
|
|
// =============================================================================
|
|
|
|
|
|
|
|
if ( ! function_exists( 'fictioneer_output_head_fonts' ) ) {
|
|
|
|
/**
|
|
|
|
* Output fonts in <head>
|
|
|
|
*
|
|
|
|
* Critical fonts that need to be loaded as fast as possible and are
|
|
|
|
* therefore inlined in the <head>.
|
|
|
|
*
|
2024-01-26 17:45:59 +01:00
|
|
|
* @since 5.0.0
|
2023-01-21 01:31:34 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
function fictioneer_output_head_fonts() {
|
|
|
|
// Setup
|
|
|
|
$uri = get_template_directory_uri() . '/fonts/';
|
|
|
|
|
|
|
|
// Start HTML ---> ?>
|
2023-08-25 21:35:19 +02:00
|
|
|
<style id="inline-fonts" type="text/css">@font-face{font-family:'Open Sans';font-style:normal;font-weight:325;font-stretch:100%;font-display:swap;src:url(<?php echo $uri; ?>open-sans-v27-latin-ext_latin/open-sans-latin-extended-325-normal.woff2) format('woff2'),local("OpenSans-Light");unicode-range:U+0100-024F,U+0259,U+1E00-1EFF,U+2020,U+20A0-20AB,U+20AD-20CF,U+2113,U+2C60-2C7F,U+A720-A7FF}@font-face{font-family:'Open Sans';font-style:normal;font-weight:325;font-stretch:100%;font-display:swap;src:url(<?php echo $uri; ?>open-sans-v27-latin-ext_latin/open-sans-latin-325-normal.woff2) format('woff2'),local("OpenSans-Light");unicode-range:U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+2000-206F,U+2074,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD}@font-face{font-family:"Open Sans";font-style:normal;font-weight:400;font-display:swap;src:local("OpenSans-Regular"),url(<?php echo $uri; ?>open-sans-v27-latin-ext_latin/open-sans-v27-latin-ext_latin-regular.woff2) format("woff2"),url(<?php echo $uri; ?>open-sans-v27-latin-ext_latin/open-sans-v27-latin-ext_latin-regular.woff) format("woff")}@font-face{font-family:"Open Sans";font-style:normal;font-weight:500;font-display:swap;src:local("OpenSans-Medium"),url(<?php echo $uri; ?>open-sans-v27-latin-ext_latin/open-sans-v27-latin-ext_latin-500.woff2) format("woff2"),url(<?php echo $uri; ?>open-sans-v27-latin-ext_latin/open-sans-v27-latin-ext_latin-500.woff) format("woff")}@font-face{font-family:"Open Sans";font-style:normal;font-weight:600;font-display:swap;src:local("OpenSans-SemiBold"),url(<?php echo $uri; ?>open-sans-v27-latin-ext_latin/open-sans-v27-latin-ext_latin-600.woff2) format("woff2"),url(<?php echo $uri; ?>open-sans-v27-latin-ext_latin/open-sans-v27-latin-ext_latin-600.woff) format("woff")}@font-face{font-family:"Open Sans";font-style:normal;font-weight:700;font-display:swap;src:local("OpenSans-Bold"),url(<?php echo $uri; ?>open-sans-v27-latin-ext_latin/open-sans-v27-latin-ext_latin-700.woff2) format("woff2"),url(<?php echo $uri; ?>open-sans-v27-latin-ext_latin/open-sans-v27-latin-ext_latin-700.woff) format("woff")}@font-face{font-family:'Open Sans';font-style:italic;font-weight:325;font-stretch:100%;font-display:swap;src:url(<?php echo $uri; ?>open-sans-v27-latin-ext_latin/open-sans-latin-extended-325-italic.woff2) format('woff2'),local("OpenSans-LightItalic");unicode-range:U+0100-024F,U+0259,U+1E00-1EFF,U+2020,U+20A0-20AB,U+20AD-20CF,U+2113,U+2C60-2C7F,U+A720-A7FF}@font-face{font-family:'Open Sans';font-style:italic;font-weight:325;font-stretch:100%;font-display:swap;src:url(<?php echo $uri; ?>open-sans-v27-latin-ext_latin/open-sans-latin-325-italic.woff2) format('woff2'),local("OpenSans-LightItalic");unicode-range:U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+2000-206F,U+2074,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD}@font-face{font-family:"Open Sans";font-style:italic;font-weight:400;font-display:swap;src:local("OpenSans-Italic"),url(<?php echo $uri; ?>open-sans-v27-latin-ext_latin/open-sans-v27-latin-ext_latin-italic.woff2) format("woff2"),url(<?php echo $uri; ?>open-sans-v27-latin-ext_latin/open-sans-v27-latin-ext_latin-italic.woff) format("woff")}@font-face{font-family:"Open Sans";font-style:italic;font-weight:500;font-display:swap;src:local("OpenSans-MediumItalic"),url(<?php echo $uri; ?>open-sans-v27-latin-ext_latin/open-sans-v27-latin-ext_latin-500italic.woff2) format("woff2"),url(<?php echo $uri; ?>open-sans-v27-latin-ext_latin/open-sans-v27-latin-ext_latin-500italic.woff) format("woff")}@font-face{font-family:"Open Sans";font-style:italic;font-weight:600;font-display:swap;src:local("OpenSans-SemiBoldItalic"),url(<?php echo $uri; ?>open-sans-v27-latin-ext_latin/open-sans-v27-latin-ext_latin-600italic.woff2) format("woff2"),url(<?php echo $uri; ?>open-sans-v27-latin-ext_latin/open-sans-v27-latin-ext_latin-600italic.woff) format("woff")}@font-face{font-family:"Open Sans";font-style:italic;font-weight:700;font-display:swap;src:local("OpenSans-BoldItalic"),url(<?php echo $uri; ?>open-sans-v27-latin-ex
|
2023-01-21 01:31:34 +01:00
|
|
|
<?php // <--- End HTML
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// =============================================================================
|
|
|
|
// OUTPUT HEAD META
|
|
|
|
// =============================================================================
|
|
|
|
|
|
|
|
if ( ! function_exists( 'fictioneer_output_head_meta' ) ) {
|
|
|
|
/**
|
|
|
|
* Output HTML <head> meta
|
|
|
|
*
|
2024-01-26 17:45:59 +01:00
|
|
|
* @since 5.0.0
|
2023-01-21 01:31:34 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
function fictioneer_output_head_meta() {
|
|
|
|
// Setup
|
|
|
|
$font_link = get_template_directory_uri() . '/css/fonts.css?ver=' . FICTIONEER_VERSION;
|
|
|
|
|
|
|
|
// Start HTML ---> ?>
|
2023-11-24 12:05:32 +01:00
|
|
|
<meta charset="<?php echo get_bloginfo( 'charset' ); ?>">
|
2023-01-21 01:31:34 +01:00
|
|
|
<meta http-equiv="content-type" content="text/html">
|
|
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
|
|
|
<meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=5.0, viewport-fit=cover">
|
|
|
|
<meta name="format-detection" content="telephone=no">
|
|
|
|
<meta name="theme-color" content="<?php echo '#' . get_background_color(); ?>">
|
|
|
|
<meta name="referrer" content="strict-origin-when-cross-origin">
|
|
|
|
<?php fictioneer_output_head_fonts(); ?>
|
|
|
|
<link rel="stylesheet" href="<?php echo $font_link; ?>" media="print" onload="this.media='all';">
|
|
|
|
<noscript><link rel="stylesheet" href="<?php echo $font_link; ?>"></noscript>
|
|
|
|
<?php // <--- End HTML
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// =============================================================================
|
|
|
|
// MODIFY ROBOTS META
|
|
|
|
// =============================================================================
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds noindex to robots meta.
|
|
|
|
*
|
|
|
|
* This is called in the header.php template.
|
|
|
|
*
|
2024-01-26 17:45:59 +01:00
|
|
|
* @since 5.0.0
|
2023-01-21 01:31:34 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
function fictioneer_add_noindex_to_robots( $robots ) {
|
|
|
|
$robots['noindex'] = true;
|
|
|
|
return $robots;
|
|
|
|
}
|
|
|
|
|
|
|
|
// =============================================================================
|
|
|
|
// OUTPUT HEAD CRITICAL SCRIPTS
|
|
|
|
// =============================================================================
|
|
|
|
|
|
|
|
if ( ! function_exists( 'fictioneer_output_head_critical_scripts' ) ) {
|
|
|
|
/**
|
|
|
|
* Output critical path scripts in <head>
|
|
|
|
*
|
|
|
|
* Critical path scripts executed in the <head> before the rest of the DOM
|
|
|
|
* is loaded. This is necessary for the light/dark switch and site settings
|
|
|
|
* to work without causing color flickering or layout shifts. This is achieved
|
|
|
|
* by adding configuration classes directly into the <html> root node, which
|
|
|
|
* is the only one available at this point.
|
|
|
|
*
|
2024-01-26 17:45:59 +01:00
|
|
|
* @since 5.0.0
|
2023-01-21 01:31:34 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
function fictioneer_output_head_critical_scripts() {
|
|
|
|
// Start HTML ---> ?>
|
2023-11-25 16:36:45 +01:00
|
|
|
<script>!function(){if("undefined"!=typeof localStorage){const t=localStorage.getItem("fcnLightmode"),e=document.documentElement;let a,o,r=localStorage.getItem("fcnSiteSettings");if(r&&(r=JSON.parse(r))&&null!==r&&"object"==typeof r){Object.entries(r).forEach((t=>{switch(t[0]){case"minimal":e.classList.toggle("minimal",t[1]);break;case"darken":a=r.darken,o=a>=0?1+Math.pow(a,2):1-Math.pow(a,2),e.style.setProperty("--darken",o);break;case"saturation":a=r.saturation,o=a>=0?1+Math.pow(a,2):1-Math.pow(a,2),e.style.setProperty("--saturation",o);break;case"font-saturation":a=r["font-saturation"],o=a>=0?1+Math.pow(a,2):1-Math.pow(a,2),e.style.setProperty("--font-saturation",o);break;case"hue-rotate":o=Number.isInteger(r["hue-rotate"])?r["hue-rotate"]:0,e.style.setProperty("--hue-rotate",`${o}deg`);break;default:e.classList.toggle(`no-${t[0]}`,!t[1])}})),e.dataset.fontWeight=r.hasOwnProperty("font-weight")?r["font-weight"]:"default",e.dataset.theme=r.hasOwnProperty("site-theme")&&!e.dataset.forceChildTheme?r["site-theme"]:"default";let t=getComputedStyle(document.documentElement).getPropertyValue("--theme-color-base").trim().split(" "),n=r.darken?r.darken:0,s=r.saturation?r.saturation:0,i=r["hue-rotate"]?r["hue-rotate"]:0,l=n>=0?1+Math.pow(n,2):1-Math.pow(n,2);r=s>=0?1+Math.pow(s,2):1-Math.pow(s,2),t=`hsl(${(parseInt(t[0])+i)%360}deg ${(parseInt(t[1])*r).toFixed(2)}% ${(parseInt(t[2])*l).toFixed(2)}%)`,document.querySelector("meta[name=theme-color]").setAttribute("content",t)}t&&(e.dataset.mode="true"==t?"light":"dark")}}();</script>
|
2023-01-21 01:31:34 +01:00
|
|
|
<?php // <--- End HTML
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-31 08:09:02 +01:00
|
|
|
// =============================================================================
|
|
|
|
// ADD EXCERPTS TO PAGES
|
|
|
|
// =============================================================================
|
|
|
|
|
|
|
|
add_post_type_support( 'page', 'excerpt' );
|
|
|
|
|
2023-06-09 11:31:40 +02:00
|
|
|
// =============================================================================
|
|
|
|
// PAGINATION
|
|
|
|
// =============================================================================
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Modifies the pagination links output for the theme
|
|
|
|
*
|
2024-01-26 17:45:59 +01:00
|
|
|
* @since 5.4.0
|
2023-06-09 11:31:40 +02:00
|
|
|
* @link https://developer.wordpress.org/reference/functions/paginate_links/
|
|
|
|
*
|
2024-01-27 13:46:03 +01:00
|
|
|
* @param array $args Optional. Array of arguments for generating the pagination links.
|
2023-06-09 11:31:40 +02:00
|
|
|
*
|
|
|
|
* @return string Modified pagination links HTML.
|
|
|
|
*/
|
|
|
|
|
|
|
|
function fictioneer_paginate_links( $args = [] ) {
|
2023-10-03 01:54:02 +02:00
|
|
|
$args['end_size'] = 1;
|
|
|
|
$args['mid_size'] = 1;
|
2023-06-09 11:31:40 +02:00
|
|
|
$pagination = paginate_links( $args );
|
|
|
|
|
|
|
|
return str_replace(
|
|
|
|
'class="page-numbers dots"',
|
|
|
|
'class="page-numbers dots" tabindex="0"',
|
|
|
|
$pagination
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-01-27 13:46:03 +01:00
|
|
|
// =============================================================================
|
|
|
|
// MODIFY ADMINBAR
|
|
|
|
// =============================================================================
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds 'Add Chapter' link to adminbar with pre-assigned chapter story
|
|
|
|
*
|
|
|
|
* @since 5.9.3
|
|
|
|
*
|
2024-01-28 15:31:16 +01:00
|
|
|
* @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance, passed by reference.
|
2024-01-27 13:46:03 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
function fictioneer_adminbar_add_chapter_link( $wp_admin_bar ) {
|
|
|
|
if ( ( is_single() && get_post_type() === 'fcn_story' ) || ( is_admin() && get_current_screen()->id === 'fcn_story' ) ) {
|
|
|
|
$story_id = get_the_ID();
|
|
|
|
$story_post = get_post( $story_id );
|
|
|
|
|
|
|
|
if ( $story_id && $story_post->post_author == get_current_user_id() ) {
|
|
|
|
$wp_admin_bar->add_node(
|
|
|
|
array(
|
|
|
|
'id' => 'fictioneer-add-chapter',
|
|
|
|
'title' => '<span class="ab-icon dashicons dashicons-text-page" style="top: 4px; font-size: 16px;"></span> ' . __( 'Add Chapter', 'fictioneer' ),
|
|
|
|
'href' => admin_url( 'post-new.php?post_type=fcn_chapter&story_id=' . $story_id ),
|
|
|
|
'meta' => array( 'class' => 'adminbar-add-chapter' )
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
add_action( 'admin_bar_menu', 'fictioneer_adminbar_add_chapter_link', 99 );
|
|
|
|
|
2023-01-21 01:31:34 +01:00
|
|
|
?>
|