| 1 | <?php
|
|---|
| 2 | /*
|
|---|
| 3 | Plugin Name: Explain my bug
|
|---|
| 4 | Plugin URI: http://wordpress.org
|
|---|
| 5 | Description: Bug proof.
|
|---|
| 6 | Author: Amaury Balmer
|
|---|
| 7 | Version: 0
|
|---|
| 8 | Author URI: http://beapi.fr
|
|---|
| 9 | */
|
|---|
| 10 |
|
|---|
| 11 | // 1. Register a custom post type
|
|---|
| 12 | add_action('init', 'register_my_cpt');
|
|---|
| 13 | function register_my_cpt() {
|
|---|
| 14 | register_post_type( 'test', array(
|
|---|
| 15 | 'public' => true,
|
|---|
| 16 | 'capability_type' => 'post',
|
|---|
| 17 | 'map_meta_cap' => true,
|
|---|
| 18 | 'hierarchical' => false,
|
|---|
| 19 | 'rewrite' => false,
|
|---|
| 20 | 'query_var' => false,
|
|---|
| 21 | 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'post-formats' ),
|
|---|
| 22 | 'menu_position' => 25 // Bug with the value 25 and 26
|
|---|
| 23 | ) );
|
|---|
| 24 | }
|
|---|
| 25 |
|
|---|
| 26 | // 2. Add menu with the function add_object_page()
|
|---|
| 27 | add_action('admin_menu', 'update_menu_admin');
|
|---|
| 28 | function update_menu_admin() {
|
|---|
| 29 | add_object_page('My Menu', 'My Menu', 'manage_options', 'my-menu', 'my_page');
|
|---|
| 30 | }
|
|---|
| 31 | function my_page() {
|
|---|
| 32 | echo 'Hello world';
|
|---|
| 33 | }
|
|---|
| 34 |
|
|---|
| 35 | // 3. See the menu, you will see that the post type test is overwrite by the custom menu.
|
|---|
| 36 | ?>
|
|---|