PHP Class Post_Command, wp-cli

Inheritance: extends WP_CLI_Command
Mostrar archivo Open project: wp-cli/wp-cli

Protected Properties

Property Type Description
$obj_fields
$obj_type

Public Methods

Method Description
__construct ( )
create ( $args, $assoc_args ) Create a new post.
delete ( $args, $assoc_args ) Delete an existing post.
edit ( $args, $_ ) Launch system editor to edit post content.
generate ( $args, $assoc_args ) Generate some posts.
get ( $args, $assoc_args ) Get details about a post.
list_ ( $_, $assoc_args ) Get a list of posts.
update ( $args, $assoc_args ) Update one or more existing posts.

Protected Methods

Method Description
_edit ( $content, $title )

Private Methods

Method Description
maybe_make_child ( )
maybe_reset_depth ( )
read_from_file_or_stdin ( string $arg ) : string Read post content from file or STDIN

Method Details

__construct() public method

public __construct ( )

_edit() protected method

protected _edit ( $content, $title )

create() public method

## OPTIONS [] : Read post content from . If this value is present, the --post_content argument will be ignored. Passing - as the filename will cause post content to be read from STDIN. [--=] : Associative args for the new post. See wp_insert_post(). [--edit] : Immediately open system's editor to write or edit post content. If content is read from a file, from STDIN, or from the --post_content argument, that text will be loaded into the editor. [--porcelain] : Output just the new post id. ## EXAMPLES # Create post and schedule for future $ wp post create --post_type=page --post_title='A future post' --post_status=future --post_date='2020-12-01 07:00:00' Success: Created post 1921. # Create post with content from given file $ wp post create ./post-content.txt --post_category=201,345 --post_title='Post from file' Success: Created post 1922.
public create ( $args, $assoc_args )

delete() public method

## OPTIONS ... : One or more IDs of posts to delete. [--force] : Skip the trash bin. [--defer-term-counting] : Recalculate term count in batch, for a performance boost. ## EXAMPLES # Delete post skipping trash $ wp post delete 123 --force Success: Deleted post 123. # Delete all pages $ wp post delete $(wp post list --post_type='page' --format=ids) Success: Trashed post 1164. Success: Trashed post 1186. # Delete all posts in the trash $ wp post delete $(wp post list --post_status=trash --format=ids) Success: Trashed post 1268. Success: Trashed post 1294.
public delete ( $args, $assoc_args )

edit() public method

## OPTIONS : The ID of the post to edit. ## EXAMPLES # Launch system editor to edit post $ wp post edit 123
public edit ( $args, $_ )

generate() public method

Creates a specified number of new posts with dummy data. ## OPTIONS [--count=] : How many posts to generate? --- default: 100 --- [--post_type=] : The type of the generated posts. --- default: post --- [--post_status=] : The status of the generated posts. --- default: publish --- [--post_author=] : The author of the generated posts. --- default: --- [--post_date=] : The date of the generated posts. Default: current date [--post_content] : If set, the command reads the post_content from STDIN. [--max_depth=] : For hierarchical post types, generate child posts down to a certain depth. --- default: 1 --- [--format=] : Render output in a particular format. --- default: progress options: - progress - ids --- ## EXAMPLES # Generate posts. $ wp post generate --count=10 --post_type=page --post_date=1999-01-04 Generating posts 100% [================================================] 0:01 / 0:04 # Generate posts with fetched content. $ curl http://loripsum.net/api/5 | wp post generate --post_content --count=10 % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 2509 100 2509 0 0 616 0 0:00:04 0:00:04 --:--:-- 616 Generating posts 100% [================================================] 0:01 / 0:04 # Add meta to every generated posts. $ wp post generate --format=ids | xargs -d ' ' -I % wp post meta add % foo bar Success: Added custom field. Success: Added custom field. Success: Added custom field.
public generate ( $args, $assoc_args )

get() public method

## OPTIONS : The ID of the post to get. [--field=] : Instead of returning the whole post, returns the value of a single field. [--fields=] : Limit the output to specific fields. Defaults to all fields. [--format=] : Render output in a particular format. --- default: table options: - table - csv - json - yaml --- ## EXAMPLES # Save the post content to a file $ wp post get 123 --field=content > file.txt
public get ( $args, $assoc_args )

list_() public method

## OPTIONS [--=] : One or more args to pass to WP_Query. [--field=] : Prints the value of a single field for each post. [--fields=] : Limit the output to specific object fields. [--format=] : Render output in a particular format. --- default: table options: - table - csv - ids - json - count - yaml --- ## AVAILABLE FIELDS These fields will be displayed by default for each post: * ID * post_title * post_name * post_date * post_status These fields are optionally available: * post_author * post_date_gmt * post_content * post_excerpt * comment_status * ping_status * post_password * to_ping * pinged * post_modified * post_modified_gmt * post_content_filtered * post_parent * guid * menu_order * post_type * post_mime_type * comment_count * filter * url ## EXAMPLES # List post $ wp post list --field=ID 568 829 1329 1695 # List posts in JSON $ wp post list --post_type=post --posts_per_page=5 --format=json [{"ID":1,"post_title":"Hello world!","post_name":"hello-world","post_date":"2015-06-20 09:00:10","post_status":"publish"},{"ID":1178,"post_title":"Markup: HTML Tags and Formatting","post_name":"markup-html-tags-and-formatting","post_date":"2013-01-11 20:22:19","post_status":"draft"}] # List all pages $ wp post list --post_type=page --fields=post_title,post_status +-------------+-------------+ | post_title | post_status | +-------------+-------------+ | Sample Page | publish | +-------------+-------------+ # List ids of all pages and posts $ wp post list --post_type=page,post --format=ids 15 25 34 37 198 # List given posts $ wp post list --post__in=1,3 +----+--------------+-------------+---------------------+-------------+ | ID | post_title | post_name | post_date | post_status | +----+--------------+-------------+---------------------+-------------+ | 3 | Lorem Ipsum | lorem-ipsum | 2016-06-01 14:34:36 | publish | | 1 | Hello world! | hello-world | 2016-06-01 14:31:12 | publish | +----+--------------+-------------+---------------------+-------------+
public list_ ( $_, $assoc_args )

update() public method

## OPTIONS ... : One or more IDs of posts to update. [] : Read post content from . If this value is present, the --post_content argument will be ignored. Passing - as the filename will cause post content to be read from STDIN. --= : One or more fields to update. See wp_update_post(). [--defer-term-counting] : Recalculate term count in batch, for a performance boost. ## EXAMPLES $ wp post update 123 --post_name=something --post_status=draft Success: Updated post 123.
public update ( $args, $assoc_args )

Property Details

$obj_fields protected_oe property

protected $obj_fields

$obj_type protected_oe property

protected $obj_type