| 1 |
<?php |
| 2 |
/** |
| 3 |
* Post Types Admin |
| 4 |
* |
| 5 |
* @class FT_Admin_Post_Types |
| 6 |
* @version 1.1.0 |
| 7 |
* @package FlashToolkit/Admin |
| 8 |
* @category Admin |
| 9 |
* @author ThemeGrill |
| 10 |
*/ |
| 11 |
|
| 12 |
if ( ! defined( 'ABSPATH' ) ) { |
| 13 |
exit; |
| 14 |
} |
| 15 |
|
| 16 |
/** |
| 17 |
* FT_Admin_Post_Types Class |
| 18 |
* |
| 19 |
* Handles the edit posts views and some functionality on the edit post screen for FT post types. |
| 20 |
*/ |
| 21 |
class FT_Admin_Post_Types { |
| 22 |
|
| 23 |
/** |
| 24 |
* Constructor. |
| 25 |
*/ |
| 26 |
public function __construct() { |
| 27 |
add_filter( 'post_updated_messages', array( $this, 'post_updated_messages' ) ); |
| 28 |
add_filter( 'bulk_post_updated_messages', array( $this, 'bulk_post_updated_messages' ), 10, 2 ); |
| 29 |
|
| 30 |
// Edit post screens |
| 31 |
add_filter( 'enter_title_here', array( $this, 'enter_title_here' ), 1, 2 ); |
| 32 |
add_filter( 'default_hidden_meta_boxes', array( $this, 'hidden_meta_boxes' ), 10, 2 ); |
| 33 |
|
| 34 |
// Meta-Box Class |
| 35 |
include_once( dirname( __FILE__ ) . '/class-flash-admin-meta-boxes.php' ); |
| 36 |
|
| 37 |
// Disable DFW feature pointer |
| 38 |
add_action( 'admin_footer', array( $this, 'disable_dfw_feature_pointer' ) ); |
| 39 |
|
| 40 |
// Disable post type view mode options |
| 41 |
add_filter( 'view_mode_post_types', array( $this, 'disable_view_mode_options' ) ); |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* Change messages when a post type is updated. |
| 46 |
* @param array $messages |
| 47 |
* @return array |
| 48 |
*/ |
| 49 |
public function post_updated_messages( $messages ) { |
| 50 |
global $post, $post_ID; |
| 51 |
|
| 52 |
$messages['portfolio'] = array( |
| 53 |
0 => '', // Unused. Messages start at index 1. |
| 54 |
1 => sprintf( __( 'Project updated. <a href="%s">View Project</a>', 'flash-toolkit' ), esc_url( get_permalink( $post_ID ) ) ), |
| 55 |
2 => __( 'Custom field updated.', 'flash-toolkit' ), |
| 56 |
3 => __( 'Custom field deleted.', 'flash-toolkit' ), |
| 57 |
4 => __( 'Project updated.', 'flash-toolkit' ), |
| 58 |
5 => isset( $_GET['revision'] ) ? sprintf( __( 'Project restored to revision from %s', 'flash-toolkit' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
| 59 |
6 => sprintf( __( 'Project published. <a href="%s">View Project</a>', 'flash-toolkit' ), esc_url( get_permalink( $post_ID ) ) ), |
| 60 |
7 => __( 'Project saved.', 'flash-toolkit' ), |
| 61 |
8 => sprintf( __( 'Project submitted. <a target="_blank" href="%s">Preview project</a>', 'flash-toolkit' ), esc_url( add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ) ), |
| 62 |
9 => sprintf( __( 'Project scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview project</a>', 'flash-toolkit' ), |
| 63 |
date_i18n( __( 'M j, Y @ G:i', 'flash-toolkit' ), strtotime( $post->post_date ) ), esc_url( get_permalink( $post_ID ) ) ), |
| 64 |
10 => sprintf( __( 'Project draft updated. <a target="_blank" href="%s">Preview project</a>', 'flash-toolkit' ), esc_url( add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ) ), |
| 65 |
); |
| 66 |
|
| 67 |
return $messages; |
| 68 |
} |
| 69 |
|
| 70 |
/** |
| 71 |
* Specify custom bulk actions messages for different post types. |
| 72 |
* @param array $bulk_messages |
| 73 |
* @param array $bulk_counts |
| 74 |
* @return array |
| 75 |
*/ |
| 76 |
public function bulk_post_updated_messages( $bulk_messages, $bulk_counts ) { |
| 77 |
|
| 78 |
$bulk_messages['portfolio'] = array( |
| 79 |
'updated' => _n( '%s project updated.', '%s projects updated.', $bulk_counts['updated'], 'flash-toolkit' ), |
| 80 |
'locked' => _n( '%s project not updated, somebody is editing it.', '%s projects not updated, somebody is editing them.', $bulk_counts['locked'], 'flash-toolkit' ), |
| 81 |
'deleted' => _n( '%s project permanently deleted.', '%s projects permanently deleted.', $bulk_counts['deleted'], 'flash-toolkit' ), |
| 82 |
'trashed' => _n( '%s project moved to the Trash.', '%s projects moved to the Trash.', $bulk_counts['trashed'], 'flash-toolkit' ), |
| 83 |
'untrashed' => _n( '%s project restored from the Trash.', '%s projects restored from the Trash.', $bulk_counts['untrashed'], 'flash-toolkit' ), |
| 84 |
); |
| 85 |
|
| 86 |
return $bulk_messages; |
| 87 |
} |
| 88 |
|
| 89 |
/** |
| 90 |
* Change title boxes in admin. |
| 91 |
* @param string $text |
| 92 |
* @param object $post |
| 93 |
* @return string |
| 94 |
*/ |
| 95 |
public function enter_title_here( $text, $post ) { |
| 96 |
switch ( $post->post_type ) { |
| 97 |
case 'portfolio' : |
| 98 |
$text = __( 'Project name', 'flash-toolkit' ); |
| 99 |
break; |
| 100 |
} |
| 101 |
|
| 102 |
return $text; |
| 103 |
} |
| 104 |
|
| 105 |
/** |
| 106 |
* Hidden default Meta-Boxes. |
| 107 |
* @param array $hidden |
| 108 |
* @param object $screen |
| 109 |
* @return array |
| 110 |
*/ |
| 111 |
public function hidden_meta_boxes( $hidden, $screen ) { |
| 112 |
if ( 'portfolio' === $screen->post_type && 'post' === $screen->base ) { |
| 113 |
$hidden = array_merge( $hidden, array( 'postcustom' ) ); |
| 114 |
} |
| 115 |
|
| 116 |
return $hidden; |
| 117 |
} |
| 118 |
|
| 119 |
/** |
| 120 |
* Disable DFW feature pointer. |
| 121 |
*/ |
| 122 |
public function disable_dfw_feature_pointer() { |
| 123 |
$screen = get_current_screen(); |
| 124 |
|
| 125 |
if ( $screen && 'portfolio' === $screen->id && 'post' === $screen->base ) { |
| 126 |
remove_action( 'admin_print_footer_scripts', array( 'WP_Internal_Pointers', 'pointer_wp410_dfw' ) ); |
| 127 |
} |
| 128 |
} |
| 129 |
|
| 130 |
/** |
| 131 |
* Removes portfolio from the list of post types that support "View Mode" switching. |
| 132 |
* View mode is seen on posts where you can switch between list or excerpt. Our post types don't support |
| 133 |
* it, so we want to hide the useless UI from the screen options tab. |
| 134 |
* |
| 135 |
* @param array $post_types Array of post types supporting view mode |
| 136 |
* @return array Array of post types supporting view mode, without portfolio |
| 137 |
*/ |
| 138 |
public function disable_view_mode_options( $post_types ) { |
| 139 |
unset( $post_types['portfolio'] ); |
| 140 |
return $post_types; |
| 141 |
} |
| 142 |
} |
| 143 |
|
| 144 |
new FT_Admin_Post_Types(); |
| 145 |
|