Yoast_Dynamic_Rewrites::add_rule
Adds a dynamic rewrite rule that transforms a URL structure to a set of query vars.
Rules registered with this method are applied dynamically and do not require the rewrite rules to be flushed in order to become active, which is a benefit over the regular WordPress core API. Note however that the dynamic application only works for rules that correspond to index.php. Non-WordPress rewrite rules still require flushing.
Any value in the $after parameter that isn't 'bottom' will result in the rule being placed at the top of the rewrite rules.
Метод класса: Yoast_Dynamic_Rewrites{}
Хуков нет.
Возвращает
null. Ничего (null).
Использование
$Yoast_Dynamic_Rewrites = new Yoast_Dynamic_Rewrites(); $Yoast_Dynamic_Rewrites->add_rule( $regex, $query, $priority );
- $regex(строка) (обязательный)
- Regular expression to match request against.
- $query(строка|массив) (обязательный)
- The corresponding query vars for this rewrite rule.
- $priority(строка)
- Priority of the new rule. Accepts
'top'or'bottom'.
По умолчанию:'bottom'
Код Yoast_Dynamic_Rewrites::add_rule() Yoast Dynamic Rewrites::add rule Yoast 27.4
public function add_rule( $regex, $query, $priority = 'bottom' ) {
if ( is_array( $query ) ) {
$query = add_query_arg( $query, 'index.php' );
}
$this->wp_rewrite->add_rule( $regex, $query, $priority );
// Do not further handle external rules.
if ( substr( $query, 0, strlen( $this->wp_rewrite->index . '?' ) ) !== $this->wp_rewrite->index . '?' ) {
return;
}
if ( $priority === 'bottom' ) {
$this->extra_rules_bottom[ $regex ] = $query;
return;
}
$this->extra_rules_top[ $regex ] = $query;
}