WP_Rewrite::init() WordPress Method

The WP_Rewrite::init() method is used to initialize the rewriting rules and structures. It is called on the 'init' action hook.

WP_Rewrite::init() #

Sets up the object’s properties.


Description

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%’.


Top ↑

More Information

Set up the object, set $permalink_structure and $category_base from the database. Set $root to $index plus ‘/’. Set $front to everything up to the start of the first tag in the permalink structure. Unset all other properties.


Top ↑

Source

File: wp-includes/class-wp-rewrite.php

	public function init() {
		$this->extra_rules         = array();
		$this->non_wp_rules        = array();
		$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;
		}
	}


Top ↑

Changelog

Changelog
VersionDescription
1.5.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by the Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.