Skip to content

Commit

Permalink
Move settings to their own packages
Browse files Browse the repository at this point in the history
  • Loading branch information
powerbuoy committed Oct 28, 2019
1 parent f7669ae commit 2ef61e3
Showing 1 changed file with 0 additions and 61 deletions.
61 changes: 0 additions & 61 deletions sleek-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,83 +60,22 @@ function get_setting ($name) {
}, SETTINGS_SECTION_NAME); # NOTE: WP Docs says this should be the add_options_page slug but that doesn't work. It needs to be the same as is later passed to do_settings_section

# Built-in fields
add_setting('google_maps_api_key', 'text', __('Google Maps API Key', 'sleek'));
# TODO: Move to sleek-google-search
# add_setting('google_search_api_key', 'text', __('Google Search API Key', 'sleek'));
# add_setting('google_search_engine_id', 'text', __('Google Search Engine ID', 'sleek'));
add_setting('head_code', 'textarea', esc_html__('Code inside <head>', 'sleek'));
add_setting('foot_code', 'textarea', esc_html__('Code just before </body>', 'sleek'));
add_setting('cookie_consent', 'textarea', esc_html__('Cookie consent text', 'sleek'));
add_setting('site_notice', 'textarea', esc_html__('Site notice', 'sleek'));
});

########
# Header
add_action('wp_head', function () {
# Custom head code
if ($code = get_setting('head_code')) {
echo $code;
}

# Cookie consent text
if ($consent = get_setting('cookie_consent')) {
$cookieConsent = $consent;
}
else {
$cookieUrl = get_option('wp_page_for_privacy_policy') ? get_permalink(get_option('wp_page_for_privacy_policy')) : 'https://cookiesandyou.com/';
$cookieConsent = apply_filters('sleek_cookie_consent', sprintf(__('We use cookies to bring you the best possible experience when browsing our site. <a href="%s" target="_blank">Read more</a> | <a href="#" class="close">Accept</a>', 'sleek'), $cookieUrl), $cookieUrl);
}

# echo '<script>SLEEK_COOKIE_CONSENT = ' . json_encode($cookieConsent) . '</script>';
});

########
# Footer
add_action('wp_footer', function () {
# Custom foot code
if ($code = get_setting('foot_code')) {
echo $code;
}

# Google Maps
if ($key = get_setting('google_maps_api_key')) {
echo "<script>
window.gmAsyncInit = function () {};
function gmInit (cb) {
if (window.google && window.google.maps) {
cb(window.google);
}
else {
var oldGMInit = window.gmAsyncInit;
window.gmAsyncInit = function () {
oldGMInit();
cb(window.google);
};
}
}
</script>";
}
});

############################
# Include google maps JS api
add_action('wp_enqueue_scripts', function () {
if ($key = get_setting('google_maps_api_key')) {
wp_register_script('google_maps', 'https://maps.googleapis.com/maps/api/js?key=' . $key . '&callback=gmAsyncInit', [], null, true);
wp_enqueue_script('google_maps');
}
});

################################
# Add Google Maps API Key to ACF
add_action('init', function () {
if ($key = get_setting('google_maps_api_key')) {
add_filter('acf/fields/google_map/api', function ($api) use ($key) {
$api['key'] = $key;

return $api;
});
}
});

0 comments on commit 2ef61e3

Please sign in to comment.