Untitled diff

Created Diff never expires
333 removals
427 lines
279 additions
419 lines
<?php
<?php
/**
/**
* Video CPT
*
* @package Videos
* @author Your Name <email@example.com>
* @license http://www.gnu.org/licenses/gpl-2.0.html
* @link http://www.blazersix.com/wordpress-code-generators/
*
* @todo Remove unused code and update where needed.
*
* @wordpress-plugin
* Plugin Name: Video CPT
* Plugin Name: Video CPT
* Plugin URI:
* Plugin URI:
* Description: A generated video custom post type implementation.
* Description: A generated video custom post type implementation.
* Version: 1.0
* Version: 1.0
* Author:
* Author:
* Author URI:
* Author URI:
* License: GPLv2 or later
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
*
* @package WordPress
* @subpackage Videos
* @author Your Name <email@example.com>
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* @link http://www.blazersix.com/wordpress-code-generators/
*
* @todo Remove unneccessary code and update where needed.
*/
*/
/**
/**
* Load the Video custom post type.
*/
add_action( 'init', array( 'Blazersix_Video', 'init' ) );
/**
* Main class.
* Main class.
*
* @todo Consider breaking the admin-related functionality into a separate
* file and including in an is_admin() conditional.
*/
*/
class Blazersix_Video {
class Blazersix_Video {
/**
/**
* Register Video custom post type.
* Register Video custom post type.
*
*
* Registers the Video custom post type and related admin interface
* Registers the Video custom post type and related admin interface
* elements (custom columns, update messages, metaboxes, standard menu and
* elements (custom columns, update messages, meta boxes, standard menu).
* screen icon CSS).
*
*
* @link http://codex.wordpress.org/Function_Reference/register_post_type
* @link http://codex.wordpress.org/Function_Reference/register_post_type
*/
*/
public static function init() {
public function init() {
$labels = array(
'name' => _x( 'Videos', 'post type general name', 'textdomain' ),
'singular_name' => _x( 'Video', 'post type singular name', 'textdomain' ),
'menu_name' => _x( 'Videos', 'admin menu', 'textdomain' ),
'name_admin_bar' => _x( 'Video', 'add new on admin bar', 'textdomain' ),
'add_new' => _x( 'Add New', 'video', 'textdomain' ),
'add_new_item' => __( 'Add New Video', 'textdomain' ),
'new_item' => __( 'New Video', 'textdomain' ),
'edit_item' => __( 'Edit Video', 'textdomain' ),
'view_item' => __( 'View Video', 'textdomain' ),
'all_items' => __( 'All Videos', 'textdomain' ),
'search_items' => __( 'Search Videos', 'textdomain' ),
'parent_item_colon' => __( 'Parent Videos:', 'textdomain' ),
'not_found' => __( 'No videos found.', 'textdomain' ),
'not_found_in_trash' => __( 'No videos found in Trash.', 'textdomain' ),
);
$capabilities = array(
// Meta capabilities.
'edit_post' => 'edit_video',
'read_post' => 'read_video',
'delete_post' => 'delete_video',
// Primitive capabilities used throughout core to check permissions.
'edit_posts' => 'edit_videos',
'edit_others_posts' => 'edit_others_videos',
'publish_posts' => 'publish_videos',
'read_private_posts' => 'read_private_videos',
// Primitive capabilites translated from meta capabilities in map_meta_cap().
'read' => 'read',
'delete_posts' => 'delete_videos',
'delete_private_posts' => 'delete_private_videos',
'delete_published_posts' => 'delete_published_videos',
'delete_others_posts' => 'delete_others_videos',
'edit_private_posts' => 'edit_private_videos',
'edit_published_posts' => 'edit_published_videos'
);
register_post_type( 'video', array(
register_post_type( 'video', array(
'can_export' => true,
'can_export' => true,
'capability_type' => array( 'video', 'videos' ),
'capability_type' => array( 'video', 'videos' ),
'capabilities' => array(
'capabilities' => $capabilities,
// Meta capabilities.
'delete_with_user' => null,
'edit_post' => 'edit_video',
'description' => '',
'read_post' => 'read_video',
'exclude_from_search' => false,
'delete_post' => 'delete_video',
'has_archive' => false,
'hierarchical' => true,
// Primitive capabilities used throughout core to check permissions.
'labels' => $labels,
'edit_posts' => 'edit_videos',
'map_meta_cap' => false,
'edit_others_posts' => 'edit_others_videos',
'menu_icon' => null,
'publish_posts' => 'publish_videos',
'menu_position' => 50,
'read_private_posts' => 'read_private_videos',
'public' => true,
'publicly_queryable' => true,
// Primitive capabilites translated from meta capabilities in map_meta_cap().
'register_meta_box_cb' => array( $this, 'register_meta_boxes' ),
'read' => 'read',
'rewrite' => array(
'delete_posts' => 'delete_videos',
'slug' => 'video',
'delete_private_posts' => 'delete_private_videos',
'with_front' => false,
'delete_published_posts' => 'delete_published_videos',
'feeds' => null,
'delete_others_posts' => 'delete_others_videos',
'pages' => true,
'edit_private_posts' => 'edit_private_videos',
'ep_mask' => EP_PERMALINK,
'edit_published_posts' => 'edit_published_videos'
),
'delete_with_user' => null,
'description' => '',
'exclude_from_search' => false,
'has_archive' => false,
'hierarchical' => true,
'labels' => array(
'name' => _x( 'Videos', 'post format general name', 'textdomain' ),
'singular_name' => _x( 'Video', 'post format singular name', 'textdomain' ),
'add_new' => _x( 'Add New', 'video', 'textdomain' ),
'add_new_item' => __( 'Add New Video', 'textdomain' ),
'edit_item' => __( 'Edit Video', 'textdomain' ),
'new_item' => __( 'New Video', 'textdomain' ),
'view_item' => __( 'View Video', 'textdomain' ),
'search_items' => __( 'Search Videos', 'textdomain' ),
'not_found' => __( 'No videos found.', 'textdomain' ),
'not_found_in_trash' => __( 'No videos found in Trash.', 'textdomain' ),
'parent_item_colon' => __( 'Parent Videos:', 'textdomain' ),
'all_items' => __( 'All Videos', 'textdomain' ),
'menu_name' => __( 'Videos', 'textdomain' ),
'name_admin_bar' => _x( 'Video', 'add new on admin bar', 'textdomain' )
),
'map_meta_cap' => false,
'menu_icon' => null,
'menu_position' => 50,
'public' => true,
'publicly_queryable' => true,
'register_meta_box_cb' => array( __CLASS__, 'register_meta_boxes' ),
'rewrite' => array(
'slug' => 'video',
'with_front' => false,
'feeds' => null,
'pages' => true,
'ep_mask' => EP_PERMALINK
),
),
'query_var' => 'video',
'query_var' => 'video',
'show_ui' => true,
'show_ui' => true,
'show_in_admin_bar' => true,
'show_in_admin_bar' => true,
'show_in_menu' => true,
'show_in_menu' => true,
'show_in_nav_menus' => false,
'show_in_nav_menus' => false,
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'page-attributes', 'post-formats' ),
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'page-attributes', 'post-formats' ),
'taxonomies' => array()
'taxonomies' => array(),
) );
) );
if ( is_admin() ) {
if ( is_admin() ) {
add_filter( 'post_updated_messages', array( __CLASS__, 'updated_messages' ) );
add_filter( 'post_updated_messages', array( $this, 'updated_messages' ) );
add_filter( 'parse_query', array( __CLASS__, 'parse_admin_query' ) );
add_filter( 'parse_query', array( $this, 'parse_admin_query' ) );
add_filter( 'manage_edit-video_columns', array( __CLASS__, 'register_columns' ) );
add_filter( 'manage_edit-video_columns', array( $this, 'register_columns' ) );
add_action( 'manage_edit-video_sortable_columns', array( __CLASS__, 'register_sortable_columns' ) );
add_action( 'manage_edit-video_sortable_columns', array( $this, 'register_sortable_columns' ) );
add_action( 'manage_video_posts_custom_column', array( __CLASS__, 'display_columns' ), 10, 2 );
add_action( 'manage_video_posts_custom_column', array( $this, 'display_columns' ), 10, 2 );
add_action( 'save_post', array( __CLASS__, 'save_post' ), 10, 2 );
add_action( 'save_post', array( $this, 'save_post' ), 10, 2 );
add_action( 'admin_head', array( __CLASS__, 'icon_css' ) );
}
add_filter( 'map_meta_cap', array( __CLASS__, 'map_meta_cap' ), 10, 4 );
}
/**
* Map Video meta capabilities to primitive capabilities.
*
* @link http://justintadlock.com/archives/2010/07/10/meta-capabilities-for-custom-post-types
* @see map_meta_cap()
*
* @param array $caps Primitive capabilities determined by core.
* @param string $cap Capability name.
* @param int $user_id User ID.
* @return array Actual capabilities for meta capability.
*/
public static function map_meta_cap( $caps, $cap, $user_id, $args ) {
$meta_caps = array( 'edit_video', 'read_video', 'delete_video' );
if ( in_array( $cap, $meta_caps ) ) {
$post = get_post( $args[0] );
if ( 'revision' == $post->post_type ) {
$post = get_post( $post->post_parent );
}
$post_type = get_post_type_object( $post->post_type );
$caps = array();
if ( ! $post_type->map_meta_cap ) {
$caps[] = $post_type->cap->$cap;
}
$user_data = get_userdata( $user_id );
$post_author_data = $user_data;
if ( ! empty( $post->post_author ) ) {
$post_author_data = get_userdata( $post->post_author );
}
switch( $cap ) {
case 'edit_video' :
// If the user is the author...
if ( is_object( $post_author_data ) && $user_id == $post_author_data->ID ) {
// If the post is published...
if ( 'publish' == $post->post_status ) {
$caps[] = $post_type->cap->edit_published_posts;
} elseif ( 'trash' == $post->post_status ) {
if ( 'publish' == get_post_meta( $post->ID, '_wp_trash_meta_status', true ) ) {
$caps[] = $post_type->cap->edit_published_posts;
}
} else {
// If the post is draft...
$caps[] = $post_type->cap->edit_posts;
}
} else {
// The user is trying to edit someone else's post.
$caps[] = $post_type->cap->edit_others_posts;
// The post is published, extra cap required.
if ( 'publish' == $post->post_status ) {
$caps[] = $post_type->cap->edit_published_posts;
} elseif ( 'private' == $post->post_status ) {
$caps[] = $post_type->cap->edit_private_posts;
}
}
break;
case 'read_video' :
$status_obj = get_post_status_object( $post->post_status );
if ( $status_obj->public ) {
$caps[] = $post_type->cap->read;
break;
}
if ( is_object( $post_author_data ) && $user_id == $post_author_data->ID ) {
$caps[] = $post_type->cap->read;
} elseif ( $status_obj->private ) {
$caps[] = $post_type->cap->read_private_posts;
} else {
$caps = map_meta_cap( 'edit_post', $user_id, $post->ID );
}
break;
case 'delete_video' :
// If the user is the author...
if ( is_object( $post_author_data ) && $user_id == $post_author_data->ID ) {
// If the post is published...
if ( 'publish' == $post->post_status ) {
$caps[] = $post_type->cap->delete_published_posts;
} elseif ( 'trash' == $post->post_status ) {
if ('publish' == get_post_meta($post->ID, '_wp_trash_meta_status', true) ) {
$caps[] = $post_type->cap->delete_published_posts;
}
} else {
// If the post is draft...
$caps[] = $post_type->cap->delete_posts;
}
} else {
// The user is trying to edit someone else's post.
$caps[] = $post_type->cap->delete_others_posts;
// The post is published, extra cap required.
if ( 'publish' == $post->post_status ) {
$caps[] = $post_type->cap->delete_published_posts;
} elseif ( 'private' == $post->post_status ) {
$caps[] = $post_type->cap->delete_private_posts;
}
}
break;
}
}
}
return $caps;
add_filter( 'map_meta_cap', array( $this, 'map_meta_cap' ), 10, 4 );
}
}
/**
/**
* Video update messages.
* Video update messages.
*
*
* @see /wp-admin/edit-form-advanced.php
* @see /wp-admin/edit-form-advanced.php
*
*
* @param array $messages The array of post update messages.
* @param array $messages The array of post update messages.
* @return array An array with new CPT update messages.
* @return array An array with new CPT update messages.
*/
*/
public static function updated_messages( $messages ) {
public function updated_messages( $messages ) {
global $post;
$post = get_post();
$post_type = get_post_type( $post );
$post_type_object = get_post_type_object( $post_type );
$messages['video'] = array(
$messages['video'] = array(
0 => '', // Unused. Messages start at index 1.
0 => '', // Unused. Messages start at index 1.
1 => sprintf( __( 'Video updated. <a href="%s">View Video</a>', 'textdomain' ), esc_url( get_permalink( $post->ID ) ) ),
1 => __( 'Video updated.', 'textdomain' ),
2 => __( 'Custom field updated.', 'textdomain' ),
2 => __( 'Custom field updated.', 'textdomain' ),
3 => __( 'Custom field deleted.', 'textdomain' ),
3 => __( 'Custom field deleted.', 'textdomain' ),
4 => __( 'Video updated.', 'textdomain' ),
4 => __( 'Video updated.', 'textdomain' ),
/* translators: %s: date and time of the revision */
/* translators: %s: date and time of the revision */
5 => isset( $_GET['revision'] ) ? sprintf( __( 'Video restored to revision from %s', 'textdomain' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
5 => isset( $_GET['revision'] ) ? sprintf( __( 'Video restored to revision from %s', 'textdomain' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
6 => sprintf( __( 'Video published. <a href="%s">View Video</a>', 'textdomain' ), esc_url( get_permalink( $post->ID ) ) ),
6 => __( 'Video published.', 'textdomain' ),
7 => __( 'Video saved.', 'textdomain' ),
7 => __( 'Video saved.', 'textdomain' ),
8 => sprintf( __( 'Video submitted. <a target="_blank" href="%s">Preview Video</a>', 'textdomain' ), esc_url( add_query_arg( 'preview', 'true', get_permalink( $post->ID ) ) ) ),
8 => __( 'Video submitted.', 'textdomain' ),
9 => sprintf( __( 'Video scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview Video</a>', 'textdomain' ),
9 => sprintf( __( 'Video scheduled for: <strong>%1$s</strong>.', 'textdomain' ),
// translators: Publish box date format, see http://php.net/date
// translators: Publish box date format, see http://php.net/date
date_i18n( __( 'M j, Y @ G:i', 'textdomain' ), strtotime( $post->post_date ) ), esc_url( get_permalink( $post->ID ) ) ),
date_i18n( __( 'M j, Y @ G:i', 'textdomain' ), strtotime( $post->post_date ) ) ),
10 => sprintf( __( 'Video draft updated. <a target="_blank" href="%s">Preview Video</a>', 'textdomain' ), esc_url( add_query_arg( 'preview', 'true', get_permalink( $post->ID ) ) ) ),
10 => __( 'Video draft updated.', 'textdomain' ),
);
);
if ( $post_type_object->publicly_queryable ) {
$permalink = get_permalink( $post->ID );
$view_link = sprintf( ' <a href="%s">%s</a>', esc_url( $permalink ), __( 'View video', 'textdomain' ) );
$messages[ $post_type ][1] .= $view_link;
$messages[ $post_type ][6] .= $view_link;
$messages[ $post_type ][9] .= $view_link;
$preview_permalink = add_query_arg( 'preview', 'true', $permalink );
$preview_link = sprintf( ' <a target="_blank" href="%s">%s</a>', esc_url( $preview_permalink ), __( 'Preview Video', 'textdomain' ) );
$messages[ $post_type ][8] .= $preview_link;
$messages[ $post_type ][10] .= $preview_link;
}
return $messages;
return $messages;
}
}
/**
/**
* Custom sort the posts on the Manage Videos screen.
* Custom sort the posts on the Manage Videos screen.
*
*
* The $wp_query object is passed by reference and any changes made to it
* will be reflected globally.
*
* @link http://codex.wordpress.org/Class_Reference/WP_Query
* @link http://codex.wordpress.org/Class_Reference/WP_Query
*
*
* @todo Update the sortable key to match the query_var set in the
* @todo Update the sortable key to match the query_var set in the
* register_sortable_columns() method.
* register_sortable_columns() method.
* @todo Implement the custom sorting rules.
* @todo Implement custom sorting rules.
*
*
* @param WP_Query $wp_query The main WP_Query object.
* @param WP_Query $wp_query The main WP_Query object passed by reference.
*/
*/
public static function parse_admin_query( $wp_query ) {
public function parse_admin_query( $wp_query ) {
// Ensure this only affects requests in the dashboard.
// Ensure this only affects requests in the admin panel.
if ( is_admin() && isset( $_GET['post_type'] ) && 'video' == $_GET['post_type'] ) {
if ( ! is_admin() || empty( $_GET['post_type'] ) || 'video' != $_GET['post_type'] ) {
// An array of custom sortable column query vars.
return;
$sortable_keys = array( 'blazersix_query-var' );
}
if ( ! empty( $_GET['orderby'] ) && in_array( $_GET['orderby'], $sortable_keys ) ) {
// An array of custom sortable column query vars.
// Set the order.
$sortable_keys = array( 'blazersix_query-var' );
$order = ( isset( $_GET['order'] ) && 'desc' == $_GET['order'] ) ? 'desc' : 'asc';
$wp_query->set( 'order', $order );
if ( ! empty( $_GET['orderby'] ) && in_array( $_GET['orderby'], $sortable_keys ) ) {
// Set the order.
// Implement custom sorting rules.
$order = ( isset( $_GET['order'] ) && 'desc' == $_GET['order'] ) ? 'desc' : 'asc';
if ( 'blazersix_query-var' == $_GET['orderby'] ) {
$wp_query->set( 'order', $order );
// An example to sort results by a custom meta field.
$wp_query->set( 'meta_key', '_blazersix_meta_key' );
// Implement custom sorting rules.
$wp_query->set( 'orderby', 'meta_value_num' );
if ( 'blazersix_query-var' == $_GET['orderby'] ) {
}
// An example to sort results by a custom meta field.
$wp_query->set( 'meta_key', '_blazersix_meta_key' );
$wp_query->set( 'orderby', 'meta_value_num' );
}
}
}
}
}
}
/**
/**
* Register custom Video columns.
* Register custom Video columns.
*
*
* @param array $columns Column names to display.
* @param array $columns Column names to display.
*/
*/
public static function register_columns( $columns ) {
public function register_columns( $columns ) {
// $columns['blazersix_custom_column_id'] = _x( 'Column Name', 'column name', 'textdomain' );
// $columns['blazersix_custom_column_id'] = _x( 'Column Name', 'column name', 'textdomain' );
return $columns;
return $columns;
}
}
/**
/**
* Register custom Video sortable columns.
* Register custom Video sortable columns.
*
*
* Registering a column as sortable will allow the table header to be
* Registering a column as sortable will allow the table header to be
* clicked to sort the Video posts. The query var assigned in this
* clicked to sort the Video posts. The query var assigned in this
* function will be passed in the URL as the value of 'orderby', along
* function will be passed in the URL as the value of 'orderby', along
* with whether or not results should be ASC or DESC. A hook should be
* with whether or not results should be ASC or DESC. A hook should be
* attached to the 'parse_query' filter in order to handle the custom
* attached to the 'parse_query' filter in order to handle the custom
* sorting rules.
* sorting rules.
*
*
* Multiple sortable columns can be registered at the same time.
* Multiple sortable columns may be registered at the same time.
*
*
* @todo Update the column identifier key and query var.
*
* @param array $columns Column query vars with their corresponding column id as the key.
* @param array $columns Column query vars with their corresponding column id as the key.
*/
*/
public static function register_sortable_columns( $columns ) {
public function register_sortable_columns( $columns ) {
$columns['blazersix_custom_column_id'] = 'blazersix_query-var';
$columns['blazersix_custom_column_id'] = 'blazersix_query-var';
return $columns;
return $columns;
}
}
/**
/**
* Display custom Video columns.
* Display custom Video columns.
*
*
* @param string $column_id The id of the column to display.
* @param string $column_id The id of the column to display.
* @param int $post_id Post ID.
* @param int $post_id Post ID.
*/
*/
public static function display_columns( $column_id, $post_id ) {
public function display_columns( $column_id, $post_id ) {
switch ( $column_id ) {
switch ( $column_id ) {
case 'blazersix_custom_column_id' :
case 'blazersix_custom_column_id' :
// Output the custom column content here.
// Output the custom column content here.
echo 'Value';
echo 'Value';
break;
break;
}
}
}
}
/**
/**
* Save Video CPT data.
* Save Video CPT data.
*
*
* @see wp_insert_post()
* @see wp_insert_post()
*
*
* @param int $post_id Post ID.
* @param int $post_id Post ID.
* @param object $post Post object.
* @param WP_Post $post Post object.
*/
*/
function save_post( $post_id, $post ) {
public function save_post( $post_id, $post ) {
$is_autosave = ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) ? true : false;
$is_autosave = defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE;
$is_revision = wp_is_post_revision( $post_id );
$is_revision = wp_is_post_revision( $post_id );
$is_valid_nonce = ( isset( $_POST['blazersix_video_nonce'] ) && wp_verify_nonce( $_POST['blazersix_video_nonce'], 'save-video_' . $post_id ) ) ? true : false;
$is_valid_nonce = isset( $_POST['blazersix_video_nonce'] ) && wp_verify_nonce( $_POST['blazersix_video_nonce'], 'save-video_' . $post_id );
// Bail if the data shouldn't be saved or intention can't be verified.
// Bail if the data shouldn't be saved or intention can't be verified.
if ( $is_autosave || $is_revision || ! $is_valid_nonce ) {
if ( $is_autosave || $is_revision || ! $is_valid_nonce ) {
return;
return;
}
}
// @todo Save custom data from $_POST global here.
// @todo Save custom data from $_POST global here.
}
}
/**
/**
* Register Video meta boxes.
* Register Video meta boxes.
*
*
* This is the callback defined in the Video CPT registration
* This is the callback defined in the Video CPT registration
* function. Meta boxes or any other functionality that should be limited
* function. Meta boxes or any other functionality that should be limited
* to the Add/Edit Video screen and occurs after 'do_meta_boxes'
* to the Add/Edit Video screen and occurs after 'do_meta_boxes'
* can be registered here.
* can be registered here.
*
*
* @param object $post The post being added or edited.
* @param WP_Post $post Post object.
*/
*/
public static function register_meta_boxes( $post ) {
public function register_meta_boxes( $post ) {
// Update these parameters and uncomment to add a meta box
// Update these parameters and uncomment to add a meta box.
// add_meta_box( 'meta-box-id', __( 'Video Meta Box', 'textdomain' ), array( __CLASS__, 'meta_box' ), 'video', 'normal', 'default' );
/*
add_meta_box(
'meta-box-id',
__( 'Video Meta Box', 'textdomain' ),
array( $this, 'meta_box' ),
'video',
'normal',
'default'
);
*/
}
}
/**
/**
* Display Video meta box.
* Display Video meta box.
*
*
* @param object $post The post being edited.
* @param WP_Post $post Post object.
* @param array $meta_box Arguments passed when the meta box was registered.
* @param array $meta_box Arguments passed when the meta box was registered.
*/
*/
public static function meta_box( $post, $meta_box ) {
public function meta_box( $post, $meta_box ) {
wp_nonce_field( 'save-video_' . $post->ID, 'blazersix_video_nonce' );
wp_nonce_field( 'save-video_' . $post->ID, 'blazersix_video_nonce' );
?>
?>
<p>
<p>
<label for="field-id">Field Label:</label><br>
<label for="field-id">Field Label:</label><br>
<input type="text" name="field_name" id="field-id" value="<?php echo esc_attr( $field_value ); ?>" class="regular-text">
<input type="text" name="field_name" id="field-id" value="<?php echo esc_attr( $field_value ); ?>" class="regular-text">
</p>
</p>
<p>
<p>
<label for="field2-id">Field Label:</label><br>
<label for="field2-id">Field Label:</label><br>
<textarea name="field2_name" id="field2-id" rows="3" class="widefat"><?php echo esc_textarea( $field2_value ); ?></textarea>
<textarea name="field2_name" id="field2-id" rows="3" class="widefat"><?php echo esc_textarea( $field2_value ); ?></textarea>
</p>
</p>
<?php
<?php
}
}
/**
/**
* Default menu and screen icon CSS.
* Map Video meta capabilities to primitive capabilities.
*
* @link http://justintadlock.com/archives/2010/07/10/meta-capabilities-for-custom-post-types
* @see map_meta_cap()
*
*
* @link http://core.trac.wordpress.org/changeset/22629
* @param array $caps Primitive capabilities determined by core.
* @todo Update units in CSS. Some default selectors are provided for
* @param string $cap Capability name.
* direction.
* @param int $user_id User ID.
* @return array Actual capabilities for meta capability.
*/
*/
public static function icon_css() {
public function map_meta_cap( $caps, $cap, $user_id, $args ) {
?>
$meta_caps = array( 'edit_video', 'read_video', 'delete_video' );
<style type="text/css">
if ( in_array( $cap, $meta_caps ) ) {
.admin-color-fresh #adminmenu li#menu-posts-video div.wp-menu-image { background-image: url("icon-template.png"); background-position: x y; }
$post = get_post( $args[0] );
.admin-color-fresh #adminmenu li#menu-posts-video:hover div.wp-menu-image,
if ( 'revision' == $post->post_type ) {
.admin-color-fresh #adminmenu li#menu-posts-video.wp-has-current-submenu div.wp-menu-image { background-position: x y; }
$post = get_post( $post->post_parent );
@media print, (-o-min-device-pixel-ratio: 5/4), (-webkit-min-device-pixel-ratio: 1.25), (min-resolution: 120dpi) {
}
.admin-color-fresh #adminmenu li#menu-posts-video div.wp-menu-image { background-position: x y; background-size: w h; }
$post_type = get_post_type_object( $post->post_type );
.admin-color-fresh #adminmenu li#menu-posts-video:hover div.wp-menu-image,
.admin-color-fresh #adminmenu li#menu-posts-video.wp-has-current-submenu div.wp-menu-image { background-position: x y; }
$caps = array();
}
if ( ! $post_type->map_meta_cap ) {
$caps[] = $post_type->cap->$cap;
.admin-color-fresh #icon-edit.icon32-posts-video { background-image: url("icon-template.png"); background-position: x y; }
}
.admin-color-classic #icon-edit.icon32-posts-video { background-image: url("icon-template.png"); background-position: x y; }
@media print, (-o-min-device-pixel-ratio: 5/4), (-webkit-min-device-pixel-ratio: 1.25), (min-resolution: 120dpi) {
$user_data = get_userdata( $user_id );
.admin-color-fresh #icon-edit.icon32-posts-video { background-position: x y ; background-size: w h; }
$post_author_data = $user_data;
.admin-color-classic #icon-edit.icon32-posts-video { background-position: x y; background-size: w h; }
if ( ! empty( $post->post_author ) ) {
$post_author_data = get_userdata( $post->post_author );
}
switch( $cap ) {
case 'edit_video' :
// If the user is the author...
if ( is_object( $post_author_data ) && $user_id == $post_author_data->ID ) {
// If the post is published...
if ( 'publish' == $post->post_status ) {
$caps[] = $post_type->cap->edit_published_posts;
} elseif ( 'trash' == $post->post_status ) {
if ( 'publish' == get_post_meta( $post->ID, '_wp_trash_meta_status', true ) ) {
$caps[] = $post_type->cap->edit_published_posts;
}
} else {
// If the post is draft...
$caps[] = $post_type->cap->edit_posts;
}
} else {
// The user is trying to edit someone else's post.
$caps[] = $post_type->cap->edit_others_posts;
// The post is published, extra cap required.
if ( 'publish' == $post->post_status ) {
$caps[] = $post_type->cap->edit_published_posts;
} elseif ( 'private' == $post->post_status ) {
$caps[] = $post_type->cap->edit_private_posts;
}
}
break;
case 'read_video' :
$status_obj = get_post_status_object( $post->post_status );
if ( $status_obj->public ) {
$caps[] = $post_type->cap->read;
break;
}
if ( is_object( $post_author_data ) && $user_id == $post_author_data->ID ) {
$caps[] = $post_type->cap->read;
} elseif ( $status_obj->private ) {
$caps[] = $post_type->cap->read_private_posts;
} else {
$caps = map_meta_cap( 'edit_post', $user_id, $post->ID );
}
break;
case 'delete_video' :
// If the user is the author...
if ( is_object( $post_author_data ) && $user_id == $post_author_data->ID ) {
// If the post is published...
if ( 'publish' == $post->post_status ) {
$caps[] = $post_type->cap->delete_published_posts;
} elseif ( 'trash' == $post->post_status ) {
if ('publish' == get_post_meta($post->ID, '_wp_trash_meta_status', true) ) {
$caps[] = $post_type->cap->delete_published_posts;
}
} else {
// If the post is draft...
$caps[] = $post_type->cap->delete_posts;
}
} else {
// The user is trying to edit someone else's post.
$caps[] = $post_type->cap->delete_others_posts;
// The post is published, extra cap required.
if ( 'publish' == $post->post_status ) {
$caps[] = $post_type->cap->delete_published_posts;
} elseif ( 'private' == $post->post_status ) {
$caps[] = $post_type->cap->delete_private_posts;
}
}
break;
}
}
}
</style>
<?php
return $caps;
}
}
}
}
$blazersix_video = new Blazersix_Video();
add_action( 'init', array( $blazersix_video, 'init' ) );