Taeram
Taeram

Reputation: 586

Wordpress - Customizing CSS Filters

I'm running Wordpress 4.1 with the TinyMCE editor. In the TinyMCE editor, I've enabled the Advanced Lists plugin, which allows customizing the list style type of list items (ex. <li style="list-style-type: lower-alpha">).

When I submit a post with a modified list style, the list-style-type declaration gets stripped out, but other CSS declarations are just fine (ex. text-align).

Looking at the Wordpress source, the CSS is being filtered by the safecss_filter_attr() function in kses.php. In safecss_filter_attr() I can see an array of CSS declarations. If I add list-style-type to that array, I can then save my post, and list-style-type is no longer filtered out.

However, editing the Wordpress source isn't maintainable, as it'll eventually be overwritten when Wordpress is upgraded. So, my question is this: How do I prevent Wordpress from filtering out the list-style-type CSS declaration in a maintainable fashion?

Upvotes: 0

Views: 1106

Answers (1)

Cal Evans
Cal Evans

Reputation: 687

That array you are editing is actually being passed as a parameter to the 'safe_style_css' filter. The return value of 'safe_style_css' is being stored in $allowed_attr. (Line 1482 in kses.php)

So in your functions.php, write a function that looks something like this.

function my_css_allow($allowed_attr) {

    if (!is_array($allowed_attr)) {
        $allowed_attr = array();
    }

    $allowed_attr[] = 'list-style-type';

    return $allowed_attr;
}

add_filter('safe_style_css','my_css_allow');

I've not tested that but it looks like it should work.

HTH,

=C=

Upvotes: 2

Related Questions