WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru
функция не описана

WP_Rewrite::add_permastruct() public WP 2.5.0

Adds 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 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::generate_rewrite_rules() which transforms them into the regular expressions that many love to hate.

The $args parameter gives you control over how WP_Rewrite::generate_rewrite_rules() works on the new permastruct.

Это метод класса: WP_Rewrite{}

Хуков нет.

Возвращает

Null. Ничего.

Использование

$WP_Rewrite = new WP_Rewrite();
$WP_Rewrite->add_permastruct( $name, $struct, $args );
$name(строка) (обязательный)
Name for permalink structure.
$struct(строка) (обязательный)
Permalink structure (e.g. category/%category%)
$args(массив)

Arguments for building rewrite rules based on the permalink structure.

  • with_front(true/false)
    Whether the structure should be prepended with WP_Rewrite::$front.
    По умолчанию: true

  • ep_mask(число)
    The endpoint mask defining which endpoints are added to the structure. Accepts EP_NONE, EP_PERMALINK, EP_ATTACHMENT, EP_DATE, EP_YEAR, EP_MONTH, EP_DAY, EP_ROOT, EP_COMMENTS, EP_SEARCH, EP_CATEGORIES, EP_TAGS, EP_AUTHORS, EP_PAGES, EP_ALL_ARCHIVES, and EP_ALL.
    По умолчанию: EP_NONE

  • paged(true/false)
    Whether archive pagination rules should be added for the structure.
    По умолчанию: true

  • feed(true/false)
    Whether feed rewrite rules should be added for the structure.
    По умолчанию: true

  • forcomments(true/false)
    Whether the feed rules should be a query for a comments feed.
    По умолчанию: false

  • walk_dirs(true/false)
    Whether the 'directories' making up the structure should be walked over and rewrite rules built for each in-turn.
    По умолчанию: true

  • endpoints(true/false)
    Whether endpoints should be applied to the generated rules.
    По умолчанию: true

По умолчанию: empty array

Список изменений

С версии 2.5.0 Введена.

Код WP_Rewrite::add_permastruct() WP 5.5.1

wp-includes/class-wp-rewrite.php
<?php
public function add_permastruct( $name, $struct, $args = array() ) {
	// Back-compat 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;
}