PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 3.5.3
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v3.5.3
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 +28 -25 3.4.23.5.3 View file →
@@ -40,9 +40,9 @@
40 40 *
41 41 * @return void
42 42 */
43 43 public function save_permalink_structure( $_saved, $_settings, $_old_settings ) {
44 - if ( ! isset($_settings['permalink_structure']) ) {
44 + if ( ! isset( $_settings['permalink_structure'] ) ) {
45 45 return;
46 46 }
47 47
48 48 $_permalink_structure = $_settings['permalink_structure'];
@@ -57,8 +57,11 @@
57 57 if ( $_permalink_structure !== $_old_settings['permalink_structure'] ) {
58 58 $this->settings->save( 'permalink_structure', $this->permalink_structure( $_permalink_structure ) );
59 59 }
60 60
61 + $old_docs_page = isset( $_old_settings['docs_page'] ) ? $_old_settings['docs_page'] : '';
62 + $current_docs_page = isset( $_settings['docs_page'] ) ? $_settings['docs_page'] : '';
63 +
61 64 /**
62 65 * This block of code decides whether it needs to be flushed or not.
63 66 * Flush happens after register the post type.
64 67 */
@@ -65,9 +68,9 @@
65 68 switch ( true ) {
66 69 case $_permalink_structure !== $_old_settings['permalink_structure']:
67 70 case $_settings['docs_slug'] !== $_old_settings['docs_slug']:
68 71 case $_settings['builtin_doc_page'] !== $_old_settings['builtin_doc_page']:
69 - case $_settings['docs_page'] !== $_old_settings['docs_page']:
72 + case $current_docs_page !== $old_docs_page:
70 73 case $_settings['tag_slug'] !== $_old_settings['tag_slug']:
71 74 case $_settings['category_slug'] !== $_old_settings['category_slug']:
72 75 $this->database->set_transient( 'betterdocs_flush_rewrite_rules', true );
73 76 break;
@@ -125,16 +128,16 @@
125 128
126 129 return $docs_slug;
127 130 }
128 131
129 - public function normalzie_doc_perma_structure( $structure ){
132 + public function normalzie_doc_perma_structure( $structure ) {
130 133 $structure = $this->permalink_structure( $structure, 'arraywithpercent' );
131 - $structure = array_reduce( $structure, function( $carry, $item ){
132 - if( strpos( $item, '%' ) !== false ) {
134 + $structure = array_reduce( $structure, function ( $carry, $item ) {
135 + if ( strpos( $item, '%' ) !== false ) {
133 136 $carry[] = $item;
134 137 } else {
135 - if ($carry && strpos(end($carry), '%') === false) {
136 - $carry[count($carry) - 1] .= "/$item";
138 + if ( $carry && strpos( end( $carry ), '%' ) === false ) {
139 + $carry[count( $carry ) - 1] .= "/$item";
137 140 } else {
138 141 $carry[] = $item;
139 142 }
140 143 }
@@ -139,39 +142,39 @@
139 142 }
140 143 }
141 144
142 145 return $carry;
143 - }, []);
146 + }, [] );
144 147
145 148 $structure[] = '%docs%';
146 149
147 - $group = array_filter( $structure, function( $item ){
148 - return strpos($item, '%') === 0;
149 - });
150 + $group = array_filter( $structure, function ( $item ) {
151 + return strpos( $item, '%' ) === 0;
152 + } );
150 153
151 154 return [
152 - 'raw' => $structure,
155 + 'raw' => $structure,
153 156 'group' => $group
154 157 ];
155 158 }
156 159
157 - public function make_regex( $segments ){
158 - return array_reduce( $segments, function( $carry, $item ){
160 + public function make_regex( $segments ) {
161 + return array_reduce( $segments, function ( $carry, $item ) {
159 162 $carry .= ( strpos( $item, '%' ) !== false ? "([^/]+)" : $item ) . '/';
160 163 return $carry;
161 - }, '') . '?$';
164 + }, '' ) . '?$';
162 165 }
163 166
164 - public function make_query( $segments ){
165 - $query = [];
167 + public function make_query( $segments ) {
168 + $query = [];
166 169 $matchId = 1;
167 170
168 - foreach( $segments as $segment ) {
169 - $query[] = trim($segment, '%') . '=$matches[' . $matchId . ']';
171 + foreach ( $segments as $segment ) {
172 + $query[] = trim( $segment, '%' ) . '=$matches[' . $matchId . ']';
170 173 $matchId++;
171 174 }
172 175
173 - return 'index.php?' . implode('&', $query) . '&post_type=docs';
176 + return 'index.php?' . implode( '&', $query ) . '&post_type=docs';
174 177 }
175 178
176 179 public function rules() {
177 180 /**
@@ -194,14 +197,14 @@
194 197
195 198 /**
196 199 * This code of blocks used to determine single docs permalink.
197 200 */
198 - $_docs_perma_struct = betterdocs()->settings->get( 'permalink_structure', 'docs' );
199 - $_normalized_structure = $this->normalzie_doc_perma_structure($_docs_perma_struct);
201 + $_docs_perma_struct = betterdocs()->settings->get( 'permalink_structure', 'docs' );
202 + $_normalized_structure = $this->normalzie_doc_perma_structure( $_docs_perma_struct );
200 203
201 - $_feed_regex = $_normalized_structure['raw'];
204 + $_feed_regex = $_normalized_structure['raw'];
202 205 $_feed_regex[] = '(feed|rdf|rss|rss2|atom)';
203 - $_feed_group = $_normalized_structure['group'];
206 + $_feed_group = $_normalized_structure['group'];
204 207 $_feed_group[] = '%feed%';
205 208
206 209 $this->add_rewrite_rule( $this->make_regex( $_feed_regex ), $this->make_query( $_feed_group ) );
207 210
@@ -230,9 +233,9 @@
230 233 $permalink = $this->remove_knowledge_base_placeholder( $permalink );
231 234 }
232 235
233 236 return apply_filters( 'betterdocs_docs_rewrite', [
234 - 'slug' => trim( $permalink, '/' ),
237 + 'slug' => trim( $permalink, '/' ),
235 238 'with_front' => false
236 239 ], $slug );
237 240 }
238 241 }