开源欣赏wordpress之文章新增页面如何实现。

简介:

本地网址http://localhost/wordpress/wp-admin/post-new.php

进而找到post-new.php页面。

进入之后,

require_once( dirname( __FILE__ ) . '/admin.php' );//引入php

if ( !isset( G E T [ ′ p o s t t y p e ′ ] ) ) post_type = 'post';
elseif ( in_array(  G E T [ ′ p o s t t y p e ′ ] , g e t p o s t t y p e s ( a r r a y ( ′ s h o w u i ′ => t r u e ) ) ) ) post_type = $_GET['post_type'];
else
wp_die( __('Invalid post type') );//进行某种验证

 

p o s t t y p e o b j e c t = g e t p o s t t y p e o b j e c t ( post_type );

if ( 'post' ==  p o s t t y p e ) $ p a r e n t f i l e = ′ e d i t . p h p ′ ; $ s u b m e n u f i l e = ′ p o s t − n e w . p h p ′ ; e l s e i f ( ′ a t t a c h m e n t ′ == post_type ) {
if ( wp_redirect( admin_url( 'media-new.php' ) ) )
exit;
} else {
s u b m e n u f i l e =" p o s t − n e w . p h p ? p o s t t y p e = post_type";
if ( isset(  post_type_object ) && post_type_object->show_in_menu &&  post_type_object->show_in_menu !== true ) { parent_file =  p o s t t y p e o b j e c t − > s h o w i n m e n u ; i f ( ! i s s e t ( _registered_pages[ get_plugin_page_hookname( "post-new.php?post_type= p o s t t y p e " , post_type_object->show_in_menu ) ] ) )
s u b m e n u f i l e = parent_file;
} else {
p a r e n t f i l e =" e d i t . p h p ? p o s t t y p e = post_type";
}
}//进行一些验证处理

 

t i t l e = post_type_object->labels->add_new_item;

$editing = true;

if ( ! current_user_can(  p o s t t y p e o b j e c t − > c a p − > e d i t p o s t s ) | | ! c u r r e n t u s e r c a n ( post_type_object->cap->create_posts ) )
wp_die( __( 'Cheatin’ uh?' ) );

// Schedule auto-draft cleanup
if ( ! wp_next_scheduled( 'wp_scheduled_auto_draft_delete' ) )
wp_schedule_event( time(), 'daily', 'wp_scheduled_auto_draft_delete' );

wp_enqueue_script( 'autosave' );

if ( is_multisite() ) {
add_action( 'admin_footer', '_admin_notice_post_locked' );
} else {
$check_users = get_users( array( 'fields' => 'ID', 'number' => 2 ) );

if ( count( $check_users ) > 1 )
add_action( 'admin_footer', '_admin_notice_post_locked' );

unset( $check_users );
}//一些乱起八糟的操作,大概是验证吧

 


// Show post form.
p o s t = g e t d e f a u l t p o s t t o e d i t ( post_type, true );
p o s t I D = post->ID;
include( ABSPATH . 'wp-admin/edit-form-advanced.php' );
include( ABSPATH . 'wp-admin/admin-footer.php' );

这里加粗的代码式引入页面的,html页面都在这里面。第一个是主要内容,第二个是脚文件。

下面我们,走进wp-admin/edit-form-advanced.php下面看看究竟。

// don't load directly
if ( !defined('ABSPATH') )
die('-1');

wp_enqueue_script('post');

if ( wp_is_mobile() )
wp_enqueue_script( 'jquery-touch-punch' );//进行一些安全验证。很清晰。内容都在方法里。

 

