32 public $__version =
'1.0.2';
51 public $url_images =
'';
60 public function __construct( $id, $args )
68 if ( !isset( $args[
'register_meta_box_cb'] ) ) {
69 $args[
'register_meta_box_cb'] = array( $this,
'register_meta_box' );
73 if ( isset( $args[
'menu_icon'] ) ) {
74 $this->url_images = trailingslashit( dirname( $args[
'menu_icon'] ) );
78 register_post_type( $id, $args );
81 $this->initAdminHook();
89 private function initAdminHook()
94 add_filter(
'admin_body_class', array( $this,
'admin_body_class' ) );
97 add_filter(
'post_updated_messages', array( $this,
'post_updated_messages' ) );
100 add_filter(
'enter_title_here', array( $this,
'_enter_title_here' ) );
103 add_action(
'save_post_' . $this->
id, array( $this,
'save_post' ), 10, 2 );
106 add_action(
'manage_' . $this->
id .
'_posts_custom_column', array( $this,
'manage_posts_custom_column' ) );
107 add_filter(
'manage_edit-' . $this->
id .
'_columns', array( $this,
'manage_edit_columns') );
108 add_filter(
'manage_edit-' . $this->
id .
'_sortable_columns', array( $this,
'manage_edit_sortable_columns' ) );
112 add_action(
'admin_head-post.php', array( $this,
'_will_load_post_list_edit' ) );
113 add_action(
'admin_head-edit.php', array( $this,
'_will_load_post_list_edit' ) );
114 add_action(
'admin_head-post-new.php', array( $this,
'_will_load_post_new' ) );
115 add_action(
'current_screen', array( $this,
'_current_screen' ) );
118 add_action(
'admin_footer-post.php', array( $this,
'admin_footer') );
121 if( !empty( $this->url_images ) ) {
122 add_action(
'admin_head', array( $this,
'admin_head' ) );
132 public function admin_head()
136 if ( $post_type != $this->
id ) {
142 <style type=
"text/css">
143 body.post-type-<?php echo $this->
id ?> .wrap > h2
145 background-image : url(<?php echo $this->url_images ?>logo-64x64.png);
146 background-repeat : no-repeat;
149 padding : 0 0 0 80px;
165 public function admin_body_class( $classes )
183 public function post_updated_messages()
197 public function _enter_title_here( $title )
201 if ( $post_type == $this->
id ) {
202 $title = $this->shouldEnterTitleHere( $title );
216 public function shouldEnterTitleHere( $title )
233 public function save_post( $post_id, $post =
'' )
237 if ( ( defined(
'DOING_AUTOSAVE' ) &&
true === DOING_AUTOSAVE ) ||
238 ( defined(
'DOING_AJAX' ) &&
true === DOING_AJAX ) ||
239 ( defined(
'DOING_CRON' ) &&
true === DOING_CRON )
245 $post_type = get_post_type();
246 $post_type_object = get_post_type_object( $post_type );
249 if (
false == $post_type || is_null( $post_type_object ) ) {
254 if ( !in_array( $post_type, array( $this->
id ) ) ) {
259 if ( isset( $post_type_object->cap->edit_posts ) ) {
260 $capability = $post_type_object->cap->edit_posts;
263 if ( !current_user_can( $capability ) ) {
270 $this->update( $post_id, $post );
285 public function update( $post_id, $post )
299 public function manage_posts_custom_column( $column )
313 public function manage_edit_columns( $columns )
328 public function manage_edit_sortable_columns( $columns )
339 public function _will_load_post_list_edit()
343 if ( $post_type == $this->
id ) {
344 $this->willLoadAdminPost();
345 if ( isset( $_REQUEST[
'action'] ) &&
'edit' == $_REQUEST[
'action'] ) {
346 $this->willLoadEditPost();
348 $this->willLoadListPost();
358 public function willLoadEditPost()
368 public function willLoadListPost()
378 public function _will_load_post_new()
382 if ( $this->
id == $post_type ) {
383 $this->willLoadAdminPost();
384 $this->willLoadPostNew();
393 public function willLoadPostNew()
403 public function willLoadAdminPost()
415 public function _current_screen( $screen )
417 if ( !empty( $screen->post_type ) && $screen->post_type == $this->id ) {
418 $this->willLoadAdminPost();
429 public function admin_footer()
439 public function register_meta_box()