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