ClarksonCore

Clarkson_Object
in package
implements JsonSerializable

Object oriented implementation of WordPress post objects.

Interfaces, Classes, Traits and Enums

JsonSerializable

Table of Contents

$type  : string
The string here is the post type name used by `::get_many()`.
__construct()  : mixed
Clarkson_Object constructor.
__get()  : mixed
Check if name is not a wp_post object property.
add_comment()  : int
Add post comment.
add_meta()  : false|int
Add post meta data.
add_term()  : array<string|int, mixed>|WP_Error
Add a single term to a post.
add_terms()  : array<string|int, mixed>|WP_Error
Bulk add terms to a post.
delete()  : void
Delete post.
delete_meta()  : bool
Delete post meta data.
get()  : Clarkson_Object|null
Clarkson Object for a WP_Post by ID.
get_attachments()  : array<string|int, Clarkson_Object>
Get the attachments for the post.
get_author()  : Clarkson_User|null
Get the post author object.
get_author_id()  : null|string
Get the post author id.
get_children()  : array<string|int, Clarkson_Object>
Get the children of the post by id.
get_content()  : string
Get the post content.
get_date()  : string
Get the date the post was created in post_date_gmt format.
get_date_i18n()  : string
Get the date in localized format.
get_excerpt()  : string
Get the post excerpt.
get_id()  : int
Get the id of a post.
get_local_date()  : string
Get the local date the post was created.
get_many()  : array<string|int, Clarkson_Object>
Get multiple posts, without pagination.
get_meta()  : mixed
Proxy for get_post_meta.
get_object()  : WP_Post
Get the WordPress post object.
get_one()  : Clarkson_Object|null
Gets the first result from a `::get_many()` query.
get_parent()  : Clarkson_Object|null
Get the parent of the post, if any.
get_permalink()  : false|string
Get the post permalink.
get_post_name()  : string
Get post name (slug) by id.
get_post_type()  : string
Get the post's post type.
get_post_type_object()  : Clarkson_Post_Type|null
Get the post's post type object.
get_raw_content()  : string
Get the raw post content.
get_status()  : string
Get the post's post status.
get_template()  : Clarkson_Template
get_terms()  : array<string|int, Clarkson_Term>|WP_Error
Retrieve the terms for a post.
get_thumbnail()  : string
Get the thumbnail HTML for the post.
get_thumbnail_id()  : int
Get the thumbnail id by post id.
get_title()  : string
Get the title of a post by id.
has_term()  : bool
Is post associated with term?
has_thumbnail()  : bool
Check if the post has a thumbnail.
jsonSerialize()  : mixed
Return a set of data to use for json output.
remove_term()  : bool|WP_Error
Remove a post term.
reset_terms()  : array<string|int, mixed>|WP_Error
Reset terms.
set_date()  : void
Set the post date/time of the post.
set_status()  : void
Update the posts status.
update_meta()  : bool|int
Update the post meta data.

Properties

$type

The string here is the post type name used by `::get_many()`.

public static string $type = 'post'

Methods

__construct()

Clarkson_Object constructor.

public __construct(WP_Post $post) : mixed
Parameters
$post : WP_Post

Post object.

Return values
mixed

__get()

Check if name is not a wp_post object property.

public __get(string $name) : mixed
Parameters
$name : string

Post name to check.

Tags
throws
Exception

Error message.

Return values
mixed

add_comment()

Add post comment.

public add_comment(string $comment_text, int $user_id) : int
Parameters
$comment_text : string

Comment text.

$user_id : int

User id.

Tags
throws
Exception

Error message.

Return values
int

add_meta()

Add post meta data.

public add_meta(string $key, string|array<string|int, mixed> $value) : false|int
Parameters
$key : string

Post meta key.

$value : string|array<string|int, mixed>

New post meta data.

Return values
false|int

add_term()

Add a single term to a post.

public add_term(Clarkson_Term $term) : array<string|int, mixed>|WP_Error
Parameters
$term : Clarkson_Term

Term data.

Return values
array<string|int, mixed>|WP_Error

Affected Term IDs.

add_terms()

Bulk add terms to a post.

public add_terms(string $taxonomy, array<string|int, Clarkson_Term$terms) : array<string|int, mixed>|WP_Error
Parameters
$taxonomy : string

Taxonomy.

$terms : array<string|int, Clarkson_Term>

Terms.

Return values
array<string|int, mixed>|WP_Error

Terms array.

delete()

Delete post.

public delete() : void
Return values
void

delete_meta()

Delete post meta data.

public delete_meta(string $key[, null $value = null ]) : bool
Parameters
$key : string

Post meta key.

$value : null = null

Null, as the value will be deleted.

Return values
bool

get_attachments()

Get the attachments for the post.

public get_attachments([array<string|int, mixed> $args = array() ]) : array<string|int, Clarkson_Object>

See issue: https://github.com/level-level/Clarkson-Core/issues/121

Parameters
$args : array<string|int, mixed> = array()

Post arguments

Return values
array<string|int, Clarkson_Object>

Attachments.

get_author_id()

Get the post author id.

public get_author_id() : null|string
Return values
null|string

get_children()

Get the children of the post by id.

public get_children([array<string|int, mixed> $args = array() ]) : array<string|int, Clarkson_Object>

See issue: https://github.com/level-level/Clarkson-Core/issues/121

Parameters
$args : array<string|int, mixed> = array()

Post arguments

Return values
array<string|int, Clarkson_Object>

Children

get_content()

Get the post content.

public get_content() : string

See: https://github.com/level-level/Clarkson-Core/issues/122

Return values
string

get_date()

Get the date the post was created in post_date_gmt format.

public get_date([string $format = 'U' ]) : string
Parameters
$format : string = 'U'

PHP Date format.

Return values
string

get_date_i18n()

Get the date in localized format.

public get_date_i18n([string $format = 'U' ][, bool $gmt = false ]) : string
Parameters
$format : string = 'U'

Date format.

$gmt : bool = false

Whether to convert to GMT for time.

Return values
string

get_excerpt()

Get the post excerpt.

public get_excerpt() : string

See the issue: https://github.com/level-level/Clarkson-Core/issues/122

Return values
string

get_id()

Get the id of a post.

public get_id() : int
Return values
int

The post id.

get_local_date()

Get the local date the post was created.

public get_local_date([string $format = 'U' ]) : string
Parameters
$format : string = 'U'

Date format.

Return values
string

get_many()

Get multiple posts, without pagination.

public static get_many(array<string|int, mixed> $args[, mixed &$post_query = null ]) : array<string|int, Clarkson_Object>
Parameters
$args : array<string|int, mixed>

Post query arguments.

$post_query : mixed = null

The $post_query is passed by reference and will be filled with the WP_Query that produced these results.

Tags
example

\Clarkson_Object::get_many( array( 'posts_per_page' => 5 ), $post_query );

Return values
array<string|int, Clarkson_Object>

get_object()

Get the WordPress post object.

public get_object() : WP_Post
Return values
WP_Post

The post object.

get_one()

Gets the first result from a `::get_many()` query.

public static get_one([array<string|int, mixed> $args = array() ]) : Clarkson_Object|null
Parameters
$args : array<string|int, mixed> = array()

Post query arguments.

Return values
Clarkson_Object|null

Get the post permalink.

public get_permalink() : false|string
Return values
false|string

Post url.

get_post_name()

Get post name (slug) by id.

public get_post_name() : string
Return values
string

Post name.

get_post_type()

Get the post's post type.

public get_post_type() : string
Return values
string

get_raw_content()

Get the raw post content.

public get_raw_content() : string
Return values
string

get_status()

Get the post's post status.

public get_status() : string
Return values
string

get_terms()

Retrieve the terms for a post.

public get_terms(string $taxonomy[, array<string|int, mixed> $args = array() ]) : array<string|int, Clarkson_Term>|WP_Error
Parameters
$taxonomy : string

Optional. The taxonomy for which to retrieve terms. Default 'post_tag'.

$args : array<string|int, mixed> = array()

Optional. arguments. Default empty array.

Return values
array<string|int, Clarkson_Term>|WP_Error

List of post tags or a WP_Error.

get_thumbnail()

Get the thumbnail HTML for the post.

public get_thumbnail([array<string|int, mixed>|string $size = 'thumbnail' ][, array<string|int, mixed>|string $attr = '' ]) : string
Parameters
$size : array<string|int, mixed>|string = 'thumbnail'

Thumbnail size.

$attr : array<string|int, mixed>|string = ''

Thumbnail attributes.

Return values
string

get_thumbnail_id()

Get the thumbnail id by post id.

public get_thumbnail_id() : int
Return values
int

The ID of the post, 0 on failure.

get_title()

Get the title of a post by id.

public get_title() : string
Return values
string

Escaped post title.

has_thumbnail()

Check if the post has a thumbnail.

public has_thumbnail() : bool
Return values
bool

jsonSerialize()

Return a set of data to use for json output.

public jsonSerialize() : mixed

We can't just return $this->_post, because these values will only return raw unfiltered data.

Return values
mixed

remove_term()

Remove a post term.

public remove_term(Clarkson_Term $term) : bool|WP_Error
Parameters
$term : Clarkson_Term

Post term.

Return values
bool|WP_Error

True on success, false or WP_Error on failure.

reset_terms()

Reset terms.

public reset_terms(string $taxonomy, array<string|int, Clarkson_Term$terms) : array<string|int, mixed>|WP_Error

Will delete all terms for a given taxonomy. Adds all passed terms or overwrites existing terms.

Parameters
$taxonomy : string

Taxonomy.

$terms : array<string|int, Clarkson_Term>

Terms.

Return values
array<string|int, mixed>|WP_Error

Affected Term IDs.

set_date()

Set the post date/time of the post.

public set_date(int $time) : void
Parameters
$time : int

PHP timestamp.

Return values
void

set_status()

Update the posts status.

public set_status(string $status) : void
Parameters
$status : string

New post status.

Return values
void

update_meta()

Update the post meta data.

public update_meta(string $key, string|array<string|int, mixed> $value) : bool|int
Parameters
$key : string

Post meta key.

$value : string|array<string|int, mixed>

New post meta data.

Return values
bool|int

        

Search results