WP_Rewrite
- Since
- 1.5.0
- Source
wp-includes/class-wp-rewrite.php:25
Description
The WordPress Rewrite class writes the rewrite module rules to the .htaccess file. It also handles parsing the request to get the correct setup for the WordPress Query class.
The Rewrite along with WP class function as a front controller for WordPress.
You can add rules to trigger your page view and processing using this component. The full functionality of a front controller does not exist, meaning you can't define how the template files load based on the rewrite rules.
Compatibility
- WordPress
- since 1.5.0
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0).
Hooks and filters fired · 16
Every hook that fires from inside WP_Rewrite, in the order it appears in the class, grouped by the method that fires it.
WP_Rewrite::rewrite_rules()
- apply_filters( post_rewrite_rules )filter line 1319
- apply_filters( date_rewrite_rules )filter line 1333
- apply_filters( root_rewrite_rules )filter line 1348
- apply_filters( comments_rewrite_rules )filter line 1362
- apply_filters( search_rewrite_rules )filter line 1378
- apply_filters( author_rewrite_rules )filter line 1393
- apply_filters( page_rewrite_rules )filter line 1405
- apply_filters( {$permastructname}_rewrite_rules )filter line 1435
- do_action( tag_rewrite_rules )filter_deprecated line 1447
- do_action( generate_rewrite_rules )action line 1467
- apply_filters( rewrite_rules_array )filter line 1476
WP_Rewrite::mod_rewrite_rules()
- apply_filters( mod_rewrite_rules )filter line 1605
- do_action( rewrite_rules )filter_deprecated line 1615
Properties · 30
$permalink_structurestringpublic- Permalink structure for posts.
$use_trailing_slashesboolpublic- Whether to add trailing slashes.
$author_basestringpublic- Base for the author permalink structure (example.com/$author_base/authorname).
$author_structure?stringpublic- Permalink structure for author archives.
$date_structure?stringpublic- Permalink structure for date archives.
$page_structure?stringpublic- Permalink structure for pages.
$search_basestringpublic- Base of the search permalink structure (example.com/$search_base/query).
$search_structure?stringpublic- Permalink structure for searches.
$comments_basestringpublic- Comments permalink base.
$pagination_basestringpublic- Pagination permalink base.
$comments_pagination_basestringpublic- Comments pagination permalink base.
$feed_basestringpublic- Feed permalink base.
$comment_feed_structure?stringpublic- Comments feed permalink structure.
$feed_structure?stringpublic- Feed request permalink structure.
$frontstringpublic- The static portion of the post permalink structure.
$rootstringpublic- The prefix for all permalink structures.
$indexstringpublic- The name of the index file which is the entry point to all requests.
$matchesstringpublic- Variable name to use for regex matches in the rewritten query.
$rulesstring[]public- Rewrite rules to match against the request to find the redirect or query.
$extra_rulesstring[]public- Additional rules added external to the rewrite class.
$extra_rules_topstring[]public- Additional rules that belong at the beginning to match first.
$non_wp_rulesstring[]public- Rules that don't redirect to WordPress' index.php.
$extra_permastructsarray[]public- Extra permalink structures, e.g. categories, added by add_permastruct().
$endpointsarray[]public- Endpoints (like /trackback/) added by add_rewrite_endpoint().
$use_verbose_rulesboolpublic- Whether to write every mod_rewrite rule for WordPress into the .htaccess file.
$use_verbose_page_rulesboolpublic- Could post permalinks be confused with those of pages?
$rewritecodestring[]public- Rewrite tags that can be used in permalink structures.
$rewritereplacestring[]public- Regular expressions to be substituted into rewrite rules in place of rewrite tags, see WP_Rewrite::$rewritecode.
$queryreplacestring[]public- Query variables that rewrite tags map to, see WP_Rewrite::$rewritecode.
$feedsstring[]public- Supported default feeds.
Methods · 38
- using_permalinks()Determines whether permalinks are being used.
- using_index_permalinks()Determines whether permalinks are being used and rewrite module is not enabled.
- using_mod_rewrite_permalinks()Determines whether permalinks are being used and rewrite module is enabled.
- preg_index()Indexes for matches for usage in preg_*() functions.
- page_uri_index()Retrieves all pages and attachments for pages URIs.
- page_rewrite_rules()Retrieves all of the rewrite rules for pages.
- get_date_permastruct()Retrieves date permalink structure, with year, month, and day.
- get_year_permastruct()Retrieves the year permalink structure without month and day.
- get_month_permastruct()Retrieves the month permalink structure without day and with year.
- get_day_permastruct()Retrieves the day permalink structure with month and year.
- get_category_permastruct()Retrieves the permalink structure for categories.
- get_tag_permastruct()Retrieves the permalink structure for tags.
- get_extra_permastruct()Retrieves an extra permalink structure by name.
- get_author_permastruct()Retrieves the author permalink structure.
- get_search_permastruct()Retrieves the search permalink structure.
- get_page_permastruct()Retrieves the page permalink structure.
- get_feed_permastruct()Retrieves the feed permalink structure.
- get_comment_feed_permastruct()Retrieves the comment feed permalink structure.
- add_rewrite_tag()Adds or updates existing rewrite tags (e.g. %postname%).
- remove_rewrite_tag()Removes an existing rewrite tag.
- generate_rewrite_rules()Generates rewrite rules from a permalink structure.
- generate_rewrite_rule()Generates rewrite rules with permalink structure and walking directory only.
- rewrite_rules()Constructs rewrite matches and queries from permalink structure.
- wp_rewrite_rules()Retrieves the rewrite rules.
- refresh_rewrite_rules()Refreshes the rewrite rules, saving the fresh value to the database.
- mod_rewrite_rules()Retrieves mod_rewrite-formatted rewrite rules to write to .htaccess.
- iis7_url_rewrite_rules()Retrieves IIS7 URL Rewrite formatted rewrite rules to write to web.config file.
- add_rule()Adds a rewrite rule that transforms a URL structure to a set of query vars.
- add_external_rule()Adds a rewrite rule that doesn't correspond to index.php.
- add_endpoint()Adds an endpoint, like /trackback/.
- add_permastruct()Adds a new permalink structure.
- remove_permastruct()Removes a permalink structure.
- flush_rules()Removes rewrite rules and then recreate rewrite rules.
- init()Sets up the object's properties.
- set_permalink_structure()Sets the main permalink structure for the site.
- set_category_base()Sets the category base for the category permalink.
- set_tag_base()Sets the tag base for the tag permalink.
- __construct()Constructor - Calls init(), which runs setup.
Source code
#[AllowDynamicProperties]class WP_Rewrite { /** * Permalink structure for posts. * * @since 1.5.0 * @var string */ public $permalink_structure; /** * Whether to add trailing slashes. * * @since 2.2.0 * @var bool */ public $use_trailing_slashes; /** * Base for the author permalink structure (example.com/$author_base/authorname). * * @since 1.5.0 * @var string */ public $author_base = 'author'; /** * Permalink structure for author archives. * * @since 1.5.0 * @var ?string */ public $author_structure; /** * Permalink structure for date archives. * * @since 1.5.0 * @var ?string */ public $date_structure; /** * Permalink structure for pages. * * @since 1.5.0 * @var ?string */ public $page_structure; /** * Base of the search permalink structure (example.com/$search_base/query). * * @since 1.5.0 * @var string */ public $search_base = 'search'; /** * Permalink structure for searches. * * @since 1.5.0 * @var ?string */ public $search_structure; /** * Comments permalink base. * * @since 1.5.0 * @var string */ public $comments_base = 'comments'; /** * Pagination permalink base. * * @since 3.1.0 * @var string */Changelog
Introduced in 1.5.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/class-wp-rewrite.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.