wp/wp-admin/post-new.php
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
equal deleted inserted replaced
4:346c88efed21 5:5e2f62d02dcd
     7  */
     7  */
     8 
     8 
     9 /** Load WordPress Administration Bootstrap */
     9 /** Load WordPress Administration Bootstrap */
    10 require_once( dirname( __FILE__ ) . '/admin.php' );
    10 require_once( dirname( __FILE__ ) . '/admin.php' );
    11 
    11 
    12 if ( !isset($_GET['post_type']) )
    12 global $post_type, $post_type_object, $post;
       
    13 
       
    14 if ( ! isset( $_GET['post_type'] ) ) {
    13 	$post_type = 'post';
    15 	$post_type = 'post';
    14 elseif ( in_array( $_GET['post_type'], get_post_types( array('show_ui' => true ) ) ) )
    16 } elseif ( in_array( $_GET['post_type'], get_post_types( array('show_ui' => true ) ) ) ) {
    15 	$post_type = $_GET['post_type'];
    17 	$post_type = $_GET['post_type'];
    16 else
    18 } else {
    17 	wp_die( __('Invalid post type') );
    19 	wp_die( __('Invalid post type') );
    18 
    20 }
    19 $post_type_object = get_post_type_object( $post_type );
    21 $post_type_object = get_post_type_object( $post_type );
    20 
    22 
    21 if ( 'post' == $post_type ) {
    23 if ( 'post' == $post_type ) {
    22 	$parent_file = 'edit.php';
    24 	$parent_file = 'edit.php';
    23 	$submenu_file = 'post-new.php';
    25 	$submenu_file = 'post-new.php';
    26 		exit;
    28 		exit;
    27 } else {
    29 } else {
    28 	$submenu_file = "post-new.php?post_type=$post_type";
    30 	$submenu_file = "post-new.php?post_type=$post_type";
    29 	if ( isset( $post_type_object ) && $post_type_object->show_in_menu && $post_type_object->show_in_menu !== true ) {
    31 	if ( isset( $post_type_object ) && $post_type_object->show_in_menu && $post_type_object->show_in_menu !== true ) {
    30 		$parent_file = $post_type_object->show_in_menu;
    32 		$parent_file = $post_type_object->show_in_menu;
    31 		if ( ! isset( $_registered_pages[ get_plugin_page_hookname( "post-new.php?post_type=$post_type", $post_type_object->show_in_menu ) ] ) )
    33 		// What if there isn't a post-new.php item for this post type?
    32 			$submenu_file = $parent_file;
    34 		if ( ! isset( $_registered_pages[ get_plugin_page_hookname( "post-new.php?post_type=$post_type", $post_type_object->show_in_menu ) ] ) ) {
       
    35 			if (	isset( $_registered_pages[ get_plugin_page_hookname( "edit.php?post_type=$post_type", $post_type_object->show_in_menu ) ] ) ) {
       
    36 				// Fall back to edit.php for that post type, if it exists
       
    37 				$submenu_file = "edit.php?post_type=$post_type";
       
    38 			} else {
       
    39 				// Otherwise, give up and highlight the parent
       
    40 				$submenu_file = $parent_file;
       
    41 			}
       
    42 		}
    33 	} else {
    43 	} else {
    34 		$parent_file = "edit.php?post_type=$post_type";
    44 		$parent_file = "edit.php?post_type=$post_type";
    35 	}
    45 	}
    36 }
    46 }
    37 
    47 
    38 $title = $post_type_object->labels->add_new_item;
    48 $title = $post_type_object->labels->add_new_item;
    39 
    49 
    40 $editing = true;
    50 $editing = true;
    41 
    51 
    42 if ( ! current_user_can( $post_type_object->cap->edit_posts ) || ! current_user_can( $post_type_object->cap->create_posts ) )
    52 if ( ! current_user_can( $post_type_object->cap->edit_posts ) || ! current_user_can( $post_type_object->cap->create_posts ) )
    43 	wp_die( __( 'Cheatin’ uh?' ) );
    53 	wp_die( __( 'Cheatin’ uh?' ), 403 );
    44 
    54 
    45 // Schedule auto-draft cleanup
    55 // Schedule auto-draft cleanup
    46 if ( ! wp_next_scheduled( 'wp_scheduled_auto_draft_delete' ) )
    56 if ( ! wp_next_scheduled( 'wp_scheduled_auto_draft_delete' ) )
    47 	wp_schedule_event( time(), 'daily', 'wp_scheduled_auto_draft_delete' );
    57 	wp_schedule_event( time(), 'daily', 'wp_scheduled_auto_draft_delete' );
    48 
    58