From 8aa89ec1cff34f4be8bfb38a2d36bdfcef5d2448 Mon Sep 17 00:00:00 2001 From: Tetrakern <26898880+Tetrakern@users.noreply.github.com> Date: Wed, 9 Aug 2023 02:46:23 +0200 Subject: [PATCH] Add conditional requires No need to load what's not used. --- functions.php | 18 ++++++++++++++---- includes/functions/_discord.php | 4 +++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/functions.php b/functions.php index 9267105c..dec49a78 100644 --- a/functions.php +++ b/functions.php @@ -361,19 +361,27 @@ require_once __DIR__ . '/includes/functions/_seo.php'; * Communicate with the Discord API. */ -require_once __DIR__ . '/includes/functions/_discord.php'; +if ( ! empty( get_option( 'fictioneer_discord_channel_comments_webhook' ) ) ) { + require_once __DIR__ . '/includes/functions/_discord.php'; +} /** * Generate ePUBs for stories. */ -require_once __DIR__ . '/includes/functions/_epub.php'; +// require_once __DIR__ . '/includes/functions/_epub.php'; + +if ( get_option( 'fictioneer_enable_epubs' ) ) { + require_once __DIR__ . '/includes/functions/_epub.php'; +} /** * Log-in and register subscribers via OAuth 2.0. */ -require_once __DIR__ . '/includes/functions/_oauth.php'; +if ( get_option( 'fictioneer_enable_oauth' ) ) { + require_once __DIR__ . '/includes/functions/_oauth.php'; +} /** * Handle comments on story pages. @@ -487,7 +495,9 @@ require_once __DIR__ . '/includes/functions/_forms.php'; * Add API. */ -require_once __DIR__ . '/includes/functions/_api.php'; +if ( get_option( 'fictioneer_enable_storygraph_api' ) ) { + require_once __DIR__ . '/includes/functions/_api.php'; +} /** * Add search. diff --git a/includes/functions/_discord.php b/includes/functions/_discord.php index 94987355..e21acfc4 100644 --- a/includes/functions/_discord.php +++ b/includes/functions/_discord.php @@ -46,7 +46,9 @@ if ( ! function_exists( 'fictioneer_discord_send_message' ) ) { function fictioneer_post_comment_to_discord( $comment_id, $comment_approved ) { // Exit conditions - if ( empty( get_option( 'fictioneer_discord_channel_comments_webhook' ) ) ) return; + if ( empty( get_option( 'fictioneer_discord_channel_comments_webhook' ) ) ) { + return; + } // Setup $comment = get_comment( $comment_id );