diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index ec523483..eeeeb573 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -306,6 +306,7 @@ Fictioneer customizes WordPress by using as many standard action and filter hook | `render_block` | `fictioneer_download_block_wrapper` | `rest_authentication_errors` | `fictioneer_restrict_rest_api` | `show_admin_bar` | `__return_false` +| `style_loader_tag` | `fictioneer_add_font_awesome_integrity` | `the_content` | `fictioneer_embed_consent_wrappers`, `fictioneer_add_lightbox_to_post_images`, `fictioneer_add_chapter_paragraph_id` | `the_password_form` | `fictioneer_password_form` | `theme_templates` | `fictioneer_disallow_page_template_select` diff --git a/INSTALLATION.md b/INSTALLATION.md index bde0e256..2eef048a 100644 --- a/INSTALLATION.md +++ b/INSTALLATION.md @@ -31,6 +31,7 @@ This guide is mainly written for people who never had their own WordPress site b * [Minimum/Maximum Values](#minimummaximum-values) * [Menus](#menus) * [Queries](#queries) + * [Font Awesome](#font-awesome) * [Constants](#constants) ## Choosing a Host @@ -858,6 +859,14 @@ if ( FICTIONEER_ENABLE_STICKY_CARDS ) { } ``` +### Font Awesome + +Fictioneer loads the free version of [Font Awesome 6.4.2](https://fontawesome.com/) by default and unless you want to use a different one or encounter compatibility issues (usually when a plugin includes FA as well), no action is required here. + +* If you want to include it via plugin (perhaps a Pro Kit) or custom function, disable the theme version under **Fictioneer > General > Compatibility**. + +* If you want to change the CDN link and integrity hash, do that by overwriting the `FICTIONEER_FA_CDN` and `FICTIONEER_FA_INTEGRITY` constants in a [child theme](https://developer.wordpress.org/themes/advanced-topics/child-themes/). You can set the integrity to `null` if not needed. + ### Constants Some options are not available in the settings because tempering with them can break the theme or result in unexpected behavior. Those options are defined via constants in the **function.php**. If you want to change them, you need a [child theme](https://developer.wordpress.org/themes/advanced-topics/child-themes/). Just override them in the child theme’s own **function.php**, but only if you know what you are doing! @@ -893,6 +902,8 @@ define( 'CONSTANT_NAME', value ); | FICTIONEER_CARD_PAGE_FOOTER_DATE | string | Page card footer date format. Default `"M j, 'y"`. | FICTIONEER_CARD_ARTICLE_FOOTER_DATE | string | Article card footer date format. Default `"M j, 'y"`. | FICTIONEER_STORY_FOOTER_B480_DATE | string | Story page footer date format (<= 480px). Default `"M j, 'y"`. +| FICTIONEER_FA_CDN | string | Font Awesome CDN URL. +| FICTIONEER_FA_INTEGRITY | string | Font Awesome integrity SHA384 hash. | FICTIONEER_COMMENTCODE_TTL | integer | How long guests can see their private/unapproved comments in _seconds_. Default `600`. | FICTIONEER_AJAX_TTL | integer | How long to cache certain AJAX requests locally in _milliseconds_. Default `60000`. | FICTIONEER_AJAX_LOGIN_TTL | integer | How long to cache AJAX authentications locally in _milliseconds_. Default `15000`. diff --git a/functions.php b/functions.php index 4ecf3ad1..ae7cab40 100644 --- a/functions.php +++ b/functions.php @@ -110,6 +110,19 @@ define( 'image/jpeg, image/png, image/webp, image/avif, image/gif, application/pdf, application/epub+zip, application/rtf, text/plain, image/svg+xml' ); +// String: Font Awesome CDN URL +if ( ! defined( 'FICTIONEER_FA_CDN' ) ) { + define( 'FICTIONEER_FA_CDN', 'https://use.fontawesome.com/releases/v6.4.2/css/all.css' ); +} + +// String: Font Awesome CDN integrity +if ( ! defined( 'FICTIONEER_FA_INTEGRITY' ) ) { + define( + 'FICTIONEER_FA_INTEGRITY', + 'sha384-blOohCVdhjmtROpu8+CfTnUWham9nkX7P7OZQMst+RUnhtoY/9qemFAkIKOYxDI3' + ); +} + /* * Date Strings */ diff --git a/includes/functions/_theme_setup.php b/includes/functions/_theme_setup.php index 322af59d..f2780555 100644 --- a/includes/functions/_theme_setup.php +++ b/includes/functions/_theme_setup.php @@ -432,59 +432,73 @@ function fictioneer_style_footer_queue() { add_action( 'get_footer', 'fictioneer_style_footer_queue' ); // ============================================================================= -// FONT AWESOME 6+ +// FONT AWESOME // ============================================================================= -if ( ! function_exists( 'fa_custom_setup_cdn_webfont' ) ) { +if ( ! function_exists( 'fictioneer_add_font_awesome_integrity' ) ) { /** - * Add Font Awesome 6+ to the site + * Enqueue Font Awesome * - * @since 4.5 + * @since 5.7.6 * @link https://fontawesome.com/docs/web/use-with/wordpress/install-manually - * @link https://fontawesome.com/account/cdn + * + * @param string $tag The link tag for the enqueued style. + * @param string $handle The style's registered handle. + * + * @return string The modified link tag. */ - function fa_custom_setup_cdn_webfont( $cdn_url = '', $integrity = null ) { - $matches = []; - $match_result = preg_match( '|/([^/]+?)\.css$|', $cdn_url, $matches ); - $resource_handle_uniqueness = ( $match_result === 1 ) ? $matches[1] : md5( $cdn_url ); - $resource_handle = "font-awesome-cdn-webfont-$resource_handle_uniqueness"; + function fictioneer_add_font_awesome_integrity( $tag, $handle ) { + // Abort conditions... + if ( empty( FICTIONEER_FA_INTEGRITY ) ) { + return $tag; + } - foreach ( ['wp_enqueue_scripts', 'admin_enqueue_scripts', 'login_enqueue_scripts'] as $action ) { + // Modify HTML + if ( $handle === 'font-awesome-cdn-webfont-fictioneer' ) { + $tag = preg_replace( '/\/>$/', 'integrity="' . FICTIONEER_FA_INTEGRITY . '" crossorigin="anonymous" />', $tag, 1 ); + } + + // 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 ) { add_action( $action, - function () use ( $cdn_url, $resource_handle ) { - wp_enqueue_style( $resource_handle, $cdn_url, [], null ); + function () { + wp_enqueue_style( 'font-awesome-cdn-webfont-fictioneer', FICTIONEER_FA_CDN, [], null ); } ); } - if ( $integrity ) { - add_filter( - 'style_loader_tag', - function( $html, $handle ) use ( $resource_handle, $integrity ) { - if ( in_array( $handle, [$resource_handle], true ) ) { - return preg_replace( - '/\/>$/', - 'integrity="' . $integrity . - '" crossorigin="anonymous" />', - $html, - 1 - ); - } else { - return $html; - } - }, - 10, - 2 - ); - } + // Filters + add_filter( 'style_loader_tag', 'fictioneer_add_font_awesome_integrity', 10, 2 ); } - fa_custom_setup_cdn_webfont( - 'https://use.fontawesome.com/releases/v6.1.2/css/all.css', - 'sha384-fZCoUih8XsaUZnNDOiLqnby1tMJ0sE7oBbNk2Xxf5x8Z4SvNQ9j83vFMa/erbVrV' - ); + // Initialize + if ( ! get_option( 'fictioneer_disable_font_awesome' ) ) { + fictioneer_add_font_awesome(); + } } // ============================================================================= diff --git a/includes/functions/settings/_register_settings.php b/includes/functions/settings/_register_settings.php index 6a1d2013..d8892971 100644 --- a/includes/functions/settings/_register_settings.php +++ b/includes/functions/settings/_register_settings.php @@ -635,6 +635,13 @@ define( 'FICTIONEER_OPTIONS', array( 'sanitize_callback' => 'fictioneer_sanitize_checkbox', 'label' => __( 'Show story changelog button', 'fictioneer' ), 'default' => false + ), + 'fictioneer_disable_font_awesome' => array( + 'name' => 'fictioneer_disable_font_awesome', + 'group' => 'fictioneer-settings-general-group', + 'sanitize_callback' => 'fictioneer_sanitize_checkbox', + 'label' => __( 'Disable Font Awesome integration', 'fictioneer' ), + 'default' => false ) ), 'integers' => array( diff --git a/includes/functions/settings/_settings_page_general.php b/includes/functions/settings/_settings_page_general.php index ab4b1ae3..a6706c47 100644 --- a/includes/functions/settings/_settings_page_general.php +++ b/includes/functions/settings/_settings_page_general.php @@ -825,6 +825,15 @@ ?> +