我可以在 functions.php 中包含 php 吗? - WordPress的
Can I Include php in functions.php? - Wordpress
我在 WP 中发布新 post 时需要调用自定义 php 脚本。此功能有效,但不包括在内。它不包括在内。它可以工作还是有任何其他方法可以将 php 文件包含在 functios.php 中?
function new_post_caller( $ID, $post ) {
include( get_template_directory() . 'call_new_post.php?ID='.$ID.'' );
}
add_action( 'publish_mypost', 'new_post_caller', 10, 2 );
使用include( get_template_directory() . '/filetoinclude.php' );
它会起作用。
函数 include() 只能包含 php/html 个文件来执行,没有 GET 或 POST 参数。
如果你想包含脚本并传递一个参数给他,你可以在包含脚本中创建函数并使用这样的构造:
要包含的一些脚本 (file.php):
function some_function ($id) {
//some code, using $id
}
并调用file.php并传递一个参数:
include('file.php');
some_function(23);
函数 include() 只是将包含文件中的代码添加到函数起源的文件中
http://php.net/manual/en/function.include.php
我在 WP 中发布新 post 时需要调用自定义 php 脚本。此功能有效,但不包括在内。它不包括在内。它可以工作还是有任何其他方法可以将 php 文件包含在 functios.php 中?
function new_post_caller( $ID, $post ) {
include( get_template_directory() . 'call_new_post.php?ID='.$ID.'' );
}
add_action( 'publish_mypost', 'new_post_caller', 10, 2 );
使用include( get_template_directory() . '/filetoinclude.php' );
它会起作用。
函数 include() 只能包含 php/html 个文件来执行,没有 GET 或 POST 参数。
如果你想包含脚本并传递一个参数给他,你可以在包含脚本中创建函数并使用这样的构造:
要包含的一些脚本 (file.php):
function some_function ($id) {
//some code, using $id
}
并调用file.php并传递一个参数:
include('file.php');
some_function(23);
函数 include() 只是将包含文件中的代码添加到函数起源的文件中 http://php.net/manual/en/function.include.php