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
Afficher le fichier Open project: wpxtreme/wpdk Class Usage Examples

Méthodes publiques

Свойство 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)

Méthodes publiques

Méthode 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

Méthode 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 méthode

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'
Résultat WPDKPost

delete() public méthode

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

duplicate() public static méthode

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. {
Résultat WPDKPost

imageAttachments() public méthode

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
Résultat boolean | WPDKHTMLTagImg

imageAttachmentsWithID() public static méthode

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
Résultat boolean | WPDKHTMLTagImg

imageContent() public méthode

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

imageContentWithID() public static méthode

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
Résultat boolean | WPDKHTMLTagImg

insert() public méthode

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

metaValue() public méthode

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

metaValues() public méthode

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

publish() public méthode

Publish a post.
Since: 1.5.16
public publish ( ) : integer | WP_Error
Résultat integer | WP_Error

thumbnail() public méthode

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'.
Résultat boolean | WPDKHTMLTagImg

thumbnailWithID() public static méthode

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'
Résultat boolean | WPDKHTMLTagImg

trash() public méthode

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
Résultat mixed False on failure

untrash() public méthode

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

update() public méthode

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
Résultat integer | WP_Error

updateMeta() public méthode

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

updateMetaWithID() public static méthode

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
Résultat integer

$__version public_oe property

Override version
public string $__version
Résultat string

$comment_count public_oe property

Number of comments, pings, and trackbacks combined
public int $comment_count
Résultat integer

$comment_status public_oe property

The comment status, ie. open. Max 20 char
public string $comment_status
Résultat 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
Résultat string

$menu_order public_oe property

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

$ping_status public_oe property

The ping status, ie. open. Max 20 char
public string $ping_status
Résultat string

$pinged public_oe property

List of urls that have been pinged (for published posts)
public array $pinged
Résultat array

$post_author public_oe property

The post author ID
public int $post_author
Résultat integer

$post_category public_oe property

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

$post_content public_oe property

The post content
public string $post_content
Résultat 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
Résultat string

$post_date public_oe property

The Post date
public string $post_date
Résultat string

$post_date_gmt public_oe property

The post date in GMT
public string $post_date_gmt
Résultat string

$post_excerpt public_oe property

The post excerpt
public string $post_excerpt
Résultat 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
Résultat array

$post_mime_type public_oe property

Typical values are: text/html, image/png, image/jpg
public string $post_mime_type
Résultat string

$post_modified public_oe property

Modified date
public string $post_modified
Résultat string

$post_modified_gmt public_oe property

Modifed date in GMT
public string $post_modified_gmt
Résultat string

$post_name public_oe property

The post name. Same as post slug. Max 200 char
public string $post_name
Résultat string

$post_parent public_oe property

Parent Post ID
public int $post_parent
Résultat integer

$post_password public_oe property

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

$post_status public_oe property

Post status, ie. publish, draft. Max 20 char
public string $post_status
Résultat string

$post_title public_oe property

The post title
public string $post_title
Résultat 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
Résultat string

$to_ping public_oe property

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