0

If someone can figure this out, man you would make my week!

Basically what I'm trying to do is echo a different value in a option based on a the users role on Wordpress.

If user is administrator echo = [email protected] If user is subscriber echo = [email protected]

Here is the code I am working with:

if ( ! empty( $note_emails ) || $include_custom ) { ?>
    <div class="gv-note-email-container">
        <label for="gv-note-email-to-<?php echo $entry_slug_esc; ?>" class="screen-reader-text"><?php echo $strings['also-email'];  ?></label>
        <select class="gv-note-email-to" name="gv-note-to" id="gv-note-email-to-<?php echo $entry_slug_esc; ?>">
            <?php foreach ( $note_emails as  $email ) {
                ?>
                <option value="[email protected]">[email protected]</option>
            <?php }
            if( $include_custom ) { ?>
            <option value="custom"><?php echo self::strings('other-email'); ?></option>
            <?php } ?>
        </select>
        <fieldset class="gv-note-to-container">
            <?php if( $include_custom ) { ?>
            <div class='gv-note-to-custom-container'>
                <label for="gv-note-email-to-custom-<?php echo $entry_slug_esc; ?>"><?php echo $strings['email-label']; ?></label>
                <input type="text" name="gv-note-to-custom" placeholder="<?php echo $strings['email-placeholder']; ?>" id="gv-note-to-custom-<?php echo $entry_slug_esc; ?>" value="" />
            </div>
            <?php } ?>
            <div class='gv-note-subject-container'>
                <label for="gv-note-subject-<?php echo $entry_slug_esc; ?>"><?php echo $strings['subject-label']; ?></label>
                <input type="text" name="gv-note-subject" placeholder="<?php echo $strings['subject']; ?>" id="gv-note-subject-<?php echo $entry_slug_esc; ?>" value="" />
            </div>
        </fieldset>
    </div>
<?php }
2
  • where do you use this code ?
    – mmm
    Commented Jan 8, 2018 at 18:43
  • I am modifying a php file inside the plugin Gravity View
    – Kevin W.
    Commented Jan 8, 2018 at 18:59

1 Answer 1

0

Something like this?

  if(current_user_can('administrator')){
    echo '<option value="[email protected]">[email protected]</option>';
  }elseif(current_user_can('subscriber')){
    echo '<option value="[email protected]">[email protected]</option>';
  }

Maybe this should be wrapped in a user logged in check like this:

if(is_user_logged_in()){
  if(current_user_can('administrator')){
    echo '<option value="[email protected]">[email protected]</option>';
  }elseif(current_user_can('subscriber')){
    echo '<option value="[email protected]">[email protected]</option>';
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.