WordPress.org

Ready to get started?Download WordPress

Forums

Smilies_init (3 posts)

  1. Jannes
    Member
    Posted 5 years ago #

    Hi

    I've created my custom smilies plugin by reworking standard WP filter functionality. Now I've gotten to the point where I'm able to use shortcuts (:C, :D, :H and :S for corresponding card symbols) in content I write. My main remaining issue is that I (and people commenting) have to put spaces if front of and after the smilie.

    I think I need to edit this (standard) line of code:
    $wp_smiliessearch[] = '/(\s|^)' . preg_quote( $smiley, '/' ) . '(\s|$)/';

    But here I'm lost, I have no idea how to continue.

  2. Jannes
    Member
    Posted 5 years ago #

    I would like every instance of :C, :D, :H and :S be replaced by it's corresponding symbol/smiley by my function. And I don't want to worry whether or not there is or isn't a space needed.

    I have found some information here, but it's in Dutch, and it's only a partial solution.

    Could anyone help me out, please?

  3. Jannes
    Member
    Posted 5 years ago #

    Just to be complete, here's all of my plugin's code:

    <?php
    /*
    Plugin Name: <a href=http://www.vikingsinspace.nl>My Smilies Init</a>
    Description: Adds card symbols to the smilies directory.
    Version: 0.1
    Author: Jannes van 't Oever
    Author URI: http://www.vikingsinspace.nl/
    */
    
    function my_smilies_init() {
    	global $wpsmiliestrans, $wp_smiliessearch, $wp_smiliesreplace;
    
    	// don't bother setting up smilies if they are disabled
    	if ( !get_option( 'use_smilies' ) )
    		return;
    
    	if ( !isset( $wpsmiliestrans ) ) {
    		$wpsmiliestrans = array(
    		       ':mrgreen:' => 'icon_mrgreen.gif',
    		       ':(' => 'icon_sad.gif',
    		       ':)' => 'icon_smile.gif',
    		       ':?' => 'icon_confused.gif',
    		       ':-D' => 'icon_biggrin.gif',
    		       ':P' => 'icon_razz.gif',
    		       ':o' => 'icon_surprised.gif',
    		       ':x' => 'icon_mad.gif',
    		       ':|' => 'icon_neutral.gif',
    		       ';)' => 'icon_wink.gif',
    		       ':!:' => 'icon_exclaim.gif',
    		       ':?:' => 'icon_question.gif',
    			  ':C' => 'icon_clubs.gif',
    			  ':D' => 'icon_diamond.gif',
    			  ':H' => 'icon_heart.gif',
    			  ':S' => 'icon_spade.gif'
    		);
    	}
    	$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' /> ";
    	}
    }
    
    remove_action('init', 'smilies_init', 5);
    add_action('init', 'my_smilies_init', 5);
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic