post_type = $post_type; $this->plural = $plural; $this->single = $single; $this->description = $description; $this->options = $options; // Regsiter post type. add_action( 'init', array( $this, 'register_post_type' ) ); // Display custom update messages for posts edits. add_filter( 'post_updated_messages', array( $this, 'updated_messages' ) ); add_filter( 'bulk_post_updated_messages', array( $this, 'bulk_updated_messages' ), 10, 2 ); } /** * Register new post type * * @return void */ public function register_post_type() { //phpcs:disable $labels = array( 'name' => $this->plural, 'singular_name' => $this->single, 'name_admin_bar' => $this->single, 'add_new' => _x( 'Add New', $this->post_type, 'bricksable' ), 'add_new_item' => sprintf( __( 'Add New %s', 'bricksable' ), $this->single ), 'edit_item' => sprintf( __( 'Edit %s', 'bricksable' ), $this->single ), 'new_item' => sprintf( __( 'New %s', 'bricksable' ), $this->single ), 'all_items' => sprintf( __( 'All %s', 'bricksable' ), $this->plural ), 'view_item' => sprintf( __( 'View %s', 'bricksable' ), $this->single ), 'search_items' => sprintf( __( 'Search %s', 'bricksable' ), $this->plural ), 'not_found' => sprintf( __( 'No %s Found', 'bricksable' ), $this->plural ), 'not_found_in_trash' => sprintf( __( 'No %s Found In Trash', 'bricksable' ), $this->plural ), 'parent_item_colon' => sprintf( __( 'Parent %s' ), $this->single ), 'menu_name' => $this->plural, ); //phpcs:enable $args = array( 'labels' => apply_filters( $this->post_type . '_labels', $labels ), 'description' => $this->description, 'public' => true, 'publicly_queryable' => true, 'exclude_from_search' => false, 'show_ui' => true, 'show_in_menu' => true, 'show_in_nav_menus' => true, 'query_var' => true, 'can_export' => true, 'rewrite' => true, 'capability_type' => 'post', 'has_archive' => true, 'hierarchical' => true, 'show_in_rest' => true, 'rest_base' => $this->post_type, 'rest_controller_class' => 'WP_REST_Posts_Controller', 'supports' => array( 'title', 'editor', 'excerpt', 'comments', 'thumbnail' ), 'menu_position' => 5, 'menu_icon' => 'dashicons-admin-post', ); $args = array_merge( $args, $this->options ); register_post_type( $this->post_type, apply_filters( $this->post_type . '_register_args', $args, $this->post_type ) ); } /** * Set up admin messages for post type * * @param array $messages Default message. * @return array Modified messages. */ public function updated_messages( $messages = array() ) { global $post, $post_ID; //phpcs:disable $messages[ $this->post_type ] = array( 0 => '', 1 => sprintf( __( '%1$s updated. %2$sView %3$s%4$s.', 'bricksable' ), $this->single, '', $this->single, '' ), 2 => __( 'Custom field updated.', 'bricksable' ), 3 => __( 'Custom field deleted.', 'bricksable' ), 4 => sprintf( __( '%1$s updated.', 'bricksable' ), $this->single ), 5 => isset( $_GET['revision'] ) ? sprintf( __( '%1$s restored to revision from %2$s.', 'bricksable' ), $this->single, wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, 6 => sprintf( __( '%1$s published. %2$sView %3$s%4$s.', 'bricksable' ), $this->single, '', $this->single, '' ), 7 => sprintf( __( '%1$s saved.', 'bricksable' ), $this->single ), 8 => sprintf( __( '%1$s submitted. %2$sPreview post%3$s%4$s.', 'bricksable' ), $this->single, '', $this->single, '' ), 9 => sprintf( __( '%1$s scheduled for: %2$s. %3$sPreview %4$s%5$s.', 'bricksable' ), $this->single, '' . date_i18n( __( 'M j, Y @ G:i', 'bricksable' ), strtotime( $post->post_date ) ) . '', '', $this->single, '' ), 10 => sprintf( __( '%1$s draft updated. %2$sPreview %3$s%4$s.', 'bricksable' ), $this->single, '', $this->single, '' ), ); //phpcs:enable return $messages; } /** * Set up bulk admin messages for post type * * @param array $bulk_messages Default bulk messages. * @param array $bulk_counts Counts of selected posts in each status. * @return array Modified messages. */ public function bulk_updated_messages( $bulk_messages = array(), $bulk_counts = array() ) { //phpcs:disable $bulk_messages[ $this->post_type ] = array( 'updated' => sprintf( _n( '%1$s %2$s updated.', '%1$s %3$s updated.', $bulk_counts['updated'], 'bricksable' ), $bulk_counts['updated'], $this->single, $this->plural ), 'locked' => sprintf( _n( '%1$s %2$s not updated, somebody is editing it.', '%1$s %3$s not updated, somebody is editing them.', $bulk_counts['locked'], 'bricksable' ), $bulk_counts['locked'], $this->single, $this->plural ), 'deleted' => sprintf( _n( '%1$s %2$s permanently deleted.', '%1$s %3$s permanently deleted.', $bulk_counts['deleted'], 'bricksable' ), $bulk_counts['deleted'], $this->single, $this->plural ), 'trashed' => sprintf( _n( '%1$s %2$s moved to the Trash.', '%1$s %3$s moved to the Trash.', $bulk_counts['trashed'], 'bricksable' ), $bulk_counts['trashed'], $this->single, $this->plural ), 'untrashed' => sprintf( _n( '%1$s %2$s restored from the Trash.', '%1$s %3$s restored from the Trash.', $bulk_counts['untrashed'], 'bricksable' ), $bulk_counts['untrashed'], $this->single, $this->plural ), ); //phpcs:enable return $bulk_messages; } }