【问题标题】:Echo Option Value Based On Wordpress User Role基于 WordPress 用户角色的 Echo 选项值
【发布时间】:2018-01-08 17:46:49
【问题描述】:

如果有人能解决这个问题,伙计,你会成为我的一周!

基本上,我要做的是根据 Wordpress 上的用户角色在选项中回显不同的值。

如果用户是管理员 echo = user@email.com 如果用户是订阅者 echo = admin@email.com

这是我正在使用的代码:

    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="admin@email.com">admin@email.com</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 }

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    你试过了吗?

    $user = wp_get_current_user();
    if ( in_array( 'administrator', (array) $user->roles ) ) {
        //This user is administrator
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-10-02
      • 2014-02-13
      • 2011-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-05
      相关资源
      最近更新 更多