| Conditions | 4 |
| Paths | 4 |
| Total Lines | 23 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 20 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 21 | public function handle() |
||
| 22 | { |
||
| 23 | if ($this->review->is_approved) { |
||
| 24 | return false; |
||
| 25 | } |
||
| 26 | if (!glsr()->can('edit_post', $this->review->ID)) { |
||
| 27 | glsr_log()->error('Cannot approve review: Invalid permission.'); |
||
| 28 | return false; |
||
| 29 | } |
||
| 30 | $args = [ |
||
| 31 | 'ID' => $this->review->ID, |
||
| 32 | 'post_status' => 'publish', |
||
| 33 | ]; |
||
| 34 | $postId = wp_update_post($args, true); |
||
| 35 | if (is_wp_error($postId)) { |
||
| 36 | glsr_log()->error($postId->get_error_message()); |
||
| 37 | return false; |
||
| 38 | } |
||
| 39 | $message = sprintf(_x('The %sreview%s was approved successfully.', 'admin-text', 'site-reviews'), |
||
| 40 | sprintf('<a href="%s">', $this->review->editUrl()), '</a>' |
||
| 41 | ); |
||
| 42 | glsr(Notice::class)->addSuccess($message); |
||
| 43 | return true; |
||
| 44 | } |
||
| 46 |