user_can_richedit() - WordPress 函数参考中文文档

返回介绍

user_can_richedit()

发布于 2017-09-11 字数 3046 浏览 1004 评论 0

user_can_richedit()

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.


返回值

(bool) True if the user can access the visual editor, false otherwise.


源代码

File: wp-includes/general-template.php

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 ( get_user_option( 'rich_editing' ) == 'true' || ! 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 ) && intval( $match[1] ) >= 534 );
			} elseif ( $is_IE ) {
				$wp_rich_edit = ( strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE ' ) === false );
			} 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 );
}

更新日志

Version 描述
2.0.0 Introduced.

相关函数

Uses

  • wp-includes/pluggable.php:
    is_user_logged_in()
  • wp-includes/general-template.php:
    user_can_richedit
  • wp-includes/vars.php:
    wp_is_mobile()
  • wp-includes/plugin.php:
    apply_filters()
  • wp-includes/user.php:
    get_user_option()

Used By

  • wp-admin/includes/media.php:
    get_media_item()
  • wp-admin/includes/media.php:
    get_compat_media_markup()
  • wp-includes/general-template.php:
    wp_default_editor()
  • wp-includes/post.php:
    sanitize_post_field()
  • wp-includes/class-wp-editor.php:
    _WP_Editors::parse_settings()

User Contributed Notes

  1. Skip to note content

    You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note

    Contributed by Codex

    Example

    Display an editor if the user can use it:

    
    if ( user_can_richedit() ) {
        wp_editor( $content, 'mycustomeditor' );
    } else {
        echo __( 'You cannot use the rich editor', 'textdomain' );
    }
    

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!