Help Needed with ACF Custom Fields and Frontend Admin in Elementor

[ad_1]

Hi everyone,

I’m facing some issues with displaying custom fields from Advanced Custom Fields (ACF) using the Frontend Admin plugin in Elementor. Here’s the current setup and what I’m trying to achieve:

Context:
1. Platform: WordPress
2. Theme: Astra Theme
3. Relevant Plugins:
– Elementor Pro
– Advanced Custom Fields (ACF)
– Frontend Admin
– MemberPress

Goal:
I want users to fill out their profiles through forms in the member area (MemberPress) and then have this data visible on a specific public page outside the member area.

Issues Encountered:
1. Displaying ACF Fields: I’m trying to use Frontend Admin shortcodes to display the ACF fields on the public page, but the data isn’t showing up correctly.
2. Custom Link: I need each user to have a custom link (URL) that points to their public profile where this data is displayed.

Current Code Configuration:
“`php
<?php
// Exit if accessed directly
if (!defined(‘ABSPATH’)) exit;

// Function to generate profile link for new users
function generate_user_profile_link($user_id) {
$user_info = get_userdata($user_id);
$user_slug = sanitize_title($user_info->user_login);
$profile_link = home_url(‘/public-profile/’ . $user_slug);
update_field(‘profile_link’, $profile_link, ‘user_’ . $user_id);
}
add_action(‘user_register’, ‘generate_user_profile_link’);

// Function to add links to existing users
function add_link_to_existing_users() {
$users = get_users();
foreach ($users as $user) {
$user_slug = sanitize_title($user->user_login);
$profile_link = home_url(‘/public-profile/’ . $user_slug);
update_field(‘profile_link’, $profile_link, ‘user_’ . $user->ID);
}
}
add_action(‘init’, ‘add_link_to_existing_users’);

// Function to add custom rewrite rules
function add_custom_rewrite_rules() {
add_rewrite_rule(‘^public-profile/([^/]*)/?’, ‘index.php?pagename=public-profile&username=$matches[1]’, ‘top’);
}
add_action(‘init’, ‘add_custom_rewrite_rules’);

// Add custom query variable
function add_custom_query_vars($vars) {
$vars[] = ‘username’;
return $vars;
}
add_filter(‘query_vars’, ‘add_custom_query_vars’);

// Function to display user ACF fields on the custom page
function display_user_acf_fields($content) {
if (is_page(‘public-profile’)) {
$username = get_query_var(‘username’);
if ($username) {
$user = get_user_by(‘slug’, $username);
if ($user) {
$user_id = $user->ID;
ob_start();
?>
<div class=”profile”>
<div class=”profile-photo”>
<?php echo do_shortcode(‘[frontend_admin form=5365]’); ?>
</div>
<div class=”profile-logo”>
<?php echo do_shortcode(‘[frontend_admin form=5391]’); ?>
</div>
<div class=”profile-personal-data”>
<?php echo do_shortcode(‘[frontend_admin form=5996]’); ?>
</div>
<div class=”profile-corporate-data”>
<?php echo do_shortcode(‘[frontend_admin form=6199]’); ?>
</div>
<div class=”profile-location”>
<?php echo do_shortcode(‘[frontend_admin form=6243]’); ?>
</div>
<div class=”other-options”>
<?php echo do_shortcode(‘[frontend_admin form=6301]’); ?>
</div>
<div class=”qr-code”>
<?php echo do_shortcode(‘[frontend_admin form=6379]’); ?>
</div>
</div>
<?php
return ob_get_clean();
} else {
return ‘<p>User not found.</p>’;
}
} else {
return ‘<p>Username not specified.</p>’;
}
}
return $content;
}
add_filter(‘the_content’, ‘display_user_acf_fields’);
?>
“`

Questions:
1. Frontend Admin Shortcodes: How can I ensure that the Frontend Admin shortcodes work correctly within the HTML widget in Elementor?
2. Public Visibility: How can I make sure that the profiles filled out in the member area are correctly displayed on a public page?
3. Best Practices: Are there better practices for setting up this integration between ACF, Frontend Admin, and Elementor?

Thanks in advance for any help or guidance you can provide!

Best regards,
Alex

[ad_2]
1 Comment
  1. Have you thought about using a membership plugin that comes with a member directory/profile feature, like Ultimate Member?

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer