-
-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathapi.php
More file actions
202 lines (180 loc) · 4.45 KB
/
Copy pathapi.php
File metadata and controls
202 lines (180 loc) · 4.45 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
<?php
declare( strict_types=1 );
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Get the output for using the links to the translations in your code
*
* @package Msls
* @since 3.0.0 The $attr parameter is optional and defaults to an empty array.
* @param mixed $attr Optional. Attributes forwarded to the switcher output. Default empty array.
* @return string
*/
function msls_get_switcher( $attr = array() ): string {
$arr = is_array( $attr ) ? $attr : array();
$obj = apply_filters( 'msls_get_output', null );
return ! is_null( $obj ) ? strval( $obj->set_tags( $arr ) ) : '';
}
/**
* Output the links to the translations in your template
*
* You can call this function directly like that
*
* if ( function_exists ( 'the_msls' ) )
* the_msls();
*
* or just use it as shortcode [sc_msls]
*
* @package Msls
* @uses get_the_msls
*
* @param string[] $arr
*/
function msls_the_switcher( array $arr = array() ): void {
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo msls_get_switcher( $arr );
}
/**
* Gets the URL of the country flag-icon for a specific locale
*
* @param string $locale
*
* @return string
*/
function msls_get_flag_url( string $locale ): string {
return ( new \lloc\Msls\Options\Options() )->get_flag_url( $locale );
}
/**
* Gets the description for a blog for a specific locale
*
* @param string $locale
* @param string $preset
*
* @return string
*/
function msls_get_blog_description( string $locale, string $preset = '' ): string {
$blog = msls_blog( $locale );
return $blog ? $blog->get_description() : $preset;
}
/**
* Gets the permalink for a translation of the current post in a given language
*
* @param string $locale
* @param string $preset
*
* @return string
*/
function msls_get_permalink( string $locale, string $preset = '' ): string {
$url = null;
$blog = msls_blog( $locale );
if ( $blog ) {
$options = \lloc\Msls\Options\Options::create();
$url = $blog->get_url( $options );
}
return $url ?? $preset;
}
/**
* Looks for the Blog instance for a specific locale
*
* @param string $locale
*
* @return \lloc\Msls\Blog\Blog|null
*/
function msls_blog( string $locale ): ?\lloc\Msls\Blog\Blog {
return msls_blog_collection()->get_blog( $locale );
}
/**
* Gets the Blog Collection instance
*
* @return \lloc\Msls\Blog\Collection
*/
function msls_blog_collection(): \lloc\Msls\Blog\Collection {
return \lloc\Msls\Blog\Collection::instance();
}
/**
* Gets the Options instance
*
* @return \lloc\Msls\Options\Options
*/
function msls_options(): \lloc\Msls\Options\Options {
return \lloc\Msls\Options\Options::instance();
}
/**
* Gets the MslsContentTypes instance
*
* @return \lloc\Msls\ContentTypes\ContentTypes
*/
function msls_content_types(): \lloc\Msls\ContentTypes\ContentTypes {
return \lloc\Msls\ContentTypes\ContentTypes::create();
}
/**
* Gets the MslsPostType instance
*
* @return \lloc\Msls\ContentTypes\PostType
*/
function msls_post_type(): \lloc\Msls\ContentTypes\PostType {
return \lloc\Msls\ContentTypes\PostType::instance();
}
/**
* Gets the MslsTaxonomy instance
*
* @return \lloc\Msls\ContentTypes\Taxonomy
*/
function msls_taxonomy(): \lloc\Msls\ContentTypes\Taxonomy {
return \lloc\Msls\ContentTypes\Taxonomy::instance();
}
/**
* Gets the Output instance
*
* @return \lloc\Msls\Frontend\Output
*/
function msls_output(): \lloc\Msls\Frontend\Output {
return \lloc\Msls\Frontend\Output::create();
}
/**
* Retrieves the OptionsPost instance.
*
* @param int $id
*
* @return \lloc\Msls\Options\Post\Post
*/
function msls_get_post( int $id ): \lloc\Msls\Options\Post\Post {
return new \lloc\Msls\Options\Post\Post( $id );
}
/**
* Retrieves the OptionsTax instance.
*
* Determines the current query based on conditional tags:
* - is_category
* - is_tag
* - is_tax
*
* @param int $id
* @return \lloc\Msls\Options\Tax\OptionsTaxInterface
*/
function msls_get_tax( int $id ): \lloc\Msls\Options\Tax\OptionsTaxInterface {
return \lloc\Msls\Options\Tax\Tax::create( $id );
}
/**
* Retrieves the OptionsQuery instance.
*
* Determines the current query based on conditional tags:
* - is_day
* - is_month
* - is_year
* - is_author
* - is_post_type_archive
*
* @return ?\lloc\Msls\Options\Query\Query
*/
function msls_get_query(): ?\lloc\Msls\Options\Query\Query {
return \lloc\Msls\Options\Query\Query::create();
}
/**
* Trivial void function for actions that do not return anything.
*
* @return void
*/
function msls_return_void(): void {
}