WordPressを読む 47-5 /blog/wp-includes/rewrite.php 5
2015/01/29
目次
- 1 /blog/wp-includes/rewrite.php 5
- 2 クラス WP_Rewrite::iis7_url_rewrite_rules()
- 3 クラス WP_Rewrite::add_rule()
- 4 クラス WP_Rewrite::add_external_rule()
- 5 クラス WP_Rewrite::add_endpoint()
- 6 クラス WP_Rewrite::add_permastruct()
- 7 クラス WP_Rewrite::flush_rules()
- 8 クラス WP_Rewrite::init()
- 9 クラス WP_Rewrite::set_permalink_structure()
- 10 クラス WP_Rewrite::set_category_base()
- 11 クラス WP_Rewrite::set_tag_base()
- 12 クラス WP_Rewrite:: __construct() コンストラクタ
/blog/wp-includes/rewrite.php 5
クラス WP_Rewrite::iis7_url_rewrite_rules()
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 | /** * Retrieve IIS7 URL Rewrite formatted rewrite rules to write to web.config file. * * Does not actually write to the web.config file, but creates the rules for * the process that will. * * @since 2.8.0 * @access public * * @return string */ public function iis7_url_rewrite_rules( $add_parent_tags = false ) { if ( ! $this->using_permalinks() ) return ''; $rules = ''; if ( $add_parent_tags ) { $rules .= '<configuration> <system.webServer> <rewrite> <rules>'; } $rules .= ' <rule name="wordpress" patternSyntax="Wildcard"> <match url="*" /> <conditions> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> </conditions> <action type="Rewrite" url="index.php" /> </rule>'; if ( $add_parent_tags ) { $rules .= ' </rules> </rewrite> </system.webServer> </configuration>'; } /** * Filter the list of rewrite rules formatted for output to a web.config. * * @since 2.8.0 * * @param string $rules Rewrite rules formatted for IIS web.config. */ $rules = apply_filters( 'iis7_url_rewrite_rules', $rules ); return $rules; } |
クラス WP_Rewrite::add_rule()
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 | /** * Add a straight rewrite rule. * * Any value in the $after parameter that isn't 'bottom' will be placed at * the top of the rules. * * @since 2.1.0 * @access public * * @param string $regex Regular expression to match against request. * @param string $redirect URL regex redirects to when regex matches request. * @param string $after Optional, default is bottom. Location to place rule. */ public function add_rule($regex, $redirect, $after = 'bottom') { //get everything up to the first ? $index = (strpos($redirect, '?') == false ? strlen($redirect) : strpos($redirect, '?')); $front = substr($redirect, 0, $index); if ( $front != $this->index ) { //it doesn't redirect to WP's index.php $this->add_external_rule($regex, $redirect); } else { if ( 'bottom' == $after) $this->extra_rules = array_merge($this->extra_rules, array($regex => $redirect)); else $this->extra_rules_top = array_merge($this->extra_rules_top, array($regex => $redirect)); //$this->extra_rules[$regex] = $redirect; } } |
クラス WP_Rewrite::add_external_rule()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | /** * Add a rule that doesn't redirect to index.php. * * Can redirect to any place. * * @since 2.1.0 * @access public * * @param string $regex Regular expression to match against request. * @param string $redirect URL regex redirects to when regex matches request. */ public function add_external_rule($regex, $redirect) { $this->non_wp_rules[$regex] = $redirect; } |
クラス WP_Rewrite::add_endpoint()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | /** * Add an endpoint, like /trackback/. * * @since 2.1.0 * @since 3.9.0 $query_var parameter added. * @access public * * @see add_rewrite_endpoint() for full documentation. * @uses WP::add_query_var() * * @param string $name Name of the endpoint. * @param int $places Endpoint mask describing the places the endpoint should be added. * @param string $query_var Name of the corresponding query variable. Default is value of $name. */ public function add_endpoint( $name, $places, $query_var = null ) { global $wp; if ( null === $query_var ) { $query_var = $name; } $this->endpoints[] = array( $places, $name, $query_var ); $wp->add_query_var( $query_var ); } |
クラス WP_Rewrite::add_permastruct()
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 | /** * Add a new permalink structure. * * A permalink structure (permastruct) is an abstract definition of a set of rewrite rules; it * is an easy way of expressing a set of regular expressions that rewrite to a set of query strings. * The new permastruct is added to the {@link WP_Rewrite::$extra_permastructs} array. When the * rewrite rules are built by {@link WP_Rewrite::rewrite_rules()} all of these extra permastructs * are passed to {@link WP_Rewrite::generate_rewrite_rules()} which transforms them into the * regular expressions that many love to hate. * * The $args parameter gives you control over how {@link WP_Rewrite::generate_rewrite_rules()} * works on the new permastruct. * * @since 2.5.0 * @access public * * @param string $name Name for permalink structure. * @param string $struct Permalink structure (e.g. category/%category%) * @param array $args Optional configuration for building the rules from the permalink structure: * - with_front (bool) - Should the structure be prepended with WP_Rewrite::$front? Default is true. * - ep_mask (int) - Endpoint mask defining what endpoints are added to the structure. Default is EP_NONE. * - paged (bool) - Should archive pagination rules be added for the structure? Default is true. * - feed (bool) - Should feed rewrite rules be added for the structure? Default is true. * - forcomments (bool) - Should the feed rules be a query for a comments feed? Default is false. * - walk_dirs (bool) - Should the 'directories' making up the structure be walked over and rewrite * rules built for each in turn? Default is true. * - endpoints (bool) - Should endpoints be applied to the generated rewrite rules? Default is true. */ public function add_permastruct( $name, $struct, $args = array() ) { // backwards compatibility for the old parameters: $with_front and $ep_mask if ( ! is_array( $args ) ) $args = array( 'with_front' => $args ); if ( func_num_args() == 4 ) $args['ep_mask'] = func_get_arg( 3 ); $defaults = array( 'with_front' => true, 'ep_mask' => EP_NONE, 'paged' => true, 'feed' => true, 'forcomments' => false, 'walk_dirs' => true, 'endpoints' => true, ); $args = array_intersect_key( $args, $defaults ); $args = wp_parse_args( $args, $defaults ); if ( $args['with_front'] ) $struct = $this->front . $struct; else $struct = $this->root . $struct; $args['struct'] = $struct; $this->extra_permastructs[ $name ] = $args; } |
クラス WP_Rewrite::flush_rules()
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 | /** * Remove rewrite rules and then recreate rewrite rules. * * Calls {@link WP_Rewrite::wp_rewrite_rules()} after removing the * 'rewrite_rules' option. If the function named 'save_mod_rewrite_rules' * exists, it will be called. * * @since 2.0.1 * @access public * @param bool $hard Whether to update .htaccess (hard flush) or just update rewrite_rules option (soft flush). Default is true (hard). */ public function flush_rules($hard = true) { delete_option('rewrite_rules'); $this->wp_rewrite_rules(); /** * Filter whether a "hard" rewrite rule flush should be performed when requested. * * A "hard" flush updates .htaccess (Apache) or web.config (IIS). * * @since 3.7.0 * * @param bool $hard Whether to flush rewrite rules "hard". Default true. */ if ( ! $hard || ! apply_filters( 'flush_rewrite_rules_hard', true ) ) { return; } if ( function_exists( 'save_mod_rewrite_rules' ) ) save_mod_rewrite_rules(); if ( function_exists( 'iis7_save_url_rewrite_rules' ) ) iis7_save_url_rewrite_rules(); } |
クラス WP_Rewrite::init()
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 | /** * Sets up the object's properties. * * The 'use_verbose_page_rules' object property will be set to true if the * permalink structure begins with one of the following: '%postname%', '%category%', * '%tag%', or '%author%'. * * @since 1.5.0 * @access public */ public function init() { $this->extra_rules = $this->non_wp_rules = $this->endpoints = array(); $this->permalink_structure = get_option('permalink_structure'); $this->front = substr($this->permalink_structure, 0, strpos($this->permalink_structure, '%')); $this->root = ''; if ( $this->using_index_permalinks() ) $this->root = $this->index . '/'; unset($this->author_structure); unset($this->date_structure); unset($this->page_structure); unset($this->search_structure); unset($this->feed_structure); unset($this->comment_feed_structure); $this->use_trailing_slashes = ( '/' == substr($this->permalink_structure, -1, 1) ); // Enable generic rules for pages if permalink structure doesn't begin with a wildcard. if ( preg_match("/^[^%]*%(?:postname|category|tag|author)%/", $this->permalink_structure) ) $this->use_verbose_page_rules = true; else $this->use_verbose_page_rules = false; } |
クラス WP_Rewrite::set_permalink_structure()
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 | /** * Set the main permalink structure for the blog. * * Will update the 'permalink_structure' option, if there is a difference * between the current permalink structure and the parameter value. Calls * {@link WP_Rewrite::init()} after the option is updated. * * Fires the 'permalink_structure_changed' action once the init call has * processed passing the old and new values * * @since 1.5.0 * @access public * * @param string $permalink_structure Permalink structure. */ public function set_permalink_structure($permalink_structure) { if ( $permalink_structure != $this->permalink_structure ) { $old_permalink_structure = $this->permalink_structure; update_option('permalink_structure', $permalink_structure); $this->init(); /** * Fires after the permalink structure is updated. * * @since 2.8.0 * * @param string $old_permalink_structure The previous permalink structure. * @param string $permalink_structure The new permalink structure. */ do_action( 'permalink_structure_changed', $old_permalink_structure, $permalink_structure ); } } |
クラス WP_Rewrite::set_category_base()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | /** * Set the category base for the category permalink. * * Will update the 'category_base' option, if there is a difference between * the current category base and the parameter value. Calls * {@link WP_Rewrite::init()} after the option is updated. * * @since 1.5.0 * @access public * * @param string $category_base Category permalink structure base. */ public function set_category_base($category_base) { if ( $category_base != get_option('category_base') ) { update_option('category_base', $category_base); $this->init(); } } |
クラス WP_Rewrite::set_tag_base()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | /** * Set the tag base for the tag permalink. * * Will update the 'tag_base' option, if there is a difference between the * current tag base and the parameter value. Calls * {@link WP_Rewrite::init()} after the option is updated. * * @since 2.3.0 * @access public * * @param string $tag_base Tag permalink structure base. */ public function set_tag_base( $tag_base ) { if ( $tag_base != get_option( 'tag_base') ) { update_option( 'tag_base', $tag_base ); $this->init(); } } |
クラス WP_Rewrite:: __construct() コンストラクタ
1 2 3 4 5 6 7 8 9 10 11 12 | /** * Constructor - Calls init(), which runs setup. * * @since 1.5.0 * @access public * * @return WP_Rewrite */ public function __construct() { $this->init(); } } |