Created
April 18, 2020 22:42
-
-
Save mavieth/5dd77fc79f9686084fd4c3def485b480 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 | |
function projects_init() { | |
register_post_type( 'projects', array( | |
'labels' => array( | |
'name' => __( 'Projects', 'twentytwenty-child' ), | |
'singular_name' => __( 'Project', 'twentytwenty-child' ), | |
'all_items' => __( 'All Projects', 'twentytwenty-child' ), | |
'new_item' => __( 'New Project', 'twentytwenty-child' ), | |
'add_new' => __( 'Add New', 'twentytwenty-child' ), | |
'add_new_item' => __( 'Add New Project', 'twentytwenty-child' ), | |
'edit_item' => __( 'Edit Project', 'twentytwenty-child' ), | |
'view_item' => __( 'View Project', 'twentytwenty-child' ), | |
'search_items' => __( 'Search Projects', 'twentytwenty-child' ), | |
'not_found' => __( 'No Projects found', 'twentytwenty-child' ), | |
'not_found_in_trash' => __( 'No Projects found in trash', 'twentytwenty-child' ), | |
'parent_item_colon' => __( 'Parent Project', 'twentytwenty-child' ), | |
'menu_name' => __( 'Projects', 'twentytwenty-child' ), | |
), | |
'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_icon' => 'dashicons-editor-ul', | |
'show_in_rest' => true, | |
'rest_base' => 'projects', | |
'rest_controller_class' => 'WP_REST_Posts_Controller', | |
) ); | |
} | |
add_action( 'init', 'projects_init' ); | |
function projects_updated_messages( $messages ) { | |
global $post; | |
$permalink = get_permalink( $post ); | |
$messages['projects'] = array( | |
0 => '', // Unused. Messages start at index 1. | |
1 => sprintf( __('Project updated. <a target="_blank" href="%s">View Project</a>', 'twentytwenty-child'), esc_url( $permalink ) ), | |
2 => __('Custom field updated.', 'twentytwenty-child'), | |
3 => __('Custom field deleted.', 'twentytwenty-child'), | |
4 => __('Project updated.', 'twentytwenty-child'), | |
/* translators: %s: date and time of the revision */ | |
5 => isset($_GET['revision']) ? sprintf( __('Project restored to revision from %s', 'twentytwenty-child'), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, | |
6 => sprintf( __('Project published. <a href="%s">View Project</a>', 'twentytwenty-child'), esc_url( $permalink ) ), | |
7 => __('Project saved.', 'twentytwenty-child'), | |
8 => sprintf( __('Project submitted. <a target="_blank" href="%s">Preview Project</a>', 'twentytwenty-child'), esc_url( add_query_arg( 'preview', 'true', $permalink ) ) ), | |
9 => sprintf( __('Project scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview Project</a>', 'twentytwenty-child'), | |
// translators: Publish box date format, see http://php.net/date | |
date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( $permalink ) ), | |
10 => sprintf( __('Project draft updated. <a target="_blank" href="%s">Preview Project</a>', 'twentytwenty-child'), esc_url( add_query_arg( 'preview', 'true', $permalink ) ) ), | |
); | |
return $messages; | |
} | |
add_filter( 'post_updated_messages', 'projects_updated_messages' ); | |
function project_category_init() { | |
register_taxonomy( 'project-category', array( 'projects' ), array( | |
'hierarchical' => false, | |
'public' => true, | |
'show_in_nav_menus' => true, | |
'show_ui' => true, | |
'show_admin_column' => false, | |
'query_var' => true, | |
'rewrite' => true, | |
'capabilities' => array( | |
'manage_terms' => 'edit_posts', | |
'edit_terms' => 'edit_posts', | |
'delete_terms' => 'edit_posts', | |
'assign_terms' => 'edit_posts' | |
), | |
'labels' => array( | |
'name' => __( 'Category', 'twentytwenty-child' ), | |
'singular_name' => _x( 'Categories', 'taxonomy general name', 'twentytwenty-child' ), | |
'search_items' => __( 'Search category', 'twentytwenty-child' ), | |
'popular_items' => __( 'Popular category', 'twentytwenty-child' ), | |
'all_items' => __( 'All category', 'twentytwenty-child' ), | |
'parent_item' => __( 'Parent categories', 'twentytwenty-child' ), | |
'parent_item_colon' => __( 'Parent categories:', 'twentytwenty-child' ), | |
'edit_item' => __( 'Edit categories', 'twentytwenty-child' ), | |
'update_item' => __( 'Update categories', 'twentytwenty-child' ), | |
'add_new_item' => __( 'New categories', 'twentytwenty-child' ), | |
'new_item_name' => __( 'New categories', 'twentytwenty-child' ), | |
'separate_items_with_commas' => __( 'Separate category with commas', 'twentytwenty-child' ), | |
'add_or_remove_items' => __( 'Add or remove category', 'twentytwenty-child' ), | |
'choose_from_most_used' => __( 'Choose from the most used category', 'twentytwenty-child' ), | |
'not_found' => __( 'No category found.', 'twentytwenty-child' ), | |
'menu_name' => __( 'Category', 'twentytwenty-child' ), | |
), | |
'show_in_rest' => true, | |
'rest_base' => 'project-category', | |
'rest_controller_class' => 'WP_REST_Terms_Controller', | |
) ); | |
} | |
add_action( 'init', 'project_category_init' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment