PHP Class WPDKPost

## Overview The WPDKPost class is a wrap of WordPress Post record. In addition this class provides a lot of methods and properties. ### Properties naming You'll see that a lot of properties class are written in lowercase and underscore mode as $post_date. This beacouse they are a map of database record. ### Post onfly ### Create a virtual post
Author: =undo= ([email protected])
Inheritance: extends WPDKObject
Datei anzeigen Open project: wpxtreme/wpdk Class Usage Examples

Public Properties

Property Type Description
$ID integer The post ID
$__version string Override version
$comment_count integer Number of comments, pings, and trackbacks combined
$comment_status string The comment status, ie. open. Max 20 char
$guid string The guid. Global Unique Identifier. The “real” URL to the post, not the permalink version. For pages, this is the actual URL. In the case of files (attachments), this holds the URL to the file.
$menu_order integer Holds values for display order of pages. Only works with pages, not posts.
$ping_status string The ping status, ie. open. Max 20 char
$pinged array List of urls that have been pinged (for published posts)
$post_author integer The post author ID
$post_category integer Number representing post category ID#. This property is not present on databse record.
$post_content string The post content
$post_content_filtered string If you’ve got a plugin that runs a very resource heavy filter on content, you might consider caching the results with post_content_filtered, and calling that from the front end instead.
$post_date string The Post date
$post_date_gmt string The post date in GMT
$post_excerpt string The post excerpt
$post_meta array A key values pair array with the list of post meta for this post.
$post_mime_type string Typical values are: text/html, image/png, image/jpg
$post_modified string Modified date
$post_modified_gmt string Modifed date in GMT
$post_name string The post name. Same as post slug. Max 200 char
$post_parent integer Parent Post ID
$post_password string Protect post password. Will be empty if no password. Max 20 char
$post_status string Post status, ie. publish, draft. Max 20 char
$post_title string The post title
$post_type string The post type. Used by Custom Post. Default 'post'. Self-explanatory for pages and posts. Any files uploaded are attachments and post revisions saved as revision
$to_ping array List of urls to ping when post is published (for unpublished posts)

Public Methods

Method Description
__construct ( string | integer | object | null $record = null, string $post_type = WPDKPostType::POST ) : WPDKPost Create an instance of WPDKPost class
delete ( ) : mixed Delete permately this post from database
duplicate ( string | integer | object $post, array $args = [] ) : WPDKPost Return an instance of WPDKPost as clone of input post. The new 'duplicate' post is stored on db.
imageAttachments ( string $size = 'full', integer $index = 1 ) : boolean | WPDKHTMLTagImg Return the nth instance of WPDKHTMLTagImg class as attachment image in this post.
imageAttachmentsWithID ( integer $post_id, string $size = 'full', integer $index = 1 ) : boolean | WPDKHTMLTagImg Return the nth instance of WPDKHTMLTagImg class as attachment image in a post.
imageContent ( ) : boolean | WPDKHTMLTagImg Return an instance of WPDKHTMLTagImg class with the first image found in this post content.
imageContentWithID ( integer $post_id ) : boolean | WPDKHTMLTagImg Return an instance of WPDKHTMLTagImg class with the first image found in the post content.
insert ( ) : integer | WP_Error Insert or update a post.
metaValue ( string $meta_key ) : boolean | mixed Return or set a single post meta value
metaValues ( string $meta_key ) : boolean | mixed Return o set post meta values
publish ( ) : integer | WP_Error Publish a post.
thumbnail ( string $size = 'full' ) : boolean | WPDKHTMLTagImg Return an instance of WPDKHTMLTagImg class with thumbmail image description. If the thumbnail is not found return FALSE. You can use the WPDKHTMLTagImg instance to read the property, get the HTML markup or display the image.
thumbnailWithID ( integer $post_id, string $size = 'full' ) : boolean | WPDKHTMLTagImg Return an instance of WPDKHTMLTagImg class with thumbmail image description. If the thumbnail is not found return FALSE. You can use the WPDKHTMLTagImg instance to read the property, get the HTML markup or display the image.
trash ( ) : mixed Moves a post or page to the Trash If trash is disabled, the post or page is permanently deleted.
untrash ( ) : mixed Restores a post or page from the Trash
update ( ) : integer | WP_Error Update this post on database. Also this method check if you are in admin backend area for this custom post.
updateMeta ( array $args = [] ) Update meta
updateMetaWithID ( integer $post_id, array $args = [] ) Update the post meta with post id

