阅读172个wordpress源代码理解wordpress的执行流程

阅读源代码是了解程序怎么执行的最好方式,写这些内容的目标是,认真的学习了wordpress, php和一些相关的知识。数字172是需要阅读的原文件数量。


一直想认真的学习下wordpress这个使用最多的建站程序,wordpress是一个博客程序,但是功能太强大了,所有cms能做事情,wordpress一样可以搞定。废话不说,直接正题。

wordpress171文件

wordpress版本

wordpress版本: 4.8

172个文件怎么确定

wordpress4.8版本安装后,使用的默认主题是 twentyseventeen,找到文件 index.php,添加两行代码,重点是 get_included_files() 获取已经加载的文件。

<?php

# 查看加载的文件
print_r(get_included_files());
die();
/**
 * The main template file
 *
 * This is the most generic template file in a WordPress theme
 * and one of the two required files for a theme (the other being style.css).
 * It is used to display a page when nothing more specific matches a query.
 * E.g., it puts together the home page when no home.php file exists.
 *
 * @link https://codex.wordpress.org/Template_Hierarchy
 *
 * @package WordPress
 * @subpackage Twenty_Seventeen
 * @since 1.0
 * @version 1.0
 */

get_header(); ?>

通过以上代码,执行后会打印加载的文件,这里文件就是阅读的对象。

打印的结果

