Professional Documents
Culture Documents
php
/**
* Post advanced form for inclusion in the administration panels.
*
* @package WordPress
* @subpackage Administration
*/
/**
* @global string $post_type
* @global WP_Post_Type $post_type_object
* @global WP_Post $post Global post object.
*/
global $post_type, $post_type_object, $post;
if ( is_multisite() ) {
add_action( 'admin_footer', '_admin_notice_post_locked' );
} else {
$check_users = get_users(
array(
'fields' => 'ID',
'number' => 2,
)
);
unset( $check_users );
}
wp_enqueue_script( 'post' );
$_wp_editor_expand = false;
$_content_editor_dfw = false;
if ( wp_is_mobile() ) {
wp_enqueue_script( 'jquery-touch-punch' );
}
/**
* Post ID global
*
* @name $post_ID
* @var int
*/
$post_ID = isset( $post_ID ) ? (int) $post_ID : 0;
$user_ID = isset( $user_ID ) ? (int) $user_ID : 0;
$action = isset( $action ) ? $action : '';
if ( $thumbnail_support ) {
add_thickbox();
wp_enqueue_media( array( 'post' => $post->ID ) );
}
/*
* @todo Document the $messages array(s).
*/
$permalink = get_permalink( $post->ID );
if ( ! $permalink ) {
$permalink = '';
}
$messages = array();
$preview_post_link_html = '';
$scheduled_post_link_html = '';
$view_post_link_html = '';
$preview_page_link_html = '';
$scheduled_page_link_html = '';
$view_page_link_html = '';
if ( $viewable ) {
}
$scheduled_date = sprintf(
/* translators: Publish box date string. 1: Date, 2: Time. */
__( '%1$s at %2$s' ),
/* translators: Publish box date format, see
https://www.php.net/manual/datetime.format.php */
date_i18n( _x( 'M j, Y', 'publish box date format' ), strtotime( $post-
>post_date ) ),
/* translators: Publish box time format, see
https://www.php.net/manual/datetime.format.php */
date_i18n( _x( 'H:i', 'publish box time format' ), strtotime( $post-
>post_date ) )
);
$messages['post'] = array(
0 => '', // Unused. Messages start at index 1.
1 => __( 'Post updated.' ) . $view_post_link_html,
2 => __( 'Custom field updated.' ),
3 => __( 'Custom field deleted.' ),
4 => __( 'Post updated.' ),
/* translators: %s: Date and time of the revision. */
5 => isset( $_GET['revision'] ) ? sprintf( __( 'Post restored to revision
from %s.' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
6 => __( 'Post published.' ) . $view_post_link_html,
7 => __( 'Post saved.' ),
8 => __( 'Post submitted.' ) . $preview_post_link_html,
/* translators: %s: Scheduled date for the post. */
9 => sprintf( __( 'Post scheduled for: %s.' ), '<strong>' .
$scheduled_date . '</strong>' ) . $scheduled_post_link_html,
10 => __( 'Post draft updated.' ) . $preview_post_link_html,
);
$messages['page'] = array(
0 => '', // Unused. Messages start at index 1.
1 => __( 'Page updated.' ) . $view_page_link_html,
2 => __( 'Custom field updated.' ),
3 => __( 'Custom field deleted.' ),
4 => __( 'Page updated.' ),
/* translators: %s: Date and time of the revision. */
5 => isset( $_GET['revision'] ) ? sprintf( __( 'Page restored to revision
from %s.' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
6 => __( 'Page published.' ) . $view_page_link_html,
7 => __( 'Page saved.' ),
8 => __( 'Page submitted.' ) . $preview_page_link_html,
/* translators: %s: Scheduled date for the page. */
9 => sprintf( __( 'Page scheduled for: %s.' ), '<strong>' .
$scheduled_date . '</strong>' ) . $scheduled_page_link_html,
10 => __( 'Page draft updated.' ) . $preview_page_link_html,
);
$messages['attachment'] = array_fill( 1, 10, __( 'Media file updated.' ) ); //
Hack, for now.
/**
* Filters the post updated messages.
*
* @since 3.0.0
*
* @param array[] $messages Post updated messages. For defaults see `$messages`
declarations above.
*/
$messages = apply_filters( 'post_updated_messages', $messages );
$message = false;
if ( isset( $_GET['message'] ) ) {
$_GET['message'] = absint( $_GET['message'] );
if ( isset( $messages[ $post_type ][ $_GET['message'] ] ) ) {
$message = $messages[ $post_type ][ $_GET['message'] ];
} elseif ( ! isset( $messages[ $post_type ] ) && isset( $messages['post']
[ $_GET['message'] ] ) ) {
$message = $messages['post'][ $_GET['message'] ];
}
}
$notice = false;
$form_extra = '';
if ( 'auto-draft' === $post->post_status ) {
if ( 'edit' === $action ) {
$post->post_title = '';
}
$autosave = false;
$form_extra .= "<input type='hidden' id='auto_draft' name='auto_draft'
value='1' />";
} else {
$autosave = wp_get_post_autosave( $post->ID );
}
$form_action = 'editpost';
$nonce_action = 'update-post_' . $post->ID;
$form_extra .= "<input type='hidden' id='post_ID' name='post_ID' value='" .
esc_attr( $post->ID ) . "' />";
// Detect if there exists an autosave newer than the post and if that autosave is
different than the post.
if ( $autosave && mysql2date( 'U', $autosave->post_modified_gmt, false ) >
mysql2date( 'U', $post->post_modified_gmt, false ) ) {
foreach ( _wp_post_revision_fields( $post ) as $autosave_field =>
$_autosave_field ) {
if ( normalize_whitespace( $autosave->$autosave_field ) !==
normalize_whitespace( $post->$autosave_field ) ) {
$notice = sprintf(
/* translators: %s: URL to view the autosave. */
__( 'There is an autosave of this post that is more recent
than the version below. <a href="%s">View the autosave</a>' ),
get_edit_post_link( $autosave->ID )
);
break;
}
}
// If this autosave isn't different from the current post, begone.
if ( ! $notice ) {
wp_delete_post_revision( $autosave->ID );
}
unset( $autosave_field, $_autosave_field );
}
// All meta boxes should be defined and added before the first do_meta_boxes() call
(or potentially during the do_meta_boxes action).
require_once ABSPATH . 'wp-admin/includes/meta-boxes.php';
register_and_do_post_meta_boxes( $post );
add_screen_option(
'layout_columns',
array(
'max' => 2,
'default' => 2,
)
);
get_current_screen()->add_help_tab(
array(
'id' => 'customize-display',
'title' => __( 'Customizing This Display' ),
'content' => $customize_display,
)
);
get_current_screen()->add_help_tab(
array(
'id' => 'title-post-editor',
'title' => __( 'Title and Post Editor' ),
'content' => $title_and_editor,
)
);
get_current_screen()->set_help_sidebar(
'<p>' . sprintf(
/* translators: %s: URL to Press This bookmarklet. */
__( 'You can also create posts with the <a href="%s">Press This
bookmarklet</a>.' ),
'tools.php'
) . '</p>' .
'<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
'<p>' . __( '<a
href="https://wordpress.org/documentation/article/write-posts-classic-
editor/">Documentation on Writing and Editing Posts</a>' ) . '</p>' .
'<p>' . __( '<a
href="https://wordpress.org/support/forums/">Support forums</a>' ) . '</p>'
);
} elseif ( 'page' === $post_type ) {
$about_pages = '<p>' . __( 'Pages are similar to posts in that they have a
title, body text, and associated metadata, but they are different in that they are
not part of the chronological blog stream, kind of like permanent posts. Pages are
not categorized or tagged, but can have a hierarchy. You can nest pages under other
pages by making one the “Parent” of the other, creating a group of
pages.' ) . '</p>' .
'<p>' . __( 'Creating a Page is very similar to creating a Post, and
the screens can be customized in the same way using drag and drop, the Screen
Options tab, and expanding/collapsing boxes as you choose. This screen also has the
distraction-free writing space, available in both the Visual and Text modes via the
Fullscreen buttons. The Page editor mostly works the same as the Post editor, but
there are some Page-specific features in the Page Attributes box.' ) . '</p>';
get_current_screen()->add_help_tab(
array(
'id' => 'about-pages',
'title' => __( 'About Pages' ),
'content' => $about_pages,
)
);
get_current_screen()->set_help_sidebar(
'<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
'<p>' . __( '<a
href="https://wordpress.org/documentation/article/pages-add-new-
screen/">Documentation on Adding New Pages</a>' ) . '</p>' .
'<p>' . __( '<a
href="https://wordpress.org/documentation/article/pages-screen/">Documentation on
Editing Pages</a>' ) . '</p>' .
'<p>' . __( '<a
href="https://wordpress.org/support/forums/">Support forums</a>' ) . '</p>'
);
} elseif ( 'attachment' === $post_type ) {
get_current_screen()->add_help_tab(
array(
'id' => 'overview',
'title' => __( 'Overview' ),
'content' =>
'<p>' . __( 'This screen allows you to edit fields for
metadata in a file within the media library.' ) . '</p>' .
'<p>' . __( 'For images only, you can click on Edit Image
under the thumbnail to expand out an inline image editor with icons for cropping,
rotating, or flipping the image as well as for undoing and redoing. The boxes on
the right give you more options for scaling the image, for cropping it, and for
cropping the thumbnail in a different way than you crop the original image. You can
click on Help in those boxes to get more information.' ) . '</p>' .
'<p>' . __( 'Note that you crop the image by clicking on it
(the Crop icon is already selected) and dragging the cropping frame to select the
desired part. Then click Save to retain the cropping.' ) . '</p>' .
'<p>' . __( 'Remember to click Update to save metadata
entered or changed.' ) . '</p>',
)
);
get_current_screen()->set_help_sidebar(
'<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
'<p>' . __( '<a href="https://wordpress.org/documentation/article/edit-
media/">Documentation on Edit Media</a>' ) . '</p>' .
'<p>' . __( '<a href="https://wordpress.org/support/forums/">Support
forums</a>' ) . '</p>'
);
}
get_current_screen()->add_help_tab(
array(
'id' => 'inserting-media',
'title' => __( 'Inserting Media' ),
'content' => $inserting_media,
)
);
}
$publish_box .= '</ul>';
get_current_screen()->add_help_tab(
array(
'id' => 'publish-box',
'title' => __( 'Publish Settings' ),
'content' => $publish_box,
)
);
get_current_screen()->add_help_tab(
array(
'id' => 'discussion-settings',
'title' => __( 'Discussion Settings' ),
'content' => $discussion_settings,
)
);
} elseif ( 'page' === $post_type ) {
$page_attributes = '<p>' . __( '<strong>Parent</strong> — You can
arrange your pages in hierarchies. For example, you could have an
“About” page that has “Life Story” and “My Dog”
pages under it. There are no limits to how many levels you can nest pages.' ) .
'</p>' .
'<p>' . __( '<strong>Template</strong> — Some themes have custom
templates you can use for certain pages that might have additional features or
custom layouts. If so, you’ll see them in this dropdown menu.' ) . '</p>' .
'<p>' . __( '<strong>Order</strong> — Pages are usually ordered
alphabetically, but you can choose your own order by entering a number (1 for
first, etc.) in this field.' ) . '</p>';
get_current_screen()->add_help_tab(
array(
'id' => 'page-attributes',
'title' => __( 'Page Attributes' ),
'content' => $page_attributes,
)
);
}
<div class="wrap">
<h1 class="wp-heading-inline">
<?php
echo esc_html( $title );
?>
</h1>
<?php
if ( isset( $post_new_file ) && current_user_can( $post_type_object->cap-
>create_posts ) ) {
echo ' <a href="' . esc_url( admin_url( $post_new_file ) ) . '" class="page-
title-action">' . esc_html( $post_type_object->labels->add_new ) . '</a>';
}
?>
<hr class="wp-header-end">
echo $form_extra;
<?php
/**
* Fires at the beginning of the edit form.
*
* At this point, the required hidden fields and nonces have already been output.
*
* @since 3.7.0
*
* @param WP_Post $post Post object.
*/
do_action( 'edit_form_top', $post );
?>
<div id="poststuff">
<div id="post-body" class="metabox-holder columns-<?php echo ( 1 ===
get_current_screen()->get_columns() ) ? '1' : '2'; ?>">
<div id="post-body-content">
if ( $post_type_object->public
&& ! ( 'pending' === get_post_status( $post ) && !
current_user_can( $post_type_object->cap->publish_posts ) )
) {
$has_sample_permalink = $sample_permalink_html && 'auto-draft' !
== $post->post_status;
?>
<div id="edit-slug-box" class="hide-if-no-js">
<?php
if ( $has_sample_permalink ) {
echo $sample_permalink_html;
}
?>
</div>
<?php
}
endif;
?>
</div>
<?php
wp_nonce_field( 'samplepermalink', 'samplepermalinknonce', false );
?>
</div><!-- /titlediv -->
<?php
}
/**
* Fires after the title field.
*
* @since 3.5.0
*
* @param WP_Post $post Post object.
*/
do_action( 'edit_form_after_title', $post );
<?php
wp_editor(
$post->post_content,
'content',
array(
'_content_editor_dfw' => $_content_editor_dfw,
'drag_drop_upload' => true,
'tabfocus_elements' => 'content-html,save-post',
'editor_height' => 300,
'tinymce' => array(
'resize' => false,
'wp_autoresize_on' => $_wp_editor_expand,
'add_unload_trigger' => false,
'wp_keep_scroll_position' => ! $is_IE,
),
)
);
?>
<table id="post-status-info"><tbody><tr>
<td id="wp-word-count" class="hide-if-no-js">
<?php
printf(
/* translators: %s: Number of words. */
__( 'Word count: %s' ),
'<span class="word-count">0</span>'
);
?>
</td>
<td class="autosave-info">
<span class="autosave-message"> </span>
<?php
if ( 'auto-draft' !== $post->post_status ) {
echo '<span id="last-edit">';
$last_user = get_userdata( get_post_meta( $post->ID, '_edit_last', true
) );
if ( $last_user ) {
/* translators: 1: Name of most recent post author, 2: Post
edited date, 3: Post edited time. */
printf( __( 'Last edited by %1$s on %2$s at %3$s' ),
esc_html( $last_user->display_name ), mysql2date( __( 'F j, Y' ), $post-
>post_modified ), mysql2date( __( 'g:i a' ), $post->post_modified ) );
} else {
/* translators: 1: Post edited date, 2: Post edited time. */
printf( __( 'Last edited on %1$s at %2$s' ), mysql2date( __( 'F
j, Y' ), $post->post_modified ), mysql2date( __( 'g:i a' ), $post-
>post_modified ) );
}
echo '</span>';
}
?>
</td>
<td id="content-resize-handle" class="hide-if-no-js"><br /></td>
</tr></tbody></table>
</div>
<?php
}
/**
* Fires after the content editor.
*
* @since 3.5.0
*
* @param WP_Post $post Post object.
*/
do_action( 'edit_form_after_editor', $post );
?>
</div><!-- /post-body-content -->
?>
</div>
<div id="postbox-container-2" class="postbox-container">
<?php
?>
</div>
<?php
/**
* Fires after all meta box sections have been output, before the closing #post-
body div.
*
* @since 2.1.0
*
* @param WP_Post $post Post object.
*/
do_action( 'dbx_post_sidebar', $post );
?>
</div><!-- /post-body -->
<br class="clear" />
</div><!-- /poststuff -->
</form>
</div>
<?php
if ( post_type_supports( $post_type, 'comments' ) ) {
wp_comment_reply();
}
?>