PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 4.2.6
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v4.2.6
4.9.1 4.9.0 4.8.2 4.8.1 4.8.0 4.7.0 4.6.2 4.6.1 4.6.0 4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 4.5.1 4.5.0 4.4.1 4.4.0 3.3.4 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.5.2 All 199 releases
← All changes | includes/Core/Rewrite.php +16 -18 4.5.04.2.6 View file →
@@ -201,9 +201,9 @@
201 201 function ( $carry, $item ) {
202 202 $carry .= ( strpos( $item, '%' ) !== false ? '([^/]+)' : $item ) . '/';
203 203 return $carry;
204 204 },
205 - '^'
205 + ''
206 206 ) . '?$';
207 207 }
208 208
209 209 public function make_query( $segments ) {
@@ -241,18 +241,28 @@
241 241 $hierarchy_slug = $this->hierarchy_based_slug_switch();
242 242
243 243 // Add rule to handle pagination attempts
244 244 $this->add_rewrite_rule(
245 - '^' . $base . '/page/([0-9]+)/?$',
245 + $base . '/page/([0-9]+)/?$',
246 246 'index.php?post_type=docs',
247 247 'top'
248 248 );
249 249
250 250 $base = $this->get_base_slug();
251 - $this->add_rewrite_rule( '^' . $base . '/(feed|rdf|rss|rss2|atom)/?$', 'index.php?post_type=docs&feed=$matches[1]' );
252 - $this->add_rewrite_rule( '^' . $base . '/authors/([0-9]+)/?$', 'index.php?post_type=docs&author=$matches[1]' );
253 - $this->add_rewrite_rule( '^' . $base . '/authors/([0-9]+)/page/([0-9]+)/?$', 'index.php?post_type=docs&author=$matches[1]&page=$matches[2]' );
251 + $this->add_rewrite_rule( $base . '/(feed|rdf|rss|rss2|atom)/?$', 'index.php?post_type=docs&feed=$matches[1]' );
252 + $this->add_rewrite_rule( $base . '/authors/([0-9]+)/?$', 'index.php?post_type=docs&author=$matches[1]' );
253 + $this->add_rewrite_rule( $base . '/authors/([0-9]+)/page/([0-9]+)/?$', 'index.php?post_type=docs&author=$matches[1]&page=$matches[2]' );
254 254
255 + if( $hierarchy_slug ) { // reigster hierarchy based slug rewrite rule, for single doc permalink
256 + $this->add_rewrite_rule( $base . '/(.+?)/([^/]+)(?:/([0-9]+))?/?$', 'index.php?doc_category=$matches[1]&docs=$matches[2]&post_type=docs' );
257 +
258 + $rewrite_rules = get_option('rewrite_rules');
259 +
260 + if( ! isset( $rewrite_rules[$base . '/(.+?)/([^/]+)(?:/([0-9]+))?/?$'] ) ) { // if this nested rule is not set then flush the rules
261 + flush_rewrite_rules();
262 + }
263 + }
264 +
255 265 /**
256 266 * This code of blocks used to determine single docs permalink.
257 267 */
258 268 $_docs_perma_struct = betterdocs()->settings->get( 'permalink_structure', 'docs' );
@@ -257,20 +267,8 @@
257 267 */
258 268 $_docs_perma_struct = betterdocs()->settings->get( 'permalink_structure', 'docs' );
259 269 $_normalized_structure = $this->normalzie_doc_perma_structure( $_docs_perma_struct );
260 270
261 - if( $hierarchy_slug ) { // register hierarchy based slug rewrite rule, for single doc permalink
262 - // When MKB or WPML is used, the actual base for single docs might differ from the generic $base
263 - $perma_base = isset( $_normalized_structure['raw'][0] ) && strpos( $_normalized_structure['raw'][0], '%' ) === false
264 - ? $_normalized_structure['raw'][0]
265 - : $base;
266 -
267 - $this->add_rewrite_rule( '^' . $perma_base . '/(.+?)/([^/]+)(?:/([0-9]+))?/?$', 'index.php?doc_category=$matches[1]&docs=$matches[2]&post_type=docs', 'top' );
268 -
269 - // Removed flush_rewrite_rules() from here. Calling flush_rewrite_rules() on the 'init' hook causes
270 - // infinite database updates and destroys custom rules when WPML or MKB dynamically filters keys.
271 - }
272 -
273 271 $_feed_regex = $_normalized_structure['raw'];
274 272 $_feed_regex[] = '(feed|rdf|rss|rss2|atom)';
275 273 $_feed_group = $_normalized_structure['group'];
276 274 $_feed_group[] = '%feed%';
@@ -281,9 +279,9 @@
281 279 $this->make_regex( $_normalized_structure['raw'] ),
282 280 $this->make_query( $_normalized_structure['group'] )
283 281 );
284 282
285 - $this->add_rewrite_rule( '^' . $base . '/(feed|rdf|rss|rss2|atom)/?$', 'index.php?post_type=docs&feed=$matches[1]' );
283 + $this->add_rewrite_rule( $base . '/(feed|rdf|rss|rss2|atom)/?$', 'index.php?post_type=docs&feed=$matches[1]' );
286 284 }
287 285
288 286 public function add_rewrite_rule( $regex, $query, $after = 'top' ) {
289 287 add_rewrite_rule( $regex, $query, $after );