Created
May 9, 2018 15:33
-
-
Save badabingbreda/7fe6596c859e2879ebf476a8e8f3dac1 to your computer and use it in GitHub Desktop.
Toolbox Filter Example - Highlight WYSIWYG with settings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'toolbox/helpers/settings/type=wysiwyg' , 'more_wysiwyg_settings' , 10, 2 ); | |
function more_wysiwyg_settings( $settings ) { | |
return array_merge( $settings, array( | |
'highlight' => array( | |
'type' => 'text', | |
'label' => __('Highlight Text', 'textdomain'), | |
), | |
'highlightcolor' => array( | |
'type' => 'color', | |
'label' => __( 'Highlight Color', 'textdomain' ), | |
'default' => '333333', | |
'show_reset' => true, | |
), | |
) ); | |
} | |
add_filter( 'toolbox/helpers/get_acf_field/type=wysiwyg' , 'highlight_wysiwyg', 10, 5 ); | |
function highlight_wysiwyg( $string, $field_object, $value, $atts, $postid ) { | |
if (isset($atts['highlight']) && $atts['highlight'] !== ''): | |
$regex = '/((?i)\b'.$atts['highlight'].'\b)/m'; | |
return preg_replace( $regex , '<span style="background-color:#'.$atts['highlightcolor'].';color:#fff;padding-left:5px;padding-right:5px;">'.'$1'.'</span>', $string); | |
endif; | |
return $string; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment