@timmse @thomas
Have the following code, function works perfectly registers new dynamic tag and creates / adds the new group.
I am working with Bricks 2.0.1 local dev, + advanced themer, no other plugins. Using a simple text element with the dynamic data tag. ssl is good.
The IP renders in the builder for admin as:
::1
My filter / function code is:
add_filter( 'bricks/dynamic_tags_list', 'add_user_ip_tag_to_builder' );
function add_user_ip_tag_to_builder( $tags ) {
$tags[] = [
'name' => '{user_ip}', // tag name to use in Bricks
'label' => 'User IP Address', // label for dynamic data dropdown
'group' => 'User Data', // custom Bricks Group
];
return $tags;
}
add_filter( 'bricks/dynamic_data/render_tag', 'get_user_ip_tag_value', 20, 3 );
function get_user_ip_tag_value( $tag, $post, $context = 'text' ) {
// Only proceed if the tag matches my custom tag
if ( $tag !== '{user_ip}' ) {
return $tag; // Return the original tag if it's not my custom tag
}
// Retrieve the user's IP address
// Fallback to HTTP_X_FORWARDED_FOR if present check this when live cloudflare (for proxies/CDNs)
$ip_address = $_SERVER['REMOTE_ADDR'];
if ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
$ip_address = $_SERVER['HTTP_X_FORWARDED_FOR'];
}
return $ip_address;
}
The problem I’m having is it’s not rendering on frontend for logged in or logged out user.
No cache and no php or js errors in console.
On the front end the tag shows as {user_ip}
Any hints on what might be the issue OR is this because this is local dev?