Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@leo020588
Created July 23, 2022 17:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leo020588/c9b82883fc1b0275e0f46bf0b0ece083 to your computer and use it in GitHub Desktop.
Save leo020588/c9b82883fc1b0275e0f46bf0b0ece083 to your computer and use it in GitHub Desktop.
Wordpress bug plugin showcase
<?php
/**
* Plugin Name: Bug Test
*/
/** 1. Add Movies Custom Post Type */
add_action( 'init', function () {
register_post_type( 'movies', [
'label' => 'Movies',
'public' => true,
'capability_type' => 'movie',
'map_meta_cap' => true,
] );
register_taxonomy( 'genre', 'movies', [
'labels' => [ 'name' => 'Genre' ],
'public' => true,
'show_in_menu' => false,
'capabilities' => [
'manage_terms' => 'manage_genres',
'edit_terms' => 'manage_genres',
'delete_terms' => 'manage_genres',
'assign_terms' => 'edit_movies',
],
] );
} );
/** 2. Hide Movies submenu */
add_action( 'admin_menu', function () {
remove_submenu_page(
'edit.php?post_type=movies',
'post-new.php?post_type=movies'
);
}, 999 );
/** 3. Register Movie Editor role */
register_activation_hook( __FILE__, function () {
add_role( 'movie-editor', 'Movie Editor', [
'read' => true,
'edit_movies' => true,
'publish_movies' => true,
'delete_movies' => true,
'delete_published_movies' => true,
'edit_published_movies' => true,
'manage_genres' => true,
] );
} );
register_deactivation_hook( __FILE__, function () {
remove_role( 'movie-editor' );
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment