0
votes

Good afternoon devs, I develop a project that consists of users profiles with a record created with fields from the ACF, including the image gallery field, my problem is ... as I only use one page to display this profile, the image gallery is makes it shared even with the option of "attached to the post", as I only use one page for this, example "/profile?userid=userid".

Is there any other good practice for doing this?

I would like suggestions.

one part profile edit

function acf_profile_edit( $atts ) {

$a = shortcode_atts( array(
    'field_group' => ''
), $atts );

$uid = get_current_user_id();

if ( ! empty ( $a['field_group'] ) && ! empty ( $uid ) ) {
    $options = array(
        'post_id' => 'user_'.$uid,
        'field_groups' => array( intval( $a['field_group'] ) ),
        'return' => add_query_arg( 'updated', 'true', get_permalink() )
    );

    ob_start();

    acf_form( $options );
    $form = ob_get_contents();

    ob_end_clean();
}

return $form;
}

add_shortcode( 'profile_edit', 'acf_profile_edit' );

Edit... This code resolved my problem

add_filter('ajax_query_attachments_args', 'restrict_images_to_user');
function restrict_images_to_user($query) {
    $gallery_images = 'field_5e4d799b34145';
    $gallery_videos = 'field_5e5597e37f2c7';
    if ( isset($_POST['query']['_acfuploader'] )
        && ( isset($_POST['query']['_acfuploader']) == $gallery_images || isset($_POST['query']['_acfuploader']) == $gallery_videos ) ) {

        $author = get_current_user_id();
        $query['author'] = $author;
    }
    return $query;
}
1
if you use userid=userid how can it not be hacked?JayDJohno
Thanks for your answer, in the case of "/profile?userid=userid", I only use it on the show profile page, on the edit page I use the word_press function get_current_user_id(). i edited answerSHARKDEV

1 Answers

0
votes

If you are using one page, use a page template called page-profile.php, the bit after page- must match the name of the page you have assigned.

Then use the WordPress Post Loop:

if (have_posts()) :
   while (have_posts()) :
      the_post();
         the_content();
   endwhile;
endif;

You can assign a username to the posts and the posts loop will only return the stuff associate with that username.

Another way would be to get the current username, then can you make an extra acf field with the username in and then do a check.

This is an example and will be exactly correct, but may be able to help you with suggestions.

If(content && username == currentuser)
{
   $content = acf content;
}

then later in your page you can echo the content where you need it and will only be the content for the current username, or you can also do it with the user id.