Skip Navigation

[Resolved] Cred-delete-relationship link is shown only if loggedin user is admin

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 0 replies, has 1 voice.

Last updated by nicolaS-3 3 weeks, 5 days ago.

Assisted by: Minesh.

Author
Posts
#2786962

Hello Minesh,
in the same Profile CT I list the bands which the current profile is related to. I'd like both the current profile and the relationship author to be able to delete the relationship. Instead, the links appears only if the current user is admin. Weird is that SOMETIMES it appeared when the user is relationship author, but not always ..... It never appears for the other user.
I've read all previous posts about this topic and tried many things you guys suggested with no success, I've also changed the view as you suggested here:
https://toolset.com/forums/topic/link-delete-relationship-not-visible/
but not even the cred-delete-post-link is shown !
Any clue ?

thanks
Regards
Nicola

Open Template 1655 on page 5 of the CT list and scroll down, there is a View RELATIONSHIPS where the link is placed

#2787063

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Can you please share the frontend post/page URL where I can see the problem.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2787295

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please share the login access details for the frontend user "BARBIE" and "FUMAFUMA".

I have set the next reply to private which means only you and I have access to it.

#2787310

I am not sure is private, please check thanks

#2787326

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please check now for users with Author role - do you able to see the delete relationship link. If yes, I've grant all permissions to role author for post type in relationship that is (band, profili and intermediary post type band-profili).

#2787491

Minesh,
unfortunately with your solution the delete link is always displayed, thus allowing ANY musician to delete the link between ANY other band and ANY other musicians in the db even though they don't even know them, and this is too much ! But I could live with those Access settings if I could find a way to show the link only when certain conditions are satisfied, which are:
1. current user = band author OR
2. current user plays in the same band of band author => relationships exist with the same band
I don't have a clue how to test #2, any idea ?
thanks

#2787583

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - I've added the following shortcode to "Custom Code" sectinon offered by Toolset with code snippet "toolset-custom-code":

add_shortcode('is_connected', 'func_check_for_connected_posts_manytomany');
function func_check_for_connected_posts_manytomany( $atts = [] ){
   
    $atts = shortcode_atts( 
        array(
            'relationship'      =>   'band-profilo',
        ), $atts );
   
  
  global $post;
  
  global $wp_query; 
  $current_postid = $wp_query->post->ID;
  
    $relationship = toolset_get_relationship( $atts['relationship'] );
   
    if ( $relationship ) {
   
        $parent = $relationship['roles']['parent']['types'][0];
        $child = $relationship['roles']['child']['types'][0];
        $type = $post->post_type;
   
        $origin = ( $parent == $type ) ? 'parent' : 'child';
   
        // Get connected posts
        $connections = toolset_get_related_posts($post->ID, $atts['relationship'], array(
            'query_by_role' => $origin,
            'role_to_return' => 'other',
            'need_found_rows' => true )
        );
      
      $found = 0;
      ///echo "postid==".$post->ID;
      foreach($connections['results'] as $k=>$v):
      		if($current_postid == $v){
               $found = 1;              
            }
      endforeach;
      
        if($found){
          	return 1;
        }else{
          return 0;
        }      
        
    }
}

The shortcode will return 1 if it found the post in relationship otherwise 0. You can add conditoinal shortcode to wreap the cred-delete-relationship shortcode.

For example:

[wpv-conditional if="( '[is_connected relationship='band-profilo']' eq '1' )"]
 then show the cred-delete-relationshihp shortcode
[/wpv-conditional]
#2787611
rel-table.jpg

Hello Minesh,
I really appreciate your snippet above, but it always return one when any relationship exist. It should return one when the current user is the band author OR when the profile open plays in the same band of the band author, please see attached table, thanks

#2788070

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please check now.

I've adjusted the code added to "Custom Code" with code snippet "toolset-custom-code" as given under:

add_shortcode('is_connected', 'func_check_for_connected_posts_manytomany');
function func_check_for_connected_posts_manytomany( $atts = [] ){
   
  
    $atts = shortcode_atts( 
        array(
            'relationship'      =>   'band-profilo',
            'currentpageid'		=> '',
            'postid' 			=> '',
        ), $atts );
   
  
  global $post;
  global $wp_query; 
  global $current_user;
  $current_postid = $wp_query->post->ID;
  
    $author_profile = get_posts(array('post_type'=>'profilo','author'=>$current_user->ID,'fields'=>'ids'));
  
  if(!empty($author_profile)){
    $profile_id_logged_user = $author_profile[0];
    
       $logged_user_bands = toolset_get_related_posts($profile_id_logged_user, 'band-profilo', array(
            'query_by_role' => 'child',
            'role_to_return' => 'other',
            'need_found_rows' => true )
        );
      
      $found = 0;
      foreach($logged_user_bands['results'] as $k=>$v):
      		if($post->ID == $v){
               $found = 1;              
            }
      endforeach;
     	
    	if($found){
          	return 1;
        }else{
          return 0;
        }      
      
  }else{ 
    return 0;
  }
}

And within your contet template:
=> hidden link
I've adjusted the conditional statement as given under:

[wpv-conditional if="( '[is_connected]' eq '1' )"]


<div style="border: 1px solid green;">[cred-delete-relationship role_items='$fromViews' relationship='band-profilo' redirect='self' style="color:white;font-size:12px;"][Leave the band][/cred-delete-relationship]</div>
[/wpv-conditional]

Can you please confirm it works as expected.

#2788071

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Update:

Sharing a bit improved code added to "Custom Code" section:

add_shortcode('is_connected', 'func_check_for_connected_posts_manytomany');
function func_check_for_connected_posts_manytomany( $atts = [] ){
   
  global $post, $wp_query, $current_user;
  
    // getting loggedin user profile post 
    $author_profile = get_posts(array('post_type'=>'profilo','author'=>$current_user->ID,'fields'=>'ids'));
  
  if(!empty($author_profile)){
    $profile_id_logged_user = $author_profile[0];
    
       $logged_user_bands = toolset_get_related_posts($profile_id_logged_user, 'band-profilo', array(
            'query_by_role' => 'child',
            'role_to_return' => 'other',
            'need_found_rows' => true )
        );
      
     /// checking post in view's loop is avaiable with loggedin user profile related post
      if(in_array($post->ID,$logged_user_bands['results'])) {
        return 1;
      } else {
        return 0;
      }
          
  }else{ 
    return 0;
  }
}
#2788118

Thank you Minesh, top support as always !
Kind regards