| 1 |
<?php |
| 2 |
/** |
| 3 |
* Bootstraps the new posts dashboard page. |
| 4 |
* |
| 5 |
* @package Gutenberg |
| 6 |
*/ |
| 7 |
|
| 8 |
add_action( 'admin_menu', 'gutenberg_replace_posts_dashboard' ); |
| 9 |
|
| 10 |
/** |
| 11 |
* Renders the new posts dashboard page. |
| 12 |
*/ |
| 13 |
function gutenberg_posts_dashboard() { |
| 14 |
wp_register_style( |
| 15 |
'wp-gutenberg-posts-dashboard', |
| 16 |
gutenberg_url( 'build/edit-site/posts.css', __FILE__ ), |
| 17 |
array( 'wp-components', 'wp-commands' ) |
| 18 |
); |
| 19 |
wp_enqueue_style( 'wp-gutenberg-posts-dashboard' ); |
| 20 |
wp_add_inline_script( 'wp-edit-site', 'window.wp.editSite.initializePostsDashboard( "gutenberg-posts-dashboard" );', 'after' ); |
| 21 |
wp_enqueue_script( 'wp-edit-site' ); |
| 22 |
|
| 23 |
echo '<div id="gutenberg-posts-dashboard"></div>'; |
| 24 |
} |
| 25 |
|
| 26 |
/** |
| 27 |
* Replaces the default posts menu item with the new posts dashboard. |
| 28 |
*/ |
| 29 |
function gutenberg_replace_posts_dashboard() { |
| 30 |
$gutenberg_experiments = get_option( 'gutenberg-experiments' ); |
| 31 |
if ( ! $gutenberg_experiments || ! array_key_exists( 'gutenberg-new-posts-dashboard', $gutenberg_experiments ) || ! $gutenberg_experiments['gutenberg-new-posts-dashboard'] ) { |
| 32 |
return; |
| 33 |
} |
| 34 |
$ptype_obj = get_post_type_object( 'post' ); |
| 35 |
add_submenu_page( |
| 36 |
'gutenberg', |
| 37 |
$ptype_obj->labels->name, |
| 38 |
$ptype_obj->labels->name, |
| 39 |
'edit_posts', |
| 40 |
'gutenberg-posts-dashboard', |
| 41 |
'gutenberg_posts_dashboard' |
| 42 |
); |
| 43 |
} |
| 44 |
|