Private Methods

Method Description
initPostByArgs ( array | object $args ) Init this instance of WPDKPost as a empty Post
initPostByID ( integer $id_post ) Init this instance of WPDKPost as post from Post ID
initPostByPost ( object $post ) Init this instance of WPDKPost as post from Post database object
postEmpty ( ) : array Return a Key value pairs array with property and value for an empty post. The properties are set to a default values.

Method Details

__construct() public method

Create an instance of WPDKPost class
public __construct ( string | integer | object | null $record = null, string $post_type = WPDKPostType::POST ) : WPDKPost
$record string | integer | object | null Optional. Post ID, post object, post slug or null
$post_type string Optional. If $record is a string (slug) then this is the post type where search. Default is 'page'
return WPDKPost

delete() public method

Delete permately this post from database
Since: 0.9
public delete ( ) : mixed
return mixed False on failure

duplicate() public static method

Return an instance of WPDKPost as clone of input post. The new 'duplicate' post is stored on db.
Since: 1.5.16
public static duplicate ( string | integer | object $post, array $args = [] ) : WPDKPost
$post string | integer | object Post ID, post object, post slug.
$args array Optional. Additional args. {
return WPDKPost

imageAttachments() public method

self::imageFromAttachmentsWithID( 2294, 'thumbnail' )->display();
Since: 1.3.1
public imageAttachments ( string $size = 'full', integer $index = 1 ) : boolean | WPDKHTMLTagImg
$size string Optional. Size of attachment image
$index integer Optional. Index of image. Default first attach image is returned
return boolean | WPDKHTMLTagImg

imageAttachmentsWithID() public static method

self::imageFromAttachmentsWithID( 2294, 'thumbnail' )->display();
Since: 1.3.1
public static imageAttachmentsWithID ( integer $post_id, string $size = 'full', integer $index = 1 ) : boolean | WPDKHTMLTagImg
$post_id integer Post id
$size string Optional. Size of attachment image
$index integer Optional. Index of image. Default first attach image is returned
return boolean | WPDKHTMLTagImg

imageContent() public method

Return an instance of WPDKHTMLTagImg class with the first image found in this post content.
Since: 1.3.1
public imageContent ( ) : boolean | WPDKHTMLTagImg
return boolean | WPDKHTMLTagImg

imageContentWithID() public static method

Return an instance of WPDKHTMLTagImg class with the first image found in the post content.
Since: 1.3.1
public static imageContentWithID ( integer $post_id ) : boolean | WPDKHTMLTagImg
$post_id integer Post ID
return boolean | WPDKHTMLTagImg

insert() public method

Insert or update a post.
Since: 1.5.16
public insert ( ) : integer | WP_Error
return integer | WP_Error

metaValue() public method

Return or set a single post meta value
Since: 1.3.1
public metaValue ( string $meta_key ) : boolean | mixed
$meta_key string Meta key
return boolean | mixed

metaValues() public method

Return o set post meta values
Since: 1.3.1
public metaValues ( string $meta_key ) : boolean | mixed
$meta_key string Meta key
return boolean | mixed

publish() public method

Publish a post.
Since: 1.5.16
public publish ( ) : integer | WP_Error
return integer | WP_Error

thumbnail() public method

Return an instance of WPDKHTMLTagImg class with thumbmail image description. If the thumbnail is not found return FALSE. You can use the WPDKHTMLTagImg instance to read the property, get the HTML markup or display the image.
Since: 1.3.1
public thumbnail ( string $size = 'full' ) : boolean | WPDKHTMLTagImg
$size string Optional. Default 'full'.
return boolean | WPDKHTMLTagImg

thumbnailWithID() public static method

Return an instance of WPDKHTMLTagImg class with thumbmail image description. If the thumbnail is not found return FALSE. You can use the WPDKHTMLTagImg instance to read the property, get the HTML markup or display the image.
Since: 1.3.1
public static thumbnailWithID ( integer $post_id, string $size = 'full' ) : boolean | WPDKHTMLTagImg
$post_id integer Post id
$size string Optional. Default 'full'
return boolean | WPDKHTMLTagImg

trash() public method

Moves a post or page to the Trash If trash is disabled, the post or page is permanently deleted.
Since: 0.9
public trash ( ) : mixed
return mixed False on failure

untrash() public method

Restores a post or page from the Trash
Since: 0.9
public untrash ( ) : mixed
return mixed False on failure

update() public method

In this case the post update if turn off and save the post meta only. Return value 0 or WP_Error on failure. The post ID on success.
Since: 0.9
public update ( ) : integer | WP_Error
return integer | WP_Error

updateMeta() public method

Update meta
Since: 1.4.20
public updateMeta ( array $args = [] )
$args array

updateMetaWithID() public static method

Update the post meta with post id
Since: 1.4.20
public static updateMetaWithID ( integer $post_id, array $args = [] )
$post_id integer Post ID
$args array Key value pairs array with meta_key => meta_value

Property Details

$ID public_oe property

The post ID
public int $ID
return integer

$__version public_oe property

Override version
public string $__version
return string

$comment_count public_oe property

Number of comments, pings, and trackbacks combined
public int $comment_count
return integer

$comment_status public_oe property

The comment status, ie. open. Max 20 char
public string $comment_status
return string

$guid public_oe property

The guid. Global Unique Identifier. The “real” URL to the post, not the permalink version. For pages, this is the actual URL. In the case of files (attachments), this holds the URL to the file.
public string $guid
return string

$menu_order public_oe property

Holds values for display order of pages. Only works with pages, not posts.
public int $menu_order
return integer

$ping_status public_oe property

The ping status, ie. open. Max 20 char
public string $ping_status
return string

$pinged public_oe property

List of urls that have been pinged (for published posts)
public array $pinged
return array

$post_author public_oe property

The post author ID
public int $post_author
return integer

$post_category public_oe property

Number representing post category ID#. This property is not present on databse record.
public int $post_category
return integer

$post_content public_oe property

The post content
public string $post_content
return string

$post_content_filtered public_oe property

If you’ve got a plugin that runs a very resource heavy filter on content, you might consider caching the results with post_content_filtered, and calling that from the front end instead.
public string $post_content_filtered
return string

$post_date public_oe property

The Post date
public string $post_date
return string

$post_date_gmt public_oe property

The post date in GMT
public string $post_date_gmt
return string

$post_excerpt public_oe property

The post excerpt
public string $post_excerpt
return string

$post_meta public_oe property

A key values pair array with the list of post meta for this post.
Since: 1.5.13
public array $post_meta
return array

$post_mime_type public_oe property

Typical values are: text/html, image/png, image/jpg
public string $post_mime_type
return string

$post_modified public_oe property

Modified date
public string $post_modified
return string

$post_modified_gmt public_oe property

Modifed date in GMT
public string $post_modified_gmt
return string

$post_name public_oe property

The post name. Same as post slug. Max 200 char
public string $post_name
return string

$post_parent public_oe property

Parent Post ID
public int $post_parent
return integer

$post_password public_oe property

Protect post password. Will be empty if no password. Max 20 char
public string $post_password
return string

$post_status public_oe property

Post status, ie. publish, draft. Max 20 char
public string $post_status
return string

$post_title public_oe property

The post title
public string $post_title
return string

$post_type public_oe property

The post type. Used by Custom Post. Default 'post'. Self-explanatory for pages and posts. Any files uploaded are attachments and post revisions saved as revision
public string $post_type
return string

$to_ping public_oe property

List of urls to ping when post is published (for unpublished posts)
public array $to_ping
return array