/wp-admin/post-new.php

https://gitlab.com/webteam/job_aag · PHP · 76 lines · 51 code · 13 blank · 12 comment · 20 complexity · 5ae636173e213f7e459d9cd6d64465e9 MD5 · raw file

  1. <?php
  2. /**
  3. * New Post Administration Screen.
  4. *
  5. * @package WordPress
  6. * @subpackage Administration
  7. */
  8. /** Load WordPress Administration Bootstrap */
  9. require_once( dirname( __FILE__ ) . '/admin.php' );
  10. global $post_type, $post_type_object, $post;
  11. if ( ! isset( $_GET['post_type'] ) ) {
  12. $post_type = 'post';
  13. } elseif ( in_array( $_GET['post_type'], get_post_types( array('show_ui' => true ) ) ) ) {
  14. $post_type = $_GET['post_type'];
  15. } else {
  16. wp_die( __('Invalid post type') );
  17. }
  18. $post_type_object = get_post_type_object( $post_type );
  19. if ( 'post' == $post_type ) {
  20. $parent_file = 'edit.php';
  21. $submenu_file = 'post-new.php';
  22. } elseif ( 'attachment' == $post_type ) {
  23. if ( wp_redirect( admin_url( 'media-new.php' ) ) )
  24. exit;
  25. } else {
  26. $submenu_file = "post-new.php?post_type=$post_type";
  27. if ( isset( $post_type_object ) && $post_type_object->show_in_menu && $post_type_object->show_in_menu !== true ) {
  28. $parent_file = $post_type_object->show_in_menu;
  29. // What if there isn't a post-new.php item for this post type?
  30. if ( ! isset( $_registered_pages[ get_plugin_page_hookname( "post-new.php?post_type=$post_type", $post_type_object->show_in_menu ) ] ) ) {
  31. if ( isset( $_registered_pages[ get_plugin_page_hookname( "edit.php?post_type=$post_type", $post_type_object->show_in_menu ) ] ) ) {
  32. // Fall back to edit.php for that post type, if it exists
  33. $submenu_file = "edit.php?post_type=$post_type";
  34. } else {
  35. // Otherwise, give up and highlight the parent
  36. $submenu_file = $parent_file;
  37. }
  38. }
  39. } else {
  40. $parent_file = "edit.php?post_type=$post_type";
  41. }
  42. }
  43. $title = $post_type_object->labels->add_new_item;
  44. $editing = true;
  45. if ( ! current_user_can( $post_type_object->cap->edit_posts ) || ! current_user_can( $post_type_object->cap->create_posts ) )
  46. wp_die( __( 'Cheatin&#8217; uh?' ), 403 );
  47. // Schedule auto-draft cleanup
  48. if ( ! wp_next_scheduled( 'wp_scheduled_auto_draft_delete' ) )
  49. wp_schedule_event( time(), 'daily', 'wp_scheduled_auto_draft_delete' );
  50. wp_enqueue_script( 'autosave' );
  51. if ( is_multisite() ) {
  52. add_action( 'admin_footer', '_admin_notice_post_locked' );
  53. } else {
  54. $check_users = get_users( array( 'fields' => 'ID', 'number' => 2 ) );
  55. if ( count( $check_users ) > 1 )
  56. add_action( 'admin_footer', '_admin_notice_post_locked' );
  57. unset( $check_users );
  58. }
  59. // Show post form.
  60. $post = get_default_post_to_edit( $post_type, true );
  61. $post_ID = $post->ID;
  62. include( ABSPATH . 'wp-admin/edit-form-advanced.php' );
  63. include( ABSPATH . 'wp-admin/admin-footer.php' );