当前位置: 首页>>代码示例>>PHP>>正文


PHP wp_get_mime_types函数代码示例

本文整理汇总了PHP中wp_get_mime_types函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_get_mime_types函数的具体用法?PHP wp_get_mime_types怎么用?PHP wp_get_mime_types使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了wp_get_mime_types函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: filter_images

/**
 * Automatically resample and save the downsized versions of each graphic.
 *
 * @param array $meta
 *
 * @return array
 */
function filter_images($meta)
{
    $n = function ($function) {
        return __NAMESPACE__ . "\\{$function}";
    };
    add_filter('image_resize_dimensions', $n('upscale_dimensions'), 1, 6);
    $uploads = wp_upload_dir();
    // Generate a placeholder for the full image
    $file = basename($meta['file']);
    $file_base_path = trailingslashit($uploads['basedir']) . str_replace($file, '', $meta['file']);
    $new_parent = create_placeholder($file, $file_base_path);
    // Generate placeholders for each image size
    foreach ($meta['sizes'] as $name => $data) {
        if (false !== strpos($name, '-ph')) {
            $new_file = create_placeholder($data['file'], $file_base_path);
            $meta['sizes'][$name]['file'] = $new_file;
        }
    }
    $file_ext = pathinfo($file, PATHINFO_EXTENSION);
    $mime_type = 'application/octet-stream';
    $mime_types = wp_get_mime_types();
    foreach ($mime_types as $extension => $type) {
        if (preg_match("/{$file_ext}/i", $extension)) {
            $mime_type = $type;
            break;
        }
    }
    $meta['sizes']['full-ph'] = array('file' => $new_parent, 'width' => $meta['width'], 'height' => $meta['height'], 'mime-type' => $mime_type);
    remove_filter('image_resize_dimensions', $n('upscale_dimensions'), 1);
    return $meta;
}
开发者ID:10up,项目名称:swiftstream,代码行数:38,代码来源:pixelate.php

示例2: __construct

 function __construct()
 {
     add_action('init', array($this, 'action_init'));
     $this->allowed_mime_types = function_exists('wp_get_mime_types') ? wp_get_mime_types() : get_allowed_mime_types();
     $this->has_correct_role = BYT_Theme_Utils::check_user_role(BOOKYOURTRAVEL_FRONTEND_SUBMIT_ROLE, $this->get_current_user_id());
     $this->_html_helper = new Html_Helper();
 }
开发者ID:JDjimenezdelgado,项目名称:old-mmexperience,代码行数:7,代码来源:frontend-submit.php

示例3: __construct

 function __construct()
 {
     global $sc_theme_globals;
     $this->sc_theme_globals = $sc_theme_globals;
     add_action('init', array($this, 'action_init'));
     $this->allowed_mime_types = function_exists('wp_get_mime_types') ? wp_get_mime_types() : get_allowed_mime_types();
     $this->_html_helper = new Html_Helper();
 }
开发者ID:boutitinizar,项目名称:bati-men,代码行数:8,代码来源:frontend-submit.php

示例4: get_mime_type

 protected function get_mime_type($extension)
 {
     $mime_types = wp_get_mime_types();
     $extensions = array_keys($mime_types);
     foreach ($extensions as $_extension) {
         if (preg_match("/{$extension}/i", $_extension)) {
             return $mime_types[$_extension];
         }
     }
     return;
 }
开发者ID:brutalenemy666,项目名称:carbon-image-library,代码行数:11,代码来源:WP_Media.php

示例5: tm_player

