1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the WPFoundation library. |
5
|
|
|
* |
6
|
|
|
* Copyright (c) 2015-present LIN3S <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace LIN3S\WPFoundation\PostTypes; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Abstract class of base post type that implements the interface. |
16
|
|
|
* This class avoids the redundant task of create the same PostType constructor. |
17
|
|
|
* Also, it comes with basic implementation of "permalink" method. |
18
|
|
|
* |
19
|
|
|
* @author Beñat Espiña <[email protected]> |
20
|
|
|
* @author Gorka Laucirica <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
class PostType implements PostTypeInterface |
|
|
|
|
23
|
|
|
{ |
24
|
|
|
private $name; |
25
|
|
|
private $options; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Constructor. |
29
|
|
|
* |
30
|
|
|
* @param string $name |
|
|
|
|
31
|
|
|
* @param array $options |
32
|
|
|
*/ |
33
|
|
|
public function __construct($name = null, $options = []) |
34
|
|
|
{ |
35
|
|
|
$this->name = $name; |
36
|
|
|
$this->options = $options; |
37
|
|
|
|
38
|
|
|
add_action('init', [$this, 'postType']); |
|
|
|
|
39
|
|
|
add_action('init', [$this, 'taxonomyType']); |
|
|
|
|
40
|
|
|
add_action('init', [$this, 'fields'], 20); |
|
|
|
|
41
|
|
|
add_action('init', [$this, 'rewriteRules'], 20); |
|
|
|
|
42
|
|
|
|
43
|
|
|
add_filter('post_type_link', [$this, 'permalink'], 1, 2); |
|
|
|
|
44
|
|
|
add_filter('term_link', [$this, 'taxonomyPermalink'], 1, 2); |
|
|
|
|
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* {@inheritdoc} |
49
|
|
|
*/ |
50
|
|
|
public function fields() |
51
|
|
|
{ |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* {@inheritdoc} |
56
|
|
|
*/ |
57
|
|
|
public function permalink($permalink, $id = 0) |
58
|
|
|
{ |
59
|
|
|
return $permalink; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* {@inheritdoc} |
64
|
|
|
*/ |
65
|
|
|
public function rewriteRules() |
66
|
|
|
{ |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* {@inheritdoc} |
71
|
|
|
*/ |
72
|
|
|
public static function serialize($postTypes) |
73
|
|
|
{ |
74
|
|
|
if (is_array($postTypes)) { |
75
|
|
|
foreach ($postTypes as $key => $postType) { |
76
|
|
|
$postTypes[$key] = static::singleSerialize($postType); |
|
|
|
|
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
return $postTypes; |
80
|
|
|
} |
81
|
|
|
$postType = $postTypes; |
82
|
|
|
|
83
|
|
|
return static::singleSerialize($postType); |
|
|
|
|
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* {@inheritdoc} |
88
|
|
|
*/ |
89
|
|
|
public function taxonomyPermalink($url, $term) |
90
|
|
|
{ |
91
|
|
|
return $url; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Static method that simplifies the process of getting all data |
96
|
|
|
* from given post. This method is called by the main serialize method. |
97
|
|
|
* |
98
|
|
|
* @param object $postType The post type |
99
|
|
|
* |
100
|
|
|
* @deprecated since version 1.7, will be removed in 2.0. Create a custom serializer class. |
101
|
|
|
* |
102
|
|
|
* @return object Serialized given post type |
103
|
|
|
*/ |
104
|
|
|
protected static function singleSerialize($postType) |
105
|
|
|
{ |
106
|
|
|
return $postType; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* {@inheritdoc} |
111
|
|
|
*/ |
112
|
|
|
public function postType() |
113
|
|
|
{ |
114
|
|
|
if ($this->name !== null && $this->options !== null) { |
115
|
|
|
register_post_type($this->name, $this->options); |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* {@inheritdoc} |
121
|
|
|
*/ |
122
|
|
|
public function taxonomyType() |
123
|
|
|
{ |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.