TermObjectController.php
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
<?php
/**
* TermObjectController.php
*
* The TermObjectController class file.
*
* PHP versions 5
*
* @author Alexander Schneider <alexanderschneider85@gmail.com>
* @copyright 2008-2017 Alexander Schneider
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2
* @version SVN: $id$
* @link http://wordpress.org/extend/plugins/user-access-manager/
*/
declare(strict_types=1);
namespace UserAccessManager\Controller\Backend;
use UserAccessManager\Object\ObjectHandler;
use UserAccessManager\UserGroup\UserGroupTypeException;
use WP_Term;
/**
* Class TermObjectController
*
* @package UserAccessManager\Controller\Backend
*/
class TermObjectController extends ObjectController
{
/**
* The function for the manage_categories_columns filter.
* @param array $defaults The table headers.
* @return array
*/
public function addTermColumnsHeader(array $defaults): array
{
$defaults[self::COLUMN_NAME] = TXT_UAM_COLUMN_ACCESS;
return $defaults;
}
/**
* The function for the manage_categories_custom_column action.
* @param string|null $content Content for the column. Multiple filter calls are possible, so we need to append.
* @param string $columnName The column name.
* @param int|string $id The id.
* @return string|null $content with content appended for self::COLUMN_NAME column
* @throws UserGroupTypeException
*/
public function addTermColumn(?string $content, string $columnName, $id): ?string
{
if ($columnName === self::COLUMN_NAME) {
$term = $this->objectHandler->getTerm($id);
$objectType = ($term !== false) ? $term->taxonomy : ObjectHandler::GENERAL_TERM_OBJECT_TYPE;
$content .= $this->getGroupColumn($objectType, $id);
}
return $content;
}
/**
* The function for the edit_{term}_form action.
* @param string|WP_Term $term The term.
* @throws UserGroupTypeException
*/
public function showTermEditForm($term)
{
if ($term instanceof WP_Term) {
$this->setObjectInformation($term->taxonomy, $term->term_id);
} else {
$this->setObjectInformation($term, null);
}
echo $this->getIncludeContents('TermEditForm.php');
}
/**
* The function for the edit_term action.
* @param int|string $termId The term id.
* @throws UserGroupTypeException
*/
public function saveTermData($termId)
{
$term = $this->objectHandler->getTerm($termId);
$objectType = ($term !== false) ? $term->taxonomy : ObjectHandler::GENERAL_TERM_OBJECT_TYPE;
$this->saveObjectData($objectType, $termId);
}
/**
* The function for the delete_{term} action.
* @param int|string $termId The id of the term.
*/
public function removeTermData($termId)
{
$this->removeObjectData(ObjectHandler::GENERAL_TERM_OBJECT_TYPE, $termId);
}
}