复制代码
$messages = array();
$messages['post'] = array(
     0 => '', // Unused. Messages start at index 1.
     1 => sprintf( __('Post updated. <a href="%s">View post</a>'), esc_url( get_permalink($post_ID) ) ),
     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 => sprintf( __('Post published. <a href="%s">View post</a>'), esc_url( get_permalink($post_ID) ) ),
     7 => __('Post saved.'),
     8 => sprintf( __('Post submitted. <a target="_blank" href="%s">Preview post</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
     9 => sprintf( __('Post scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview post</a>'),
        // translators: Publish box date format, see http://php.net/date
        date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ),
    10 => sprintf( __('Post draft updated. <a target="_blank" href="%s">Preview post</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
);
$messages['page'] = array(
     0 => '', // Unused. Messages start at index 1.
     1 => sprintf( __('Page updated. <a href="%s">View page</a>'), esc_url( get_permalink($post_ID) ) ),
     2 => __('Custom field updated.'),
     3 => __('Custom field deleted.'),
     4 => __('Page updated.'),
     5 => isset($_GET['revision']) ? sprintf( __('Page restored to revision from %s'), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
     6 => sprintf( __('Page published. <a href="%s">View page</a>'), esc_url( get_permalink($post_ID) ) ),
     7 => __('Page saved.'),
     8 => sprintf( __('Page submitted. <a target="_blank" href="%s">Preview page</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
     9 => sprintf( __('Page scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview page</a>'), date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ),
    10 => sprintf( __('Page draft updated. <a target="_blank" href="%s">Preview page</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
);
$messages['attachment'] = array_fill( 1, 10, __( 'Media attachment updated.' ) ); // Hack, for now.
复制代码

点评:这里是一个信息,已数组的方式保存。貌似跑题了。

 

好了,看了那么多也不知道干什么的代码。

require_once( ABSPATH . 'wp-admin/admin-header.php' );
exit;//我在这里断了一下。

结果就看到了下面的界面。

这里貌似是导航吗。不错不错。继续往下看。

<?php screen_icon(); ?>//这个是图标展示的方法调用。

 

<?php
echo esc_html(  t i t l e ) ; i f ( i s s e t ( post_new_file ) && current_user_can(  p o s t t y p e o b j e c t − > c a p − > c r e a t e p o s t s ) ) e c h o ′ < a h r e f = " ′ . e s c u r l ( a d m i n u r l ( post_new_file ) ) . '" class="add-new-h2">' . esc_html( $post_type_object->labels->add_new ) . '</a>';
?>//撰写新文章

 

<?php if (  n o t i c e ) : ? >< d i v i d =" n o t i c e " c l a s s =" e r r o r ">< p i d =" h a s − n e w e r − a u t o s a v e ">< ? p h p e c h o notice ?></p></div>
<?php endif; ?>
<?php if (  m e s s a g e ) : ? >< d i v i d =" m e s s a g e " c l a s s =" u p d a t e d ">< p >< ? p h p e c h o message; ?></p></div>
<?php endif; ?>//这段代码没有影响。

 

<div id="lost-connection-notice" class="error hidden">
<p><span class="spinner"></span> <?php _e( '<strong>Connection lost.</strong> Saving has been disabled until you&#8217;re reconnected.' ); ?>
<span class="hide-if-no-sessionstorage"><?php _e( 'We&#8217;re backing up this post in your browser, just in case.' ); ?></span>
</p>
</div>//这段也没有什么影响。

 

复制代码
<?php
/**
 * Fires inside the post editor <form> tag.
 *
 * @since 3.0.0
 *
 * @param WP_Post $post Post object.
 */
?>
<form name="post" action="post.php" method="post" id="post"<?php do_action( 'post_edit_form_tag', $post ); ?>>
<?php wp_nonce_field($nonce_action); ?>
<input type="hidden" id="user-id" name="user_ID" value="<?php echo (int) $user_ID ?>" />
<input type="hidden" id="hiddenaction" name="action" value="<?php echo esc_attr( $form_action ) ?>" />
<input type="hidden" id="originalaction" name="originalaction" value="<?php echo esc_attr( $form_action ) ?>" />
<input type="hidden" id="post_author" name="post_author" value="<?php echo esc_attr( $post->post_author ); ?>" />
<input type="hidden" id="post_type" name="post_type" value="<?php echo esc_attr( $post_type ) ?>" />
<input type="hidden" id="original_post_status" name="original_post_status" value="<?php echo esc_attr( $post->post_status) ?>" />
<input type="hidden" id="referredby" name="referredby" value="<?php echo esc_url(wp_get_referer()); ?>" />
<?php if ( ! empty( $active_post_lock ) ) { ?>
<input type="hidden" id="active_post_lock" value="<?php echo esc_attr( implode( ':', $active_post_lock ) ); ?>" />
<?php
}
if ( 'draft' != get_post_status( $post ) )
    wp_original_referer_field(true, 'previous');

echo $form_extra;

wp_nonce_field( 'autosave', 'autosavenonce', false );
wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false );
wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
?>
复制代码

点评:一些隐藏的参数。

<?php wp_editor( $post->post_content, 'content', array(
'dfw' => true,
'tabfocus_elements' => 'insert-media-button,save-post',
'editor_height' => 360,
) ); ?>

//这段代码去除后,就看不到编辑框了。看来编辑框是用这个wp_editor方法写出来的。

复制代码
<div id="postbox-container-1" class="postbox-container">
<?php

if ( 'page' == $post_type ) {
/**
* Fires before meta boxes with 'side' context are output for the 'page' post type.
*
* The submitpage box is a meta box with 'side' context, so this hook fires just before it is output.
*
* @since 2.5.0
*
* @param WP_Post $post Post object.
*/
do_action( 'submitpage_box', $post );
}
else {
/**
* Fires before meta boxes with 'side' context are output for all post types other than 'page'.
*
* The submitpost box is a meta box with 'side' context, so this hook fires just before it is output.
*
* @since 2.5.0
*
* @param WP_Post $post Post object.
*/
do_action( 'submitpost_box', $post );
}


do_meta_boxes($post_type, 'side', $post);

?>
</div>
复制代码

//去除这个之后右边的编辑框就没有了

 

大概就是这样,里面的页面都是写在某些方法中了。


本文转自TBHacker博客园博客,原文链接:http://www.cnblogs.com/jiqing9006/p/3450454.html,如需转载请自行联系原作者

相关文章
|
缓存 JavaScript 数据库
如何快速地将WordPress文章内所有外部图片转换为本地链接?
nicen-localize-image 是一款适用于 Wordpress 的插件,旨在本地化文章中的外部图片。主要功能包括:发布前通过编辑器插件本地化、手动发布时自动本地化、定时发布时自动本地化以及批量本地化已发布文章的图片。支持自定义保存路径、添加 alt 属性优化 SEO
492 60
|
前端开发 数据安全/隐私保护
“WP页面水印助手”的WordPress插件
“WP页面水印助手”的WordPress插件
381 14
如何将WordPress文章中的外链图片自动下载到本地?
在WordPress中使用外链图片可能影响稳定性与加载速度,而手动下载上传又过于繁琐。为此,推荐一款强大的开源插件——**nicen-localize-image**。它可自动将外链图片保存到本地,支持文章发布前、手动发布、定时发布时自动本地化,以及对已发布文章进行批量处理。插件功能丰富、操作简单,有效提升效率,确保图片资源的稳定性和页面性能。
521 3
|
存储 监控 安全
用户为啥跳出页面?装这个WordPress插件,直接看回放!
nicen-replay 是一款强大的用户行为监控与回放插件,可完整记录用户在网站上的操作,如点击、滚动、输入等,并以视频形式呈现,助您深度分析用户行为。支持表单填写回放(隐私脱敏)、轻量无感监控,且数据存储于本地服务器,安全合规。适用于电商、内容创作、企业官网等多种场景,帮助优化用户体验和提升转化率。
406 3
|
搜索推荐
WordPress文章配图插件
文章配图插件可自动为文章创建缩略图并添加图片,支持背景颜色、本地图片和Pixabay图片三种配图方式。功能包括设置缩略图参数、添加标题文字、虚化背景、生成特色图片等。注意事项涵盖主题兼容性、图片来源限制及文件管理。更新后新增多图添加、Pixabay搜索配图等功能,提升使用灵活性与内容丰富度。
589 9
|
关系型数据库 MySQL 索引
WordPress文章推荐插件
这是一款功能强大的WordPress插件,支持在文章底部和侧边栏推荐最新、随机、相关文章及标签。主要特点包括:无需依赖文章标签即可实现相关文章推荐;支持全文索引搜索,提升搜索速度与准确性;可自定义侧边栏HTML模板和样式;兼容默认搜索功能替换,优化搜索体验。插件适合技术新手和进阶用户,提供免费技术支持,但默认列表样式如需改为图文样式需额外收费。注意:全文索引功能需MySQL 5.7及以上版本。
429 0
|
自然语言处理 PHP SEO
WordPress文章自动标签插件
文章自动标签插件可为文章智能生成标签并添加标签链接。支持PHP、SCWS及结巴分词,可设置字段、最少字数与语言限制,还支持SEO优化和自定义标签类型。注意事项包括仅无标签时生成,且结巴分词需更多内存。更新内容含新增分词方式与绑定功能,截图展示设置界面与效果。
596 0
wordpress如何添加tag标签页面
如何在 WordPress 中添加标签页面
973 2
|
前端开发 PHP 数据安全/隐私保护
WordPress独立资源下载页面插件,基于Xydown美化
xydown是一款wordpress的独立下载页面插件,主要适用于wp建站用户使用,有些用户在发布文章的时候想要添加一些下载资源,使用这款插件可以把下载的内容独立出来,支持添加本地下载或者百度网盘蓝奏网盘的网址,并且可以自定义文件信息,包括设置文件名称、文件大小、更新日志以及适用版本等内容,同时还支持自定义文件信息以及添加自定义广告等。
698 1
WordPress独立资源下载页面插件,基于Xydown美化