开源欣赏wordpress之文章新增页面如何实现。
本地网址http://localhost/wordpress/wp-admin/post-new.php
进而找到post-new.php页面。
进入之后,
require_once( dirname( __FILE__ ) . '/admin.php' );//引入php
if ( !isset($_GET['post_type']) )
$post_type = 'post';
elseif ( in_array( $_GET['post_type'], get_post_types( array('show_ui' => true ) ) ) )
$post_type = $_GET['post_type'];
else
wp_die( __('Invalid post type') );//进行某种验证
$post_type_object = get_post_type_object( $post_type );
if ( 'post' == $post_type ) {
$parent_file = 'edit.php';
$submenu_file = 'post-new.php';
} elseif ( 'attachment' == $post_type ) {
if ( wp_redirect( admin_url( 'media-new.php' ) ) )
exit;
} else {
$submenu_file = "post-new.php?post_type=$post_type";
if ( isset( $post_type_object ) && $post_type_object->show_in_menu && $post_type_object->show_in_menu !== true ) {
$parent_file = $post_type_object->show_in_menu;
if ( ! isset( $_registered_pages[ get_plugin_page_hookname( "post-new.php?post_type=$post_type", $post_type_object->show_in_menu ) ] ) )
$submenu_file = $parent_file;
} else {
$parent_file = "edit.php?post_type=$post_type";
}
}//进行一些验证处理
$title = $post_type_object->labels->add_new_item;
$editing = true;
if ( ! current_user_can( $post_type_object->cap->edit_posts ) || ! current_user_can( $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.
$post = get_default_post_to_edit( $post_type, true );
$post_ID = $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(
=> '', // Unused. Messages start at index 1.
=> sprintf( __('Post updated. <a href="%s">View post</a>'), esc_url( get_permalink($post_ID) ) ),
=> __('Custom field updated.'),
=> __('Custom field deleted.'),
=> __('Post updated.'),
/* translators: %s: date and time of the revision */
=> isset($_GET['revision']) ? sprintf( __('Post restored to revision from %s'), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
=> sprintf( __('Post published. <a href="%s">View post</a>'), esc_url( get_permalink($post_ID) ) ),
=> __('Post saved.'),
=> sprintf( __('Post submitted. <a target="_blank" href="%s">Preview post</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
=> 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) ) ),
=> 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(
=> '', // Unused. Messages start at index 1.
=> sprintf( __('Page updated. <a href="%s">View page</a>'), esc_url( get_permalink($post_ID) ) ),
=> __('Custom field updated.'),
=> __('Custom field deleted.'),
=> __('Page updated.'),
=> isset($_GET['revision']) ? sprintf( __('Page restored to revision from %s'), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
=> sprintf( __('Page published. <a href="%s">View page</a>'), esc_url( get_permalink($post_ID) ) ),
=> __('Page saved.'),
=> sprintf( __('Page submitted. <a target="_blank" href="%s">Preview page</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
=> 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) ) ),
=> sprintf( __('Page draft updated. <a target="_blank" href="%s">Preview page</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
);
$messages[, , __( 'Media attachment updated.' ) ); // Hack, for now.
点评:这里是一个信息,已数组的方式保存。貌似跑题了。
好了,看了那么多也不知道干什么的代码。
require_once( ABSPATH . 'wp-admin/admin-header.php' );
exit;//我在这里断了一下。
结果就看到了下面的界面。

这里貌似是导航吗。不错不错。继续往下看。
<?php screen_icon(); ?>//这个是图标展示的方法调用。
<?php
echo esc_html( $title );
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="add-new-h2">' . esc_html( $post_type_object->labels->add_new ) . '</a>';
?>//撰写新文章
<?php if ( $notice ) : ?>
<div id="notice" class="error"><p id="has-newer-autosave"><?php echo $notice ?></p></div>
<?php endif; ?>
<?php if ( $message ) : ?>
<div id="message" class="updated"><p><?php echo $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’re reconnected.' ); ?>
<span class="hide-if-no-sessionstorage"><?php _e( 'We’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', , ) ); ?>
//这段代码去除后,就看不到编辑框了。看来编辑框是用这个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>
//去除这个之后右边的编辑框就没有了
大概就是这样,里面的页面都是写在某些方法中了。
开源欣赏wordpress之文章新增页面如何实现。的更多相关文章
- 开源欣赏wordpress之用户新增user-new.php
require_once( dirname( __FILE__ ) . '/admin.php' ); 引入根文件. if ( is_multisite() ) { if ( ! current_us ...
- 开源欣赏wordpress之intall.php
引导式安装 $weblog_title = isset( $_POST['weblog_title'] ) ? trim( wp_unslash( $_POST['weblog_title'] ) ) ...
- 开源欣赏wordpress之post.php
switch($action) { case 'postajaxpost': case 'post': case 'post-quickpress-publish': case 'post-quick ...
- 为WordPress某个文章添加额外的样式
如需把css直接写在某文章,把下面代码放如function.php /* 为特定文章添加特定css最简单的方式. */ /*添加自定义CSS的meta box*/ add_action('admin_ ...
- WordPress发布文章/页面时自动添加默认的自定义字段
如果你每篇文章或页面都需要插入同一个自定义字段和值,可以考虑在WordPress发布文章/页面时,自动添加默认的自定义字段.将下面的代码添加到当前主题的 functions.php 即可: 1 2 3 ...
- Halo 开源项目学习(四):发布文章与页面
基本介绍 博客最基本的功能就是让作者能够自由发布自己的文章,分享自己观点,记录学习的过程.Halo 为用户提供了发布文章和展示自定义页面的功能,下面我们分析一下这些功能的实现过程. 管理员发布文章 H ...
- WordPress 撰写文章页面显示所有标签
WordPress 撰写文章时,点击"从常用标签中选择"只显示45个常用的标签,很多情况下还需手工再次输入标签,这样的限制感觉很不方便,通过下面的方法可以解除这个限制,显示全部标签 ...
- SEO优化:WordPress发布文章主动推送到百度,加快收录保护原创
工作实在太忙,也没时间打理网站.最近公司额外交待了一些网站 SEO 方面的优化任务让我关注(这就是啥都要会.啥都要做的苦逼运维的真实写照了...). 于是抽空看了下百度站长平台,至少看到了2个新消息: ...
- 黄聪:在WordPress后台文章编辑器的上方或下方添加提示内容
WordPress 3.5 新增了一对非常有用的挂钩,可以快速在WordPress后台文章编辑器的上方或下方添加提示内容,下面是一个简单的例子,直接将代码添加到主题的 functions.php 文件 ...
随机推荐
- js收集错误信息,错误上报
线上的代码可有有时候用户会反应不好使,一般是因为js造成的! 尤其在移动端各个手机之前的差异特别大. 下面这段代码是获取能帮助你! <script> window.onerror = fu ...
- Eclipse + CDT + YAGARTO + J-Link,STM32开源开发环境搭建与调试
Eclipse+CDT+YAGARTO+J-Li:开源开发环境搭建与调试:作者:Chongqing:邮箱:ycq.no1@163.com:文档版本:V1.0:发布日期:2014-08-04:前言:此文 ...
- Linux用户基础
http://itercast.com/lecture/21 操作系统通过用户.组概念来管理使用计算机的人 用户代表一个使用计算机的使用者,操作系统通过用户概念限制一个使用者能够访问的资源 组用来组织 ...
- Linux权限管理(笔记)
权限管理:r: w:x: 三类用户:u: 属主g: 属组o: 其它用户 chown: 改变文件属主(只有管理员可以使用此命令)# chown USERNAME file,... -R: 修改目录 ...
- Linux硬盘分区和格式化
分区与格式化 先用fdisk分区,分区完成后再用mkfs格式化并创建文件系统,挂载,磁盘就能使用啦. 分区的原理: MBR:主引导扇区 主分区表:64bytes,最多只能分四个主 ...
- Unity PlayerPrefs类进行扩展(整个对象进行保存)
盘子脸在制作单机游戏的时候,先以为没有好多数据需要保存本地. 就没有使用json等格式自己进行保存. 使用PlayerPrefs类,但是后面字段越来越多的时候. PlayerPrefs保存就发现要手动 ...
- 小贝_mysql建表以及列属性
mysql建表以及列属性 简要: 一.建表原则 二.具体的列属性说明 一.建表原则 建表: 事实上就是声明列的过程,数据终于是以文件的形式放在硬盘(内存) 列: 不同的列类型占的空间不一样. 选列的原 ...
- [每日一题] 11gOCP 1z0-052 :2013-09-4 block header grows............................................A33
转载请注明出处:http://write.blog.csdn.net/postedit/11100311 正确答案是:AD 要理解这道题就要去了解数据块的结构.引用OCPPPT中的一幅图: 从这幅图中 ...
- [Immutable + AngularJS] Use Immutable .List() for Angular array
const stores = Immutable.List([ { name: 'Store42', position: { latitude: 61.45, longitude: 23.11, }, ...
- linux下安装swftools工具
swfTools是一种实用工具与Adobe Flash文件(swf文件)工作的集合.可以把(pdf/gif/png/jpeg/jpg/font/wav) 7种格式转换为swf文件.一般常用于文件在线浏 ...