wordpress edit.php,分析wordpress后台分类目录edit-tags.php 文件分析

----------------------------------wp-admin/edit-tags.php 分类页面--------------------------------

//$taxnow

在/wp-admin/admin.php 行105 赋值

//get_taxonomy() 方法定义在 wp-includes/taxonomy.php 行187

//get_taxonomy()

获取分类对象 行10$tax = get_taxonomy( $taxnow );

//判断权限 ,如果当前用户不包含权限

current_user_can()方法返回false 提示:开玩笑,呵?if ( !current_user_can(

$tax->cap->manage_terms ) )

wp_die( __( 'Cheatin’ uh?'

) );

//根据参数不同,实例不同的WP_List_Table类的。//

_get_list_table方法定义在wp-admin/includes/list-table.php 行20$wp_list_table =

_get_list_table('WP_Terms_List_Table');

//获取一共有多少页$pagenum =

$wp_list_table->get_pagenum();

//获取分类目录$title =

$tax->labels->name;

//判断 $post_type 是否等于

post 不等于执行if ( 'post' != $post_type ) {

$parent_file =

"edit.php?post_type=$post_type";

$submenu_file =

"edit-tags.php?taxonomy=$taxonomy&post_type=$post_type";

} else if ( 'link_category' == $tax->name ) {

$parent_file = 'link-manager.php';

$submenu_file =

'edit-tags.php?taxonomy=link_category';

} else {

$parent_file = 'edit.php';

$submenu_file =

"edit-tags.php?taxonomy=$taxonomy";

}

//行35

// current_action()

从$action里面获取当前操作选择switch (

$wp_list_table->current_action() ) {

//添加标签是执行case 'add-tag':

check_admin_referer( 'add-tag' );

//判断权限 if

( !current_user_can(

$tax->cap->edit_terms ) )

wp_die( __(

'Cheatin’ uh?' ) );

//添加标签,并返回$ret 提示信息,

//wp_insert_term() 定义在wp-includes/taxonomy.php

行1928

$ret = wp_insert_term( $_POST['tag-name'],

$taxonomy, $_POST );

$location = 'edit-tags.php?taxonomy=' .

$taxonomy;

if ( 'post' != $post_type )

$location .=

'&post_type=' . $post_type;

//检索原始引用页

,如果存在true if ( $referer =

wp_get_original_referer() ) {

if ( false !== strpos(

$referer, 'edit-tags.php' ) )

$location =

$referer;

}

//判断ret是否为空,不为空,跳转到相应的网址,并提示信息 if

( $ret && !is_wp_error( $ret )

)

//add_query_arg()

检索修改后的URL查询字符串

//add_query_arg()定义在

wp-includes/functions.php 行1390 $location =

add_query_arg( 'message', 1, $location );

else

$location = add_query_arg(

'message', 4, $location );

//wp_redirect将用户重定向到一个预先制定的绝对URI。

//wp_redirect() 定义在

wp-includes/pluggable.php 行891 wp_redirect( $location );

exit;

break;

//执行删除分类时执行case

'delete':

$location = 'edit-tags.php?taxonomy=' .

$taxonomy;

if ( 'post' != $post_type )

$location .=

'&post_type=' . $post_type;

//分别从

'_wp_http_referer'、HTTP引用页或当前页面检索引用页。

//检索失败返回false,成功则返回会引用页URL。

//

wp_get_referer方法定义在wp-includes/functions.php

行2005 if ( $referer =

wp_get_referer() ) {

if ( false !== strpos(

$referer, 'edit-tags.php' ) )

$location =

$referer;

}

if ( !isset( $_REQUEST['tag_ID'] ) ) {

wp_redirect( $location );

exit;

}

$tag_ID = (int) $_REQUEST['tag_ID'];

check_admin_referer( 'delete-tag_'

. $tag_ID );

//判断权限 if (

!current_user_can(

$tax->cap->delete_terms ) )

wp_die( __(

'Cheatin’ uh?' ) );

//执行删除方法 $tag_ID

=id $taxonomy=category

//wp_delete_term定义在wp-includes/taxonomy.php

行1662 wp_delete_term( $tag_ID,

$taxonomy );

$location = add_query_arg( 'message', 2,

$location );

wp_redirect( $location );

exit;

break;

//批量删除时执行case

'bulk-delete':

check_admin_referer( 'bulk-tags' );

if ( !current_user_can(

$tax->cap->delete_terms ) )

