[英]I am not including any file in my theme then how wordpress functions are working
我只是無法理解的是如何加載Wordpress函數。當我向這樣的Wordpress掛鈎添加操作時。
<?php
function test() {
echo "Test";
}
add_action('wp_enqueue_scripts','test');
?>
這段代碼適用於我想做的事情,但是add_action函數從哪里來。 我知道Wordpress會以某種方式來處理它,但我只是不明白如何在不實際包含文件的情況下調用它。 我試圖將該文件包含在該文件之前要包含的另一個文件中,但是隨后我將得到一個未定義錯誤的函數。 我只是真的想知道其背后的邏輯。
您會在wp-includes / plugin.php中找到此函數的初始化:
function add_action($tag, $function_to_add, $priority = 10, $accepted_args = 1) {
return add_filter($tag, $function_to_add, $priority, $accepted_args);
}
您可以在包含此文件的任何位置使用該功能。
WordPress擁有此文檔以及更多@ https://developer.wordpress.org/reference/functions/add_action/
它的工作方式是,在打開的WordPress網站上運行的第一個文件是index.php,該文件需要wp-blog-header.php
/** Loads the WordPress Environment and Template */
require( dirname( __FILE__ ) . '/wp-blog-header.php' );
然后wp-blog-header.php需要wp-load.php和template-loader.php
// Load the WordPress library.
require_once( dirname(__FILE__) . '/wp-load.php' );
// Set up the WordPress query.
wp();
// Load the theme template.
require_once( ABSPATH . WPINC . '/template-loader.php' );
這里的wp-load.php文件需要wp-config.php
if ( file_exists( ABSPATH . 'wp-config.php') ) {
/** The config file resides in ABSPATH */
require_once( ABSPATH . 'wp-config.php' );
}
和wp-config.php文件需要wp-settings.php
require_once(ABSPATH . 'wp-settings.php');
和wp-settings加載wp-includes / plugin.php文件
define( 'WPINC', 'wp-includes' );
// Include files required for initialization.
require( ABSPATH . WPINC . '/load.php' );
require( ABSPATH . WPINC . '/default-constants.php' );
require_once( ABSPATH . WPINC . '/plugin.php' );
和wp-includes / plugin.php文件中具有add_action函數
function add_action($tag, $function_to_add, $priority = 10, $accepted_args = 1) {
return add_filter($tag, $function_to_add, $priority, $accepted_args);
}
和wp-includes / template-loader.php加載主題模板。
require_once( ABSPATH . WPINC . '/template-loader.php' );
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.