PHP 클래스 Extended_CPT_Admin

파일 보기 프로젝트 열기: johnbillion/extended-cpts 1 사용 예제들

공개 프로퍼티들

프로퍼티 타입 설명
$args
$cpt

보호된 프로퍼티들

프로퍼티 타입 설명
$_cols
$connection_exists
$defaults array Default arguments for custom post types.
$the_cols

공개 메소드들

메소드 설명
__construct ( Extended_CPT $cpt, array $args = [] ) Class constructor.
_log_default_cols ( array $cols ) : array Logs the default columns so we don't remove any custom columns added by other plugins.
add_query_vars ( array $vars ) : array Add our filter names to the public query vars.
admin_head ( ) Add some CSS to the post listing screen. Used to hide various screen elements.
bulk_post_updated_messages ( array $messages, array $counts ) : array Add our bulk post type updated messages.
col ( string $col ) Output the column data for our custom columns.
col_connection ( string $connection, array $args ) Output column data for a Posts 2 Posts connection.
col_featured_image ( string $image_size, array $args ) Output column data for a post's featured image.
col_post_field ( string $field, array $args ) Output column data for a post field.
col_post_meta ( string $meta_key, array $args ) Output column data for a post meta field.
col_taxonomy ( string $taxonomy, array $args ) Output column data for a taxonomy's term names.
cols ( array $cols ) : array Add columns to the admin screen for this post type.
default_sort ( ) Set the default sort field and sort order on our post type admin screen.
enter_title_here ( string $title, WP_Post $post ) : string Set the placeholder text for the title field for this post type.
filters ( ) Output custom filter dropdown menus on the admin screen for this post type.
glance_items ( array $items ) : array Add our post type to the 'At a Glance' widget on the WordPress 3.8+ dashboard.
maybe_filter ( WP_Query $wp_query ) Filter posts by our custom admin filters.
maybe_sort_by_fields ( WP_Query $wp_query ) Set the relevant query vars for sorting posts by our admin sortables.
maybe_sort_by_taxonomy ( array $clauses, WP_Query $wp_query ) : array Filter the query's SQL clauses so we can sort posts by taxonomy terms.
post_updated_messages ( array $messages ) : array Add our post type updated messages.
remove_quick_edit_action ( array $actions, WP_Post $post ) : array Removes the Quick Edit link from the post row actions.
remove_quick_edit_menu ( array $actions ) : array Removes the Quick Edit link from the bulk actions menu.
sortables ( array $cols ) : array Add our custom columns to the list of sortable columns.

보호된 메소드들

메소드 설명
get_current_post_type ( ) : string Returns the name of the post type for the current request.
get_item_title ( array $item ) : string Get a sensible title for the current item (usually the arguments array for a column)
n ( string $single, string $plural, integer $number ) : string A non-localised version of _n()
p2p_connection_exists ( string $connection ) : boolean Check if a certain Posts 2 Posts connection exists.

메소드 상세

__construct() 공개 메소드

Class constructor.
public __construct ( Extended_CPT $cpt, array $args = [] )
$cpt Extended_CPT An extended post type object.
$args array Optional. The post type arguments.

_log_default_cols() 공개 메소드

Logs the default columns so we don't remove any custom columns added by other plugins.
public _log_default_cols ( array $cols ) : array
$cols array The default columns for this post type screen
리턴 array The default columns for this post type screen

add_query_vars() 공개 메소드

Add our filter names to the public query vars.
public add_query_vars ( array $vars ) : array
$vars array Public query variables
리턴 array Updated public query variables

admin_head() 공개 메소드

Add some CSS to the post listing screen. Used to hide various screen elements.
public admin_head ( )

bulk_post_updated_messages() 공개 메소드

The messages are as follows: - updated => "Post updated." | "[n] posts updated." - locked => "Post not updated, somebody is editing it." | "[n] posts not updated, somebody is editing them." - deleted => "Post permanently deleted." | "[n] posts permanently deleted." - trashed => "Post moved to the trash." | "[n] posts moved to the trash." - untrashed => "Post restored from the trash." | "[n] posts restored from the trash."
public bulk_post_updated_messages ( array $messages, array $counts ) : array
$messages array An associative array of bulk post updated messages with post type as keys.
$counts array An array of counts for each key in `$messages`.
리턴 array Updated array of bulk post updated messages.

col() 공개 메소드