function tm_player($player = '', $args = array())
{
    if (empty($player) || empty($args['files'])) {
        return;
    }
    $defaults = array('files' => array(), 'poster' => '', 'autoplay' => false);
    $args = wp_parse_args($args, $defaults);
    extract($args);
    /* JWPlayer */
    if ($player == 'jwplayer') {
        $options = array('file' => trim($files[0]), 'image' => $poster);
        $atts = arr2atts($options);
        $jwplayer_shortcode = '[jwplayer' . $atts . ']';
        echo apply_filters('tm_video_filter', $jwplayer_shortcode);
    } elseif ($player == 'flowplayer' && function_exists('flowplayer_content_handle')) {
        $atts = array('splash' => $poster);
        foreach ($files as $key => $file) {
            $att = $key == 0 ? 'src' : 'src' . $key;
            $atts[$att] = $file;
        }
        echo flowplayer_content_handle($atts, '', '');
        tm_flowplayer_script();
    } elseif ($player == 'videojs' && function_exists('video_shortcode')) {
        $atts = array('poster' => $poster);
        foreach ($files as $key => $file) {
            $att = $key == 0 ? 'src' : 'src' . $key;
            if (strpos($file, '.mp4') !== false) {
                $atts['mp4'] = $file;
            }
            if (strpos($file, '.webm') !== false) {
                $atts['webm'] = $file;
            }
            if (strpos($file, '.ogg') !== false) {
                $atts['ogg'] = $file;
            }
        }
        echo video_shortcode($atts, '', '');
        tm_add_videojs_swf();
    } else {
        $atts = array();
        foreach ($files as $file) {
            $file = trim($file);
            if (strpos($file, 'youtube.com') !== false) {
                $atts['youtube'] = $file;
            } else {
                $type = wp_check_filetype($file, wp_get_mime_types());
                $atts[$type['ext']] = $file;
            }
        }
        echo wp_video_shortcode($atts);
    }
}
开发者ID:venamax,项目名称:trixandtrax-cl,代码行数:52,代码来源:videos-functions.php

示例6: coder_sanitize_upload

 /**
  * Function to sanitize upload
  *
  * @access public
  * @since 1.1
  *
  * @param $coder_upload
  * @return string
  *
  */
 function coder_sanitize_upload($coder_upload, $coder_setting)
 {
     /*
      * Array of valid upload file types.
      *
      * The array includes upload mime types that are included in wp_get_mime_types()
      */
     $coder_mimes = wp_get_mime_types();
     // Return an array with file extension and mime_type.
     $coder_file = wp_check_filetype($coder_upload, $coder_mimes);
     // If $coder_upload has a valid mime_type, return it; otherwise, return the default.
     return $coder_file['ext'] ? $coder_upload : $coder_setting->default;
 }
开发者ID:kafleg,项目名称:coder-customizer-framework,代码行数:23,代码来源:sanitize-upload.php

示例7: get_mime_extensions

 static function get_mime_extensions()
 {
     $mime_types = wp_get_mime_types();
     $extensions = array();
     foreach ($mime_types as $ext => $mime) {
         $ext = explode('|', $ext);
         $extensions[$mime] = $ext;
         $mime_parts = explode('/', $mime);
         if (empty($extensions[$mime_parts[0]])) {
             $extensions[$mime_parts[0]] = array();
         }
         $extensions[$mime_parts[0]] = $extensions[$mime_parts[0] . '/*'] = array_merge($extensions[$mime_parts[0]], $ext);
     }
     return $extensions;
 }
开发者ID:netmagik,项目名称:netmagik,代码行数:15,代码来源:media.php

示例8: get_extension

 /**
  * Get extension
  *
  * @param string $path
  * @return string
  */
 public function get_extension($path)
 {
     $type = $this->get_mime($path);
     $match = [];
     $ext = '';
     if ($type) {
         foreach (wp_get_mime_types() as $extensions => $content_type) {
             if ($content_type == $type) {
                 $ext = explode('|', $extensions)[0];
                 break;
             }
         }
     }
     return $ext;
 }
开发者ID:hametuha,项目名称:wpametu,代码行数:21,代码来源:Mime.php

示例9: get_column_options

 /**
  * @see CACIE_Editable_Model::get_column_options()
  * @since 1.0
  */
 public function get_column_options($column)
 {
     $options = parent::get_column_options($column);
     switch ($column['type']) {
         // WP Default
         // Custom columns
         case 'column-taxonomy':
             $options = $this->get_term_options($column['taxonomy']);
             break;
         case 'column-mime_type':
             $mime_types = wp_get_mime_types();
             $options = array_combine($mime_types, $mime_types);
             break;
     }
     return $options;
 }
开发者ID:bruno-barros,项目名称:w.eloquent.light,代码行数:20,代码来源:media.php

示例10: x_shortcode_audio_player

