post-new.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /**
  3. * New Post Administration Screen.
  4. *
  5. * @package WordPress
  6. * @subpackage Administration
  7. */
  8. /** Load WordPress Administration Bootstrap */
  9. require_once __DIR__ . '/admin.php';
  10. /**
  11. * @global string $post_type
  12. * @global object $post_type_object
  13. * @global WP_Post $post Global post object.
  14. */
  15. global $post_type, $post_type_object, $post;
  16. if ( ! isset( $_GET['post_type'] ) ) {
  17. $post_type = 'post';
  18. } elseif ( in_array( $_GET['post_type'], get_post_types( array( 'show_ui' => true ) ), true ) ) {
  19. $post_type = $_GET['post_type'];
  20. } else {
  21. wp_die( __( 'Invalid post type.' ) );
  22. }
  23. $post_type_object = get_post_type_object( $post_type );
  24. if ( 'post' === $post_type ) {
  25. $parent_file = 'edit.php';
  26. $submenu_file = 'post-new.php';
  27. } elseif ( 'attachment' === $post_type ) {
  28. if ( wp_redirect( admin_url( 'media-new.php' ) ) ) {
  29. exit;
  30. }
  31. } else {
  32. $submenu_file = "post-new.php?post_type=$post_type";
  33. if ( isset( $post_type_object ) && $post_type_object->show_in_menu && true !== $post_type_object->show_in_menu ) {
  34. $parent_file = $post_type_object->show_in_menu;
  35. // What if there isn't a post-new.php item for this post type?
  36. if ( ! isset( $_registered_pages[ get_plugin_page_hookname( "post-new.php?post_type=$post_type", $post_type_object->show_in_menu ) ] ) ) {
  37. if ( isset( $_registered_pages[ get_plugin_page_hookname( "edit.php?post_type=$post_type", $post_type_object->show_in_menu ) ] ) ) {
  38. // Fall back to edit.php for that post type, if it exists.
  39. $submenu_file = "edit.php?post_type=$post_type";
  40. } else {
  41. // Otherwise, give up and highlight the parent.
  42. $submenu_file = $parent_file;
  43. }
  44. }
  45. } else {
  46. $parent_file = "edit.php?post_type=$post_type";
  47. }
  48. }
  49. $title = $post_type_object->labels->add_new_item;
  50. $editing = true;
  51. if ( ! current_user_can( $post_type_object->cap->edit_posts ) || ! current_user_can( $post_type_object->cap->create_posts ) ) {
  52. wp_die(
  53. '<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' .
  54. '<p>' . __( 'Sorry, you are not allowed to create posts as this user.' ) . '</p>',
  55. 403
  56. );
  57. }
  58. $post = get_default_post_to_edit( $post_type, true );
  59. $post_ID = $post->ID;
  60. /** This filter is documented in wp-admin/post.php */
  61. if ( apply_filters( 'replace_editor', false, $post ) !== true ) {
  62. if ( use_block_editor_for_post( $post ) ) {
  63. require ABSPATH . 'wp-admin/edit-form-blocks.php';
  64. } else {
  65. wp_enqueue_script( 'autosave' );
  66. require ABSPATH . 'wp-admin/edit-form-advanced.php';
  67. }
  68. } else {
  69. // Flag that we're not loading the block editor.
  70. $current_screen = get_current_screen();
  71. $current_screen->is_block_editor( false );
  72. }
  73. require_once ABSPATH . 'wp-admin/admin-footer.php';