CPT
Class to handle the Custom Post Type and Taxonomies.
Namespace: WebberZone\Knowledge_Base
Since: 2.3.0
Source: includes/class-cpt.php line 22
Methods
__construct()
Constructor.
Since: 2.3.0
Line: 29
public function __construct( );
register_kb_types() static
Register taxonomies before the post type so taxonomy rewrite rules are generated first and take precedence over CPT attachment rules.
Since: 3.1.0
Line: 39
static public function register_kb_types( );
register_post_type() static
Register Knowledge Base Post Type.
Since: 2.3.0
Line: 49
static public function register_post_type( );
sanitize_slug() static
Sanitize slug while preserving slashes and optionally removing placeholders.
Since: 3.0.0
Line: 160
static public function sanitize_slug( string $slug, bool $remove_placeholders = ... ): string;
| Type | Name | Description |
|---|---|---|
string |
$slug |
The slug to sanitize. |
bool |
$remove_placeholders |
Whether to remove placeholders. Default true. |
Returns: string — Sanitized slug.
get_taxonomy_slug() static
Get a taxonomy’s rewrite slug, falling back to the setting’s default when it is blank.
Without the fallback WordPress would use the taxonomy name (e.g. /wzkb_product/).
Since: 3.1.5
Line: 184
static public function get_taxonomy_slug( string $key ): string;
| Type | Name | Description |
|---|---|---|
string |
$key |
Setting key: product_slug, category_slug or tag_slug. |
Returns: string — Sanitized slug.
register_taxonomies() static
Register Knowledgebase Custom Taxonomies.
Since: 2.3.0
Line: 292
static public function register_taxonomies( );
filter_root_level_permalink() static
Filter KB article permalinks to remove the CPT slug when using %postname% structure.
Since: 3.0.0
Line: 380
static public function filter_root_level_permalink( $permalink, $post ): string;
| Type | Name | Description |
|---|---|---|
string |
$permalink |
The post’s permalink. |
\WP_Post |
$post |
The post object. |
Returns: string — Filtered permalink.
maybe_query_kb_article() static
Maybe query KB article if regular post isn’t found.
When using %postname% structure, WordPress will try to find a regular post first. If not found, we check if there’s a KB article with that slug.
Since: 3.0.0
Line: 402
static public function maybe_query_kb_article( $query );
| Type | Name | Description |
|---|---|---|
\WP_Query |
$query |
The WP_Query instance. |
add_root_level_rewrite_rules() static
Add root-level rewrite rules for KB articles when using %postname% structure.
This allows KB articles to use the same permalink structure as regular posts. Note: These rules are added but WordPress will try regular posts first, then fall back to KB articles.
Since: 3.0.0
Line: 467
static public function add_root_level_rewrite_rules( );
maybe_route_root_level_page_request() static
Route a root-level URL parsed as a page to a KB article when no such page exists.
On sites whose permalink structure is not /%postname%/, a single-segment URL only matches the page rules, so maybe_query_kb_article() never sees a post name.
Since: 3.1.5
Line: 486
static public function maybe_route_root_level_page_request( $query_vars ): array;
| Type | Name | Description |
|---|---|---|
array |
$query_vars |
Parsed query vars. |
Returns: array — Filtered query vars.
add_taxonomy_rewrite_rules() static
Add taxonomy rewrite rules with top priority.
This ensures taxonomy archive URLs are matched before post type attachment rules.
Since: 3.0.0
Line: 509
static public function add_taxonomy_rewrite_rules( );