Google Maps API Key 未使用 AdvancedCustomFields 进行设置



我正在开发一个WordPress网站,该网站使用AdvancedCustomFields插件在页面上显示Google地图。几个月前地图显示正确,没有错误,但 API 密钥不再发送?在"网络"选项卡下,我可以看到没有 API 密钥的 API 请求正在发送。

我最初对现有代码所做的唯一更改是将 API 密钥从旧的(可能已过期的?)密钥更新为新密钥。

在 #acf.php 中,我有以下代码来设置 ACF 映射字段的 API 密钥。

function carbon_acf_init_google_maps_api_key() {
    $google_maps_api_key = 'xxxxxMyAPIKeyxxxxxxxx';
    acf_update_setting( 'google_api_key', $google_maps_api_key );
}
add_action( 'acf/init', 'carbon_acf_init_google_maps_api_key' );

我希望正确设置API密钥并正确显示地图。相反,我没有看到任何变化,开发控制台的网络选项卡仍然显示没有密钥的 API 调用。

我正在使用,对我有用。

function my_acf_google_map_api( $api ){
    $api['key'] = '********************************';
    return $api;
}
add_filter('acf/fields/google_map/api', 'my_acf_google_map_api');

最新更新