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\Fields\Templates; |
13
|
|
|
|
14
|
|
|
use LIN3S\WPFoundation\PostTypes\Fields\Fields; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Abstract page fields class that extends the fields basic |
18
|
|
|
* behaviour, implementing the "connector" and "removeScreenAttributes" |
19
|
|
|
* methods with the common use case. |
20
|
|
|
* |
21
|
|
|
* @author Beñat Espiña <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
abstract class PageFields extends Fields |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* Constructor. |
27
|
|
|
*/ |
28
|
|
|
public function __construct() |
29
|
|
|
{ |
30
|
|
|
parent::__construct(); |
31
|
|
|
|
32
|
|
|
$newPostId = filter_input(INPUT_GET, 'post', FILTER_SANITIZE_NUMBER_INT); |
33
|
|
|
$updatePostId = filter_input(INPUT_POST, 'post_ID', FILTER_SANITIZE_NUMBER_INT); |
34
|
|
|
|
35
|
|
|
if (isset($newPostId)) { |
36
|
|
|
$postId = absint($newPostId); |
37
|
|
|
} elseif (isset($updatePostId)) { |
38
|
|
|
$postId = absint($updatePostId); |
39
|
|
|
} else { |
40
|
|
|
add_action('add_meta_boxes', [$this, 'addMetaBox']); |
|
|
|
|
41
|
|
|
} |
42
|
|
|
if (false === isset($postId) || $this->name === get_post_meta($postId, '_wp_page_template', true)) { |
|
|
|
|
43
|
|
|
add_action('admin_init', [$this, 'addScreenAttributes']); |
|
|
|
|
44
|
|
|
add_action('admin_init', [$this, 'removeScreenAttributes']); |
|
|
|
|
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* {@inheritdoc} |
50
|
|
|
*/ |
51
|
|
View Code Duplication |
public function connector() |
|
|
|
|
52
|
|
|
{ |
53
|
|
|
return [ |
54
|
|
|
[ |
55
|
|
|
[ |
56
|
|
|
'param' => 'post_type', |
57
|
|
|
'operator' => '==', |
58
|
|
|
'value' => 'page', |
59
|
|
|
], |
60
|
|
|
[ |
61
|
|
|
'param' => 'page_template', |
62
|
|
|
'operator' => '==', |
63
|
|
|
'value' => $this->name, |
64
|
|
|
], |
65
|
|
|
], |
66
|
|
|
]; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* {@inheritdoc} |
71
|
|
|
*/ |
72
|
|
|
public function removeScreenAttributes() |
73
|
|
|
{ |
74
|
|
|
remove_post_type_support('page', 'comments'); |
|
|
|
|
75
|
|
|
remove_post_type_support('page', 'custom-fields'); |
|
|
|
|
76
|
|
|
remove_post_type_support('page', 'editor'); |
|
|
|
|
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Callback that adds the meta box. |
81
|
|
|
*/ |
82
|
|
|
public function addMetaBox() |
83
|
|
|
{ |
84
|
|
|
add_meta_box( |
85
|
|
|
'lin3s-id-default-meta-box', |
86
|
|
|
'LIN3S INFO', |
87
|
|
|
[$this, 'metaBox'], |
88
|
|
|
'page' |
89
|
|
|
); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Callback that prints the meta box. |
94
|
|
|
* |
95
|
|
|
* @param mixed $post The post |
96
|
|
|
* @param string $box The box |
97
|
|
|
*/ |
98
|
|
|
public function metaBox($post, $box) |
|
|
|
|
99
|
|
|
{ |
100
|
|
|
echo <<<'EOF' |
101
|
|
|
<h1 style="text-align: center;"> |
102
|
|
|
PLEASE ADD <strong>PAGE TITLE</strong> AND SELECT A TEMPLATE IN THE <strong>TEMPLATE SELECTOR</strong> |
103
|
|
|
</h1> |
104
|
|
|
EOF; |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|