Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save badabingbreda/7fe6596c859e2879ebf476a8e8f3dac1 to your computer and use it in GitHub Desktop.
Save badabingbreda/7fe6596c859e2879ebf476a8e8f3dac1 to your computer and use it in GitHub Desktop.
Toolbox Filter Example - Highlight WYSIWYG with settings
<?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