forked from lloc/Multisite-Language-Switcher
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMslsOptionsQuery.php
More file actions
93 lines (78 loc) · 1.92 KB
/
MslsOptionsQuery.php
File metadata and controls
93 lines (78 loc) · 1.92 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
<?php declare( strict_types=1 );
namespace lloc\Msls;
/**
* MslsOptionsQuery
*
* @package Msls
*/
class MslsOptionsQuery extends MslsOptions {
/**
* Rewrite with front
*
* @var bool
*/
public ?bool $with_front = true;
/**
* @var MslsSqlCacher
*/
protected MslsSqlCacher $sql_cache;
public function __construct( MslsSqlCacher $sql_cache ) {
parent::__construct();
$this->sql_cache = $sql_cache;
}
/**
* @return array<string, mixed>
*/
public static function get_params(): array {
return array();
}
/**
* Factory method
*
* @param int $id This parameter is unused here.
*
* @return ?MslsOptionsQuery
*/
public static function create( $id = 0 ): ?MslsOptionsQuery {
if ( is_day() ) {
$query_class = MslsOptionsQueryDay::class;
} elseif ( is_month() ) {
$query_class = MslsOptionsQueryMonth::class;
} elseif ( is_year() ) {
$query_class = MslsOptionsQueryYear::class;
} elseif ( is_author() ) {
$query_class = MslsOptionsQueryAuthor::class;
} elseif ( is_post_type_archive() ) {
$query_class = MslsOptionsQueryPostType::class;
}
if ( ! isset( $query_class ) ) {
return null;
}
$sql_cache = MslsSqlCacher::create( $query_class, $query_class::get_params() );
return new $query_class( $sql_cache );
}
public function get_permalink( string $language ): string {
return (string) apply_filters(
'msls_options_get_permalink',
$this->get_postlink( $language ),
$language
);
}
/**
* Get postlink
*
* @param string $language
*
* @return string
*/
public function get_postlink( $language ) {
if ( $this->has_value( $language ) ) {
$post_link = $this->get_current_link();
if ( ! empty( $post_link ) ) {
$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 );
}
}
return '';
}
}