• Resolved pad

    (@pad)


    Hi guys,

    I have my own set of smileys and at the moment, set them in functions.php, but everytime I upgrade wordpress I have to reupload them and edit the file and it’s most tedious.

    I was wondering how to write a simple plugin based off this piece of documentation in the functions.php file:

    Plugins may override the default smiley list by setting the $wpsmiliestrans
    * to an array, with the key the code the blogger types in and the value the
    * image file.

    I would be ever so grateful for a response.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    Like so:

    /*
    Plugin Name: Smiley replace
    */
    global $wpsmiliestrans;
    
    $wpsmiliestrans = array (
    ... stuff just like in the functions.php but with your changes ...
    );

    That’s it.

    Thread Starter pad

    (@pad)

    Thanks so much for this.

    Is there a way to add this bit to the plugin too, so I can change the directory of my smileys?

    $siteurl = get_option( 'siteurl' );
    	foreach ( (array) $wpsmiliestrans as $smiley => $img ) {
    		$wp_smiliessearch[] = '/(\s|^)' . preg_quote( $smiley, '/' ) . '(\s|$)/';
    		$smiley_masked = attribute_escape( trim( $smiley ) );
    		$wp_smiliesreplace[] = " <img src='$siteurl/wp-includes/images/smilies/$img' alt='$smiley_masked' class='wp-smiley' />

    Thanks a lot Otto!

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    Well, if you want that too, then you’d do it slightly differently.

    Copy the entire smilies_init function into your plugin. Rename it to something else, like my_smilies_init and modify it however you like. Then add this code at the bottom of the plugin:

    remove_action('init', 'smilies_init', 5);
    add_action('init', 'my_smilies_init', 5);
    Thread Starter pad

    (@pad)

    Thank you very much indeed.

    pad

    Otto42
    wonderful ??

    my first plugin and it works – without any error ??

    thanks a lot!

    Monika

    I’ve created a custom smilies_init as well, but I have a small problem remaining.

    WP is kinda strict that there should be a space in front of and after the smiley. I would like to circumvent that. Is that possible?

    $siteurl = get_option( 'siteurl' );
    foreach ( (array) $wpsmiliestrans as $smiley => $img ) {
    $wp_smiliessearch[] = '/(\s|^)' . preg_quote( $smiley, '/' ) . '(\s|$)/';
    $smiley_masked = attribute_escape( trim( $smiley ) );
    $wp_smiliesreplace[] = " <img src='$siteurl/wp-includes/images/smilies/$img' alt='$smiley_masked' class='wp-smiley' /> ";

    I think I need to edit some line here, but I don’t really understand what’s happening here.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How to write a simple smiley plugin with $wpsmiliestrans? :)’ is closed to new replies.