From 3dedafdfa4c7c51d216d568bc1981ed4b576b8f1 Mon Sep 17 00:00:00 2001 From: PieterT2000 Date: Mon, 8 Jun 2020 11:27:04 +0200 Subject: [PATCH] add acf return filter for empty values --- functions.php | 58 +++++++++++++++++++++++++++++++++++---------------- 1 file changed, 40 insertions(+), 18 deletions(-) diff --git a/functions.php b/functions.php index e261b35..d2a20b7 100644 --- a/functions.php +++ b/functions.php @@ -2,6 +2,24 @@ add_theme_support('custom-logo'); add_theme_support('menus'); +// Add custom settings to general settings +add_filter('admin_init', 'register_fields'); + +function register_fields() +{ + register_setting('general', 'frontend-dir', 'esc_attr'); + add_settings_field('frontend-dir', '', 'print_custom_field', 'general'); +} + +function print_custom_field() +{ + $host = explode(".", $_SERVER['HTTP_HOST']); + $defaultValue = $host[count($host) - 2]; // get the second-last item in the array to strip of also the TLD + + $value = get_option('frontend-dir', $defaultValue); + echo ''; +} + // Add site logo to rest api add_action('rest_api_init', 'add_logo_to_JSON'); @@ -82,6 +100,28 @@ function clickHandlerRebuildButton() ' . __('Frontend Directory', 'frontend-dir') . '', 'print_custom_field', 'general'); -} - -function print_custom_field() -{ - $host = explode(".", $_SERVER['HTTP_HOST']); - $defaultValue = $host[count($host) - 2]; // get the second-last item in the array to strip of also the TLD - - $value = get_option('frontend-dir', $defaultValue); - echo ''; -}