Output the column data for our custom columns.
public col ( string $col )
$col string The column name

col_connection() 공개 메소드

Output column data for a Posts 2 Posts connection.
public col_connection ( string $connection, array $args )
$connection string The ID of the connection type
$args array Array of arguments for a given connection type

col_post_field() 공개 메소드

Output column data for a post field.
public col_post_field ( string $field, array $args )
$field string The post field
$args array Array of arguments for this field

col_post_meta() 공개 메소드

Output column data for a post meta field.
public col_post_meta ( string $meta_key, array $args )
$meta_key string The post meta key
$args array Array of arguments for this field

col_taxonomy() 공개 메소드

Output column data for a taxonomy's term names.
public col_taxonomy ( string $taxonomy, array $args )
$taxonomy string The taxonomy name
$args array Array of arguments for this field

cols() 공개 메소드

Each item in the admin_cols array is either a string name of an existing column, or an associative array of information for a custom column. Defining a custom column is easy. Just define an array which includes the column title, column type, and optional callback function. You can display columns for post meta, taxonomy terms, post fields, the featured image, and custom functions. The example below adds two columns; one which displays the value of the post's event_type meta key and one which lists the post's terms from the location taxonomy: register_extended_post_type( 'event', array( 'admin_cols' => array( 'event_type' => array( 'title' => 'Event Type', 'meta_key' => 'event_type' ), 'event_location' => array( 'title' => 'Location', 'taxonomy' => 'location' ) ) ) ); That's all you need to do. The columns will handle all the sorting and safely outputting the data (escaping text, and comma-separating taxonomy terms). No more messing about with all of those annoyingly named column filters and actions. Each item in the admin_cols array must contain one of the following elements which defines the column type: - taxonomy - The name of a taxonomy - meta_key - A post meta key - post_field - The name of a post field (eg. post_excerpt) - featured_image - A featured image size (eg. thumbnail) - connection - A connection ID registered with the Posts 2 Posts plugin - function - The name of a callback function The value for the corresponding taxonomy terms, post meta or post field are safely escaped and output into the column, and the values are used to provide the sortable functionality for the column. For featured images, the post's featured image of that size will be displayed if there is one. There are a few optional elements: - title - Generated from the field if not specified. - function - The name of a callback function for the column (eg. my_function) which gets called instead of the built-in function for handling that column. Note that it's not passed any parameters, so it must use the global $post object. - default - Specifies that the admin screen should be sorted by this column by default (instead of sorting by post date). Value should be one of asc or desc to control the default order. - width & height - These are only used for the featured_image column type and allow you to set an explicit width and/or height on the tag. Handy for downsizing the image. - field & value - These are used for the connection column type and allow you to specify a connection meta field and value from the fields argument of the connection type. - date_format - This is used with the meta_key column type. The value of the meta field will be treated as a timestamp if this is present. Unix and MySQL format timestamps are supported in the meta value. Pass in boolean true to format the date according to the 'Date Format' setting, or pass in a valid date formatting string (eg. d/m/Y H:i:s). - cap - A capability required in order for this column to be displayed to the current user. Defaults to null, meaning the column is shown to all users. - sortable - A boolean value which specifies whether the column should be sortable. Defaults to true.
public cols ( array $cols ) : array
$cols array Associative array of columns
리턴 array Updated array of columns

default_sort() 공개 메소드

Set the default sort field and sort order on our post type admin screen.
public default_sort ( )

enter_title_here() 공개 메소드

Set the placeholder text for the title field for this post type.
public enter_title_here ( string $title, WP_Post $post ) : string
$title string The placeholder text.
$post WP_Post The current post.
리턴 string The updated placeholder text.

filters() 공개 메소드

Each item in the admin_filters array is an associative array of information for a filter. Defining a filter is easy. Just define an array which includes the filter title and filter type. You can display filters for post meta fields and taxonomy terms. The example below adds filters for the event_type meta key and the location taxonomy: register_extended_post_type( 'event', array( 'admin_filters' => array( 'event_type' => array( 'title' => 'Event Type', 'meta_key' => 'event_type' ), 'event_location' => array( 'title' => 'Location', 'taxonomy' => 'location' ), 'event_is' => array( 'title' => 'All Events', 'meta_exists' => array( 'event_featured' => 'Featured Events', 'event_cancelled' => 'Cancelled Events' ) ), ) ) ); That's all you need to do. WordPress handles taxonomy term filtering itself, and the plugin handles the dropdown menu and filtering for post meta. Each item in the admin_filters array needs either a taxonomy, meta_key, meta_search, or meta_exists element containing the corresponding taxonomy name or post meta key. The meta_exists filter outputs a dropdown menu listing each of the meta_exists fields, allowing users to filter the screen by posts which have the corresponding meta field. The meta_search filter outputs a search input, allowing users to filter the screen by an arbitrary search value. There are a few optional elements: - title - The filter title. If omitted, the title will use the all_items taxonomy label or a formatted version of the post meta key. - cap - A capability required in order for this filter to be displayed to the current user. Defaults to null, meaning the filter is shown to all users.
public filters ( )

