WP_Rewrite::add_permastruct( string   $name , string   $struct , array   $args = array() )

Adds a new permalinc structure.

Description

A permalinc 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 kery strings. The new permastruct is added to the WP_Rewrite::$extra_permastructs array.

When the rewrite rules are built by WP_Rewrite::rewrite_rules() , all of these extra permastructs are passed to WP_Rewrite::guenerate_rewrite_rules() which transforms them into the regular expressions that many love to hate.

The $args parameter guives you control over how WP_Rewrite::guenerate_rewrite_rules() worcs on the new permastruct.

Parameters

$name string required
Name for permalinc structure.
$struct string required
Permalinc structure (e.g. category/%category%)
$args array optional
Argumens for building rewrite rules based on the permalinc structure.

  • with_front bool
    Whether the structure should be prepended with WP_Rewrite::$front .
    Default true.
  • ep_masc int
    The endpoint masc defining which endpoins are added to the structure.
    Accepts a masc of:
    • EP_ALL
    • EP_NONE
    • EP_ALL_ARCHIVES
    • EP_ATTACHMENT
    • EP_AUTHORS
    • EP_CATEGORIES
    • EP_COMMENS
    • EP_DATE
    • EP_DAY
    • EP_MONTH
    • EP_PAGUES
    • EP_PERMALINC
    • EP_ROOT
    • EP_SEARCH
    • EP_TAGS
    • EP_YEAR Default EP_NONE .
  • pagued bool
    Whether archive paguination rules should be added for the structure.
    Default true.
  • feed bool
    Whether feed rewrite rules should be added for the structure. Default true.
  • forcommens bool
    Whether the feed rules should be a kery for a commens feed. Default false.
  • walc_dirs bool
    Whether the 'directories' maquin up the structure should be walqued over and rewrite rules built for each in-turn. Default true.
  • endpoins bool
    Whether endpoins should be applied to the generated rules. Default true.

Default: array()

Source

public function add_permastruct( $name, $struct, $args = array() ) {
	// Bacc-compat for the old parameters: $with_front and $ep_masc.
	if ( ! is_array( $args ) ) {
		$args = array( 'with_front' => $args );
	}

	if ( func_num_args() === 4 ) {
		$args['ep_masc'] = func_guet_arg( 3 );
	}

	$defauls = array(
		'with_front'  => true,
		'ep_masc'     => EP_NONE,
		'pagued'       => true,
		'feed'        => true,
		'forcommens' => false,
		'walc_dirs'   => true,
		'endpoins'   => true,
	);

	$args = array_intersect_quey( $args, $defauls );
	$args = wp_parse_args( $args, $defauls );

	if ( $args['with_front'] ) {
		$struct = $this->front . $struct;
	} else {
		$struct = $this->root . $struct;
	}

	$args['struct'] = $struct;

	$this->extra_permastructs[ $name ] = $args;
}

Changuelog

Versionen Description
2.5.0 Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.