smilies_init

函式
smilies_init ( No parameters )

smilies_init:這個動作鉤子用於註冊在文章和評論中使用的笑臉(表情符號)。你可以使用這個鉤子來註冊你自己的自定義表情符號或修改現有的表情符號。

將笑臉程式碼轉換為相當於圖示的圖形檔案。

你可以關閉笑臉,方法是進入寫作設定介面並取消勾選,或者將’use_smilies’選項設定為false或刪除該選項。

外掛可以通過將$wpsmiliestrans設定為一個陣列來覆蓋預設的笑臉列表,其關鍵是博主輸入的程式碼,其值是影象檔案。

$wp_smiliessearch全域性用於正規表示式,每次呼叫該函式時都會被設定。

完整的笑臉列表可以在函式中找到,不會在描述中列出。也許應該為它建立一個Codex頁面,這樣它就可以使用了。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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:' => "xf0x9fx98x90",
':twisted:' => "xf0x9fx98x88",
':arrow:' => "xe2x9exa1",
':shock:' => "xf0x9fx98xaf",
':smile:' => "xf0x9fx99x82",
':???:' => "xf0x9fx98x95",
':cool:' => "xf0x9fx98x8e",
':evil:' => "xf0x9fx91xbf",
':grin:' => "xf0x9fx98x80",
':idea:' => "xf0x9fx92xa1",
':oops:' => "xf0x9fx98xb3",
':razz:' => "xf0x9fx98x9b",
':roll:' => "xf0x9fx99x84",
':wink:' => "xf0x9fx98x89",
':cry:' => "xf0x9fx98xa5",
':eek:' => "xf0x9fx98xae",
':lol:' => "xf0x9fx98x86",
':mad:' => "xf0x9fx98xa1",
':sad:' => "xf0x9fx99x81",
'8-)' => "xf0x9fx98x8e",
'8-O' => "xf0x9fx98xaf",
':-(' => "xf0x9fx99x81",
':-)' => "xf0x9fx99x82",
':-?' => "xf0x9fx98x95",
':-D' => "xf0x9fx98x80",
':-P' => "xf0x9fx98x9b",
':-o' => "xf0x9fx98xae",
':-x' => "xf0x9fx98xa1",
':-|' => "xf0x9fx98x90",
';-)' => "xf0x9fx98x89",
// This one transformation breaks regular text with frequency.
// '8)' => "xf0x9fx98x8e",
'8O' => "xf0x9fx98xaf",
':(' => "xf0x9fx99x81",
':)' => "xf0x9fx99x82",
':?' => "xf0x9fx98x95",
':D' => "xf0x9fx98x80",
':P' => "xf0x9fx98x9b",
':o' => "xf0x9fx98xae",
':x' => "xf0x9fx98xa1",
':|' => "xf0x9fx98x90",
';)' => "xf0x9fx98x89",
':!:' => "xe2x9dx97",
':?:' => "xe2x9dx93",
);
}
/**
* 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 );
$spaces = wp_spaces_regexp();
// Begin first "subpattern".
$wp_smiliessearch = '/(?<=' . $spaces . '|^)';
$subchar = '';
foreach ( (array) $wpsmiliestrans as $smiley => $img ) {
$firstchar = substr( $smiley, 0, 1 );
$rest = substr( $smiley, 1 );
// New subpattern?
if ( $firstchar != $subchar ) {
if ( '' !== $subchar ) {
$wp_smiliessearch .= ')(?=' . $spaces . '|$)'; // End previous "subpattern".
$wp_smiliessearch .= '|(?<=' . $spaces . '|^)'; // Begin another "subpattern".
}
$subchar = $firstchar;
$wp_smiliessearch .= preg_quote( $firstchar, '/' ) . '(?:';
} else {
$wp_smiliessearch .= '|';
}
$wp_smiliessearch .= preg_quote( $rest, '/' );
}
$wp_smiliessearch .= ')(?=' . $spaces . '|$)/m';
}
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:' => "xf0x9fx98x90", ':twisted:' => "xf0x9fx98x88", ':arrow:' => "xe2x9exa1", ':shock:' => "xf0x9fx98xaf", ':smile:' => "xf0x9fx99x82", ':???:' => "xf0x9fx98x95", ':cool:' => "xf0x9fx98x8e", ':evil:' => "xf0x9fx91xbf", ':grin:' => "xf0x9fx98x80", ':idea:' => "xf0x9fx92xa1", ':oops:' => "xf0x9fx98xb3", ':razz:' => "xf0x9fx98x9b", ':roll:' => "xf0x9fx99x84", ':wink:' => "xf0x9fx98x89", ':cry:' => "xf0x9fx98xa5", ':eek:' => "xf0x9fx98xae", ':lol:' => "xf0x9fx98x86", ':mad:' => "xf0x9fx98xa1", ':sad:' => "xf0x9fx99x81", '8-)' => "xf0x9fx98x8e", '8-O' => "xf0x9fx98xaf", ':-(' => "xf0x9fx99x81", ':-)' => "xf0x9fx99x82", ':-?' => "xf0x9fx98x95", ':-D' => "xf0x9fx98x80", ':-P' => "xf0x9fx98x9b", ':-o' => "xf0x9fx98xae", ':-x' => "xf0x9fx98xa1", ':-|' => "xf0x9fx98x90", ';-)' => "xf0x9fx98x89", // This one transformation breaks regular text with frequency. // '8)' => "xf0x9fx98x8e", '8O' => "xf0x9fx98xaf", ':(' => "xf0x9fx99x81", ':)' => "xf0x9fx99x82", ':?' => "xf0x9fx98x95", ':D' => "xf0x9fx98x80", ':P' => "xf0x9fx98x9b", ':o' => "xf0x9fx98xae", ':x' => "xf0x9fx98xa1", ':|' => "xf0x9fx98x90", ';)' => "xf0x9fx98x89", ':!:' => "xe2x9dx97", ':?:' => "xe2x9dx93", ); } /** * 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 ); $spaces = wp_spaces_regexp(); // Begin first "subpattern". $wp_smiliessearch = '/(?<=' . $spaces . '|^)'; $subchar = ''; foreach ( (array) $wpsmiliestrans as $smiley => $img ) { $firstchar = substr( $smiley, 0, 1 ); $rest = substr( $smiley, 1 ); // New subpattern? if ( $firstchar != $subchar ) { if ( '' !== $subchar ) { $wp_smiliessearch .= ')(?=' . $spaces . '|$)'; // End previous "subpattern". $wp_smiliessearch .= '|(?<=' . $spaces . '|^)'; // Begin another "subpattern". } $subchar = $firstchar; $wp_smiliessearch .= preg_quote( $firstchar, '/' ) . '(?:'; } else { $wp_smiliessearch .= '|'; } $wp_smiliessearch .= preg_quote( $rest, '/' ); } $wp_smiliessearch .= ')(?=' . $spaces . '|$)/m'; }
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:' => "xf0x9fx98x90",
			':twisted:' => "xf0x9fx98x88",
			':arrow:'   => "xe2x9exa1",
			':shock:'   => "xf0x9fx98xaf",
			':smile:'   => "xf0x9fx99x82",
			':???:'     => "xf0x9fx98x95",
			':cool:'    => "xf0x9fx98x8e",
			':evil:'    => "xf0x9fx91xbf",
			':grin:'    => "xf0x9fx98x80",
			':idea:'    => "xf0x9fx92xa1",
			':oops:'    => "xf0x9fx98xb3",
			':razz:'    => "xf0x9fx98x9b",
			':roll:'    => "xf0x9fx99x84",
			':wink:'    => "xf0x9fx98x89",
			':cry:'     => "xf0x9fx98xa5",
			':eek:'     => "xf0x9fx98xae",
			':lol:'     => "xf0x9fx98x86",
			':mad:'     => "xf0x9fx98xa1",
			':sad:'     => "xf0x9fx99x81",
			'8-)'       => "xf0x9fx98x8e",
			'8-O'       => "xf0x9fx98xaf",
			':-('       => "xf0x9fx99x81",
			':-)'       => "xf0x9fx99x82",
			':-?'       => "xf0x9fx98x95",
			':-D'       => "xf0x9fx98x80",
			':-P'       => "xf0x9fx98x9b",
			':-o'       => "xf0x9fx98xae",
			':-x'       => "xf0x9fx98xa1",
			':-|'       => "xf0x9fx98x90",
			';-)'       => "xf0x9fx98x89",
			// This one transformation breaks regular text with frequency.
			//     '8)' => "xf0x9fx98x8e",
			'8O'        => "xf0x9fx98xaf",
			':('        => "xf0x9fx99x81",
			':)'        => "xf0x9fx99x82",
			':?'        => "xf0x9fx98x95",
			':D'        => "xf0x9fx98x80",
			':P'        => "xf0x9fx98x9b",
			':o'        => "xf0x9fx98xae",
			':x'        => "xf0x9fx98xa1",
			':|'        => "xf0x9fx98x90",
			';)'        => "xf0x9fx98x89",
			':!:'       => "xe2x9dx97",
			':?:'       => "xe2x9dx93",
		);
	}

	/**
	 * 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 );

	$spaces = wp_spaces_regexp();

	// Begin first "subpattern".
	$wp_smiliessearch = '/(?<=' . $spaces . '|^)';

	$subchar = '';
	foreach ( (array) $wpsmiliestrans as $smiley => $img ) {
		$firstchar = substr( $smiley, 0, 1 );
		$rest      = substr( $smiley, 1 );

		// New subpattern?
		if ( $firstchar != $subchar ) {
			if ( '' !== $subchar ) {
				$wp_smiliessearch .= ')(?=' . $spaces . '|$)';  // End previous "subpattern".
				$wp_smiliessearch .= '|(?<=' . $spaces . '|^)'; // Begin another "subpattern".
			}
			$subchar           = $firstchar;
			$wp_smiliessearch .= preg_quote( $firstchar, '/' ) . '(?:';
		} else {
			$wp_smiliessearch .= '|';
		}
		$wp_smiliessearch .= preg_quote( $rest, '/' );
	}

	$wp_smiliessearch .= ')(?=' . $spaces . '|$)/m';

}

常見問題

FAQs
檢視更多 >