^ 回到顶部
  • 人生没有定律,每个人都有自己的节奏
  • 本站wordpress建站教程均通过实践后发布,希望对你有帮助
  • 希望你的坚持,都是因为热爱,而不是因为不甘心
  • 8年wordpress建站经验,5星服务品质
  • 那些不愿意让你吃亏的人,才是真正值得你深交的人,也是值得你付出时间的人
  • 阿里云2核2g仅需86元/年

wordpress函数get_allowed_mime_types()用法示例

get_allowed_mime_types( int|WP_User $user = null )

Retrieve list of allowed mime types and file extensions.


描述


参数

$user

(int|WP_User)
(Optional)
User to check. Defaults to current user.

新用户2核2g仅需86元/年    领取1153套模板    免费cdn流量包    ¥3188礼包

Default value: null


返回值

(array) Array of mime types keyed by the file extension regex corresponding to those types.


源代码

File: wp-includes/functions.php

function get_allowed_mime_types( $user = null ) {
	$t = wp_get_mime_types();

	unset( $t['swf'], $t['exe'] );
	if ( function_exists( 'current_user_can' ) )
		$unfiltered = $user ? user_can( $user, 'unfiltered_html' ) : current_user_can( 'unfiltered_html' );

	if ( empty( $unfiltered ) )
		unset( $t['htm|html'] );

	/**
	 * Filters list of allowed mime types and file extensions.
	 *
	 * @since 2.0.0
	 *
	 * @param array            $t    Mime types keyed by the file extension regex corresponding to
	 *                               those types. 'swf' and 'exe' removed from full list. 'htm|html' also
	 *                               removed depending on '$user' capabilities.
	 * @param int|WP_User|null $user User ID, User object or null if not provided (indicates current user).
	 */
	return apply_filters( 'upload_mimes', $t, $user );
}

更新日志

Version 描述
2.8.6 Introduced.

相关函数

Uses

  • wp-includes/capabilities.php:
    user_can()
  • wp-includes/capabilities.php:
    current_user_can()
  • wp-includes/functions.php:
    wp_get_mime_types()
  • wp-includes/functions.php:
    upload_mimes
  • wp-includes/plugin.php:
    apply_filters()

Used By

  • wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php:
    WP_REST_Attachments_Controller::get_media_types()
  • wp-includes/formatting.php:
    sanitize_file_name()
  • wp-includes/functions.php:
    wp_check_filetype()
  • wp-includes/functions.php:
    wp_check_filetype_and_ext()
  • wp-includes/media.php:
    wp_plupload_default_settings()
  • wp-includes/media.php:
    wp_enqueue_media()
  • Show 1 more used by
    Hide more used by


  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

    Function to retrieve the mime type icon of a file by its extension.

    
    <?php
    /**
     * Get mime type icon URL based on file extension.
     *
     * @param $file_ext The file extension to get the icon for.
     * @return string Icon URL.
     */
    function wpdocs_get_icon_by_file_extension($file_ext) {
    	$mimes = get_allowed_mime_types();
    	if ( ! empty( $mimes ) ) {
    		foreach ($ mimes as $type => $mime ) {
    			if ( false !== strpos( $type, $file_ext ) ) {
    				return wp_mime_type_icon($mime);
    			}
    		}
    	}
    }
    ?>
    <img src="<?php echo esc_url( wpdocs_get_icon_by_file_extension( 'mp4' ) ); ?>" />
    

让小雨知道,这篇文章帮到了你
扫码关注微信公众号zs40086(微搜片)随时随地微信看片,抢先福利电影等你来

热门推荐

如有疑问,请前往问答中心反馈!

反馈