Created
November 3, 2021 16:03
-
-
Save ethanclevenger91/9ac4ebfedc563c3313a6f52e83434103 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Registers the `dog` post type. | |
*/ | |
function dog_init() { | |
register_post_type( 'dog', array( | |
'labels' => array( | |
'name' => __( 'Dogs', 'YOUR-TEXTDOMAIN' ), | |
'singular_name' => __( 'Dog', 'YOUR-TEXTDOMAIN' ), | |
'all_items' => __( 'All Dogs', 'YOUR-TEXTDOMAIN' ), | |
'archives' => __( 'Dog Archives', 'YOUR-TEXTDOMAIN' ), | |
'attributes' => __( 'Dog Attributes', 'YOUR-TEXTDOMAIN' ), | |
'insert_into_item' => __( 'Insert into dog', 'YOUR-TEXTDOMAIN' ), | |
'uploaded_to_this_item' => __( 'Uploaded to this dog', 'YOUR-TEXTDOMAIN' ), | |
'featured_image' => _x( 'Featured Image', 'dog', 'YOUR-TEXTDOMAIN' ), | |
'set_featured_image' => _x( 'Set featured image', 'dog', 'YOUR-TEXTDOMAIN' ), | |
'remove_featured_image' => _x( 'Remove featured image', 'dog', 'YOUR-TEXTDOMAIN' ), | |
'use_featured_image' => _x( 'Use as featured image', 'dog', 'YOUR-TEXTDOMAIN' ), | |
'filter_items_list' => __( 'Filter dogs list', 'YOUR-TEXTDOMAIN' ), | |
'items_list_navigation' => __( 'Dogs list navigation', 'YOUR-TEXTDOMAIN' ), | |
'items_list' => __( 'Dogs list', 'YOUR-TEXTDOMAIN' ), | |
'new_item' => __( 'New Dog', 'YOUR-TEXTDOMAIN' ), | |
'add_new' => __( 'Add New', 'YOUR-TEXTDOMAIN' ), | |
'add_new_item' => __( 'Add New Dog', 'YOUR-TEXTDOMAIN' ), | |
'edit_item' => __( 'Edit Dog', 'YOUR-TEXTDOMAIN' ), | |
'view_item' => __( 'View Dog', 'YOUR-TEXTDOMAIN' ), | |
'view_items' => __( 'View Dogs', 'YOUR-TEXTDOMAIN' ), | |
'search_items' => __( 'Search dogs', 'YOUR-TEXTDOMAIN' ), | |
'not_found' => __( 'No dogs found', 'YOUR-TEXTDOMAIN' ), | |
'not_found_in_trash' => __( 'No dogs found in trash', 'YOUR-TEXTDOMAIN' ), | |
'parent_item_colon' => __( 'Parent Dog:', 'YOUR-TEXTDOMAIN' ), | |
'menu_name' => __( 'Dogs', 'YOUR-TEXTDOMAIN' ), | |
), | |
'public' => true, | |
'hierarchical' => false, | |
'show_ui' => true, | |
'show_in_nav_menus' => true, | |
'supports' => array( 'title', 'editor' ), | |
'has_archive' => true, | |
'rewrite' => true, | |
'query_var' => true, | |
'menu_position' => null, | |
'menu_icon' => 'dashicons-admin-post', | |
'show_in_rest' => true, | |
'rest_base' => 'dog', | |
'rest_controller_class' => 'WP_REST_Posts_Controller', | |
) ); | |
} | |
add_action( 'init', 'dog_init' ); | |
/** | |
* Sets the post updated messages for the `dog` post type. | |
* | |
* @param array $messages Post updated messages. | |
* @return array Messages for the `dog` post type. | |
*/ | |
function dog_updated_messages( $messages ) { | |
global $post; | |
$permalink = get_permalink( $post ); | |
$messages['dog'] = array( | |
0 => '', // Unused. Messages start at index 1. | |
/* translators: %s: post permalink */ | |
1 => sprintf( __( 'Dog updated. <a target="_blank" href="%s">View dog</a>', 'YOUR-TEXTDOMAIN' ), esc_url( $permalink ) ), | |
2 => __( 'Custom field updated.', 'YOUR-TEXTDOMAIN' ), | |
3 => __( 'Custom field deleted.', 'YOUR-TEXTDOMAIN' ), | |
4 => __( 'Dog updated.', 'YOUR-TEXTDOMAIN' ), | |
/* translators: %s: date and time of the revision */ | |
5 => isset( $_GET['revision'] ) ? sprintf( __( 'Dog restored to revision from %s', 'YOUR-TEXTDOMAIN' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, | |
/* translators: %s: post permalink */ | |
6 => sprintf( __( 'Dog published. <a href="%s">View dog</a>', 'YOUR-TEXTDOMAIN' ), esc_url( $permalink ) ), | |
7 => __( 'Dog saved.', 'YOUR-TEXTDOMAIN' ), | |
/* translators: %s: post permalink */ | |
8 => sprintf( __( 'Dog submitted. <a target="_blank" href="%s">Preview dog</a>', 'YOUR-TEXTDOMAIN' ), esc_url( add_query_arg( 'preview', 'true', $permalink ) ) ), | |
/* translators: 1: Publish box date format, see https://secure.php.net/date 2: Post permalink */ | |
9 => sprintf( __( 'Dog scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview dog</a>', 'YOUR-TEXTDOMAIN' ), | |
date_i18n( __( 'M j, Y @ G:i', 'YOUR-TEXTDOMAIN' ), strtotime( $post->post_date ) ), esc_url( $permalink ) ), | |
/* translators: %s: post permalink */ | |
10 => sprintf( __( 'Dog draft updated. <a target="_blank" href="%s">Preview dog</a>', 'YOUR-TEXTDOMAIN' ), esc_url( add_query_arg( 'preview', 'true', $permalink ) ) ), | |
); | |
return $messages; | |
} | |
add_filter( 'post_updated_messages', 'dog_updated_messages' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment