user_can_richedit()WP 2.0.0

Determines whether the user can access the visual editor.

Checks if the user can access the visual editor and that it's supported by the user's browser.

Хуки из функции

Возвращает

true|false. True if the user can access the visual editor, false otherwise.

Использование

user_can_richedit();

Заметки

  • Global. true|false. $wp_rich_edit Whether the user can access the visual editor.
  • Global. true|false. $is_gecko Whether the browser is Gecko-based.
  • Global. true|false. $is_opera Whether the browser is Opera.
  • Global. true|false. $is_safari Whether the browser is Safari.
  • Global. true|false. $is_chrome Whether the browser is Chrome.
  • Global. true|false. $is_IE Whether the browser is Internet Explorer.
  • Global. true|false. $is_edge Whether the browser is Microsoft Edge.

Список изменений

С версии 2.0.0 Введена.

Код user_can_richedit() WP 6.5.2

function user_can_richedit() {
	global $wp_rich_edit, $is_gecko, $is_opera, $is_safari, $is_chrome, $is_IE, $is_edge;

	if ( ! isset( $wp_rich_edit ) ) {
		$wp_rich_edit = false;

		if ( 'true' === get_user_option( 'rich_editing' ) || ! is_user_logged_in() ) { // Default to 'true' for logged out users.
			if ( $is_safari ) {
				$wp_rich_edit = ! wp_is_mobile() || ( preg_match( '!AppleWebKit/(\d+)!', $_SERVER['HTTP_USER_AGENT'], $match ) && (int) $match[1] >= 534 );
			} elseif ( $is_IE ) {
				$wp_rich_edit = str_contains( $_SERVER['HTTP_USER_AGENT'], 'Trident/7.0;' );
			} elseif ( $is_gecko || $is_chrome || $is_edge || ( $is_opera && ! wp_is_mobile() ) ) {
				$wp_rich_edit = true;
			}
		}
	}

	/**
	 * Filters whether the user can access the visual editor.
	 *
	 * @since 2.1.0
	 *
	 * @param bool $wp_rich_edit Whether the user can access the visual editor.
	 */
	return apply_filters( 'user_can_richedit', $wp_rich_edit );
}