• Hello dear developer, hello dear user,

    i run a plugin that works as a job-database – it is a plugin that is called participant-databaae; this plugin shows up;

    employer with their adress: applicants with their data ? but: there is a set of sensible data like
    – e-mail-adress
    – adress: town, street, housenumer

    Those sensible data should be hidden? for the non registered users of Participant database. Well – that Participants Database doesn?t have a special ?login?-feature: In other words: There is no way to know if someone is a registered user or not – unless they are logged in to a user account on the site.

    If we want to hide fields from users that are not logged in, there are two ways to go: we can use either a custom template or a PHP shortcode snippet – something like this:

    
    <?php
    $fields = 'first_name,last_name';
    if ( is_user_logged_in() ) {
      $fields = 'first_name,last_name,email,address,city';
    }
    echo do_shortcode( '[pdb_single fields="' . $fields . '" ]' );
    ?>

    we can make use use of a ?use PHP in the content? plugin or do this in a custom WP template.

Viewing 2 replies - 1 through 2 (of 2 total)
  • how did you create the fields?

    Moderator bcworkz

    (@bcworkz)

    Templates are tricky to implement from plugins. I’d avoid that strategy. How does your plugin normally generate its output? I’m guessing either a shortcode or filter hook. You should focus on modifying what your plugin already does, there is no need to take a completely different approach.

    As you suspect, it all revolves around is_user_logged_in(). Your suggestion of altering the passed shortcode parameters will work if that is how you normally execute your shortcodes. But if the shortcode is part of post content, you cannot add PHP to post content.

    You could place the is_user_logged_in() logic right in the shortcode handler itself, roughly something like this:

    // assume variables have been assigned proper values prior to this
    $output .= $last_name . ', ';
    $output .= $first_name . '<br>';
    if ( is_user_logged_in()) {
       $output .= $email . '<br>'; 
       $output .= $address . '<br>';
       // plus other fields as required...
    }
    return $output;

    Similar code could be used in a filter callback if that is how you are managing output.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘hiding some data : methods to accomplish this ?’ is closed to new replies.