wp_die( __(

'Cheatin’ uh?' ) );

//获取要删除的标签数组 $tags =

(array) $_REQUEST['delete_tags'];

//循环执行 foreach

( $tags as $tag_ID ) {

//调用删除方法 wp_delete_term(

$tag_ID, $taxonomy );

}

$location = 'edit-tags.php?taxonomy=' .

$taxonomy;

if ( 'post' != $post_type )

$location .=

'&post_type=' . $post_type;

if ( $referer = wp_get_referer() ) {

if ( false !== strpos(

$referer, 'edit-tags.php' ) )

$location =

$referer;

}

$location = add_query_arg( 'message', 6,

$location );

wp_redirect( $location );

exit;

break;

//在加载编辑页面时执行case 'edit':

$title =

$tax->labels->edit_item;

require_once ( 'admin-header.php' );

//获取tag_ID $tag_ID

= (int) $_REQUEST['tag_ID'];

//根据$tag_ID查询数据,并赋值给$tag

//get_term()定义在wp-includes/taxonomy.php

行804 $tag = get_term( $tag_ID,

$taxonomy, OBJECT, 'edit' );

include( './edit-tag-form.php' );

break;

//编辑后添加执行case

'editedtag':

//获取tag_ID $tag_ID = (int)

$_POST['tag_ID'];

check_admin_referer( 'update-tag_' . $tag_ID

);

if ( !current_user_can(

$tax->cap->edit_terms ) )

wp_die( __(

'Cheatin’ uh?' ) );

//执行更新方法

//wp_update_term定义在

wp-includes/taxonomy.php 行2230 $ret = wp_update_term( $tag_ID,

$taxonomy, $_POST );

$location = 'edit-tags.php?taxonomy=' .

$taxonomy;

if ( 'post' != $post_type )

$location .=

'&post_type=' . $post_type;

//检索原始引用页(若引用页存在)

//如果没有原始引用页,返回false,如有则返回原始引用页。

//wp_get_original_referer()

方法定义在wp-includes/functions.php

行2028 if ( $referer =

wp_get_original_referer() ) {

if ( false !== strpos(

$referer, 'edit-tags.php' ) )

$location =

$referer;

}

if ( $ret &&

!is_wp_error( $ret ) )

$location = add_query_arg(

'message', 3, $location );

else

$location = add_query_arg(

'message', 5, $location );

wp_redirect( $location );

exit;

break;

//如果以上都不符合时,执行default:

if ( ! empty($_REQUEST['_wp_http_referer']) ) {

//remove_query_arg从查询字符串中删除某个条目或列表项 //array('_wp_http_referer',

'_wpnonce')需要被删除的查询关键字

//remove_query_arg()定义在

wp-includes/functions.php中 行1464 $location = remove_query_arg(

array('_wp_http_referer', '_wpnonce'),

stripslashes($_SERVER['REQUEST_URI']) );

if ( ! empty( $_REQUEST['paged'] ) )

$location = add_query_arg(

'paged', (int) $_REQUEST['paged'] );

wp_redirect( $location );

exit;

}

//wp_enqueue_script将js脚本添加到WordPress已生成页面的安全方法 行204

//wp_enqueue_script()方法定义在 wp-includes/functions.wp-scripts.php

中 行96wp_enqueue_script('admin-tags');

//判断变量$taxonomy 如果等于'category'

或'link_category' 或

'post_tag'

// 将帮助提示信息赋值给$help 行208if ( 'category' == $taxonomy || 'link_category' ==

$taxonomy || 'post_tag' == $taxonomy )

{

//add_contextual_help

添加一个页面上的帮助文本 行256

//add_contextual_help()方法定义在

wp-admin/includes/template.php中

行1814 add_contextual_help($current_screen,

$help);

unset($help);

}

//加载后台管理头部文件和菜单

require_once ('admin-header.php');

//生成分类列表html

行305<?php

$wp_list_table->display(); ?>

//判断是否为添加,如果返回true 生成添加分类html 行350

if (

current_user_can($tax->cap->edit_terms)

) {

//生成编辑html 行424

$wp_list_table->inline_edit(); ?>

//加载后台管理底部文件 行430

include('./admin-footer.php');
------本页内容已结束,喜欢请分享------

感谢您的来访,获取更多精彩文章请收藏本站。

© 版权声明
THE END
喜欢就支持一下吧
点赞10 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容