我正在使用一个名为 Super Socializer 的插件它允许用户使用 Twitter 和 Facebook 登录。我想用 HTML 文本替换社交登录图标。我是 WordPress 中使用过滤器的新手,这种方法对我来说是新的。
该插件包含允许我添加过滤器的代码:
$customInterface = apply_filters('the_champ_login_interface_filter', '', $theChampLoginOptions, $widget);
我用文本更改图标的方法是在functions.php中执行此操作:
`add_filter('the_champ_login_interface_filter', 'changeIconsToText');
function changeIconsToText() {
// code to change icons to text
}`
这个问题是我不知道从这里去哪里。如何获取包含图标的变量并将其更改为文本?任何帮助将不胜感激,谢谢!
最佳答案
该插件的制造商很快就给出了解决方案,因此我将其发布在这里供其他需要它的人使用。在functions.php中,只需创建一个函数,然后应用您的更改,然后添加一个过滤器。
function heateor_ss_custom_social_login_icons( $html, $theChampLoginOptions, $widget ) {
if ( isset( $theChampLoginOptions['providers'] ) && is_array($theChampLoginOptions['providers'] ) && count( $theChampLoginOptions['providers'] ) > 0 ) {
$html = the_champ_login_notifications( $theChampLoginOptions );
if ( ! $widget ) {
$html .= '<div class="the_champ_outer_login_container">';
if ( isset( $theChampLoginOptions['title'] ) && $theChampLoginOptions['title'] != '' ) {
$html .= '<div class="the_champ_social_login_title">' . $theChampLoginOptions['title'] . '</div>';
}
}
$html .= '<div class="the_champ_login_container"><ul class="the_champ_login_ul">';
if ( isset( $theChampLoginOptions['providers'] ) && is_array( $theChampLoginOptions['providers'] ) && count( $theChampLoginOptions['providers'] ) > 0 ) {
foreach ( $theChampLoginOptions['providers'] as $provider ) {
$html .= '<li><i ';
// id
if( $provider == 'google' ) {
$html .= 'id="theChamp' . ucfirst( $provider ) . 'Button" ';
}
// class
$html .= 'class="theChampLogin theChamp' . ucfirst( $provider ) . 'Background theChamp' . ucfirst( $provider ) . 'Login" ';
$html .= 'alt="Login with ';
$html .= ucfirst( $provider );
$html .= '" title="Login with ';
if ( $provider == 'live' ) {
$html .= 'Windows Live';
} else {
$html .= ucfirst( $provider );
}
if ( current_filter() == 'comment_form_top' || current_filter() == 'comment_form_must_log_in_after' ) {
$html .= '" onclick="theChampCommentFormLogin = true; theChampInitiateLogin(this)" >';
} else {
$html .= '" onclick="theChampInitiateLogin(this)" >';
}
$html .= '<ss style="display:block" class="theChampLoginSvg theChamp' . ucfirst( $provider ) . 'LoginSvg"></ss></i></li>';
}
}
$html .= '</ul></div>';
if ( ! $widget ) {
$html .= '</div><div style="clear:both; margin-bottom: 6px"></div>';
}
}
return $html;
}
add_filter( 'the_champ_login_interface_filter', 'heateor_ss_custom_social_login_icons', 10, 3 );
关于wordpress - 为 Super Socializer 社交登录添加过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41784597/