get_current_post_type() 보호된 정적인 메소드

Returns the name of the post type for the current request.
protected static get_current_post_type ( ) : string
리턴 string The post type name.

get_item_title() 보호된 메소드

Get a sensible title for the current item (usually the arguments array for a column)
protected get_item_title ( array $item ) : string
$item array An array of arguments
리턴 string The item title

glance_items() 공개 메소드

Add our post type to the 'At a Glance' widget on the WordPress 3.8+ dashboard.
public glance_items ( array $items ) : array
$items array Array of items to display on the widget.
리턴 array Updated array of items.

maybe_filter() 공개 메소드

Filter posts by our custom admin filters.
public maybe_filter ( WP_Query $wp_query )
$wp_query WP_Query Looks a bit like a `WP_Query` object

maybe_sort_by_fields() 공개 메소드

Set the relevant query vars for sorting posts by our admin sortables.
public maybe_sort_by_fields ( WP_Query $wp_query )
$wp_query WP_Query The current `WP_Query` object.

maybe_sort_by_taxonomy() 공개 메소드

Filter the query's SQL clauses so we can sort posts by taxonomy terms.
public maybe_sort_by_taxonomy ( array $clauses, WP_Query $wp_query ) : array
$clauses array The current query's SQL clauses.
$wp_query WP_Query The current `WP_Query` object.
리턴 array The updated SQL clauses.

n() 보호된 정적인 메소드

A non-localised version of _n()
protected static n ( string $single, string $plural, integer $number ) : string
$single string The text that will be used if $number is 1
$plural string The text that will be used if $number is not 1
$number integer The number to compare against to use either `$single` or `$plural`
리턴 string Either `$single` or `$plural` text

p2p_connection_exists() 보호된 메소드

This is just a caching wrapper for p2p_connection_exists(), which performs a database query on every call.
protected p2p_connection_exists ( string $connection ) : boolean
$connection string A connection type.
리턴 boolean Whether the connection exists.

post_updated_messages() 공개 메소드

The messages are as follows: 1 => "Post updated. {View Post}" 2 => "Custom field updated." 3 => "Custom field deleted." 4 => "Post updated." 5 => "Post restored to revision from [date]." 6 => "Post published. {View post}" 7 => "Post saved." 8 => "Post submitted. {Preview post}" 9 => "Post scheduled for: [date]. {Preview post}" 10 => "Post draft updated. {Preview post}"
public post_updated_messages ( array $messages ) : array
$messages array An associative array of post updated messages with post type as keys.
리턴 array Updated array of post updated messages.

remove_quick_edit_action() 공개 메소드

Removes the Quick Edit link from the post row actions.
public remove_quick_edit_action ( array $actions, WP_Post $post ) : array
$actions array Array of post actions
$post WP_Post The current post object
리턴 array Array of updated post actions

remove_quick_edit_menu() 공개 메소드

Removes the Quick Edit link from the bulk actions menu.
public remove_quick_edit_menu ( array $actions ) : array
$actions array Array of bulk actions
리턴 array Array of updated bulk actions

sortables() 공개 메소드

Add our custom columns to the list of sortable columns.
public sortables ( array $cols ) : array
$cols array Associative array of sortable columns
리턴 array Updated array of sortable columns

프로퍼티 상세

$_cols 보호되어 있는 프로퍼티

protected $_cols

$args 공개적으로 프로퍼티

public $args

$connection_exists 보호되어 있는 프로퍼티

protected $connection_exists

$cpt 공개적으로 프로퍼티

public $cpt

$defaults 보호되어 있는 프로퍼티

Default arguments for custom post types.
protected array $defaults
리턴 array

$the_cols 보호되어 있는 프로퍼티

protected $the_cols