forked from lloc/Multisite-Language-Switcher
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMslsOptionsTax.php
More file actions
140 lines (116 loc) · 2.95 KB
/
MslsOptionsTax.php
File metadata and controls
140 lines (116 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php declare( strict_types=1 );
namespace lloc\Msls;
/**
* MslsOptionsTax
*
* @package Msls
*/
class MslsOptionsTax extends MslsOptions implements OptionsTaxInterface {
public const SEPARATOR = '_term_';
/**
* @var bool
*/
protected bool $autoload = false;
/**
* @param int $id
*
* @return OptionsTaxInterface
*/
public static function create( $id = 0 ): OptionsTaxInterface {
$id = ! empty( $id ) ? (int) $id : get_queried_object_id();
$req = self::get_content_type( $id );
switch ( $req ) {
case 'category':
$options = new MslsOptionsTaxTermCategory( $id );
break;
case 'post_tag':
$options = new MslsOptionsTaxTerm( $id );
break;
default:
$options = new MslsOptionsTax( $id );
}
return $options->handle_rewrite();
}
/**
* @param int $id
*
* @return string
*/
public static function get_content_type( int $id ): string {
if ( is_admin() ) {
return msls_content_types()->acl_request();
}
return ( is_category( $id ) ? 'category' : ( is_tag( $id ) ? 'post_tag' : '' ) );
}
public function handle_rewrite(): OptionsTaxInterface {
global $wp_rewrite;
$this->with_front = ! empty( $wp_rewrite->extra_permastructs[ $this->get_tax_query() ]['with_front'] );
return $this;
}
/**
* Get the queried taxonomy
*
* @return string
*/
public function get_tax_query() {
global $wp_query;
if ( class_exists( 'WooCommerce' ) && is_woocommerce() && isset( $wp_query->tax_query->queries[1]['taxonomy'] ) ) {
return $wp_query->tax_query->queries[1]['taxonomy'];
} elseif ( isset( $wp_query->tax_query->queries[0]['taxonomy'] ) ) {
return $wp_query->tax_query->queries[0]['taxonomy'];
}
return parent::get_tax_query();
}
/**
* Get postlink
*
* @param string $language
*
* @return string
*/
public function get_postlink( $language ) {
$post_link = '';
if ( $this->has_value( $language ) ) {
$post_link = $this->get_term_link( (int) $this->__get( $language ) );
}
$post_link = apply_filters_deprecated( 'check_url', array( $post_link, $this ), '2.7.1', MslsOptions::MSLS_GET_POSTLINK_HOOK );
return apply_filters( MslsOptions::MSLS_GET_POSTLINK_HOOK, $post_link, $this );
}
public function get_permalink( string $language ): string {
return (string) apply_filters(
'msls_options_get_permalink',
$this->get_postlink( $language ),
$language
);
}
/**
* Get current link
*
* @return string
*/
public function get_current_link(): string {
return $this->get_term_link( $this->get_arg( 0, 0 ) );
}
/**
* Wraps the call to get_term_link
*
* @param int $term_id
*
* @return string
*/
public function get_term_link( $term_id ) {
if ( ! empty( $term_id ) ) {
$taxonomy = $this->get_tax_query();
if ( ! empty( $taxonomy ) ) {
$link = get_term_link( $term_id, $taxonomy );
if ( ! is_wp_error( $link ) ) {
return $link;
}
}
}
return '';
}
public static function get_base_option(): string {
return '';
}
}