9
9
*/
10
10
class MslsOptionsTaxTerm extends MslsOptionsTax {
11
11
12
- /**
13
- * Base option
14
- *
15
- * @var string
16
- */
17
- protected $ base_option = 'tag_base ' ;
12
+ const BASE_OPTION = 'tag_base ' ;
18
13
19
- /**
20
- * Base definition
21
- *
22
- * @var string
23
- */
24
- protected $ base_defined = 'tag ' ;
14
+ const BASE_DEFINED = 'tag ' ;
25
15
26
16
/**
27
17
* Rewrite with front
@@ -33,8 +23,8 @@ class MslsOptionsTaxTerm extends MslsOptionsTax {
33
23
/**
34
24
* Check and correct URL
35
25
*
36
- * @param string $url
37
- * @param MslsOptions $options
26
+ * @param string $url
27
+ * @param MslsOptionsTaxTerm $options
38
28
*
39
29
* @return string
40
30
*/
@@ -43,32 +33,38 @@ public function check_base( $url, $options ) {
43
33
return $ url ;
44
34
}
45
35
46
- global $ wp_rewrite ;
36
+ $ tax_query = $ options ->get_tax_query ();
37
+ $ base_defined = self ::get_base_defined ( $ tax_query );
38
+ $ base_option = self ::get_base_option ();
47
39
48
- $ base_defined = $ options ->base_defined ;
40
+ if ( $ base_defined != $ base_option ) {
41
+ $ search = '/ ' . $ base_defined . '/ ' ;
42
+ $ replace = '/ ' . $ base_option . '/ ' ;
43
+ $ url = str_replace ( $ search , $ replace , $ url );
44
+ }
49
45
50
- $ permastruct = $ wp_rewrite ->get_extra_permastruct ( $ options ->get_tax_query () );
46
+ return $ url ;
47
+ }
48
+
49
+ protected static function get_base_defined ( string $ tax_query ): string {
50
+ global $ wp_rewrite ;
51
+
52
+ $ permastruct = $ wp_rewrite ->get_extra_permastruct ( $ tax_query );
51
53
if ( $ permastruct ) {
52
54
$ permastruct = explode ( '/ ' , $ permastruct );
53
55
end ( $ permastruct );
54
56
$ permastruct = prev ( $ permastruct );
55
57
if ( false !== $ permastruct ) {
56
- $ base_defined = $ permastruct ;
58
+ return $ permastruct ;
57
59
}
58
60
}
59
61
60
- $ base_option = get_option ( $ options ->base_option );
61
- if ( empty ( $ base_option ) ) {
62
- $ base_option = $ options ->base_defined ;
63
- }
62
+ return self ::BASE_DEFINED ;
63
+ }
64
64
65
- if ( $ base_defined != $ base_option ) {
66
- $ search = '/ ' . $ base_defined . '/ ' ;
67
- $ replace = '/ ' . $ base_option . '/ ' ;
68
- $ count = 1 ;
69
- $ url = str_replace ( $ search , $ replace , $ url , $ count );
70
- }
65
+ protected static function get_base_option (): string {
66
+ $ base_option = get_option ( self ::BASE_OPTION , '' );
71
67
72
- return $ url ;
68
+ return $ base_option ?: self :: BASE_DEFINED ;
73
69
}
74
70
}
0 commit comments