PHP Class Extended_CPT_Admin

Afficher le fichier Open project: johnbillion/extended-cpts Class Usage Examples

Méthodes publiques

Свойство Type Description
$args
$cpt

Protected Properties

Свойство Type Description
$_cols
$connection_exists
$defaults array Default arguments for custom post types.
$the_cols

Méthodes publiques

Méthode Description
__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.

Méthodes protégées

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

Method Details

__construct() public méthode

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() public méthode

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
Résultat array The default columns for this post type screen

add_query_vars() public méthode

Add our filter names to the public query vars.
public add_query_vars ( array $vars ) : array
$vars array Public query variables
Résultat array Updated public query variables

admin_head() public méthode

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

bulk_post_updated_messages() public méthode

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`.
Résultat array Updated array of bulk post updated messages.

col() public méthode

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

col_connection() public méthode

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() public méthode

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() public méthode

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() public méthode

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() public méthode

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
Résultat array Updated array of columns

default_sort() public méthode

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

enter_title_here() public méthode

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.
Résultat string The updated placeholder text.

filters() public méthode

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() protected static méthode

Returns the name of the post type for the current request.
protected static get_current_post_type ( ) : string
Résultat string The post type name.

get_item_title() protected méthode

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
Résultat string The item title

glance_items() public méthode

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.
Résultat array Updated array of items.

maybe_filter() public méthode

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() public méthode

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() public méthode

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.
Résultat array The updated SQL clauses.

n() protected static méthode

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`
Résultat string Either `$single` or `$plural` text

p2p_connection_exists() protected méthode

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.
Résultat boolean Whether the connection exists.

post_updated_messages() public méthode

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.
Résultat array Updated array of post updated messages.

remove_quick_edit_action() public méthode

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
Résultat array Array of updated post actions

remove_quick_edit_menu() public méthode

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

sortables() public méthode

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

Property Details

$_cols protected_oe property

protected $_cols

$args public_oe property

public $args

$connection_exists protected_oe property

protected $connection_exists

$cpt public_oe property

public $cpt

$defaults protected_oe property

Default arguments for custom post types.
protected array $defaults
Résultat array

$the_cols protected_oe property

protected $the_cols