WordPressを読む 35-6 /blog/wp-includes/general-template.php 6
2014/12/18
目次
- 1 /blog/wp-includes/general-template.php 6
- 2 関数 language_attributes()
- 3 関数 paginate_links()
- 4 関数 wp_admin_css_color()
- 5 関数 register_admin_color_schemes()
- 6 関数 wp_admin_css_uri()
- 7 関数 wp_admin_css()
- 8 関数 add_thickbox()
- 9 関数 wp_generator()
- 10 関数 the_generator()
- 11 関数 get_the_generator()
- 12 関数 checked()
- 13 関数 selected()
- 14 関数 disabled()
- 15 関数 __checked_selected_helper()
- 16 関数 wp_heartbeat_settings()
/blog/wp-includes/general-template.php 6
関数 language_attributes()
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 | /** * Display the language attributes for the html tag. * * Builds up a set of html attributes containing the text direction and language * information for the page. * * @since 2.1.0 * * @param string $doctype The type of html document (xhtml|html). */ function language_attributes($doctype = 'html') { $attributes = array(); if ( function_exists( 'is_rtl' ) && is_rtl() ) $attributes[] = 'dir="rtl"'; if ( $lang = get_bloginfo('language') ) { if ( get_option('html_type') == 'text/html' || $doctype == 'html' ) $attributes[] = "lang=\"$lang\""; if ( get_option('html_type') != 'text/html' || $doctype == 'xhtml' ) $attributes[] = "xml:lang=\"$lang\""; } $output = implode(' ', $attributes); /** * Filter the language attributes for display in the html tag. * * @since 2.5.0 * * @param string $output A space-separated list of language attributes. */ echo apply_filters( 'language_attributes', $output ); } |
関数 paginate_links()
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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | /** * Retrieve paginated link for archive post pages. * * Technically, the function can be used to create paginated link list for any * area. The 'base' argument is used to reference the url, which will be used to * create the paginated links. The 'format' argument is then used for replacing * the page number. It is however, most likely and by default, to be used on the * archive post pages. * * The 'type' argument controls format of the returned value. The default is * 'plain', which is just a string with the links separated by a newline * character. The other possible values are either 'array' or 'list'. The * 'array' value will return an array of the paginated link list to offer full * control of display. The 'list' value will place all of the paginated links in * an unordered HTML list. * * The 'total' argument is the total amount of pages and is an integer. The * 'current' argument is the current page number and is also an integer. * * An example of the 'base' argument is "http://example.com/all_posts.php%_%" * and the '%_%' is required. The '%_%' will be replaced by the contents of in * the 'format' argument. An example for the 'format' argument is "?page=%#%" * and the '%#%' is also required. The '%#%' will be replaced with the page * number. * * You can include the previous and next links in the list by setting the * 'prev_next' argument to true, which it is by default. You can set the * previous text, by using the 'prev_text' argument. You can set the next text * by setting the 'next_text' argument. * * If the 'show_all' argument is set to true, then it will show all of the pages * instead of a short list of the pages near the current page. By default, the * 'show_all' is set to false and controlled by the 'end_size' and 'mid_size' * arguments. The 'end_size' argument is how many numbers on either the start * and the end list edges, by default is 1. The 'mid_size' argument is how many * numbers to either side of current page, but not including current page. * * It is possible to add query vars to the link by using the 'add_args' argument * and see {@link add_query_arg()} for more information. * * The 'before_page_number' and 'after_page_number' arguments allow users to * augment the links themselves. Typically this might be to add context to the * numbered links so that screen reader users understand what the links are for. * The text strings are added before and after the page number - within the * anchor tag. * * @since 2.1.0 * * @param string|array $args Optional. Override defaults. * @return array|string String of page links or array of page links. */ function paginate_links( $args = '' ) { global $wp_query, $wp_rewrite; $total = ( isset( $wp_query->max_num_pages ) ) ? $wp_query->max_num_pages : 1; $current = ( get_query_var( 'paged' ) ) ? intval( get_query_var( 'paged' ) ) : 1; $pagenum_link = html_entity_decode( get_pagenum_link() ); $query_args = array(); $url_parts = explode( '?', $pagenum_link ); if ( isset( $url_parts[1] ) ) { wp_parse_str( $url_parts[1], $query_args ); } $pagenum_link = remove_query_arg( array_keys( $query_args ), $pagenum_link ); $pagenum_link = trailingslashit( $pagenum_link ) . '%_%'; $format = $wp_rewrite->using_index_permalinks() && ! strpos( $pagenum_link, 'index.php' ) ? 'index.php/' : ''; $format .= $wp_rewrite->using_permalinks() ? user_trailingslashit( $wp_rewrite->pagination_base . '/%#%', 'paged' ) : '?paged=%#%'; $defaults = array( 'base' => $pagenum_link, // http://example.com/all_posts.php%_% : %_% is replaced by format (below) 'format' => $format, // ?page=%#% : %#% is replaced by the page number 'total' => $total, 'current' => $current, 'show_all' => false, 'prev_next' => true, 'prev_text' => __('« Previous'), 'next_text' => __('Next »'), 'end_size' => 1, 'mid_size' => 2, 'type' => 'plain', 'add_args' => false, // array of query args to add 'add_fragment' => '', 'before_page_number' => '', 'after_page_number' => '' ); $args = wp_parse_args( $args, $defaults ); // Who knows what else people pass in $args $total = (int) $args['total']; if ( $total < 2 ) { return; } $current = (int) $args['current']; $end_size = (int) $args['end_size']; // Out of bounds? Make it the default. if ( $end_size < 1 ) { $end_size = 1; } $mid_size = (int) $args['mid_size']; if ( $mid_size < 0 ) { $mid_size = 2; } $add_args = is_array( $args['add_args'] ) ? $args['add_args'] : false; $r = ''; $page_links = array(); $dots = false; if ( $args['prev_next'] && $current && 1 < $current ) : $link = str_replace( '%_%', 2 == $current ? '' : $args['format'], $args['base'] ); $link = str_replace( '%#%', $current - 1, $link ); if ( $add_args ) $link = add_query_arg( $add_args, $link ); $link .= $args['add_fragment']; /** * Filter the paginated links for the given archive pages. * * @since 3.0.0 * * @param string $link The paginated link URL. */ $page_links[] = '<a class="prev page-numbers" href="' . esc_url( apply_filters( 'paginate_links', $link ) ) . '">' . $args['prev_text'] . '</a>'; endif; for ( $n = 1; $n <= $total; $n++ ) : if ( $n == $current ) : $page_links[] = "<span class='page-numbers current'>" . $args['before_page_number'] . number_format_i18n( $n ) . $args['after_page_number'] . "</span>"; $dots = true; else : if ( $args['show_all'] || ( $n <= $end_size || ( $current && $n >= $current - $mid_size && $n <= $current + $mid_size ) || $n > $total - $end_size ) ) : $link = str_replace( '%_%', 1 == $n ? '' : $args['format'], $args['base'] ); $link = str_replace( '%#%', $n, $link ); if ( $add_args ) $link = add_query_arg( $add_args, $link ); $link .= $args['add_fragment']; /** This filter is documented in wp-includes/general-template.php */ $page_links[] = "<a class='page-numbers' href='" . esc_url( apply_filters( 'paginate_links', $link ) ) . "'>" . $args['before_page_number'] . number_format_i18n( $n ) . $args['after_page_number'] . "</a>"; $dots = true; elseif ( $dots && ! $args['show_all'] ) : $page_links[] = '<span class="page-numbers dots">' . __( '…' ) . '</span>'; $dots = false; endif; endif; endfor; if ( $args['prev_next'] && $current && ( $current < $total || -1 == $total ) ) : $link = str_replace( '%_%', $args['format'], $args['base'] ); $link = str_replace( '%#%', $current + 1, $link ); if ( $add_args ) $link = add_query_arg( $add_args, $link ); $link .= $args['add_fragment']; /** This filter is documented in wp-includes/general-template.php */ $page_links[] = '<a class="next page-numbers" href="' . esc_url( apply_filters( 'paginate_links', $link ) ) . '">' . $args['next_text'] . '</a>'; endif; switch ( $args['type'] ) { case 'array' : return $page_links; case 'list' : $r .= "<ul class='page-numbers'>\n\t<li>"; $r .= join("</li>\n\t<li>", $page_links); $r .= "</li>\n</ul>\n"; break; default : $r = join("\n", $page_links); break; } return $r; } |
関数 wp_admin_css_color()
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 | /** * Registers an admin colour scheme css file. * * Allows a plugin to register a new admin colour scheme. For example: * <code> * wp_admin_css_color('classic', __('Classic'), admin_url("css/colors-classic.css"), * array('#07273E', '#14568A', '#D54E21', '#2683AE')); * * * @since 2.5.0 * * @param string $key The unique key for this theme. * @param string $name The name of the theme. * @param string $url The url of the css file containing the colour scheme. * @param array $colors Optional An array of CSS color definitions which are used to give the user a feel for the theme. * @param array $icons Optional An array of CSS color definitions used to color any SVG icons */ function wp_admin_css_color( $key, $name, $url, $colors = array(), $icons = array() ) { global $_wp_admin_css_colors; if ( !isset($_wp_admin_css_colors) ) $_wp_admin_css_colors = array(); $_wp_admin_css_colors[$key] = (object) array( 'name' => $name, 'url' => $url, 'colors' => $colors, 'icon_colors' => $icons, ); } |
関数 register_admin_color_schemes()
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 50 51 52 53 54 55 56 57 58 59 60 61 62 | /** * Registers the default Admin color schemes * * @since 3.0.0 */ function register_admin_color_schemes() { $suffix = is_rtl() ? '-rtl' : ''; $suffix .= defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; wp_admin_css_color( 'fresh', _x( 'Default', 'admin color scheme' ), false, array( '#222', '#333', '#0074a2', '#2ea2cc' ), array( 'base' => '#999', 'focus' => '#2ea2cc', 'current' => '#fff' ) ); // Other color schemes are not available when running out of src if ( false !== strpos( $GLOBALS['wp_version'], '-src' ) ) return; wp_admin_css_color( 'light', _x( 'Light', 'admin color scheme' ), admin_url( "css/colors/light/colors$suffix.css" ), array( '#e5e5e5', '#999', '#d64e07', '#04a4cc' ), array( 'base' => '#999', 'focus' => '#ccc', 'current' => '#ccc' ) ); wp_admin_css_color( 'blue', _x( 'Blue', 'admin color scheme' ), admin_url( "css/colors/blue/colors$suffix.css" ), array( '#096484', '#4796b3', '#52accc', '#74B6CE' ), array( 'base' => '#e5f8ff', 'focus' => '#fff', 'current' => '#fff' ) ); wp_admin_css_color( 'midnight', _x( 'Midnight', 'admin color scheme' ), admin_url( "css/colors/midnight/colors$suffix.css" ), array( '#25282b', '#363b3f', '#69a8bb', '#e14d43' ), array( 'base' => '#f1f2f3', 'focus' => '#fff', 'current' => '#fff' ) ); wp_admin_css_color( 'sunrise', _x( 'Sunrise', 'admin color scheme' ), admin_url( "css/colors/sunrise/colors$suffix.css" ), array( '#b43c38', '#cf4944', '#dd823b', '#ccaf0b' ), array( 'base' => '#f3f1f1', 'focus' => '#fff', 'current' => '#fff' ) ); wp_admin_css_color( 'ectoplasm', _x( 'Ectoplasm', 'admin color scheme' ), admin_url( "css/colors/ectoplasm/colors$suffix.css" ), array( '#413256', '#523f6d', '#a3b745', '#d46f15' ), array( 'base' => '#ece6f6', 'focus' => '#fff', 'current' => '#fff' ) ); wp_admin_css_color( 'ocean', _x( 'Ocean', 'admin color scheme' ), admin_url( "css/colors/ocean/colors$suffix.css" ), array( '#627c83', '#738e96', '#9ebaa0', '#aa9d88' ), array( 'base' => '#f2fcff', 'focus' => '#fff', 'current' => '#fff' ) ); wp_admin_css_color( 'coffee', _x( 'Coffee', 'admin color scheme' ), admin_url( "css/colors/coffee/colors$suffix.css" ), array( '#46403c', '#59524c', '#c7a589', '#9ea476' ), array( 'base' => '#f3f2f1', 'focus' => '#fff', 'current' => '#fff' ) ); } |
関数 wp_admin_css_uri()
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 | /** * Display the URL of a WordPress admin CSS file. * * @see WP_Styles::_css_href and its style_loader_src filter. * * @since 2.3.0 * * @param string $file file relative to wp-admin/ without its ".css" extension. */ function wp_admin_css_uri( $file = 'wp-admin' ) { if ( defined('WP_INSTALLING') ) { $_file = "./$file.css"; } else { $_file = admin_url("$file.css"); } $_file = add_query_arg( 'version', get_bloginfo( 'version' ), $_file ); /** * Filter the URI of a WordPress admin CSS file. * * @since 2.3.0 * * @param string $_file Relative path to the file with query arguments attached. * @param string $file Relative path to the file, minus its ".css" extension. */ return apply_filters( 'wp_admin_css_uri', $_file, $file ); } |
関数 wp_admin_css()
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 50 51 52 53 54 55 | /** * Enqueues or directly prints a stylesheet link to the specified CSS file. * * "Intelligently" decides to enqueue or to print the CSS file. If the * 'wp_print_styles' action has *not* yet been called, the CSS file will be * enqueued. If the wp_print_styles action *has* been called, the CSS link will * be printed. Printing may be forced by passing true as the $force_echo * (second) parameter. * * For backward compatibility with WordPress 2.3 calling method: If the $file * (first) parameter does not correspond to a registered CSS file, we assume * $file is a file relative to wp-admin/ without its ".css" extension. A * stylesheet link to that generated URL is printed. * * @since 2.3.0 * @uses $wp_styles WordPress Styles Object * * @param string $file Optional. Style handle name or file name (without ".css" extension) relative * to wp-admin/. Defaults to 'wp-admin'. * @param bool $force_echo Optional. Force the stylesheet link to be printed rather than enqueued. */ function wp_admin_css( $file = 'wp-admin', $force_echo = false ) { global $wp_styles; if ( !is_a($wp_styles, 'WP_Styles') ) $wp_styles = new WP_Styles(); // For backward compatibility $handle = 0 === strpos( $file, 'css/' ) ? substr( $file, 4 ) : $file; if ( $wp_styles->query( $handle ) ) { if ( $force_echo || did_action( 'wp_print_styles' ) ) // we already printed the style queue. Print this one immediately wp_print_styles( $handle ); else // Add to style queue wp_enqueue_style( $handle ); return; } /** * Filter the stylesheet link to the specified CSS file. * * If the site is set to display right-to-left, the RTL stylesheet link * will be used instead. * * @since 2.3.0 * * @param string $file Style handle name or filename (without ".css" extension) * relative to wp-admin/. Defaults to 'wp-admin'. */ echo apply_filters( 'wp_admin_css', "<link rel='stylesheet' href='" . esc_url( wp_admin_css_uri( $file ) ) . "' type='text/css' />\n", $file ); if ( function_exists( 'is_rtl' ) && is_rtl() ) { /** This filter is documented in wp-includes/general-template.php */ echo apply_filters( 'wp_admin_css', "<link rel='stylesheet' href='" . esc_url( wp_admin_css_uri( "$file-rtl" ) ) . "' type='text/css' />\n", "$file-rtl" ); } } |
関数 add_thickbox()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | /** * Enqueues the default ThickBox js and css. * * If any of the settings need to be changed, this can be done with another js * file similar to media-upload.js. That file should * require array('thickbox') to ensure it is loaded after. * * @since 2.5.0 */ function add_thickbox() { wp_enqueue_script( 'thickbox' ); wp_enqueue_style( 'thickbox' ); if ( is_network_admin() ) add_action( 'admin_head', '_thickbox_path_admin_subfolder' ); } |
関数 wp_generator()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | /** * Display the XHTML generator that is generated on the wp_head hook. * * @since 2.5.0 */ function wp_generator() { /** * Filter the output of the XHTML generator tag. * * @since 2.5.0 * * @param string $generator_type The XHTML generator. */ the_generator( apply_filters( 'wp_generator_type', 'xhtml' ) ); } |
関数 the_generator()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | /** * Display the generator XML or Comment for RSS, ATOM, etc. * * Returns the correct generator type for the requested output format. Allows * for a plugin to filter generators overall the the_generator filter. * * @since 2.5.0 * * @param string $type The type of generator to output - (html|xhtml|atom|rss2|rdf|comment|export). */ function the_generator( $type ) { /** * Filter the output of the XHTML generator tag for display. * * @since 2.5.0 * * @param string $generator_type The generator output. * @param string $type The type of generator to output. Accepts 'html', * 'xhtml', 'atom', 'rss2', 'rdf', 'comment', 'export'. */ echo apply_filters( 'the_generator', get_the_generator($type), $type ) . "\n"; } |
関数 get_the_generator()
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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | /** * Creates the generator XML or Comment for RSS, ATOM, etc. * * Returns the correct generator type for the requested output format. Allows * for a plugin to filter generators on an individual basis using the * 'get_the_generator_{$type}' filter. * * @since 2.5.0 * * @param string $type The type of generator to return - (html|xhtml|atom|rss2|rdf|comment|export). * @return string The HTML content for the generator. */ function get_the_generator( $type = '' ) { if ( empty( $type ) ) { $current_filter = current_filter(); if ( empty( $current_filter ) ) return; switch ( $current_filter ) { case 'rss2_head' : case 'commentsrss2_head' : $type = 'rss2'; break; case 'rss_head' : case 'opml_head' : $type = 'comment'; break; case 'rdf_header' : $type = 'rdf'; break; case 'atom_head' : case 'comments_atom_head' : case 'app_head' : $type = 'atom'; break; } } switch ( $type ) { case 'html': $gen = '<meta name="generator" content="WordPress ' . get_bloginfo( 'version' ) . '">'; break; case 'xhtml': $gen = '<meta name="generator" content="WordPress ' . get_bloginfo( 'version' ) . '" />'; break; case 'atom': $gen = '<generator uri="http://wordpress.org/" version="' . get_bloginfo_rss( 'version' ) . '">WordPress</generator>'; break; case 'rss2': $gen = '<generator>http://wordpress.org/?v=' . get_bloginfo_rss( 'version' ) . '</generator>'; break; case 'rdf': $gen = '<admin:generatorAgent rdf:resource="http://wordpress.org/?v=' . get_bloginfo_rss( 'version' ) . '" />'; break; case 'comment': $gen = '<!-- generator="WordPress/' . get_bloginfo( 'version' ) . '" -->'; break; case 'export': $gen = '<!-- generator="WordPress/' . get_bloginfo_rss('version') . '" created="'. date('Y-m-d H:i') . '" -->'; break; } /** * Filter the HTML for the retrieved generator type. * * The dynamic portion of the hook name, $type, refers to the generator type. * * @since 2.5.0 * * @param string $gen The HTML markup output to 'wp_head()'. * @param string $type The type of generator. Accepts 'html', 'xhtml', 'atom', * 'rss2', 'rdf', 'comment', 'export'. */ return apply_filters( "get_the_generator_{$type}", $gen, $type ); } |
関数 checked()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | /** * Outputs the html checked attribute. * * Compares the first two arguments and if identical marks as checked * * @since 1.0.0 * * @param mixed $checked One of the values to compare * @param mixed $current (true) The other value to compare if not just true * @param bool $echo Whether to echo or just return the string * @return string html attribute or empty string */ function checked( $checked, $current = true, $echo = true ) { return __checked_selected_helper( $checked, $current, $echo, 'checked' ); } |
関数 selected()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | /** * Outputs the html selected attribute. * * Compares the first two arguments and if identical marks as selected * * @since 1.0.0 * * @param mixed $selected One of the values to compare * @param mixed $current (true) The other value to compare if not just true * @param bool $echo Whether to echo or just return the string * @return string html attribute or empty string */ function selected( $selected, $current = true, $echo = true ) { return __checked_selected_helper( $selected, $current, $echo, 'selected' ); } |
関数 disabled()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | /** * Outputs the html disabled attribute. * * Compares the first two arguments and if identical marks as disabled * * @since 3.0.0 * * @param mixed $disabled One of the values to compare * @param mixed $current (true) The other value to compare if not just true * @param bool $echo Whether to echo or just return the string * @return string html attribute or empty string */ function disabled( $disabled, $current = true, $echo = true ) { return __checked_selected_helper( $disabled, $current, $echo, 'disabled' ); } |
関数 __checked_selected_helper()
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 | /** * Private helper function for checked, selected, and disabled. * * Compares the first two arguments and if identical marks as $type * * @since 2.8.0 * @access private * * @param mixed $helper One of the values to compare * @param mixed $current (true) The other value to compare if not just true * @param bool $echo Whether to echo or just return the string * @param string $type The type of checked|selected|disabled we are doing * @return string html attribute or empty string */ function __checked_selected_helper( $helper, $current, $echo, $type ) { if ( (string) $helper === (string) $current ) $result = " $type='$type'"; else $result = ''; if ( $echo ) echo $result; return $result; } |
関数 wp_heartbeat_settings()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | /** * Default settings for heartbeat * * Outputs the nonce used in the heartbeat XHR * * @since 3.6.0 * * @param array $settings * @return array $settings */ function wp_heartbeat_settings( $settings ) { if ( ! is_admin() ) $settings['ajaxurl'] = admin_url( 'admin-ajax.php', 'relative' ); if ( is_user_logged_in() ) $settings['nonce'] = wp_create_nonce( 'heartbeat-nonce' ); return $settings; } |