Esempio n. 1
0
 /**
  * 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);
 }
Esempio n. 2
0
/**
 * 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);
 }
 /**
  * @ticket 37738
  */
 public function test_get_instance_should_fail_for_class()
 {
     $class = new stdClass();
     $found = WP_Comment::get_instance($class);
     $this->assertFalse($found);
 }