| @@ -1,5 +1,18 @@ | ||
| 1 | 1 | <?php |
| 2 | +/** | |
| 3 | + * PostObjectController.php | |
| 4 | + * | |
| 5 | + * The PostObjectController class file. | |
| 6 | + * | |
| 7 | + * PHP versions 5 | |
| 8 | + * | |
| 9 | + * @author Alexander Schneider <alexanderschneider85@gmail.com> | |
| 10 | + * @copyright 2008-2017 Alexander Schneider | |
| 11 | + * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 | |
| 12 | + * @version SVN: $id$ | |
| 13 | + * @link http://wordpress.org/extend/plugins/user-access-manager/ | |
| 14 | + */ | |
| 2 | 15 | |
| 3 | 16 | declare(strict_types=1); |
| 4 | 17 | |
| 5 | 18 | namespace UserAccessManager\Controller\Backend; |
| @@ -7,10 +20,21 @@ | ||
| 7 | 20 | use UserAccessManager\Object\ObjectHandler; |
| 8 | 21 | use UserAccessManager\UserGroup\UserGroupTypeException; |
| 9 | 22 | use WP_Post; |
| 10 | 23 | |
| 24 | +/** | |
| 25 | + * Class PostObjectController | |
| 26 | + * | |
| 27 | + * @package UserAccessManager\Controller\Backend | |
| 28 | + */ | |
| 11 | 29 | class PostObjectController extends ObjectController |
| 12 | 30 | { |
| 31 | + /** | |
| 32 | + * The function for the manage_posts_columns and | |
| 33 | + * the manage_pages_columns filter. | |
| 34 | + * @param array $defaults The table headers. | |
| 35 | + * @return array | |
| 36 | + */ | |
| 13 | 37 | public function addPostColumnsHeader(array $defaults): array |
| 14 | 38 | { |
| 15 | 39 | $defaults[self::COLUMN_NAME] = TXT_UAM_COLUMN_ACCESS; |
| 16 | 40 | return $defaults; |
| @@ -16,11 +40,14 @@ | ||
| 16 | 40 | return $defaults; |
| 17 | 41 | } |
| 18 | 42 | |
| 19 | 43 | /** |
| 44 | + * The function for the manage_users_custom_column action. | |
| 45 | + * @param string $columnName The column name. | |
| 46 | + * @param int|string $id The id. | |
| 20 | 47 | * @throws UserGroupTypeException |
| 21 | 48 | */ |
| 22 | - public function addPostColumn(string $columnName, int|string|null $id): void | |
| 49 | + public function addPostColumn(string $columnName, $id) | |
| 23 | 50 | { |
| 24 | 51 | if ($columnName === self::COLUMN_NAME) { |
| 25 | 52 | $post = $this->objectHandler->getPost($id); |
| 26 | 53 | echo $this->getGroupColumn($post->post_type, $post->ID); |
| @@ -27,11 +54,13 @@ | ||
| 27 | 54 | } |
| 28 | 55 | } |
| 29 | 56 | |
| 30 | 57 | /** |
| 58 | + * The function for the uam_post_access meta box. | |
| 59 | + * @param mixed $post The post. | |
| 31 | 60 | * @throws UserGroupTypeException |
| 32 | 61 | */ |
| 33 | - public function editPostContent(mixed $post): void | |
| 62 | + public function editPostContent($post) | |
| 34 | 63 | { |
| 35 | 64 | if ($post instanceof WP_Post) { |
| 36 | 65 | $this->setObjectInformation($post->post_type, $post->ID); |
| 37 | 66 | } |
| @@ -38,9 +67,13 @@ | ||
| 38 | 67 | |
| 39 | 68 | echo $this->getIncludeContents('PostEditForm.php'); |
| 40 | 69 | } |
| 41 | 70 | |
| 42 | - public function addBulkAction(string $columnName): void | |
| 71 | + /** | |
| 72 | + * Adds the bulk edit form. | |
| 73 | + * @param $columnName | |
| 74 | + */ | |
| 75 | + public function addBulkAction($columnName) | |
| 43 | 76 | { |
| 44 | 77 | if ($columnName === self::COLUMN_NAME) { |
| 45 | 78 | $this->getObjectInformation()->setObjectId(null); |
| 46 | 79 | echo $this->getIncludeContents('BulkEditForm.php'); |
| @@ -47,11 +80,13 @@ | ||
| 47 | 80 | } |
| 48 | 81 | } |
| 49 | 82 | |
| 50 | 83 | /** |
| 84 | + * The function for the save_post action. | |
| 85 | + * @param mixed $postParam The post id or a array of a post. | |
| 51 | 86 | * @throws UserGroupTypeException |
| 52 | 87 | */ |
| 53 | - public function savePostData(mixed $postParam): void | |
| 88 | + public function savePostData($postParam) | |
| 54 | 89 | { |
| 55 | 90 | $postId = (is_array($postParam) === true) ? $postParam['ID'] : $postParam; |
| 56 | 91 | $post = $this->objectHandler->getPost($postId); |
| 57 | 92 | $postType = $post->post_type; |
| @@ -66,11 +101,13 @@ | ||
| 66 | 101 | $this->saveObjectData($postType, $postId); |
| 67 | 102 | } |
| 68 | 103 | |
| 69 | 104 | /** |
| 105 | + * The function for the add_attachment action. | |
| 106 | + * @param int $postId | |
| 70 | 107 | * @throws UserGroupTypeException |
| 71 | 108 | */ |
| 72 | - public function addAttachment(int|string|null $postId): void | |
| 109 | + public function addAttachment(int $postId) | |
| 73 | 110 | { |
| 74 | 111 | $post = $this->objectHandler->getPost($postId); |
| 75 | 112 | $postType = $post->post_type; |
| 76 | 113 | $postId = $post->ID; |
| @@ -85,8 +122,13 @@ | ||
| 85 | 122 | $this->saveObjectData($postType, $postId, $defaultGroups, true); |
| 86 | 123 | } |
| 87 | 124 | |
| 88 | 125 | /** |
| 126 | + * The function for the attachment_fields_to_save filter. | |
| 127 | + * We have to use this because the attachment actions work | |
| 128 | + * not in the way we need. | |
| 129 | + * @param array $attachment The attachment id. | |
| 130 | + * @return array | |
| 89 | 131 | * @throws UserGroupTypeException |
| 90 | 132 | */ |
| 91 | 133 | public function saveAttachmentData(array $attachment): array |
| 92 | 134 | { |
| @@ -95,13 +137,14 @@ | ||
| 95 | 137 | return $attachment; |
| 96 | 138 | } |
| 97 | 139 | |
| 98 | 140 | /** |
| 141 | + * The function for the wp_ajax_save_attachment_compat filter. | |
| 99 | 142 | * @throws UserGroupTypeException |
| 100 | 143 | */ |
| 101 | - public function saveAjaxAttachmentData(): void | |
| 144 | + public function saveAjaxAttachmentData() | |
| 102 | 145 | { |
| 103 | - $attachmentId = (int) $this->getRequestParameter('id'); | |
| 146 | + $attachmentId = $this->getRequestParameter('id'); | |
| 104 | 147 | $userGroups = $this->getRequestParameter(self::DEFAULT_GROUPS_FORM_NAME); |
| 105 | 148 | |
| 106 | 149 | $this->saveObjectData( |
| 107 | 150 | ObjectHandler::GENERAL_POST_OBJECT_TYPE, |
| @@ -109,9 +152,13 @@ | ||
| 109 | 152 | $userGroups |
| 110 | 153 | ); |
| 111 | 154 | } |
| 112 | 155 | |
| 113 | - public function removePostData(int|string|null $postId): void | |
| 156 | + /** | |
| 157 | + * The function for the delete_post action. | |
| 158 | + * @param int|string $postId The post id. | |
| 159 | + */ | |
| 160 | + public function removePostData($postId) | |
| 114 | 161 | { |
| 115 | 162 | $post = $this->objectHandler->getPost($postId); |
| 116 | 163 | $this->removeObjectData($post->post_type, $postId); |
| 117 | 164 | } |
| @@ -116,11 +163,15 @@ | ||
| 116 | 163 | $this->removeObjectData($post->post_type, $postId); |
| 117 | 164 | } |
| 118 | 165 | |
| 119 | 166 | /** |
| 167 | + * The function for the media_meta action. | |
| 168 | + * @param array $formFields The meta. | |
| 169 | + * @param WP_Post $post The post. | |
| 170 | + * @return array | |
| 120 | 171 | * @throws UserGroupTypeException |
| 121 | 172 | */ |
| 122 | - public function showMediaFile(array $formFields, ?WP_Post $post = null): array | |
| 173 | + public function showMediaFile(array $formFields, $post = null): array | |
| 123 | 174 | { |
| 124 | 175 | if ($this->getRequestParameter('action') !== 'edit') { |
| 125 | 176 | $attachmentId = $this->getRequestParameter('attachment_id'); |
| 126 | 177 | |