PHP Класс 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
Автор: =undo= ([email protected])
Наследование: extends WPDKObject
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$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)

Открытые методы

Метод Описание
__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

Приватные методы

Метод Описание
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.

Описание методов

__construct() публичный Метод

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'
Результат WPDKPost

delete() публичный Метод

Delete permately this post from database
С версии: 0.9
public delete ( ) : mixed
Результат mixed False on failure

duplicate() публичный статический Метод

Return an instance of WPDKPost as clone of input post. The new 'duplicate' post is stored on db.
С версии: 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. {
Результат WPDKPost

imageAttachments() публичный Метод

self::imageFromAttachmentsWithID( 2294, 'thumbnail' )->display();
С версии: 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
Результат boolean | WPDKHTMLTagImg

imageAttachmentsWithID() публичный статический Метод

self::imageFromAttachmentsWithID( 2294, 'thumbnail' )->display();
С версии: 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
Результат boolean | WPDKHTMLTagImg

imageContent() публичный Метод

Return an instance of WPDKHTMLTagImg class with the first image found in this post content.
С версии: 1.3.1
public imageContent ( ) : boolean | WPDKHTMLTagImg
Результат boolean | WPDKHTMLTagImg

imageContentWithID() публичный статический Метод

Return an instance of WPDKHTMLTagImg class with the first image found in the post content.
С версии: 1.3.1
public static imageContentWithID ( integer $post_id ) : boolean | WPDKHTMLTagImg
$post_id integer Post ID
Результат boolean | WPDKHTMLTagImg

insert() публичный Метод

Insert or update a post.
С версии: 1.5.16
public insert ( ) : integer | WP_Error
Результат integer | WP_Error

metaValue() публичный Метод

Return or set a single post meta value
С версии: 1.3.1
public metaValue ( string $meta_key ) : boolean | mixed
$meta_key string Meta key
Результат boolean | mixed

metaValues() публичный Метод

Return o set post meta values
С версии: 1.3.1
public metaValues ( string $meta_key ) : boolean | mixed
$meta_key string Meta key
Результат boolean | mixed

publish() публичный Метод

Publish a post.
С версии: 1.5.16
public publish ( ) : integer | WP_Error
Результат integer | WP_Error

thumbnail() публичный Метод

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.
С версии: 1.3.1
public thumbnail ( string $size = 'full' ) : boolean | WPDKHTMLTagImg
$size string Optional. Default 'full'.
Результат boolean | WPDKHTMLTagImg

thumbnailWithID() публичный статический Метод

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.
С версии: 1.3.1
public static thumbnailWithID ( integer $post_id, string $size = 'full' ) : boolean | WPDKHTMLTagImg
$post_id integer Post id
$size string Optional. Default 'full'
Результат boolean | WPDKHTMLTagImg

trash() публичный Метод

Moves a post or page to the Trash If trash is disabled, the post or page is permanently deleted.
С версии: 0.9
public trash ( ) : mixed
Результат mixed False on failure

untrash() публичный Метод

Restores a post or page from the Trash
С версии: 0.9
public untrash ( ) : mixed
Результат mixed False on failure

update() публичный Метод

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.
С версии: 0.9
public update ( ) : integer | WP_Error
Результат integer | WP_Error

updateMeta() публичный Метод

Update meta
С версии: 1.4.20
public updateMeta ( array $args = [] )
$args array

updateMetaWithID() публичный статический Метод

Update the post meta with post id
С версии: 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

Описание свойств

$ID публичное свойство

The post ID
public int $ID
Результат integer

$__version публичное свойство

Override version
public string $__version
Результат string

$comment_count публичное свойство

Number of comments, pings, and trackbacks combined
public int $comment_count
Результат integer

$comment_status публичное свойство

The comment status, ie. open. Max 20 char
public string $comment_status
Результат string

$guid публичное свойство

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
Результат string

$menu_order публичное свойство

Holds values for display order of pages. Only works with pages, not posts.
public int $menu_order
Результат integer

$ping_status публичное свойство

The ping status, ie. open. Max 20 char
public string $ping_status
Результат string

$pinged публичное свойство

List of urls that have been pinged (for published posts)
public array $pinged
Результат array

$post_author публичное свойство

The post author ID
public int $post_author
Результат integer

$post_category публичное свойство

Number representing post category ID#. This property is not present on databse record.
public int $post_category
Результат integer

$post_content публичное свойство

The post content
public string $post_content
Результат string

$post_content_filtered публичное свойство

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
Результат string

$post_date публичное свойство

The Post date
public string $post_date
Результат string

$post_date_gmt публичное свойство

The post date in GMT
public string $post_date_gmt
Результат string

$post_excerpt публичное свойство

The post excerpt
public string $post_excerpt
Результат string

$post_meta публичное свойство

A key values pair array with the list of post meta for this post.
С версии: 1.5.13
public array $post_meta
Результат array

$post_mime_type публичное свойство

Typical values are: text/html, image/png, image/jpg
public string $post_mime_type
Результат string

$post_modified публичное свойство

Modified date
public string $post_modified
Результат string

$post_modified_gmt публичное свойство

Modifed date in GMT
public string $post_modified_gmt
Результат string

$post_name публичное свойство

The post name. Same as post slug. Max 200 char
public string $post_name
Результат string

$post_parent публичное свойство

Parent Post ID
public int $post_parent
Результат integer

$post_password публичное свойство

Protect post password. Will be empty if no password. Max 20 char
public string $post_password
Результат string

$post_status публичное свойство

Post status, ie. publish, draft. Max 20 char
public string $post_status
Результат string

$post_title публичное свойство

The post title
public string $post_title
Результат string

$post_type публичное свойство

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
Результат string

$to_ping публичное свойство

List of urls to ping when post is published (for unpublished posts)
public array $to_ping
Результат array