WordPressを読む 29-3 /blog/wp-includes/theme.php 3
2014/12/12
目次
- 1 /blog/wp-includes/theme.php 3
- 2 関数 display_header_text()
- 3 関数 get_header_image()
- 4 関数 _get_random_header_data()
- 5 関数 get_random_header_image()
- 6 関数 is_random_header_image()
- 7 関数 header_image()
- 8 関数 get_uploaded_header_images()
- 9 関数 get_custom_header()
- 10 関数 register_default_headers()
- 11 関数 unregister_default_headers()
- 12 関数 get_background_image()
- 13 関数 background_image()
- 14 関数 get_background_color()
- 15 関数 background_color()
- 16 関数 _custom_background_cb()
- 17 関数 add_editor_style()
- 18 関数 remove_editor_styles()
- 19 関数 get_editor_stylesheets()
/blog/wp-includes/theme.php 3
関数 display_header_text()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | /** * Whether to display the header text. * * @since 3.4.0 * * @return bool */ function display_header_text() { if ( ! current_theme_supports( 'custom-header', 'header-text' ) ) return false; $text_color = get_theme_mod( 'header_textcolor', get_theme_support( 'custom-header', 'default-text-color' ) ); return 'blank' != $text_color; } |
関数 get_header_image()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | /** * Retrieve header image for custom header. * * @since 2.1.0 * * @return string */ function get_header_image() { $url = get_theme_mod( 'header_image', get_theme_support( 'custom-header', 'default-image' ) ); if ( 'remove-header' == $url ) return false; if ( is_random_header_image() ) $url = get_random_header_image(); return esc_url_raw( set_url_scheme( $url ) ); } |
関数 _get_random_header_data()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | /** * Get random header image data from registered images in theme. * * @since 3.4.0 * * @access private * * @return string Path to header image */ function _get_random_header_data() { static $_wp_random_header; if ( empty( $_wp_random_header ) ) { global $_wp_default_headers; $header_image_mod = get_theme_mod( 'header_image', '' ); $headers = array(); if ( 'random-uploaded-image' == $header_image_mod ) $headers = get_uploaded_header_images(); elseif ( ! empty( $_wp_default_headers ) ) { if ( 'random-default-image' == $header_image_mod ) { $headers = $_wp_default_headers; } else { if ( current_theme_supports( 'custom-header', 'random-default' ) ) $headers = $_wp_default_headers; } } if ( empty( $headers ) ) return new stdClass; $_wp_random_header = (object) $headers[ array_rand( $headers ) ]; $_wp_random_header->url = sprintf( $_wp_random_header->url, get_template_directory_uri(), get_stylesheet_directory_uri() ); $_wp_random_header->thumbnail_url = sprintf( $_wp_random_header->thumbnail_url, get_template_directory_uri(), get_stylesheet_directory_uri() ); } return $_wp_random_header; } |
関数 get_random_header_image()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | /** * Get random header image url from registered images in theme. * * @since 3.2.0 * * @return string Path to header image */ function get_random_header_image() { $random_image = _get_random_header_data(); if ( empty( $random_image->url ) ) return ''; return $random_image->url; } |
関数 is_random_header_image()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | /** * Check if random header image is in use. * * Always true if user expressly chooses the option in Appearance > Header. * Also true if theme has multiple header images registered, no specific header image * is chosen, and theme turns on random headers with add_theme_support(). * * @since 3.2.0 * * @param string $type The random pool to use. any|default|uploaded * @return boolean */ function is_random_header_image( $type = 'any' ) { $header_image_mod = get_theme_mod( 'header_image', get_theme_support( 'custom-header', 'default-image' ) ); if ( 'any' == $type ) { if ( 'random-default-image' == $header_image_mod || 'random-uploaded-image' == $header_image_mod || ( '' != get_random_header_image() && empty( $header_image_mod ) ) ) return true; } else { if ( "random-$type-image" == $header_image_mod ) return true; elseif ( 'default' == $type && empty( $header_image_mod ) && '' != get_random_header_image() ) return true; } return false; } |
関数 header_image()
1 2 3 4 5 6 7 8 | /** * Display header image URL. * * @since 2.1.0 */ function header_image() { echo esc_url( get_header_image() ); } |
関数 get_uploaded_header_images()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | /** * Get the header images uploaded for the current theme. * * @since 3.2.0 * * @return array */ function get_uploaded_header_images() { $header_images = array(); // @todo caching $headers = get_posts( array( 'post_type' => 'attachment', 'meta_key' => '_wp_attachment_is_custom_header', 'meta_value' => get_option('stylesheet'), 'orderby' => 'none', 'nopaging' => true ) ); if ( empty( $headers ) ) return array(); foreach ( (array) $headers as $header ) { $url = esc_url_raw( wp_get_attachment_url( $header->ID ) ); $header_data = wp_get_attachment_metadata( $header->ID ); $header_index = basename($url); $header_images[$header_index] = array(); $header_images[$header_index]['attachment_id'] = $header->ID; $header_images[$header_index]['url'] = $url; $header_images[$header_index]['thumbnail_url'] = $url; if ( isset( $header_data['width'] ) ) $header_images[$header_index]['width'] = $header_data['width']; if ( isset( $header_data['height'] ) ) $header_images[$header_index]['height'] = $header_data['height']; } return $header_images; } |
関数 get_custom_header()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | /** * Get the header image data. * * @since 3.4.0 * * @return object */ function get_custom_header() { global $_wp_default_headers; if ( is_random_header_image() ) { $data = _get_random_header_data(); } else { $data = get_theme_mod( 'header_image_data' ); if ( ! $data && current_theme_supports( 'custom-header', 'default-image' ) ) { $directory_args = array( get_template_directory_uri(), get_stylesheet_directory_uri() ); $data = array(); $data['url'] = $data['thumbnail_url'] = vsprintf( get_theme_support( 'custom-header', 'default-image' ), $directory_args ); if ( ! empty( $_wp_default_headers ) ) { foreach ( (array) $_wp_default_headers as $default_header ) { $url = vsprintf( $default_header['url'], $directory_args ); if ( $data['url'] == $url ) { $data = $default_header; $data['url'] = $url; $data['thumbnail_url'] = vsprintf( $data['thumbnail_url'], $directory_args ); break; } } } } } $default = array( 'url' => '', 'thumbnail_url' => '', 'width' => get_theme_support( 'custom-header', 'width' ), 'height' => get_theme_support( 'custom-header', 'height' ), ); return (object) wp_parse_args( $data, $default ); } |
関数 register_default_headers()
1 2 3 4 5 6 7 8 9 10 11 12 | /** * Register a selection of default headers to be displayed by the custom header admin UI. * * @since 3.0.0 * * @param array $headers Array of headers keyed by a string id. The ids point to arrays containing 'url', 'thumbnail_url', and 'description' keys. */ function register_default_headers( $headers ) { global $_wp_default_headers; $_wp_default_headers = array_merge( (array) $_wp_default_headers, (array) $headers ); } |
関数 unregister_default_headers()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | /** * Unregister default headers. * * This function must be called after register_default_headers() has already added the * header you want to remove. * * @see register_default_headers() * @since 3.0.0 * * @param string|array $header The header string id (key of array) to remove, or an array thereof. * @return bool|void A single header returns true on success, false on failure. * There is currently no return value for multiple headers. */ function unregister_default_headers( $header ) { global $_wp_default_headers; if ( is_array( $header ) ) { array_map( 'unregister_default_headers', $header ); } elseif ( isset( $_wp_default_headers[ $header ] ) ) { unset( $_wp_default_headers[ $header ] ); return true; } else { return false; } } |
関数 get_background_image()
1 2 3 4 5 6 7 8 9 10 | /** * Retrieve background image for custom background. * * @since 3.0.0 * * @return string */ function get_background_image() { return get_theme_mod('background_image', get_theme_support( 'custom-background', 'default-image' ) ); } |
関数 background_image()
1 2 3 4 5 6 7 8 | /** * Display background image path. * * @since 3.0.0 */ function background_image() { echo get_background_image(); } |
関数 get_background_color()
1 2 3 4 5 6 7 8 9 10 | /** * Retrieve value for custom background color. * * @since 3.0.0 * * @return string */ function get_background_color() { return get_theme_mod('background_color', get_theme_support( 'custom-background', 'default-color' ) ); } |
関数 background_color()
1 2 3 4 5 6 7 8 | /** * Display background color value. * * @since 3.0.0 */ function background_color() { echo get_background_color(); } |
関数 _custom_background_cb()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | /** * Default custom background callback. * * @since 3.0.0 * @access protected */ function _custom_background_cb() { // $background is the saved custom image, or the default image. $background = set_url_scheme( get_background_image() ); // $color is the saved custom color. // A default has to be specified in style.css. It will not be printed here. $color = get_background_color(); if ( $color === get_theme_support( 'custom-background', 'default-color' ) ) { $color = false; } if ( ! $background && ! $color ) return; $style = $color ? "background-color: #$color;" : ''; if ( $background ) { $image = " background-image: url('$background');"; $repeat = get_theme_mod( 'background_repeat', get_theme_support( 'custom-background', 'default-repeat' ) ); if ( ! in_array( $repeat, array( 'no-repeat', 'repeat-x', 'repeat-y', 'repeat' ) ) ) $repeat = 'repeat'; $repeat = " background-repeat: $repeat;"; $position = get_theme_mod( 'background_position_x', get_theme_support( 'custom-background', 'default-position-x' ) ); if ( ! in_array( $position, array( 'center', 'right', 'left' ) ) ) $position = 'left'; $position = " background-position: top $position;"; $attachment = get_theme_mod( 'background_attachment', get_theme_support( 'custom-background', 'default-attachment' ) ); if ( ! in_array( $attachment, array( 'fixed', 'scroll' ) ) ) $attachment = 'scroll'; $attachment = " background-attachment: $attachment;"; $style .= $image . $repeat . $position . $attachment; } ?> <style type="text/css" id="custom-background-css"> body.custom-background { <?php echo trim( $style ); ?> } </style> <?php } |
関数 add_editor_style()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | /** * Add callback for custom TinyMCE editor stylesheets. * * The parameter $stylesheet is the name of the stylesheet, relative to * the theme root. It also accepts an array of stylesheets. * It is optional and defaults to 'editor-style.css'. * * This function automatically adds another stylesheet with -rtl prefix, e.g. editor-style-rtl.css. * If that file doesn't exist, it is removed before adding the stylesheet(s) to TinyMCE. * If an array of stylesheets is passed to add_editor_style(), * RTL is only added for the first stylesheet. * * Since version 3.4 the TinyMCE body has .rtl CSS class. * It is a better option to use that class and add any RTL styles to the main stylesheet. * * @since 3.0.0 * * @param mixed $stylesheet Optional. Stylesheet name or array thereof, relative to theme root. * Defaults to 'editor-style.css' */ function add_editor_style( $stylesheet = 'editor-style.css' ) { add_theme_support( 'editor-style' ); if ( ! is_admin() ) return; global $editor_styles; $editor_styles = (array) $editor_styles; $stylesheet = (array) $stylesheet; if ( is_rtl() ) { $rtl_stylesheet = str_replace('.css', '-rtl.css', $stylesheet[0]); $stylesheet[] = $rtl_stylesheet; } $editor_styles = array_merge( $editor_styles, $stylesheet ); } |
関数 remove_editor_styles()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | /** * Removes all visual editor stylesheets. * * @since 3.1.0 * * @return bool True on success, false if there were no stylesheets to remove. */ function remove_editor_styles() { if ( ! current_theme_supports( 'editor-style' ) ) return false; _remove_theme_support( 'editor-style' ); if ( is_admin() ) $GLOBALS['editor_styles'] = array(); return true; } |
関数 get_editor_stylesheets()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | /** * Retrieve any registered editor stylesheets * * @since 4.0.0 * * @global $editor_styles Registered editor stylesheets * * @return array If registered, a list of editor stylesheet URLs. */ function get_editor_stylesheets() { $stylesheets = array(); // load editor_style.css if the current theme supports it if ( ! empty( $GLOBALS['editor_styles'] ) && is_array( $GLOBALS['editor_styles'] ) ) { $editor_styles = $GLOBALS['editor_styles']; $editor_styles = array_unique( array_filter( $editor_styles ) ); $style_uri = get_stylesheet_directory_uri(); $style_dir = get_stylesheet_directory(); // Support externally referenced styles (like, say, fonts). foreach ( $editor_styles as $key => $file ) { if ( preg_match( '~^(https?:)?//~', $file ) ) { $stylesheets[] = esc_url_raw( $file ); unset( $editor_styles[ $key ] ); } } // Look in a parent theme first, that way child theme CSS overrides. if ( is_child_theme() ) { $template_uri = get_template_directory_uri(); $template_dir = get_template_directory(); foreach ( $editor_styles as $key => $file ) { if ( $file && file_exists( "$template_dir/$file" ) ) { $stylesheets[] = "$template_uri/$file"; } } } foreach ( $editor_styles as $file ) { if ( $file && file_exists( "$style_dir/$file" ) ) { $stylesheets[] = "$style_uri/$file"; } } } return $stylesheets; } |