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.
Parameters
$namestring
Name for permalink structure.
$structstring
Permalink structure (e.g. category/%category%)
$argsarrayoptional
Arguments for building rewrite rules based on the permalink structure. Default empty array.Default: array()
$with_frontbooldefault: true
Whether the structure should be prepended with WP_Rewrite::$front.
$ep_maskintdefault: EP_NONE
The endpoint mask defining which endpoints are added to the structure. Accepts a mask of: - EP_ALL - EP_NONE - EP_ALL_ARCHIVES - EP_ATTACHMENT - EP_AUTHORS - EP_CATEGORIES - EP_COMMENTS - EP_DATE - EP_DAY - EP_MONTH - EP_PAGES - EP_PERMALINK - EP_ROOT - EP_SEARCH - EP_TAGS - EP_YEAR
$pagedbooldefault: true
Whether archive pagination rules should be added for the structure.
$feedbooldefault: true
Whether feed rewrite rules should be added for the structure.
$forcommentsbooldefault: false
Whether the feed rules should be a query for a comments feed.
$walk_dirsbooldefault: true
Whether the 'directories' making up the structure should be walked over and rewrite rules built for each in-turn.
$endpointsbooldefault: true
Whether endpoints should be applied to the generated rules.
Uses · 1
wp_parse_args()Merges user defined arguments into defaults array.
1818publicfunctionadd_permastruct($name,$struct,$args=array()){1819// Back-compat for the old parameters: $with_front and $ep_mask.1820if(!is_array($args)){1821$args=array('with_front'=>$args);1822}18231824if(func_num_args()===4){1825$args['ep_mask']=func_get_arg(3);1826}18271828$defaults=array(1829'with_front'=>true,1830'ep_mask'=>EP_NONE,1831'paged'=>true,1832'feed'=>true,1833'forcomments'=>false,1834'walk_dirs'=>true,1835'endpoints'=>true,1836);18371838$args=array_intersect_key($args,$defaults);1839$args=wp_parse_args($args,$defaults);18401841if($args['with_front']){1842$struct=$this->front.$struct;1843}else{1844$struct=$this->root.$struct;1845}18461847$args['struct']=$struct;18481849$this->extra_permastructs[$name]=$args;1850}
History
Introduced in 2.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 6.8.8 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.