Array
(
    [0] => \index.php
    [1] => \wp-blog-header.php
    [2] => \wp-load.php
    [3] => \wp-config.php
    [4] => \wp-settings.php
    [5] => \wp-includes\load.php
    [6] => \wp-includes\default-constants.php
    [7] => \wp-includes\plugin.php
    [8] => \wp-includes\class-wp-hook.php
    [9] => \wp-includes\version.php
    [10] => \wp-includes\compat.php
    [11] => \wp-includes\random_compat\random.php
    [12] => \wp-includes\random_compat\byte_safe_strings.php
    [13] => \wp-includes\random_compat\cast_to_int.php
    [14] => \wp-includes\random_compat\error_polyfill.php
    [15] => \wp-includes\random_compat\random_bytes_mcrypt.php
    [16] => \wp-includes\random_compat\random_int.php
    [17] => \wp-includes\class-wp-list-util.php
    [18] => \wp-includes\functions.php
    [19] => \wp-includes\option.php
    [20] => \wp-includes\class-wp-matchesmapregex.php
    [21] => \wp-includes\class-wp.php
    [22] => \wp-includes\class-wp-error.php
    [23] => \wp-includes\pomo\mo.php
    [24] => \wp-includes\pomo\translations.php
    [25] => \wp-includes\pomo\entry.php
    [26] => \wp-includes\pomo\streams.php
    [27] => \wp-includes\wp-db.php
    [28] => \wp-includes\cache.php
    [29] => \wp-includes\default-filters.php
    [30] => \wp-includes\l10n.php
    [31] => \wp-includes\class-wp-locale.php
    [32] => \wp-includes\class-wp-locale-switcher.php
    [33] => \wp-includes\class-wp-walker.php
    [34] => \wp-includes\class-wp-ajax-response.php
    [35] => \wp-includes\formatting.php
    [36] => \wp-includes\capabilities.php
    [37] => \wp-includes\class-wp-roles.php
    [38] => \wp-includes\class-wp-role.php
    [39] => \wp-includes\class-wp-user.php
    [40] => \wp-includes\class-wp-query.php
    [41] => \wp-includes\query.php
    [42] => \wp-includes\date.php
    [43] => \wp-includes\theme.php
    [44] => \wp-includes\class-wp-theme.php
    [45] => \wp-includes\template.php
    [46] => \wp-includes\user.php
    [47] => \wp-includes\class-wp-user-query.php
    [48] => \wp-includes\class-wp-session-tokens.php
    [49] => \wp-includes\class-wp-user-meta-session-tokens.php
    [50] => \wp-includes\meta.php
    [51] => \wp-includes\class-wp-meta-query.php
    [52] => \wp-includes\class-wp-metadata-lazyloader.php
    [53] => \wp-includes\general-template.php
    [54] => \wp-includes\link-template.php
    [55] => \wp-includes\author-template.php
    [56] => \wp-includes\post.php
    [57] => \wp-includes\class-walker-page.php
    [58] => \wp-includes\class-walker-page-dropdown.php
    [59] => \wp-includes\class-wp-post-type.php
    [60] => \wp-includes\class-wp-post.php
    [61] => \wp-includes\post-template.php
    [62] => \wp-includes\revision.php
    [63] => \wp-includes\post-formats.php
    [64] => \wp-includes\post-thumbnail-template.php
    [65] => \wp-includes\category.php
    [66] => \wp-includes\class-walker-category.php
    [67] => \wp-includes\class-walker-category-dropdown.php
    [68] => \wp-includes\category-template.php
    [69] => \wp-includes\comment.php
    [70] => \wp-includes\class-wp-comment.php
    [71] => \wp-includes\class-wp-comment-query.php
    [72] => \wp-includes\class-walker-comment.php
    [73] => \wp-includes\comment-template.php
    [74] => \wp-includes\rewrite.php
    [75] => \wp-includes\class-wp-rewrite.php
    [76] => \wp-includes\feed.php
    [77] => \wp-includes\bookmark.php
    [78] => \wp-includes\bookmark-template.php
    [79] => \wp-includes\kses.php
    [80] => \wp-includes\cron.php
    [81] => \wp-includes\deprecated.php
    [82] => \wp-includes\script-loader.php
    [83] => \wp-includes\class-wp-dependency.php
    [84] => \wp-includes\class.wp-dependencies.php
    [85] => \wp-includes\class.wp-scripts.php
    [86] => \wp-includes\functions.wp-scripts.php
    [87] => \wp-includes\class.wp-styles.php
    [88] => \wp-includes\functions.wp-styles.php
    [89] => \wp-includes\taxonomy.php
    [90] => \wp-includes\class-wp-taxonomy.php
    [91] => \wp-includes\class-wp-term.php
    [92] => \wp-includes\class-wp-term-query.php
    [93] => \wp-includes\class-wp-tax-query.php
    [94] => \wp-includes\update.php
    [95] => \wp-includes\canonical.php
    [96] => \wp-includes\shortcodes.php
    [97] => \wp-includes\embed.php
    [98] => \wp-includes\class-wp-embed.php
    [99] => \wp-includes\class-oembed.php
    [100] => \wp-includes\class-wp-oembed-controller.php
    [101] => \wp-includes\media.php
    [102] => \wp-includes\http.php
    [103] => \wp-includes\class-http.php
    [104] => \wp-includes\class-requests.php
    [105] => \wp-includes\class-wp-http-streams.php
    [106] => \wp-includes\class-wp-http-curl.php
    [107] => \wp-includes\class-wp-http-proxy.php
    [108] => \wp-includes\class-wp-http-cookie.php
    [109] => \wp-includes\class-wp-http-encoding.php
    [110] => \wp-includes\class-wp-http-response.php
    [111] => \wp-includes\class-wp-http-requests-response.php
    [112] => \wp-includes\class-wp-http-requests-hooks.php
    [113] => \wp-includes\Requests\Hooks.php
    [114] => \wp-includes\Requests\Hooker.php
    [115] => \wp-includes\widgets.php
    [116] => \wp-includes\class-wp-widget.php
    [117] => \wp-includes\class-wp-widget-factory.php
    [118] => \wp-includes\nav-menu.php
    [119] => \wp-includes\nav-menu-template.php
    [120] => \wp-includes\class-walker-nav-menu.php
    [121] => \wp-includes\admin-bar.php
    [122] => \wp-includes\rest-api.php
    [123] => \wp-includes\rest-api\class-wp-rest-server.php
    [124] => \wp-includes\rest-api\class-wp-rest-response.php
    [125] => \wp-includes\rest-api\class-wp-rest-request.php
    [126] => \wp-includes\rest-api\endpoints\class-wp-rest-controller.php
    [127] => \wp-includes\rest-api\endpoints\class-wp-rest-posts-controller.php
    [128] => \wp-includes\rest-api\endpoints\class-wp-rest-attachments-controller.php
    [129] => \wp-includes\rest-api\endpoints\class-wp-rest-post-types-controller.php
    [130] => \wp-includes\rest-api\endpoints\class-wp-rest-post-statuses-controller.php
    [131] => \wp-includes\rest-api\endpoints\class-wp-rest-revisions-controller.php
    [132] => \wp-includes\rest-api\endpoints\class-wp-rest-taxonomies-controller.php
    [133] => \wp-includes\rest-api\endpoints\class-wp-rest-terms-controller.php
    [134] => \wp-includes\rest-api\endpoints\class-wp-rest-users-controller.php
    [135] => \wp-includes\rest-api\endpoints\class-wp-rest-comments-controller.php
    [136] => \wp-includes\rest-api\endpoints\class-wp-rest-settings-controller.php
    [137] => \wp-includes\rest-api\fields\class-wp-rest-meta-fields.php
    [138] => \wp-includes\rest-api\fields\class-wp-rest-comment-meta-fields.php
    [139] => \wp-includes\rest-api\fields\class-wp-rest-post-meta-fields.php
    [140] => \wp-includes\rest-api\fields\class-wp-rest-term-meta-fields.php
    [141] => \wp-includes\rest-api\fields\class-wp-rest-user-meta-fields.php
    [142] => \wp-includes\vars.php
    [143] => \wp-includes\pluggable.php
    [144] => \wp-includes\pluggable-deprecated.php
    [145] => \wp-includes\default-widgets.php
    [146] => \wp-includes\widgets\class-wp-widget-pages.php
    [147] => \wp-includes\widgets\class-wp-widget-links.php
    [148] => \wp-includes\widgets\class-wp-widget-search.php
    [149] => \wp-includes\widgets\class-wp-widget-archives.php
    [150] => \wp-includes\widgets\class-wp-widget-media.php
    [151] => \wp-includes\widgets\class-wp-widget-media-audio.php
    [152] => \wp-includes\widgets\class-wp-widget-media-image.php
    [153] => \wp-includes\widgets\class-wp-widget-media-video.php
    [154] => \wp-includes\widgets\class-wp-widget-meta.php
    [155] => \wp-includes\widgets\class-wp-widget-calendar.php
    [156] => \wp-includes\widgets\class-wp-widget-text.php
    [157] => \wp-includes\widgets\class-wp-widget-categories.php
    [158] => \wp-includes\widgets\class-wp-widget-recent-posts.php
    [159] => \wp-includes\widgets\class-wp-widget-recent-comments.php
    [160] => \wp-includes\widgets\class-wp-widget-rss.php
    [161] => \wp-includes\widgets\class-wp-widget-tag-cloud.php
    [162] => \wp-includes\widgets\class-wp-nav-menu-widget.php
    [163] => \wp-content\themes\twentyseventeen\functions.php
    [164] => \wp-content\themes\twentyseventeen\inc\custom-header.php
    [165] => \wp-content\themes\twentyseventeen\inc\template-tags.php
    [166] => \wp-content\themes\twentyseventeen\inc\template-functions.php
    [167] => \wp-content\themes\twentyseventeen\inc\customizer.php
    [168] => \wp-content\themes\twentyseventeen\inc\icon-functions.php
    [169] => \wp-includes\template-loader.php
    [170] => \wp-includes\class-wp-admin-bar.php
    [171] => \wp-content\themes\twentyseventeen\index.php
)