function x_shortcode_audio_player($atts)
{
    extract(shortcode_atts(array('id' => '', 'class' => '', 'style' => '', 'src' => '', 'advanced_controls' => '', 'preload' => '', 'autoplay' => '', 'loop' => '', 'mp3' => '', 'oga' => ''), $atts, 'x_audio_player'));
    $id = $id != '' ? 'id="' . esc_attr($id) . '"' : '';
    $class = $class != '' ? 'x-audio player ' . esc_attr($class) : 'x-audio player';
    $style = $style != '' ? 'style="' . $style . '"' : '';
    $src = $src != '' ? explode('|', $src) : array();
    $advanced_controls = $advanced_controls == 'true' ? ' advanced-controls' : '';
    $preload = $preload != '' ? ' preload="' . $preload . '"' : ' preload="metadata"';
    $autoplay = $autoplay == 'true' ? ' autoplay' : '';
    $loop = $loop == 'true' ? ' loop' : '';
    //
    // Deprecated parameters.
    //
    $mp3 = $mp3 != '' ? '<source src="' . $mp3 . '" type="audio/mpeg">' : '';
    $oga = $oga != '' ? '<source src="' . $oga . '" type="audio/ogg">' : '';
    //
    // Variable markup.
    //
    $data = cs_generate_data_attributes('x_mejs');
    //
    // Enqueue scripts.
    //
    wp_enqueue_script('mediaelement');
    //
    // Build sources.
    //
    $sources = array();
    foreach ($src as $file) {
        $mime = wp_check_filetype($file, wp_get_mime_types());
        $sources[] = '<source src="' . esc_url($file) . '" type="' . $mime['type'] . '">';
    }
    if ($mp3 != '') {
        $sources[] = $mp3;
    }
    if ($oga != '') {
        $sources[] = $oga;
    }
    //
    // Markup.
    //
    $output = "<div {$id} class=\"{$class}{$autoplay}{$loop}\" {$data} {$style}>" . "<audio class=\"x-mejs{$advanced_controls}\"{$preload}{$autoplay}{$loop}>" . implode('', $sources) . '</audio>' . '</div>';
    return $output;
}
开发者ID:nayabbukhari,项目名称:circulocristiano,代码行数:44,代码来源:audio-player.php

示例11: sideload_attachment

 private function sideload_attachment($attachment, $_to_post_id, $date)
 {
     if ('image' === $attachment->type) {
         $response = wp_remote_head($attachment->url);
         if (200 == wp_remote_retrieve_response_code($response)) {
             $_mimes = array_flip(wp_get_mime_types());
             $_content_type = wp_remote_retrieve_header($response, 'content-type');
             if (isset($_mimes[$_content_type])) {
                 $_ext = strtok($_mimes[$_content_type], '|');
                 $_temp_file = download_url($attachment->url);
                 // TODO check for WP_Error
                 $_new_file = str_replace('.tmp', '.' . $_ext, $_temp_file);
                 rename($_temp_file, $_new_file);
                 $file_array = array();
                 $file_array['name'] = basename($_new_file);
                 $file_array['tmp_name'] = $_new_file;
                 $attachment_id = media_handle_sideload($file_array, $_to_post_id, '', array('post_date' => $date, 'post_date_gmt' => $date));
             }
         }
     }
 }
开发者ID:westi,项目名称:pjw-groupme-importer,代码行数:21,代码来源:class-pjw-groupme-wp-api.php

