Slide 38
Slide 38 text
function get_permastructs() {
global $wp_rewrite;
if ( get_option( 'page_for_posts' ) ) {
$home_structs = [
'front-page' => '/',
'home' => get_page_uri( get_option( 'page_for_posts' ) )
];
} else {
$home_structs = [
'home' => '/'
];
}
$extra_permastructs = array_map( function ( $permastruct ) {
return $permastruct['struct'];
}, $wp_rewrite->extra_permastructs );
$permastructs = [
'search' => $wp_rewrite->get_search_permastruct(),
'author' => $wp_rewrite->get_author_permastruct(),
'date' => $wp_rewrite->get_date_permastruct(),
'month' => $wp_rewrite->get_month_permastruct(),
'year' => $wp_rewrite->get_year_permastruct(),
];
if ( $wp_rewrite->use_verbose_page_rules ) {
$permastructs['post'] = $wp_rewrite->permalink_structure;
$permastructs['page'] = $wp_rewrite->get_page_permastruct();
} else {
$permastructs['page'] = $wp_rewrite->get_page_permastruct();
$permastructs['post'] = $wp_rewrite->permalink_structure;
}
$permastructs = array_merge( $home_structs, $extra_permastructs, $permastructs );
return array_map( function ( $key, $value ) {
$struct = trim( preg_replace( '/%([^\/]+)%/', ':$1', $value ), '/\\' );
$struct = str_replace(
[':year',':monthnum',':day',':post_id'],
[':year(\\d{4})',':monthnum(\\d{1,2})',':day(\\d{1,2})',':post_id(\\d+)'],
$struct
);
return [
'name' => $key,
'path' => untrailingslashit( '/' . $struct ) . '/:endpoint(page)?/:page(\\d*)'
];
}, array_keys( $permastructs ), array_values( $permastructs ) );
}
38