/** * Use this method to prevent excluding something that was not configured by FakerPress * * @param array|int|\WP_Comment $comment The ID for the Post or the Object * @return bool */ public static function delete($comment) { if (is_array($comment)) { $deleted = array(); foreach ($comment as $id) { $id = $id instanceof \WP_Comment ? $id->comment_ID : $id; if (!is_numeric($id)) { continue; } $deleted[$id] = self::delete($id); } return $deleted; } if (is_numeric($comment)) { $comment = \WP_Comment::get_instance($comment); } if (!$comment instanceof \WP_Comment) { return false; } $flag = (bool) get_comment_meta($comment->comment_ID, self::$flag, true); if (true !== $flag) { return false; } return wp_delete_comment($comment->comment_ID, true); }
/** * Retrieves comment data given a comment ID or comment object. * * If an object is passed then the comment data will be cached and then returned * after being passed through a filter. If the comment is empty, then the global * comment variable will be used, if it is set. * * @since 2.0.0 * * @global WP_Comment $comment * * @param WP_Comment|string|int $comment Comment to retrieve. * @param string $output Optional. OBJECT or ARRAY_A or ARRAY_N constants. * @return WP_Comment|array|null Depends on $output value. */ function get_comment(&$comment = null, $output = OBJECT) { if (empty($comment) && isset($GLOBALS['comment'])) { $comment = $GLOBALS['comment']; } if ($comment instanceof WP_Comment) { $_comment = $comment; } elseif (is_object($comment)) { $_comment = new WP_Comment($comment); } else { $_comment = WP_Comment::get_instance($comment); } if (!$_comment) { return null; } /** * Fires after a comment is retrieved. * * @since 2.3.0 * * @param mixed $_comment Comment data. */ $_comment = apply_filters('get_comment', $_comment); if ($output == OBJECT) { return $_comment; } elseif ($output == ARRAY_A) { return $_comment->to_array(); } elseif ($output == ARRAY_N) { return array_values($_comment->to_array()); } return $_comment; }
public function get_comment($id) { return WP_Comment::get_instance($id); }
/** * Prepares links for the request. * * @since 4.7.0 * @access protected * * @param WP_Comment $comment Comment object. * @return array Links for the given comment. */ protected function prepare_links($comment) { $links = array('self' => array('href' => rest_url(sprintf('%s/%s/%d', $this->namespace, $this->rest_base, $comment->comment_ID))), 'collection' => array('href' => rest_url(sprintf('%s/%s', $this->namespace, $this->rest_base)))); if (0 !== (int) $comment->user_id) { $links['author'] = array('href' => rest_url('wp/v2/users/' . $comment->user_id), 'embeddable' => true); } if (0 !== (int) $comment->comment_post_ID) { $post = get_post($comment->comment_post_ID); if (!empty($post->ID)) { $obj = get_post_type_object($post->post_type); $base = !empty($obj->rest_base) ? $obj->rest_base : $obj->name; $links['up'] = array('href' => rest_url('wp/v2/' . $base . '/' . $comment->comment_post_ID), 'embeddable' => true, 'post_type' => $post->post_type); } } if (0 !== (int) $comment->comment_parent) { $links['in-reply-to'] = array('href' => rest_url(sprintf('%s/%s/%d', $this->namespace, $this->rest_base, $comment->comment_parent)), 'embeddable' => true); } // Only grab one comment to verify the comment has children. $comment_children = $comment->get_children(array('number' => 1, 'count' => true)); if (!empty($comment_children)) { $args = array('parent' => $comment->comment_ID); $rest_url = add_query_arg($args, rest_url($this->namespace . '/' . $this->rest_base)); $links['children'] = array('href' => $rest_url); } return $links; }
/** * @ticket 37738 */ public function test_get_instance_should_fail_for_class() { $class = new stdClass(); $found = WP_Comment::get_instance($class); $this->assertFalse($found); }