Support

Account

Forum Replies Created

  • John your a legend :-)….

  • The above did not work for me

    Changed:
    $value_activity = get_field( “activity” );
    to:
    $field = $_POST[‘acf’][‘activity’];

    Still did not get the field value and not sure I can change to my_acf_save_post( $post_id ) as I need to know if it is a new created post or if the post is updated.

  • 10 out 10 for the plugin!

    Just wanted to say that if you could add this feature to your plugin you would solve a lot of peoples needs from all the google searching I have done on the subject that follows suit of what you have created.

    There has been times I need to display the fields values but not let it be edited by certain user roles for front end forms and added profile page fields so if the following could be added to your plugin it would be a massive help.

    My work around for front end forms was to created if(user roles can) and then creating the forms for each role to display only editiable fields and echo out the data at top from fields that was removed.

    Feature request would be:
    Tick box for selecting if the content data should be displayed and if this is selected add a before and after field for allowing html values so the user can style the displayed data.

  • Hi,

    I have a front end form and have found a solution to setting fields as not editable for different user roles. I have my code in the themes single post and run the below code when I’m getting the posts.

    while ( have_posts() ) : the_post();
    
     if(current_user_can('administrator'))
     {
         // get post id from have post	 
         $post = get_the_ID();
    
        // This is our form on front end and admins role can see and edit all fields
        $new_post = array(
            'post_id'            => $post, // get the post from id above
            'new_post'           => false,
            // PUT IN YOUR OWN FIELD GROUP ID(s)
    	  //'field_groups'       => array(12), // Create post field group ID(s)
            'form'               => true,
    	    'return'             => '%post_url%', // Redirect to post url
            'html_before_fields' => '',
            'html_after_fields'  => '<hr />',
            'uploader'           => 'wp',
            'honeypot'           => true,
            //'fields'             => array('building'),
            'submit_value'       => 'Update activity',
            'updated_message'    => 'Saved!'
        );
    
     }
    //  can be any user role even a custom user role  if(current_user_can(‘editor’))  or everyone else like below
     else
     {
    
         // Display the fields only no editing for set user role
         echo '<hr /><div class="acf-label"><label for="">Building</label></div>';
         echo '<div class="acf-input"><div class="acf-input-wrap">'.get_field('building').' </div>';
         
         // get post id from have post	 
         $post = get_the_ID();
    
        // This is our form on front end
        $new_post = array(
            'post_id'            => $post, // get the post from id above
            'new_post'           => false,
            // PUT IN YOUR OWN FIELD GROUP ID(s)
    	//'field_groups'       => array(12), // Create post field group ID(s)
            'form'               => true,
    	'return'             => '%post_url%', // Redirect to post url
            'html_before_fields' => '',
            'html_after_fields'  => '<hr />',
            'uploader'           => 'wp',
            'honeypot'           => true,
            // Add your fields here **** Note if you have tabs you need to use the field_key for them to display might be worth using all field_keys
            'fields'             => array('field_5859bd81f57e7','activity','start_date','completed_date','status','field_5859be28a1187','task_details', 'field_5859bda0f57e8','comments', 'field_5859be7473422' ,'document'),
            'submit_value'       => 'Update activity',
            'updated_message'    => 'Saved!'
        );
    
     }
     
     
    acf_form( $new_post );
    
    endwhile;

    Some fields can be made to be disabled using the following code but this does not work for select field and other types I even tried to add css injection but that made the tab fields not display and did not work on the user select field how ever I tried to dirty hack.

    //////////////////////////////////////////////////////////////////
    // Render our field to stop non roles from editing
    //////////////////////////////////////////////////////////////////
    add_filter('acf/prepare_field/name=activity', 'my_acf_prepare_field');
    function my_acf_prepare_field( $field ) 
    {
    
     $current_user = wp_get_current_user();
     $cu = $current_user->user_login;
     $value_personcu = get_field( “activity” );
     $select_staff_id = $value_personcu['ID'];
     $rr =  $current_user->ID;
    
     if( current_user_can('administrator') ){}
     else
     {
       // set a text field to non editable
       $field['disabled'] = true; 
     }
      return $field;
    }
    
  • Hi,

    Sorry I know this is an old post but wanted to share my solution with you in case it suits better.

    I have a front end form and have found a solution to setting fields as not editable for different user roles. I have my code in the themes single post and run the below code when I’m getting the posts.

    while ( have_posts() ) : the_post();
    
     if(current_user_can('administrator'))
     {
         // get post id from have post	 
         $post = get_the_ID();
    
        // This is our form on front end and admins role can see and edit all fields
        $new_post = array(
            'post_id'            => $post, // get the post from id above
            'new_post'           => false,
            // PUT IN YOUR OWN FIELD GROUP ID(s)
    	  //'field_groups'       => array(12), // Create post field group ID(s)
            'form'               => true,
    	    'return'             => '%post_url%', // Redirect to post url
            'html_before_fields' => '',
            'html_after_fields'  => '<hr />',
            'uploader'           => 'wp',
            'honeypot'           => true,
            //'fields'             => array('building'),
            'submit_value'       => 'Update activity',
            'updated_message'    => 'Saved!'
        );
    
     }
    //  can be any user role even a custom user role  if(current_user_can(‘editor’))  or everyone else like below
     else
     {
    
         // Display the fields only no editing for set user role
         echo '<hr /><div class="acf-label"><label for="">Building</label></div>';
         echo '<div class="acf-input"><div class="acf-input-wrap">'.get_field('building').' </div>';
         
         // get post id from have post	 
         $post = get_the_ID();
    
        // This is our form on front end
        $new_post = array(
            'post_id'            => $post, // get the post from id above
            'new_post'           => false,
            // PUT IN YOUR OWN FIELD GROUP ID(s)
    	//'field_groups'       => array(12), // Create post field group ID(s)
            'form'               => true,
    	'return'             => '%post_url%', // Redirect to post url
            'html_before_fields' => '',
            'html_after_fields'  => '<hr />',
            'uploader'           => 'wp',
            'honeypot'           => true,
            // Add your fields here **** Note if you have tabs you need to use the field_key for them to display might be worth using all field_keys
            'fields'             => array('field_5859bd81f57e7','activity','start_date','completed_date','status','field_5859be28a1187','task_details', 'field_5859bda0f57e8','comments', 'field_5859be7473422' ,'document'),
            'submit_value'       => 'Update activity',
            'updated_message'    => 'Saved!'
        );
    
     }
     
     
    acf_form( $new_post );
    
    endwhile;
    

    Some fields can be made to be disabled using the following code but this does not work for select field and other types I even tried to add css injection but that made the tab fields not display and did not work on the user select field how ever I tried to dirty hack.

    //////////////////////////////////////////////////////////////////
    // Render our field to stop non roles from editing
    //////////////////////////////////////////////////////////////////
    add_filter('acf/prepare_field/name=activity', 'my_acf_prepare_field');
    function my_acf_prepare_field( $field ) 
    {
    
     $current_user = wp_get_current_user();
     $cu = $current_user->user_login;
     $value_personcu = get_field( “activity” );
     $select_staff_id = $value_personcu['ID'];
     $rr =  $current_user->ID;
    
     if( current_user_can('administrator') ){}
     else
     {
       // set a text field to non editable
       $field['disabled'] = true; 
     }
      return $field;
    }
    
  • Hi, Not sure how your linking your posts so I am going to go on a limb and just give you some code you might be able to edit to get your data but note I could be way of due to not seeing your codes or having much to go on.

    I have not tested this so I might not have it all completely correct you will need to debug if not or change to suit your needs.

    
    // only fires when viewing currently logged-in user's profile page
    add_action( 'show_user_profile', 'my_show_extra_profile_fields' );
    // only fires when viewing another user's profile page
    add_action( 'edit_user_profile', 'my_show_extra_profile_fields' );
    
    // you can add different actions for either of the above hocks
    
    //adding our function for calling on user profile both edit and show
    function my_show_extra_profile_fields($user_id) { 
    
    // get the users name as user field in ACF
    $user_d = get_user_by( 'id', $user_id )
    $nice_name_user = $user_d->username;
    
    //query for info of posts change to suit below
    query_posts(array(
        'orderby' => 'post_date' , 
        'post_type' => 'post or custom post name' , 
        'meta_key' => 'custom acf name', 
        'meta_value' => $nice_name_user ,
        'posts_per_page' => 100)
      );
    
    if (have_posts()) :
    while (have_posts()) : the_post();
    
    //echo out your info here
    echo'<p>'.get_field( "the acf name of filed to display from the post" ).'</p>';
    
    endwhile;
    endif;
    wp_reset_query(); 
    
     }
Viewing 6 posts - 1 through 6 (of 6 total)