Support » Plugins » Hacks » Parse certain smilies without whitespace

  • I use some smilies that are in brackets fe. [Xd] etc. and I want to to be able to parse only this group without the mandatory whitespace.

    I’m not good enough with php to figure it out myself.

    I searched, but failed to come up with a decent answer.

    Anyone here knows how to do this?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    You might try adding square brackets to the regexp passed in the ‘wp_spaces_regexp’ filter. Then the brackets will be considered one of the mandatory whitespaces for the smilie conversion routine.

    I don’t know if this will have other undesirable effects.

    The other thing to try is define new smilies that include the brackets and add the definitions to the global $wpsmiliestrans array. If the array is not yet set, call smilies_init() to set it. Run the modified array through krsort() to complete the process. Naturally you would need whitespace outside the brackets for this one to work.

    Allright, I’ll try this step by step. Any good sources you can suggest where I can try to figure out what you’re saying 🙂

    Moderator bcworkz

    (@bcworkz)

    🙂 sorry about being so obscure, it’s hard sometimes to know what level of understanding people possess.

    There’s always the Codex, for example, using filters is explained in the Plugin API. Regexp is not limited to WP, so a general Internet search should turn up some explanations.

    More specifically, the best source for me is the core source code itself. The source for smilies_init() explains a lot. You can see how the similes are defined. I don’t know what the hexcodes mean, I assume they are character codes for a smiley font. It doesn’t really matter, you’re not inventing new smiley images, only new smiley text that will be substituted for the same hexcode or image reference.

    The comment at line 3165 explains why we need to krsort() the definition array.

    The final part with the foreach loop is hard to follow, but the only thing important is how the regexp pattern for whitespaces (contained in $spaces) plays an important part in building the regexp for finding smiley text. You can see how $spaces is defined in wp_spaces_regexp() and how the ‘wp_spaces_regexp’ filter is applied. This is where you could define brackets as “whitespace”. Of course, understanding regexp is crucial. Even if you do understand regexp, it’s often difficult to imagine what any particular regexp actually does. There are several online tools that let you fiddle with regexp to see exactly how any particular regexp is applied. For example regexr.com

    Happy learning!

    Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Parse certain smilies without whitespace’ is closed to new replies.