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