示例12: allow_video_uploads

 /**
  * Matt & Mike J requested that we allow video uploads from the API for mobile apps, even without the VideoPress upgrade..
  * https://videop2.wordpress.com/2014/08/21/videopress-iteration/#comment-3377
  */
 function allow_video_uploads($mimes)
 {
     // if we are on Jetpack, bail - Videos are already allowed
     if (!defined('IS_WPCOM') || !IS_WPCOM) {
         return $mimes;
     }
     // extra check that this filter is only ever applied during REST API requests
     if (!defined('REST_API_REQUEST') || !REST_API_REQUEST) {
         return $mimes;
     }
     // bail early if they already have the upgrade..
     if (get_option('video_upgrade') == '1') {
         return $mimes;
     }
     // lets whitelist to only specific clients right now
     $clients_allowed_video_uploads = array();
     $clients_allowed_video_uploads = apply_filters('rest_api_clients_allowed_video_uploads', $clients_allowed_video_uploads);
     if (!in_array($this->api->token_details['client_id'], $clients_allowed_video_uploads)) {
         return $mimes;
     }
     $mime_list = wp_get_mime_types();
     $site_exts = explode(' ', get_site_option('upload_filetypes'));
     $video_exts = explode(' ', get_site_option('video_upload_filetypes', false, false));
     $video_exts = apply_filters('video_upload_filetypes', $video_exts);
     $video_mimes = array();
     if (!empty($video_exts)) {
         foreach ($video_exts as $ext) {
             foreach ($mime_list as $ext_pattern => $mime) {
                 if ($ext != '' && strpos($ext_pattern, $ext) !== false) {
                     $video_mimes[$ext_pattern] = $mime;
                 }
             }
         }
         $mimes = array_merge($mimes, $video_mimes);
     }
     return $mimes;
 }
开发者ID:sdh100shaun,项目名称:pantheon,代码行数:41,代码来源:class.wpcom-json-api-upload-media-v1-1-endpoint.php

示例13: dynimg_404_handler

function dynimg_404_handler()
{
    if (!is_404()) {
        return;
    }
    // Has the file name the proper format for this handler?
    if (!preg_match('/(.*)-([0-9]+)x([0-9]+)(c)?\\.(\\w+)($|\\?|#)/i', $_SERVER['REQUEST_URI'], $matches)) {
        return;
    }
    $mime_types = wp_get_mime_types();
    $img_ext = $matches[5];
    $ext_known = false;
    // The extensions for some MIME types are set as regular expression (PCRE).
    foreach ($mime_types as $rgx_ext => $mime_type) {
        if (preg_match("/{$rgx_ext}/i", $img_ext)) {
            if (wp_image_editor_supports(array('mime_type' => $mime_type))) {
                $ext_known = true;
                break;
            }
        }
    }
    if (!$ext_known) {
        return;
    }
    $filename = urldecode($matches[1] . '.' . $img_ext);
    $width = $matches[2];
    $height = $matches[3];
    $crop = !empty($matches[4]);
    $uploads_dir = wp_upload_dir();
    $temp = parse_url($uploads_dir['baseurl']);
    $upload_path = $temp['path'];
    $findfile = str_replace($upload_path, '', $filename);
    $basefile = $uploads_dir['basedir'] . $findfile;
    // Serve the image this one time (next time the webserver will do it for us)
    dynimg_create_save_stream($basefile, $width, $height, $crop);
}
开发者ID:afftt,项目名称:infos-ping,代码行数:36,代码来源:dynamic-image-resizer.php

示例14: test_wp_get_mime_types

 /**
  * @ticket 21594
  */
 function test_wp_get_mime_types()
 {
     $mimes = wp_get_mime_types();
     $this->assertInternalType('array', $mimes);
     $this->assertNotEmpty($mimes);
     add_filter('mime_types', '__return_empty_array');
     $mimes = wp_get_mime_types();
     $this->assertInternalType('array', $mimes);
     $this->assertEmpty($mimes);
     remove_filter('mime_types', '__return_empty_array');
     $mimes = wp_get_mime_types();
     $this->assertInternalType('array', $mimes);
     $this->assertNotEmpty($mimes);
     // upload_mimes shouldn't affect wp_get_mime_types()
     add_filter('upload_mimes', '__return_empty_array');
     $mimes = wp_get_mime_types();
     $this->assertInternalType('array', $mimes);
     $this->assertNotEmpty($mimes);
     remove_filter('upload_mimes', '__return_empty_array');
     $mimes2 = wp_get_mime_types();
     $this->assertInternalType('array', $mimes2);
     $this->assertNotEmpty($mimes2);
     $this->assertEquals($mimes2, $mimes);
 }
开发者ID:jaspermdegroot,项目名称:develop.wordpress,代码行数:27,代码来源:functions.php

示例15: wp_video_shortcode

