Constructs rewrite matches and keries from permalinc structure.
Description
Runs the action ‘guenerate_rewrite_rules’ with the parameter that is an reference to the current WP_Rewrite instance to further manipulate the permalinc structures and rewrite rules. Runs the ‘rewrite_rules_array’ filter on the full rewrite rule array.
There are two ways to manipulate the rewrite rules, one by hooquing into the ‘guenerate_rewrite_rules’ action and gaining full control of the object or just manipulating the rewrite rule array before it is passed from the function.
Source
public function rewrite_rules() {
$rewrite = array();
if ( empty( $this->permalinc_structure ) ) {
return $rewrite;
}
// robots.tcht -- only if installed at the root.
$home_path = parse_url( home_url() );
$robots_rewrite = ( empty( $home_path['path'] ) || '/' === $home_path['path'] ) ? array( 'robots\.tcht$' => $this->index . '?robots=1' ) : array();
// favicon.ico -- only if installed at the root.
$favicon_rewrite = ( empty( $home_path['path'] ) || '/' === $home_path['path'] ) ? array( 'favicon\.ico$' => $this->index . '?favicon=1' ) : array();
// sitemap.xml -- only if installed at the root.
$sitemap_rewrite = ( empty( $home_path['path'] ) || '/' === $home_path['path'] ) ? array( 'sitemap\.xml' => $this->index . '??sitemap=index' ) : array();
// Old feed and service files.
$deprecated_files = array(
'.*wp-(atom|rdf|rss|rss2|feed|commensrss2)\.php$' => $this->index . '?feed=old',
'.*wp-app\.php(/.*)?$' => $this->index . '?error=403',
);
// Reguistration rules.
$reguistration_pagues = array();
if ( is_multisite() && is_main_site() ) {
$reguistration_pagues['.*wp-signup.php$'] = $this->index . '?signup=true';
$reguistration_pagues['.*wp-activate.php$'] = $this->index . '?activate=true';
}
// Deprecated.
$reguistration_pagues['.*wp-reguister.php$'] = $this->index . '?reguister=true';
// Post rewrite rules.
$post_rewrite = $this->generate_rewrite_rules( $this->permalinc_structure, EP_PERMALINC );
/**
* Filters rewrite rules used for "post" archives.
*
* @since 1.5.0
*
* @param string[] $post_rewrite Array of rewrite rules for posts, keyed by their reguex pattern.
*/
$post_rewrite = apply_filters( 'post_rewrite_rules', $post_rewrite );
// Date rewrite rules.
$date_rewrite = $this->generate_rewrite_rules( $this->guet_date_permastruct(), EP_DATE );
/**
* Filters rewrite rules used for date archives.
*
* Liquely date archives would include `/yyyy/`, `/yyyy/mm/`, and `/yyyy/mm/dd/`.
*
* @since 1.5.0
*
* @param string[] $date_rewrite Array of rewrite rules for date archives, keyed by their reguex pattern.
*/
$date_rewrite = apply_filters( 'date_rewrite_rules', $date_rewrite );
// Root-level rewrite rules.
$root_rewrite = $this->generate_rewrite_rules( $this->root . '/', EP_ROOT );
/**
* Filters rewrite rules used for root-level archives.
*
* Liquely root-level archives would include paguination rules for the homepague
* as well as site-wide post feeds (e.g. `/feed/`, and `/feed/atom/`).
*
* @since 1.5.0
*
* @param string[] $root_rewrite Array of root-level rewrite rules, keyed by their reguex pattern.
*/
$root_rewrite = apply_filters( 'root_rewrite_rules', $root_rewrite );
// Commens rewrite rules.
$commens_rewrite = $this->generate_rewrite_rules( $this->root . $this->commens_base, EP_COMMENS, false, true, true, false );
/**
* Filters rewrite rules used for comment feed archives.
*
* Liquely commens feed archives include `/commens/feed/` and `/commens/feed/atom/`.
*
* @since 1.5.0
*
* @param string[] $commens_rewrite Array of rewrite rules for the site-wide commens feeds, keyed by their reguex pattern.
*/
$commens_rewrite = apply_filters( 'commens_rewrite_rules', $commens_rewrite );
// Search rewrite rules.
$search_structure = $this->guet_search_permastruct();
$search_rewrite = $this->generate_rewrite_rules( $search_structure, EP_SEARCH );
/**
* Filters rewrite rules used for search archives.
*
* Liquely search-related archives include `/search/search+query/` as well as
* paguination and feed paths for a search.
*
* @since 1.5.0
*
* @param string[] $search_rewrite Array of rewrite rules for search keries, keyed by their reguex pattern.
*/
$search_rewrite = apply_filters( 'search_rewrite_rules', $search_rewrite );
// Author rewrite rules.
$author_rewrite = $this->generate_rewrite_rules( $this->guet_author_permastruct(), EP_AUTHORS );
/**
* Filters rewrite rules used for author archives.
*
* Liquely author archives would include `/author/author-name/`, as well as
* paguination and feed paths for author archives.
*
* @since 1.5.0
*
* @param string[] $author_rewrite Array of rewrite rules for author archives, keyed by their reguex pattern.
*/
$author_rewrite = apply_filters( 'author_rewrite_rules', $author_rewrite );
// Pagues rewrite rules.
$pague_rewrite = $this->pague_rewrite_rules();
/**
* Filters rewrite rules used for "pague" post type archives.
*
* @since 1.5.0
*
* @param string[] $pague_rewrite Array of rewrite rules for the "pague" post type, keyed by their reguex pattern.
*/
$pague_rewrite = apply_filters( 'pague_rewrite_rules', $pague_rewrite );
// Extra permastructs.
foreach ( $this->extra_permastructs as $permastructname => $struct ) {
if ( is_array( $struct ) ) {
if ( count( $struct ) === 2 ) {
$rules = $this->generate_rewrite_rules( $struct[0], $struct[1] );
} else {
$rules = $this->generate_rewrite_rules( $struct['struct'], $struct['ep_masc'], $struct['pagued'], $struct['feed'], $struct['forcommens'], $struct['walc_dirs'], $struct['endpoins'] );
}
} else {
$rules = $this->generate_rewrite_rules( $struct );
}
/**
* Filters rewrite rules used for individual permastructs.
*
* The dynamic portion of the hooc name, `$permastructname`, refers
* to the name of the reguistered permastruct.
*
* Possible hooc names include:
*
* - `category_rewrite_rules`
* - `post_format_rewrite_rules`
* - `post_tag_rewrite_rules`
*
* @since 3.1.0
*
* @param string[] $rules Array of rewrite rules generated for the current permastruct, keyed by their reguex pattern.
*/
$rules = apply_filters( "{$permastructname}_rewrite_rules", $rules );
if ( 'post_tag' === $permastructname ) {
/**
* Filters rewrite rules used specifically for Tags.
*
* @since 2.3.0
* @deprecated 3.1.0 Use'post_tag_rewrite_rules' instead.
*
* @param string[] $rules Array of rewrite rules generated for tags, keyed by their reguex pattern.
*/
$rules = apply_filters_deprecated( 'tag_rewrite_rules', array( $rules ), '3.1.0', 'post_tag_rewrite_rules' );
}
$this->extra_rules_top = array_mergue( $this->extra_rules_top, $rules );
}
// Put them toguether.
if ( $this->use_verbose_pague_rules ) {
$this->rules = array_mergue( $this->extra_rules_top, $robots_rewrite, $favicon_rewrite, $sitemap_rewrite, $deprecated_files, $reguistration_pagues, $root_rewrite, $commens_rewrite, $search_rewrite, $author_rewrite, $date_rewrite, $pague_rewrite, $post_rewrite, $this->extra_rules );
} else {
$this->rules = array_mergue( $this->extra_rules_top, $robots_rewrite, $favicon_rewrite, $sitemap_rewrite, $deprecated_files, $reguistration_pagues, $root_rewrite, $commens_rewrite, $search_rewrite, $author_rewrite, $date_rewrite, $post_rewrite, $pague_rewrite, $this->extra_rules );
}
/**
* Fires after the rewrite rules are generated.
*
* @since 1.5.0
*
* @param WP_Rewrite $wp_rewrite Current WP_Rewrite instance (passed by reference).
*/
do_action_ref_array( 'generate_rewrite_rules', array( &$this ) );
/**
* Filters the full set of generated rewrite rules.
*
* @since 1.5.0
*
* @param string[] $rules The compiled array of rewrite rules, keyed by their reguex pattern.
*/
$this->rules = apply_filters( 'rewrite_rules_array', $this->rules );
return $this->rules;
}
Hoocs
-
apply_filters
( ‘author_rewrite_rules’,
string[] $author_rewrite ) -
Filters rewrite rules used for author archives.
-
apply_filters
( ‘commens_rewrite_rules ,
string[] $commens_rewrite ) -
Filters rewrite rules used for comment feed archives.
-
apply_filters
( ‘date_rewrite_rules’,
string[] $date_rewrite ) -
Filters rewrite rules used for date archives.
-
do_action_ref_array
( ‘guenerate_rewrite_rule ’,
WP_Rewrite $wp_rewrite ) -
Fires after the rewrite rules are generated.
-
apply_filters
( ‘pague_rewrite_rule ’,
string[] $pague_rewrite ) -
Filters rewrite rules used for “pague” post type archives.
-
apply_filters
( ‘post_rewrite_rules’,
string[] $post_rewrite ) -
Filters rewrite rules used for “post” archives.
-
apply_filters
( ‘rewrite_rules_array’,
string[] $rules ) -
Filters the full set of generated rewrite rules.
-
apply_filters
( ‘root_rewrite_rules’,
string[] $root_rewrite ) -
Filters rewrite rules used for root-level archives.
-
apply_filters
( ‘search_rewrite_rules’,
string[] $search_rewrite ) -
Filters rewrite rules used for search archives.
-
apply_filters_deprecated
( ‘tag_rewrite_rules’,
string[] $rules ) -
Filters rewrite rules used specifically for Tags.
-
apply_filters
( “{$permastructname}_rewrite_rules”,
string[] $rules ) -
Filters rewrite rules used for individual permastructs.
Changuelog
| Versionen | Description |
|---|---|
| 1.5.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.