wppaste
WordPress

smilies_init()

Since
2.2.0
Source
wp-includes/functions.php:4888
Converts smiley code to the icon graphic file equivalent.

Description

You can turn off smilies, by going to the write setting screen and unchecking the box, or by setting 'use_smilies' option to false or removing the option.

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.

The $wp_smiliessearch global is for the regular expression and is set each time the function is called.

The full list of smilies can be found in the function and won't be listed in the description. Probably should create a Codex page for it, so that it is available.

Compatibility

WordPress
since 2.2.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Performance profile

How much work a call to smilies_init() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Heavy

Reads stored settings via get_option(), cached per request but not free on a cold cache.

Scaling
Scales with input

The body loops, so the work grows with how much data it finds.

Instructions
7–35

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 68.

Plugin surface
1 hook

Third-party callbacks on 'smilies' run inside this call, and their cost is not bounded by anything here.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What it touches

  • optionoption read or writeget_option()called directly
  • hookthird-party callbacksapply_filters()called directly
  • cacheobject cachewp_cache_get()one call below smilies_init()
  • serializeserialisationmaybe_unserialize()one call below smilies_init()

Further down the call graph this can also reach query and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 3 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost smilies_init() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
!get_option()7get_option()
get_option()17–18get_option(), apply_filters()
get_option()33–35get_option(), apply_filters(), krsort(), wp_spaces_regexp()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev687–357
8.5687–357
8.4687–3576 fewer instructions than PHP 8.3
8.3747–357
8.2747–357
8.1747–357
7.4747–357

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Hooks and filters fired · 1

One hook fires while smilies_init() runs, in this order:

  1. apply_filters( smilies )filterline 4956 (+68 into the body)

    Filters all the smilies.

Uses · 3

Source code

function smilies_init() {	global $wpsmiliestrans, $wp_smiliessearch; 	// Don't bother setting up smilies if they are disabled.	if ( ! get_option( 'use_smilies' ) ) {		return;	} 	if ( ! isset( $wpsmiliestrans ) ) {		$wpsmiliestrans = array(			':mrgreen:' => 'mrgreen.png',			':neutral:' => "\xf0\x9f\x98\x90",			':twisted:' => "\xf0\x9f\x98\x88",			':arrow:'   => "\xe2\x9e\xa1",			':shock:'   => "\xf0\x9f\x98\xaf",			':smile:'   => "\xf0\x9f\x99\x82",			':???:'     => "\xf0\x9f\x98\x95",			':cool:'    => "\xf0\x9f\x98\x8e",			':evil:'    => "\xf0\x9f\x91\xbf",			':grin:'    => "\xf0\x9f\x98\x80",			':idea:'    => "\xf0\x9f\x92\xa1",			':oops:'    => "\xf0\x9f\x98\xb3",			':razz:'    => "\xf0\x9f\x98\x9b",			':roll:'    => "\xf0\x9f\x99\x84",			':wink:'    => "\xf0\x9f\x98\x89",			':cry:'     => "\xf0\x9f\x98\xa5",			':eek:'     => "\xf0\x9f\x98\xae",			':lol:'     => "\xf0\x9f\x98\x86",			':mad:'     => "\xf0\x9f\x98\xa1",			':sad:'     => "\xf0\x9f\x99\x81",			'8-)'       => "\xf0\x9f\x98\x8e",			'8-O'       => "\xf0\x9f\x98\xaf",			':-('       => "\xf0\x9f\x99\x81",			':-)'       => "\xf0\x9f\x99\x82",			':-?'       => "\xf0\x9f\x98\x95",			':-D'       => "\xf0\x9f\x98\x80",			':-P'       => "\xf0\x9f\x98\x9b",			':-o'       => "\xf0\x9f\x98\xae",			':-x'       => "\xf0\x9f\x98\xa1",			':-|'       => "\xf0\x9f\x98\x90",			';-)'       => "\xf0\x9f\x98\x89",			// This one transformation breaks regular text with frequency.			//     '8)' => "\xf0\x9f\x98\x8e",			'8O'        => "\xf0\x9f\x98\xaf",			':('        => "\xf0\x9f\x99\x81",			':)'        => "\xf0\x9f\x99\x82",			':?'        => "\xf0\x9f\x98\x95",			':D'        => "\xf0\x9f\x98\x80",			':P'        => "\xf0\x9f\x98\x9b",			':o'        => "\xf0\x9f\x98\xae",			':x'        => "\xf0\x9f\x98\xa1",			':|'        => "\xf0\x9f\x98\x90",			';)'        => "\xf0\x9f\x98\x89",			':!:'       => "\xe2\x9d\x97",			':?:'       => "\xe2\x9d\x93",		);	} 	/**	 * Filters all the smilies.	 *	 * This filter must be added before `smilies_init` is run, as	 * it is normally only run once to setup the smilies regex.	 *	 * @since 4.7.0	 *	 * @param string[] $wpsmiliestrans List of the smilies' hexadecimal representations, keyed by their smily code.	 */	$wpsmiliestrans = apply_filters( 'smilies', $wpsmiliestrans ); 	if ( count( $wpsmiliestrans ) === 0 ) {		return;	} 	/*	 * NOTE: we sort the smilies in reverse key order. This is to make sure	 * we match the longest possible smilie (:???: vs :?) as the regular	 * expression used below is first-match	 */	krsort( $wpsmiliestrans );

Changelog

Introduced in 2.2.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/functions.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.