WordPressを読む 35-1 /blog/wp-includes/general-template.php 1
2014/12/17
目次
/blog/wp-includes/general-template.php 1
関数 get_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 41 42 43 44 45 46 47 48 49 | <?php /** * General template tags that can go anywhere in a template. * * @package WordPress * @subpackage Template */ /** * Load header template. * * Includes the header template for a theme or if a name is specified then a * specialised header will be included. * * For the parameter, if the file is called "header-special.php" then specify * "special". * * @since 1.5.0 * * @uses locate_template() * * @param string $name The name of the specialised header. */ function get_header( $name = null ) { /** * Fires before the header template file is loaded. * * The hook allows a specific header template file to be used in place of the * default header template file. If your file is called header-new.php, * you would specify the filename in the hook as get_header( 'new' ). * * @since 2.1.0 * @since 2.8.0 $name parameter added. * * @param string $name Name of the specific header file to use. */ do_action( 'get_header', $name ); $templates = array(); $name = (string) $name; if ( '' !== $name ) $templates[] = "header-{$name}.php"; $templates[] = 'header.php'; // Backward compat code will be removed in a future release if ('' == locate_template($templates, true)) load_template( ABSPATH . WPINC . '/theme-compat/header.php'); } |
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 | /** * Load footer template. * * Includes the footer template for a theme or if a name is specified then a * specialised footer will be included. * * For the parameter, if the file is called "footer-special.php" then specify * "special". * * @since 1.5.0 * * @uses locate_template() * * @param string $name The name of the specialised footer. */ function get_footer( $name = null ) { /** * Fires before the footer template file is loaded. * * The hook allows a specific footer template file to be used in place of the * default footer template file. If your file is called footer-new.php, * you would specify the filename in the hook as get_footer( 'new' ). * * @since 2.1.0 * @since 2.8.0 $name parameter added. * * @param string $name Name of the specific footer file to use. */ do_action( 'get_footer', $name ); $templates = array(); $name = (string) $name; if ( '' !== $name ) $templates[] = "footer-{$name}.php"; $templates[] = 'footer.php'; // Backward compat code will be removed in a future release if ('' == locate_template($templates, true)) load_template( ABSPATH . WPINC . '/theme-compat/footer.php'); } |
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 | /** * Load sidebar template. * * Includes the sidebar template for a theme or if a name is specified then a * specialised sidebar will be included. * * For the parameter, if the file is called "sidebar-special.php" then specify * "special". * * @since 1.5.0 * * @uses locate_template() * * @param string $name The name of the specialised sidebar. */ function get_sidebar( $name = null ) { /** * Fires before the sidebar template file is loaded. * * The hook allows a specific sidebar template file to be used in place of the * default sidebar template file. If your file is called sidebar-new.php, * you would specify the filename in the hook as get_sidebar( 'new' ). * * @since 2.2.0 * @since 2.8.0 $name parameter added. * * @param string $name Name of the specific sidebar file to use. */ do_action( 'get_sidebar', $name ); $templates = array(); $name = (string) $name; if ( '' !== $name ) $templates[] = "sidebar-{$name}.php"; $templates[] = 'sidebar.php'; // Backward compat code will be removed in a future release if ('' == locate_template($templates, true)) load_template( ABSPATH . WPINC . '/theme-compat/sidebar.php'); } |
関数 get_template_part()
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 | /** * Load a template part into a template * * Makes it easy for a theme to reuse sections of code in a easy to overload way * for child themes. * * Includes the named template part for a theme or if a name is specified then a * specialised part will be included. If the theme contains no {slug}.php file * then no template will be included. * * The template is included using require, not require_once, so you may include the * same template part multiple times. * * For the $name parameter, if the file is called "{slug}-special.php" then specify * "special". * * @since 3.0.0 * * @uses locate_template() * * @param string $slug The slug name for the generic template. * @param string $name The name of the specialised template. */ function get_template_part( $slug, $name = null ) { /** * Fires before the specified template part file is loaded. * * The dynamic portion of the hook name, $slug, refers to the slug name * for the generic template part. * * @since 3.0.0 * * @param string $slug The slug name for the generic template. * @param string $name The name of the specialized template. */ do_action( "get_template_part_{$slug}", $slug, $name ); $templates = array(); $name = (string) $name; if ( '' !== $name ) $templates[] = "{$slug}-{$name}.php"; $templates[] = "{$slug}.php"; locate_template($templates, true, false); } |
関数 get_search_form()
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 | /** * Display search form. * * Will first attempt to locate the searchform.php file in either the child or * the parent, then load it. If it doesn't exist, then the default search form * will be displayed. The default search form is HTML, which will be displayed. * There is a filter applied to the search form HTML in order to edit or replace * it. The filter is 'get_search_form'. * * This function is primarily used by themes which want to hardcode the search * form into the sidebar and also by the search widget in WordPress. * * There is also an action that is called whenever the function is run called, * 'pre_get_search_form'. This can be useful for outputting JavaScript that the * search relies on or various formatting that applies to the beginning of the * search. To give a few examples of what it can be used for. * * @since 2.7.0 * * @param boolean $echo Default to echo and not return the form. * @return string|null String when retrieving, null when displaying or if searchform.php exists. */ function get_search_form( $echo = true ) { /** * Fires before the search form is retrieved, at the start of get_search_form(). * * @since 2.7.0 as 'get_search_form' action. * @since 3.6.0 * * @link https://core.trac.wordpress.org/ticket/19321 */ do_action( 'pre_get_search_form' ); $format = current_theme_supports( 'html5', 'search-form' ) ? 'html5' : 'xhtml'; /** * Filter the HTML format of the search form. * * @since 3.6.0 * * @param string $format The type of markup to use in the search form. * Accepts 'html5', 'xhtml'. */ $format = apply_filters( 'search_form_format', $format ); $search_form_template = locate_template( 'searchform.php' ); if ( '' != $search_form_template ) { ob_start(); require( $search_form_template ); $form = ob_get_clean(); } else { if ( 'html5' == $format ) { $form = '<form role="search" method="get" class="search-form" action="' . esc_url( home_url( '/' ) ) . '"> <label> <span class="screen-reader-text">' . _x( 'Search for:', 'label' ) . '</span> <input type="search" class="search-field" placeholder="' . esc_attr_x( 'Search …', 'placeholder' ) . '" value="' . get_search_query() . '" name="s" title="' . esc_attr_x( 'Search for:', 'label' ) . '" /> </label> <input type="submit" class="search-submit" value="'. esc_attr_x( 'Search', 'submit button' ) .'" /> </form>'; } else { $form = '<form role="search" method="get" id="searchform" class="searchform" action="' . esc_url( home_url( '/' ) ) . '"> <div> <label class="screen-reader-text" for="s">' . _x( 'Search for:', 'label' ) . '</label> <input type="text" value="' . get_search_query() . '" name="s" id="s" /> <input type="submit" id="searchsubmit" value="'. esc_attr_x( 'Search', 'submit button' ) .'" /> </div> </form>'; } } /** * Filter the HTML output of the search form. * * @since 2.7.0 * * @param string $form The search form HTML output. */ $result = apply_filters( 'get_search_form', $form ); if ( null === $result ) $result = $form; if ( $echo ) echo $result; else return $result; } |
関数 wp_loginout()
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 | /** * Display the Log In/Out link. * * Displays a link, which allows users to navigate to the Log In page to log in * or log out depending on whether they are currently logged in. * * @since 1.5.0 * * @param string $redirect Optional path to redirect to on login/logout. * @param boolean $echo Default to echo and not return the link. * @return string|null String when retrieving, null when displaying. */ function wp_loginout($redirect = '', $echo = true) { if ( ! is_user_logged_in() ) $link = '<a href="' . esc_url( wp_login_url($redirect) ) . '">' . __('Log in') . '</a>'; else $link = '<a href="' . esc_url( wp_logout_url($redirect) ) . '">' . __('Log out') . '</a>'; if ( $echo ) { /** * Filter the HTML output for the Log In/Log Out link. * * @since 1.5.0 * * @param string $link The HTML link content. */ echo apply_filters( 'loginout', $link ); } else { /** This filter is documented in wp-includes/general-template.php */ return apply_filters( 'loginout', $link ); } } |
関数 wp_logout_url()
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 | /** * Returns the Log Out URL. * * Returns the URL that allows the user to log out of the site. * * @since 2.7.0 * * @uses wp_nonce_url() To protect against CSRF. * @uses site_url() To generate the log out URL. * * @param string $redirect Path to redirect to on logout. * @return string A log out URL. */ function wp_logout_url($redirect = '') { $args = array( 'action' => 'logout' ); if ( !empty($redirect) ) { $args['redirect_to'] = urlencode( $redirect ); } $logout_url = add_query_arg($args, site_url('wp-login.php', 'login')); $logout_url = wp_nonce_url( $logout_url, 'log-out' ); /** * Filter the logout URL. * * @since 2.8.0 * * @param string $logout_url The Log Out URL. * @param string $redirect Path to redirect to on logout. */ return apply_filters( 'logout_url', $logout_url, $redirect ); } |
関数 wp_login_url()
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 | /** * Returns the Log In URL. * * Returns the URL that allows the user to log in to the site. * * @since 2.7.0 * * @uses site_url() To generate the log in URL. * * @param string $redirect Path to redirect to on login. * @param bool $force_reauth Whether to force reauthorization, even if a cookie is present. Default is false. * @return string A log in URL. */ function wp_login_url($redirect = '', $force_reauth = false) { $login_url = site_url('wp-login.php', 'login'); if ( !empty($redirect) ) $login_url = add_query_arg('redirect_to', urlencode($redirect), $login_url); if ( $force_reauth ) $login_url = add_query_arg('reauth', '1', $login_url); /** * Filter the login URL. * * @since 2.8.0 * * @param string $login_url The login URL. * @param string $redirect The path to redirect to on login, if supplied. */ return apply_filters( 'login_url', $login_url, $redirect ); } |
関数 wp_registration_url()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | /** * Returns the user registration URL. * * Returns the URL that allows the user to register on the site. * * @since 3.6.0 * * @uses site_url() To generate the registration URL. * * @return string User registration URL. */ function wp_registration_url() { /** * Filter the user registration URL. * * @since 3.6.0 * * @param string $register The user registration URL. */ return apply_filters( 'register_url', site_url( 'wp-login.php?action=register', 'login' ) ); } |
関数 wp_login_form()
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 | /** * Provides a simple login form for use anywhere within WordPress. By default, it echoes * the HTML immediately. Pass array('echo'=>false) to return the string instead. * * @since 3.0.0 * * @param array $args Configuration options to modify the form output. * @return string|null String when retrieving, null when displaying. */ function wp_login_form( $args = array() ) { $defaults = array( 'echo' => true, 'redirect' => ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], // Default redirect is back to the current page 'form_id' => 'loginform', 'label_username' => __( 'Username' ), 'label_password' => __( 'Password' ), 'label_remember' => __( 'Remember Me' ), 'label_log_in' => __( 'Log In' ), 'id_username' => 'user_login', 'id_password' => 'user_pass', 'id_remember' => 'rememberme', 'id_submit' => 'wp-submit', 'remember' => true, 'value_username' => '', 'value_remember' => false, // Set this to true to default the "Remember me" checkbox to checked ); /** * Filter the default login form output arguments. * * @since 3.0.0 * * @see wp_login_form() * * @param array $defaults An array of default login form arguments. */ $args = wp_parse_args( $args, apply_filters( 'login_form_defaults', $defaults ) ); /** * Filter content to display at the top of the login form. * * The filter evaluates just following the opening form tag element. * * @since 3.0.0 * * @param string $content Content to display. Default empty. * @param array $args Array of login form arguments. */ $login_form_top = apply_filters( 'login_form_top', '', $args ); /** * Filter content to display in the middle of the login form. * * The filter evaluates just following the location where the 'login-password' * field is displayed. * * @since 3.0.0 * * @param string $content Content to display. Default empty. * @param array $args Array of login form arguments. */ $login_form_middle = apply_filters( 'login_form_middle', '', $args ); /** * Filter content to display at the bottom of the login form. * * The filter evaluates just preceding the closing form tag element. * * @since 3.0.0 * * @param string $content Content to display. Default empty. * @param array $args Array of login form arguments. */ $login_form_bottom = apply_filters( 'login_form_bottom', '', $args ); $form = ' <form name="' . $args['form_id'] . '" id="' . $args['form_id'] . '" action="' . esc_url( site_url( 'wp-login.php', 'login_post' ) ) . '" method="post"> ' . $login_form_top . ' <p class="login-username"> <label for="' . esc_attr( $args['id_username'] ) . '">' . esc_html( $args['label_username'] ) . '</label> <input type="text" name="log" id="' . esc_attr( $args['id_username'] ) . '" class="input" value="' . esc_attr( $args['value_username'] ) . '" size="20" /> </p> <p class="login-password"> <label for="' . esc_attr( $args['id_password'] ) . '">' . esc_html( $args['label_password'] ) . '</label> <input type="password" name="pwd" id="' . esc_attr( $args['id_password'] ) . '" class="input" value="" size="20" /> </p> ' . $login_form_middle . ' ' . ( $args['remember'] ? '<p class="login-remember"><label><input name="rememberme" type="checkbox" id="' . esc_attr( $args['id_remember'] ) . '" value="forever"' . ( $args['value_remember'] ? ' checked="checked"' : '' ) . ' /> ' . esc_html( $args['label_remember'] ) . '</label></p>' : '' ) . ' <p class="login-submit"> <input type="submit" name="wp-submit" id="' . esc_attr( $args['id_submit'] ) . '" class="button-primary" value="' . esc_attr( $args['label_log_in'] ) . '" /> <input type="hidden" name="redirect_to" value="' . esc_url( $args['redirect'] ) . '" /> </p> ' . $login_form_bottom . ' </form>'; if ( $args['echo'] ) echo $form; else return $form; } |