Diff
checker
Texte
Texte
Images
Documents
Excel
Dossiers
Legal
Enterprise
Application de bureau
Prix
Se connecter
Télécharger Diffchecker Desktop
Comparer le texte
Trouver la différence entre deux fichiers texte
Outils
Historique
Éditeur live
Cacher identiques
Sans retour à la ligne
Vue
Divisé
Unifié
Niveau de précision
Intelligent
Mot
Caractère
Coloration syntaxique
Choisir la syntaxe
Ignorer
Transformer le texte
Aller au premier écart
Modifier l'entrée
Diffchecker Desktop
La façon la plus sécurisée d'utiliser Diffchecker. Obtenez l'application Diffchecker Desktop : vos diffs ne quittent jamais votre ordinateur !
Obtenir Desktop
Untitled diff
Créé
il y a 11 ans
Le diff n'expire jamais
Effacer
Exporter
Partager
Expliquer
307 suppressions
Lignes
Total
Supprimé
Caractères
Total
Supprimé
Pour continuer à utiliser cette fonctionnalité, passez à
Diff
checker
Pro
Voir les prix
427 lignes
Copier tout
260 ajouts
Lignes
Total
Ajouté
Caractères
Total
Ajouté
Pour continuer à utiliser cette fonctionnalité, passez à
Diff
checker
Pro
Voir les prix
419 lignes
Copier tout
<?php
<?php
/**
/**
Copier
Copié
Copier
Copié
Text moved with changes from lines 11-18 (93.5% similarity)
* 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
Copier
Copié
Copier
Copié
* 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
Copier
Copié
Copier
Copié
* Author:
* Author:
* Author URI:
* Author URI:
* License: GPL
v2 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
Copier
Copié
Copier
Copié
Text moved with changes to lines 3-12 (93.5% similarity)
*
* @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.
*/
*/
/**
/**
Copier
Copié
Copier
Copié
* Load the Video custom post type.
*/
add_action( 'init', array( 'Blazersix_Video', 'init' ) );
/**
* Main class.
* Main class.
Copier
Copié
Copier
Copié
*
* @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
Copier
Copié
Copier
Copié
* elements (custom columns, update messages, meta
boxes, 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
*/
*/
Copier
Copié
Copier
Copié
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(
Copier
Copié
Copier
Copié
'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
),
),
Copier
Copié
Copier
Copié
'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()
,
) );
) );
Copier
Copié
Copier
Copié
if ( is_admin() ) {
if ( is_admin() ) {
Copier
Copié
Copier
Copié
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' ) );
}
}
Copier
Copié
Copier
Copié
add_filter( 'map_meta_cap', array(
__CLASS__
, 'map_meta_cap' ), 10, 4 );
add_filter( 'map_meta_cap', array(
$this
, 'map_meta_cap' ), 10, 4 );
}
}
Copier
Copié
Copier
Copié
Text moved with changes from lines 227-237 (94.0% similarity)
/**
* Video update messages.
*
* @see /wp-admin/edit-form-advanced.php
*
* @param array $messages The array of post update messages.
* @return array An array with new CPT update messages.
*/
public function updated_messages( $messages ) {
$post = get_post();
$post_type = get_post_type( $post );
$post_type_object = get_post_type_object( $post_type );
$messages['video'] = array(
0 => '', // Unused. Messages start at index 1.
1 => __( 'Video updated.', 'textdomain' ),
Text moved from lines 242-246
2 => __( 'Custom field updated.', 'textdomain' ),
3 => __( 'Custom field deleted.', 'textdomain' ),
4 => __( 'Video updated.', 'textdomain' ),
/* 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,
6 => __( 'Video published.', 'textdomain' ),
7 => __( 'Video saved.', 'textdomain' ),
8 => __( 'Video submitted.', 'textdomain' ),
9 => sprintf( __( 'Video scheduled for: <strong>%1$s</strong>.', 'textdomain' ),
// translators: Publish box date format, see http://php.net/date
date_i18n( __( 'M j, Y @ G:i', 'textdomain' ), strtotime( $post->post_date ) ) ),
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;
}
/**
* Custom sort the posts on the Manage Videos screen.
*
* @link http://codex.wordpress.org/Class_Reference/WP_Query
*
* @todo Update the sortable key to match the query_var set in the
* register_sortable_columns() method.
* @todo Implement custom sorting rules.
*
* @param WP_Query $wp_query The main WP_Query object passed by reference.
*/
public function parse_admin_query( $wp_query ) {
// Ensure this only affects requests in the admin panel.
if ( ! is_admin() || empty( $_GET['post_type'] ) || 'video' != $_GET['post_type'] ) {
return;
}
// An array of custom sortable column query vars.
$sortable_keys = array( 'blazersix_query-var' );
if ( ! empty( $_GET['orderby'] ) && in_array( $_GET['orderby'], $sortable_keys ) ) {
// Set the order.
$order = ( isset( $_GET['order'] ) && 'desc' == $_GET['order'] ) ? 'desc' : 'asc';
$wp_query->set( 'order', $order );
// Implement custom sorting rules.
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' );
Text moved with changes from lines 290-300 (96.4% similarity)
}
}
}
/**
* Register custom Video columns.
*
* @param array $columns Column names to display.
*/
public function register_columns( $columns ) {
// $columns['blazersix_custom_column_id'] = _x( 'Column Name', 'column name', 'textdomain' );
Text moved with changes from lines 302-319 (91.7% similarity)
return $columns;
}
/**
* Register custom Video sortable columns.
*
* Registering a column as sortable will allow the table header to be
* 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
* 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
* sorting rules.
*
* Multiple sortable columns may be registered at the same time.
*
* @param array $columns Column query vars with their corresponding column id as the key.
*/
public function register_sortable_columns( $columns ) {
$columns['blazersix_custom_column_id'] = 'blazersix_query-var';
Text moved with changes from lines 324-353 (95.5% similarity)
return $columns;
}
/**
* Display custom Video columns.
*
* @param string $column_id The id of the column to display.
* @param int $post_id Post ID.
*/
public function display_columns( $column_id, $post_id ) {
switch ( $column_id ) {
case 'blazersix_custom_column_id' :
// Output the custom column content here.
echo 'Value';
break;
}
}
/**
* Save Video CPT data.
*
* @see wp_insert_post()
*
* @param int $post_id Post ID.
* @param WP_Post $post Post object.
*/
public function save_post( $post_id, $post ) {
$is_autosave = defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE;
$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 );
Text moved from lines 355-358
// Bail if the data shouldn't be saved or intention can't be verified.
if ( $is_autosave || $is_revision || ! $is_valid_nonce ) {
return;
}
Text moved with changes from lines 360-374 (95.5% similarity)
// @todo Save custom data from $_POST global here.
}
/**
* Register Video meta boxes.
*
* This is the callback defined in the Video CPT registration
* function. Meta boxes or any other functionality that should be limited
* to the Add/Edit Video screen and occurs after 'do_meta_boxes'
* can be registered here.
*
* @param WP_Post $post Post object.
*/
public function register_meta_boxes( $post ) {
// Update these parameters and uncomment to add a meta box.
/*
add_meta_box(
'meta-box-id',
__( 'Video Meta Box', 'textdomain' ),
array( $this, 'meta_box' ),
'video',
'normal',
'default'
);
*/
Text moved with changes from lines 376-397 (95.7% similarity)
}
/**
* Display Video meta box.
*
* @param WP_Post $post Post object.
* @param array $meta_box Arguments passed when the meta box was registered.
*/
public function meta_box( $post, $meta_box ) {
wp_nonce_field( 'save-video_' . $post->ID, 'blazersix_video_nonce' );
?>
<p>
<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">
</p>
<p>
<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>
</p>
<?php
}
/**
/**
* Map Video meta capabilities to primitive capabilities.
* Map Video meta capabilities to primitive capabilities.
*
*
* @link http://justintadlock.com/archives/2010/07/10/meta-capabilities-for-custom-post-types
* @link http://justintadlock.com/archives/2010/07/10/meta-capabilities-for-custom-post-types
* @see map_meta_cap()
* @see map_meta_cap()
*
*
* @param array $caps Primitive capabilities determined by core.
* @param array $caps Primitive capabilities determined by core.
* @param string $cap Capability name.
* @param string $cap Capability name.
* @param int $user_id User ID.
* @param int $user_id User ID.
* @return array Actual capabilities for meta capability.
* @return array Actual capabilities for meta capability.
*/
*/
Copier
Copié
Copier
Copié
public
static
function map_meta_cap( $caps, $cap, $user_id, $args ) {
public
function map_meta_cap( $caps, $cap, $user_id, $args ) {
$meta_caps = array( 'edit_video', 'read_video', 'delete_video' );
$meta_caps = array( 'edit_video', 'read_video', 'delete_video' );
if ( in_array( $cap, $meta_caps ) ) {
if ( in_array( $cap, $meta_caps ) ) {
$post = get_post( $args[0] );
$post = get_post( $args[0] );
if ( 'revision' == $post->post_type ) {
if ( 'revision' == $post->post_type ) {
$post = get_post( $post->post_parent );
$post = get_post( $post->post_parent );
}
}
$post_type = get_post_type_object( $post->post_type );
$post_type = get_post_type_object( $post->post_type );
Copier
Copié
Copier
Copié
$caps = array();
$caps = array();
if ( ! $post_type->map_meta_cap ) {
if ( ! $post_type->map_meta_cap ) {
$caps[] = $post_type->cap->$cap;
$caps[] = $post_type->cap->$cap;
}
}
Copier
Copié
Copier
Copié
$user_data = get_userdata( $user_id );
$user_data = get_userdata( $user_id );
$post_author_data = $user_data;
$post_author_data = $user_data;
if ( ! empty( $post->post_author ) ) {
if ( ! empty( $post->post_author ) ) {
$post_author_data = get_userdata( $post->post_author );
$post_author_data = get_userdata( $post->post_author );
}
}
Copier
Copié
Copier
Copié
switch( $cap ) {
switch( $cap ) {
case 'edit_video' :
case 'edit_video' :
// If the user is the author...
// If the user is the author...
if ( is_object( $post_author_data ) && $user_id == $post_author_data->ID ) {
if ( is_object( $post_author_data ) && $user_id == $post_author_data->ID ) {
// If the post is published...
// If the post is published...
if ( 'publish' == $post->post_status ) {
if ( 'publish' == $post->post_status ) {
$caps[] = $post_type->cap->edit_published_posts;
$caps[] = $post_type->cap->edit_published_posts;
} elseif ( 'trash' == $post->post_status ) {
} elseif ( 'trash' == $post->post_status ) {
if ( 'publish' == get_post_meta( $post->ID, '_wp_trash_meta_status', true ) ) {
if ( 'publish' == get_post_meta( $post->ID, '_wp_trash_meta_status', true ) ) {
$caps[] = $post_type->cap->edit_published_posts;
$caps[] = $post_type->cap->edit_published_posts;
}
}
} else {
} else {
// If the post is draft...
// If the post is draft...
$caps[] = $post_type->cap->edit_posts;
$caps[] = $post_type->cap->edit_posts;
}
}
} else {
} else {
// The user is trying to edit someone else's post.
// The user is trying to edit someone else's post.
$caps[] = $post_type->cap->edit_others_posts;
$caps[] = $post_type->cap->edit_others_posts;
// The post is published, extra cap required.
// The post is published, extra cap required.
if ( 'publish' == $post->post_status ) {
if ( 'publish' == $post->post_status ) {
$caps[] = $post_type->cap->edit_published_posts;
$caps[] = $post_type->cap->edit_published_posts;
} elseif ( 'private' == $post->post_status ) {
} elseif ( 'private' == $post->post_status ) {
$caps[] = $post_type->cap->edit_private_posts;
$caps[] = $post_type->cap->edit_private_posts;
}
}
}
}
break;
break;
Copier
Copié
Copier
Copié
case 'read_video' :
case 'read_video' :
$status_obj = get_post_status_object( $post->post_status );
$status_obj = get_post_status_object( $post->post_status );
if ( $status_obj->public ) {
if ( $status_obj->public ) {
$caps[] = $post_type->cap->read;
$caps[] = $post_type->cap->read;
break;
break;
}
}
Copier
Copié
Copier
Copié
if ( is_object( $post_author_data ) && $user_id == $post_author_data->ID ) {
if ( is_object( $post_author_data ) && $user_id == $post_author_data->ID ) {
$caps[] = $post_type->cap->read;
$caps[] = $post_type->cap->read;
} elseif ( $status_obj->private ) {
} elseif ( $status_obj->private ) {
$caps[] = $post_type->cap->read_private_posts;
$caps[] = $post_type->cap->read_private_posts;
} else {
} else {
$caps = map_meta_cap( 'edit_post', $user_id, $post->ID );
$caps = map_meta_cap( 'edit_post', $user_id, $post->ID );
}
}
break;
break;
Copier
Copié
Copier
Copié
case 'delete_video' :
case 'delete_video' :
// If the user is the author...
// If the user is the author...
if ( is_object( $post_author_data ) && $user_id == $post_author_data->ID ) {
if ( is_object( $post_author_data ) && $user_id == $post_author_data->ID ) {
// If the post is published...
// If the post is published...
if ( 'publish' == $post->post_status ) {
if ( 'publish' == $post->post_status ) {
$caps[] = $post_type->cap->delete_published_posts;
$caps[] = $post_type->cap->delete_published_posts;
} elseif ( 'trash' == $post->post_status ) {
} elseif ( 'trash' == $post->post_status ) {
if ('publish' == get_post_meta($post->ID, '_wp_trash_meta_status', true) ) {
if ('publish' == get_post_meta($post->ID, '_wp_trash_meta_status', true) ) {
$caps[] = $post_type->cap->delete_published_posts;
$caps[] = $post_type->cap->delete_published_posts;
}
}
} else {
} else {
// If the post is draft...
// If the post is draft...
$caps[] = $post_type->cap->delete_posts;
$caps[] = $post_type->cap->delete_posts;
}
}
} else {
} else {
// The user is trying to edit someone else's post.
// The user is trying to edit someone else's post.
$caps[] = $post_type->cap->delete_others_posts;
$caps[] = $post_type->cap->delete_others_posts;
// The post is published, extra cap required.
// The post is published, extra cap required.
if ( 'publish' == $post->post_status ) {
if ( 'publish' == $post->post_status ) {
$caps[] = $post_type->cap->delete_published_posts;
$caps[] = $post_type->cap->delete_published_posts;
} elseif ( 'private' == $post->post_status ) {
} elseif ( 'private' == $post->post_status ) {
$caps[] = $post_type->cap->delete_private_posts;
$caps[] = $post_type->cap->delete_private_posts;
}
}
}
}
break;
break;
}
}
}
}
Copier
Copié
Copier
Copié
return $caps;
return $caps;
}
}
Copier
Copié
Copier
Copié
Text moved with changes to lines 118-128 (94.0% similarity)
/**
* Video update messages.
*
* @see /wp-admin/edit-form-advanced.php
*
* @param array $messages The array of post update messages.
* @return array An array with new CPT update messages.
*/
public static function updated_messages( $messages ) {
global $post;
$messages['video'] = array(
0 => '', // Unused. Messages start at index 1.
1 => sprintf( __( 'Video updated. <a href="%s">View Video</a>', 'textdomain' ), esc_url( get_permalink( $post->ID ) ) ),
Text moved to lines 135-139
2 => __( 'Custom field updated.', 'textdomain' ),
3 => __( 'Custom field deleted.', 'textdomain' ),
4 => __( 'Video updated.', 'textdomain' ),
/* 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,
6 => sprintf( __( 'Video published. <a href="%s">View Video</a>', 'textdomain' ), esc_url( get_permalink( $post->ID ) ) ),
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 ) ) ) ),
9 => sprintf( __( 'Video scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview Video</a>', 'textdomain' ),
// 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 ) ) ),
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 ) ) ) ),
);
return $messages;
}
/**
* 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
*
* @todo Update the sortable key to match the query_var set in the
* register_sortable_columns() method.
* @todo Implement the custom sorting rules.
*
* @param WP_Query $wp_query The main WP_Query object.
*/
public static function parse_admin_query( $wp_query ) {
// Ensure this only affects requests in the dashboard.
if ( is_admin() && isset( $_GET['post_type'] ) && 'video' == $_GET['post_type'] ) {
// An array of custom sortable column query vars.
$sortable_keys = array( 'blazersix_query-var' );
if ( ! empty( $_GET['orderby'] ) && in_array( $_GET['orderby'], $sortable_keys ) ) {
// Set the order.
$order = ( isset( $_GET['order'] ) && 'desc' == $_GET['order'] ) ? 'desc' : 'asc';
$wp_query->set( 'order', $order );
// Implement custom sorting rules.
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' );
}
Text moved with changes to lines 196-206 (96.4% similarity)
}
}
}
/**
* Register custom Video columns.
*
* @param array $columns Column names to display.
*/
public static function register_columns( $columns ) {
// $columns['blazersix_custom_column_id'] = _x( 'Column Name', 'column name', 'textdomain' );
Text moved with changes to lines 208-225 (91.7% similarity)
return $columns;
}
/**
* Register custom Video sortable columns.
*
* Registering a column as sortable will allow the table header to be
* 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
* 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
* sorting rules.
*
* Multiple sortable columns can 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.
*/
public static function register_sortable_columns( $columns ) {
$columns['blazersix_custom_column_id'] = 'blazersix_query-var';
Text moved with changes to lines 228-257 (95.5% similarity)
return $columns;
}
/**
* Display custom Video columns.
*
* @param string $column_id The id of the column to display.
* @param int $post_id Post ID.
*/
public static function display_columns( $column_id, $post_id ) {
switch ( $column_id ) {
case 'blazersix_custom_column_id' :
// Output the custom column content here.
echo 'Value';
break;
}
}
/**
* Save Video CPT data.
*
* @see wp_insert_post()
*
* @param int $post_id Post ID.
* @param object $post Post object.
*/
function save_post( $post_id, $post ) {
$is_autosave = ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) ? true : false;
$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;
Text moved to lines 259-262
// Bail if the data shouldn't be saved or intention can't be verified.
if ( $is_autosave || $is_revision || ! $is_valid_nonce ) {
return;
}
Text moved with changes to lines 264-278 (95.5% similarity)
// @todo Save custom data from $_POST global here.
}
/**
* Register Video meta boxes.
*
* This is the callback defined in the Video CPT registration
* function. Meta boxes or any other functionality that should be limited
* to the Add/Edit Video screen and occurs after 'do_meta_boxes'
* can be registered here.
*
* @param object $post The post being added or edited.
*/
public static function register_meta_boxes( $post ) {
// 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' );
Text moved with changes to lines 289-310 (95.7% similarity)
}
/**
* Display Video meta box.
*
* @param object $post The post being edited.
* @param array $meta_box Arguments passed when the meta box was registered.
*/
public static function meta_box( $post, $meta_box ) {
wp_nonce_field( 'save-video_' . $post->ID, 'blazersix_video_nonce' );
?>
<p>
<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">
</p>
<p>
<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>
</p>
<?php
}
/**
* Default menu and screen icon CSS.
*
* @link http://core.trac.wordpress.org/changeset/22629
* @todo Update units in CSS. Some default selectors are provided for
* direction.
*/
public static function icon_css() {
?>
<style type="text/css">
.admin-color-fresh #adminmenu li#menu-posts-video div.wp-menu-image { background-image: url("icon-template.png"); background-position: x y; }
.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; }
@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; }
.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; }
}
.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) {
.admin-color-fresh #icon-edit.icon32-posts-video { background-position: x y ; background-size: w h; }
.admin-color-classic #icon-edit.icon32-posts-video { background-position: x y; background-size: w h; }
}
</style>
<?php
}
}
}
Copier
Copié
Copier
Copié
$blazersix_video = new Blazersix_Video();
add_action( 'init', array( $blazersix_video, 'init' ) );
Différences enregistrées
Texte d'origine
Ouvrir un fichier
<?php /** * Plugin Name: Video CPT * Plugin URI: * Description: A generated video custom post type implementation. * Version: 1.0 * Author: * Author URI: * License: GPLv2 or later * 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. * * @todo Consider breaking the admin-related functionality into a separate * file and including in an is_admin() conditional. */ class Blazersix_Video { /** * Register Video custom post type. * * Registers the Video custom post type and related admin interface * elements (custom columns, update messages, metaboxes, standard menu and * screen icon CSS). * * @link http://codex.wordpress.org/Function_Reference/register_post_type */ public static function init() { register_post_type( 'video', array( 'can_export' => true, 'capability_type' => array( 'video', 'videos' ), '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' ), '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', 'show_ui' => true, 'show_in_admin_bar' => true, 'show_in_menu' => true, 'show_in_nav_menus' => false, 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'page-attributes', 'post-formats' ), 'taxonomies' => array() ) ); if ( is_admin() ) { add_filter( 'post_updated_messages', array( __CLASS__, 'updated_messages' ) ); add_filter( 'parse_query', array( __CLASS__, 'parse_admin_query' ) ); add_filter( 'manage_edit-video_columns', array( __CLASS__, 'register_columns' ) ); add_action( 'manage_edit-video_sortable_columns', array( __CLASS__, 'register_sortable_columns' ) ); add_action( 'manage_video_posts_custom_column', array( __CLASS__, 'display_columns' ), 10, 2 ); add_action( 'save_post', array( __CLASS__, '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; } /** * Video update messages. * * @see /wp-admin/edit-form-advanced.php * * @param array $messages The array of post update messages. * @return array An array with new CPT update messages. */ public static function updated_messages( $messages ) { global $post; $messages['video'] = array( 0 => '', // Unused. Messages start at index 1. 1 => sprintf( __( 'Video updated. <a href="%s">View Video</a>', 'textdomain' ), esc_url( get_permalink( $post->ID ) ) ), 2 => __( 'Custom field updated.', 'textdomain' ), 3 => __( 'Custom field deleted.', 'textdomain' ), 4 => __( 'Video updated.', 'textdomain' ), /* 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, 6 => sprintf( __( 'Video published. <a href="%s">View Video</a>', 'textdomain' ), esc_url( get_permalink( $post->ID ) ) ), 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 ) ) ) ), 9 => sprintf( __( 'Video scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview Video</a>', 'textdomain' ), // 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 ) ) ), 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 ) ) ) ), ); return $messages; } /** * 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 * * @todo Update the sortable key to match the query_var set in the * register_sortable_columns() method. * @todo Implement the custom sorting rules. * * @param WP_Query $wp_query The main WP_Query object. */ public static function parse_admin_query( $wp_query ) { // Ensure this only affects requests in the dashboard. if ( is_admin() && isset( $_GET['post_type'] ) && 'video' == $_GET['post_type'] ) { // An array of custom sortable column query vars. $sortable_keys = array( 'blazersix_query-var' ); if ( ! empty( $_GET['orderby'] ) && in_array( $_GET['orderby'], $sortable_keys ) ) { // Set the order. $order = ( isset( $_GET['order'] ) && 'desc' == $_GET['order'] ) ? 'desc' : 'asc'; $wp_query->set( 'order', $order ); // Implement custom sorting rules. 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. * * @param array $columns Column names to display. */ public static function register_columns( $columns ) { // $columns['blazersix_custom_column_id'] = _x( 'Column Name', 'column name', 'textdomain' ); return $columns; } /** * Register custom Video sortable columns. * * Registering a column as sortable will allow the table header to be * 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 * 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 * sorting rules. * * Multiple sortable columns can 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. */ public static function register_sortable_columns( $columns ) { $columns['blazersix_custom_column_id'] = 'blazersix_query-var'; return $columns; } /** * Display custom Video columns. * * @param string $column_id The id of the column to display. * @param int $post_id Post ID. */ public static function display_columns( $column_id, $post_id ) { switch ( $column_id ) { case 'blazersix_custom_column_id' : // Output the custom column content here. echo 'Value'; break; } } /** * Save Video CPT data. * * @see wp_insert_post() * * @param int $post_id Post ID. * @param object $post Post object. */ function save_post( $post_id, $post ) { $is_autosave = ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) ? true : false; $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; // Bail if the data shouldn't be saved or intention can't be verified. if ( $is_autosave || $is_revision || ! $is_valid_nonce ) { return; } // @todo Save custom data from $_POST global here. } /** * Register Video meta boxes. * * This is the callback defined in the Video CPT registration * function. Meta boxes or any other functionality that should be limited * to the Add/Edit Video screen and occurs after 'do_meta_boxes' * can be registered here. * * @param object $post The post being added or edited. */ public static function register_meta_boxes( $post ) { // 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' ); } /** * Display Video meta box. * * @param object $post The post being edited. * @param array $meta_box Arguments passed when the meta box was registered. */ public static function meta_box( $post, $meta_box ) { wp_nonce_field( 'save-video_' . $post->ID, 'blazersix_video_nonce' ); ?> <p> <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"> </p> <p> <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> </p> <?php } /** * Default menu and screen icon CSS. * * @link http://core.trac.wordpress.org/changeset/22629 * @todo Update units in CSS. Some default selectors are provided for * direction. */ public static function icon_css() { ?> <style type="text/css"> .admin-color-fresh #adminmenu li#menu-posts-video div.wp-menu-image { background-image: url("icon-template.png"); background-position: x y; } .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; } @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; } .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; } } .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) { .admin-color-fresh #icon-edit.icon32-posts-video { background-position: x y ; background-size: w h; } .admin-color-classic #icon-edit.icon32-posts-video { background-position: x y; background-size: w h; } } </style> <?php } }
Texte modifié
Ouvrir un fichier
<?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 URI: * Description: A generated video custom post type implementation. * Version: 1.0 * Author: * Author URI: * License: GPL-2.0+ * License URI: http://www.gnu.org/licenses/gpl-2.0.html */ /** * Main class. */ class Blazersix_Video { /** * Register Video custom post type. * * Registers the Video custom post type and related admin interface * elements (custom columns, update messages, meta boxes, standard menu). * * @link http://codex.wordpress.org/Function_Reference/register_post_type */ 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( 'can_export' => true, 'capability_type' => array( 'video', 'videos' ), 'capabilities' => $capabilities, 'delete_with_user' => null, 'description' => '', 'exclude_from_search' => false, 'has_archive' => false, 'hierarchical' => true, 'labels' => $labels, 'map_meta_cap' => false, 'menu_icon' => null, 'menu_position' => 50, 'public' => true, 'publicly_queryable' => true, 'register_meta_box_cb' => array( $this, 'register_meta_boxes' ), 'rewrite' => array( 'slug' => 'video', 'with_front' => false, 'feeds' => null, 'pages' => true, 'ep_mask' => EP_PERMALINK, ), 'query_var' => 'video', 'show_ui' => true, 'show_in_admin_bar' => true, 'show_in_menu' => true, 'show_in_nav_menus' => false, 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'page-attributes', 'post-formats' ), 'taxonomies' => array(), ) ); if ( is_admin() ) { add_filter( 'post_updated_messages', array( $this, 'updated_messages' ) ); add_filter( 'parse_query', array( $this, 'parse_admin_query' ) ); add_filter( 'manage_edit-video_columns', array( $this, 'register_columns' ) ); add_action( 'manage_edit-video_sortable_columns', array( $this, 'register_sortable_columns' ) ); add_action( 'manage_video_posts_custom_column', array( $this, 'display_columns' ), 10, 2 ); add_action( 'save_post', array( $this, 'save_post' ), 10, 2 ); } add_filter( 'map_meta_cap', array( $this, 'map_meta_cap' ), 10, 4 ); } /** * Video update messages. * * @see /wp-admin/edit-form-advanced.php * * @param array $messages The array of post update messages. * @return array An array with new CPT update messages. */ public function updated_messages( $messages ) { $post = get_post(); $post_type = get_post_type( $post ); $post_type_object = get_post_type_object( $post_type ); $messages['video'] = array( 0 => '', // Unused. Messages start at index 1. 1 => __( 'Video updated.', 'textdomain' ), 2 => __( 'Custom field updated.', 'textdomain' ), 3 => __( 'Custom field deleted.', 'textdomain' ), 4 => __( 'Video updated.', 'textdomain' ), /* 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, 6 => __( 'Video published.', 'textdomain' ), 7 => __( 'Video saved.', 'textdomain' ), 8 => __( 'Video submitted.', 'textdomain' ), 9 => sprintf( __( 'Video scheduled for: <strong>%1$s</strong>.', 'textdomain' ), // translators: Publish box date format, see http://php.net/date date_i18n( __( 'M j, Y @ G:i', 'textdomain' ), strtotime( $post->post_date ) ) ), 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; } /** * Custom sort the posts on the Manage Videos screen. * * @link http://codex.wordpress.org/Class_Reference/WP_Query * * @todo Update the sortable key to match the query_var set in the * register_sortable_columns() method. * @todo Implement custom sorting rules. * * @param WP_Query $wp_query The main WP_Query object passed by reference. */ public function parse_admin_query( $wp_query ) { // Ensure this only affects requests in the admin panel. if ( ! is_admin() || empty( $_GET['post_type'] ) || 'video' != $_GET['post_type'] ) { return; } // An array of custom sortable column query vars. $sortable_keys = array( 'blazersix_query-var' ); if ( ! empty( $_GET['orderby'] ) && in_array( $_GET['orderby'], $sortable_keys ) ) { // Set the order. $order = ( isset( $_GET['order'] ) && 'desc' == $_GET['order'] ) ? 'desc' : 'asc'; $wp_query->set( 'order', $order ); // Implement custom sorting rules. 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. * * @param array $columns Column names to display. */ public function register_columns( $columns ) { // $columns['blazersix_custom_column_id'] = _x( 'Column Name', 'column name', 'textdomain' ); return $columns; } /** * Register custom Video sortable columns. * * Registering a column as sortable will allow the table header to be * 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 * 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 * sorting rules. * * Multiple sortable columns may be registered at the same time. * * @param array $columns Column query vars with their corresponding column id as the key. */ public function register_sortable_columns( $columns ) { $columns['blazersix_custom_column_id'] = 'blazersix_query-var'; return $columns; } /** * Display custom Video columns. * * @param string $column_id The id of the column to display. * @param int $post_id Post ID. */ public function display_columns( $column_id, $post_id ) { switch ( $column_id ) { case 'blazersix_custom_column_id' : // Output the custom column content here. echo 'Value'; break; } } /** * Save Video CPT data. * * @see wp_insert_post() * * @param int $post_id Post ID. * @param WP_Post $post Post object. */ public function save_post( $post_id, $post ) { $is_autosave = defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE; $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 ); // Bail if the data shouldn't be saved or intention can't be verified. if ( $is_autosave || $is_revision || ! $is_valid_nonce ) { return; } // @todo Save custom data from $_POST global here. } /** * Register Video meta boxes. * * This is the callback defined in the Video CPT registration * function. Meta boxes or any other functionality that should be limited * to the Add/Edit Video screen and occurs after 'do_meta_boxes' * can be registered here. * * @param WP_Post $post Post object. */ public function register_meta_boxes( $post ) { // Update these parameters and uncomment to add a meta box. /* add_meta_box( 'meta-box-id', __( 'Video Meta Box', 'textdomain' ), array( $this, 'meta_box' ), 'video', 'normal', 'default' ); */ } /** * Display Video meta box. * * @param WP_Post $post Post object. * @param array $meta_box Arguments passed when the meta box was registered. */ public function meta_box( $post, $meta_box ) { wp_nonce_field( 'save-video_' . $post->ID, 'blazersix_video_nonce' ); ?> <p> <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"> </p> <p> <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> </p> <?php } /** * 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 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; } } $blazersix_video = new Blazersix_Video(); add_action( 'init', array( $blazersix_video, 'init' ) );
Trouver la différence