根据用户角色更改音频播放器的颜色

时间:2019-12-03 作者:Jim Duggan

我已经用这个CSS代码更改了Wordpress音频播放器的颜色。

/* change colours of audio player */

.mejs-controls,
.mejs-mediaelement,
.mejs-container {
    background: url(\'\') !important;
    background-color: #1f7dcd !important;
}


/* change the color of the current time bar */
.mejs-controls .mejs-time-rail .mejs-time-current {
    background: #dece66 !important;
}
现在,我想把它换成不同的颜色depending on the role of the user 其帖子/评论已附加到。

因此,如果mp3文件是由editor, 它使用不同的颜色,如果它是由subscriber, 它有不同的颜色。

这有可能吗。如果是这样,我会怎么做?

1 个回复
最合适的回答,由SO网友:Sam 整理而成

下面将检查post creators角色,并根据该角色设置音频播放器的颜色。

在插件中创建,以便在更新主题时在更新函数文件时停止主题更新。

不知道如何根据嵌入播放器的人的每条评论来执行此操作,因为这需要为每个嵌入的播放器向html中添加标记,为每个标记分配不同的CSS样式。

<?php
    /**
    * Plugin Name: Change colour of the audio player
    * Plugin URI: http://www.web.com
    * Description: Adds colour to the audio player
    * Version: 1.0
    * Author: Name
    * Author URI: http://www.web.com

    */

 add_action( \'wp\',\'my_special_action\' ); function my_special_action() {

//Check if it is a post to run the code

  if (is_single())
  {

  //Get post ID
  $post_idz = get_the_ID();
  //Pull all field data of post
  $post_fields = get_post($post_idz);
  //Get authors ID 
  $author = $post_fields->post_author;
  //Get author roles
  $user_meta=get_userdata($author); 
  $user_roles=$user_meta->roles; 

//Check author has role

//Start ADD_ROLE_NAME
if (in_array("ADD_ROLE_NAME", $user_roles))
{
  ?>
    <style>
    /* change colours of audio player */

    .mejs-controls,
    .mejs-mediaelement,
    .mejs-container {
        background: url(\'\') !important;
        background-color: #1f7dcd !important;
    }


    /* change the color of the current time bar */
    .mejs-controls .mejs-time-rail .mejs-time-current {
        background: #dece66 !important;
    }

    </style>

    <?php
} 
//End ADD_ROLE_NAME



} }

相关推荐

如何让RTL.css成为占主导地位的css代码?

我有一个多语言网站,英语(默认)和阿拉伯语,还有一个家长主题和一个孩子主题。现在,我想按以下顺序加载CSS:英语:家长式。css然后是子样式。阿拉伯语css:父样式。css然后是子样式。css然后是父RTL。css然后是子RTL。css,因为我总是希望子css在父css上占主导地位,也希望RTL在RTL模式下占主导地位。我添加了以下代码:<?php add_action( \'wp_enqueue_scripts\', \'theme__child_enqueue_styles\' );&#