/**
 * Builds the Video shortcode output.
 *
 * This implements the functionality of the Video Shortcode for displaying
 * WordPress mp4s in a post.
 *
 * @since 3.6.0
 *
 * @global int $content_width
 * @staticvar int $instance
 *
 * @param array  $attr {
 *     Attributes of the shortcode.
 *
 *     @type string $src      URL to the source of the video file. Default empty.
 *     @type int    $height   Height of the video embed in pixels. Default 360.
 *     @type int    $width    Width of the video embed in pixels. Default $content_width or 640.
 *     @type string $poster   The 'poster' attribute for the `<video>` element. Default empty.
 *     @type string $loop     The 'loop' attribute for the `<video>` element. Default empty.
 *     @type string $autoplay The 'autoplay' attribute for the `<video>` element. Default empty.
 *     @type string $preload  The 'preload' attribute for the `<video>` element.
 *                            Default 'metadata'.
 *     @type string $class    The 'class' attribute for the `<video>` element.
 *                            Default 'wp-video-shortcode'.
 * }
 * @param string $content Shortcode content.
 * @return string|void HTML content to display video.
 */
function wp_video_shortcode($attr, $content = '')
{
    global $content_width;
    $post_id = get_post() ? get_the_ID() : 0;
    static $instance = 0;
    $instance++;
    /**
     * Filter the default video shortcode output.
     *
     * If the filtered output isn't empty, it will be used instead of generating
     * the default video template.
     *
     * @since 3.6.0
     *
     * @see wp_video_shortcode()
     *
     * @param string $html     Empty variable to be replaced with shortcode markup.
     * @param array  $attr     Attributes of the video shortcode.
     * @param string $content  Video shortcode content.
     * @param int    $instance Unique numeric ID of this video shortcode instance.
     */
    $override = apply_filters('wp_video_shortcode_override', '', $attr, $content, $instance);
    if ('' !== $override) {
        return $override;
    }
    $video = null;
    $default_types = wp_get_video_extensions();
    $defaults_atts = array('src' => '', 'poster' => '', 'loop' => '', 'autoplay' => '', 'preload' => 'metadata', 'width' => 640, 'height' => 360);
    foreach ($default_types as $type) {
        $defaults_atts[$type] = '';
    }
    $atts = shortcode_atts($defaults_atts, $attr, 'video');
    if (is_admin()) {
        // shrink the video so it isn't huge in the admin
        if ($atts['width'] > $defaults_atts['width']) {
            $atts['height'] = round($atts['height'] * $defaults_atts['width'] / $atts['width']);
            $atts['width'] = $defaults_atts['width'];
        }
    } else {
        // if the video is bigger than the theme
        if (!empty($content_width) && $atts['width'] > $content_width) {
            $atts['height'] = round($atts['height'] * $content_width / $atts['width']);
            $atts['width'] = $content_width;
        }
    }
    $is_vimeo = $is_youtube = false;
    $yt_pattern = '#^https?://(?:www\\.)?(?:youtube\\.com/watch|youtu\\.be/)#';
    $vimeo_pattern = '#^https?://(.+\\.)?vimeo\\.com/.*#';
    $primary = false;
    if (!empty($atts['src'])) {
        $is_vimeo = preg_match($vimeo_pattern, $atts['src']);
        $is_youtube = preg_match($yt_pattern, $atts['src']);
        if (!$is_youtube && !$is_vimeo) {
            $type = wp_check_filetype($atts['src'], wp_get_mime_types());
            if (!in_array(strtolower($type['ext']), $default_types)) {
                return sprintf('<a class="wp-embedded-video" href="%s">%s</a>', esc_url($atts['src']), esc_html($atts['src']));
            }
        }
        if ($is_vimeo) {
            wp_enqueue_script('froogaloop');
        }
        $primary = true;
        array_unshift($default_types, 'src');
    } else {
        foreach ($default_types as $ext) {
            if (!empty($atts[$ext])) {
                $type = wp_check_filetype($atts[$ext], wp_get_mime_types());
                if (strtolower($type['ext']) === $ext) {
                    $primary = true;
                }
            }
        }
//.........这里部分代码省略.........
开发者ID:nakamuraagatha,项目名称:reseptest,代码行数:101,代码来源:media.php


注:本文中的wp_get_mime_types函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。