예제 #1
0
 /**
  * @inheritdoc
  */
 public function init($path)
 {
     $postId = filter_input(INPUT_GET, 'postid', FILTER_SANITIZE_NUMBER_INT);
     $post = $postId ? get_post($postId) : false;
     $allowed = apply_filters(Launcher::SLUG . '_post_types', ['post']);
     if (!$post instanceof WP_Post || $this->meta->has($post->ID, $post->post_author) || !in_array($post->post_type, $allowed, true)) {
         return false;
     }
     $this->post = $post;
     $this->author = new WP_User($post->post_author);
     $this->path = $path;
     $mail = $this->author && $this->author->exists() ? $this->author->get('user_email') : false;
     return $mail && filter_var($mail, FILTER_VALIDATE_EMAIL);
 }
예제 #2
0
 /**
  * @inheritdoc
  */
 public function init($path)
 {
     $postId = filter_input(INPUT_GET, 'post', FILTER_SANITIZE_NUMBER_INT);
     $post = $postId ? get_post($postId) : false;
     if (!$post instanceof WP_Post) {
         return false;
     }
     $this->hasMeta = $this->meta->has($post->ID, $post->post_author);
     $this->path = $path;
     if (!in_array($post->post_status, ['pending', 'draft'], true) && $this->hasMeta) {
         $this->meta->delete($post->ID);
     } elseif ($post->post_status === 'pending' && (int) $post->post_author !== (int) get_current_user_id()) {
         /** @var \stdClass $postType */
         /** @var \stdClass $caps */
         $postType = get_post_type_object($post->post_type);
         $caps = $postType->cap;
         $this->inited = !user_can($post->post_author, $caps->publish_posts);
     }
     return $this->inited;
 }
예제 #3
0
 /**
  * Print the 'Rejected Status' column according to post meta.
  *
  * @param string $column
  * @param string $pid
  */
 private function columnContent($column, $pid)
 {
     if ($column !== Launcher::SLUG . '_status') {
         return;
     }
     $post = get_post($pid);
     $allowed = apply_filters(Launcher::SLUG . '_post_types', ['post']);
     if (!in_array($post->post_type, $allowed, true)) {
         return;
     }
     $has = $this->meta->has($pid);
     $status = $post->post_status;
     if (!in_array($status, ['pending', 'draft'], true)) {
         $has and $this->meta->delete($pid);
     }
     if ($status === 'pending') {
         $has ? esc_html_e('Rejected', 'reject-notify') : esc_html_e('Needs Approval', 'reject-notify');
     }
 }
예제 #4
0
 /**
  * Validate request data.
  */
 private function validate()
 {
     $errors = [esc_html__('Wrong data error.', 'reject-notify'), esc_html__('Missing data error.', 'reject-notify'), esc_html__('Error on validating nonce.', 'reject-notify'), esc_html__('Invalid recipient mail.', 'reject-notify'), esc_html__('Post author was already rejected and notified.', 'reject-notify')];
     $callbacks = [function ($error) {
         $allowed = apply_filters(Launcher::SLUG . '_post_types', ['post']);
         $post = $this->data['postid'] ? get_post($this->data['postid']) : false;
         return $post instanceof WP_Post && in_array($post->post_type, $allowed, true) ? '' : $error;
     }, function ($error) {
         return array_filter($this->data) === $this->data ? '' : $error;
     }, function ($error) {
         return wp_verify_nonce($this->data[FormCase::NONCE], FormCase::NONCE . get_current_blog_id()) ? '' : $error;
     }, function ($error) {
         return filter_var($this->data['recipient'], FILTER_VALIDATE_EMAIL) ? '' : $error;
     }, function ($error) {
         return $this->meta->has($this->data['postid'], $this->authorID) ? $error : '';
     }];
     $error = '';
     while (empty($error) && !empty($callbacks)) {
         $i = !isset($i) ? 0 : ++$i;
         $error = call_user_func(array_shift($callbacks), $errors[$i]);
     }
     $this->error = $error;
 }