【发布时间】:2020-12-17 17:40:09
【问题描述】:
这是关于 WordPress 插件的。
我看其他人的 WordPress 插件都有这样的代码:
example.php
<?php
$display = get_option( 'display' );
if(!defined('PLUGIN_DIR'))
define('PLUGIN_DIR', dirname(__FILE__));
function init() {
load_plugin_textdomain('example', false, basename( dirname( __FILE__ ) ) . '/lang' );
}
add_action('plugins_loaded', 'init');
include(PLUGIN_DIR . '/includes/display.php');
?>
然后有一个包含 display.php 的文件夹
有这样的代码: 显示.php
<?php
function display(){
//thecodes
}
?>
我已经尝试过这个编码概念。从我的分析来看,如果我没记错的话,这个调用display.php中函数的代码,调用函数display(){}代码
这是我的结构:
>includes
>>functions.php
achan.php
index.php
而且,这是我的代码:
achan.php
<?php
$test = get_option('test');
define(PLUGIN_DIR . dirname(__FILE__));
include(PLUGIN_DIR . 'includes/functions.php');
function testing(){
global $test;
echo ($test);
}
add_action('bbp_theme_after_reply_author_details', 'testing');
?>
在包含文件夹中,有functions.php 我的代码是这样的: 函数.php
<?php
function test(){
echo "HELLO";
}
?>
但不工作。我的代码有问题吗? Hello 未显示在 bbp_theme_after_reply_author_details。或者也许有更有效的方法来调用另一个文件夹 PHP 文件中的函数?谢谢你,网络开发者。
【问题讨论】: