admin管理员组文章数量:1426907
I've recently created a custom WordPress plugin to keep track of submissions, reviews etc things on my website.
I built all of this in a single main plugin file and before launch I'm looking to clean it up a little and split the code into separate files. I've spent the last couple hours trying to figure this out myself and have had no joy.
main.php
include plugin_dir_path( __FILE__ ) . 'reviews.php';
reviewsPanel();
reviews.php
<?php
function reviewsPanel() {
?>
echo "test";
<?php
}
?>
Each file is in the plugin directory and the plugin_dir_path function does return the correct path.
Thanks for the help.
I've recently created a custom WordPress plugin to keep track of submissions, reviews etc things on my website.
I built all of this in a single main plugin file and before launch I'm looking to clean it up a little and split the code into separate files. I've spent the last couple hours trying to figure this out myself and have had no joy.
main.php
include plugin_dir_path( __FILE__ ) . 'reviews.php';
reviewsPanel();
reviews.php
<?php
function reviewsPanel() {
?>
echo "test";
<?php
}
?>
Each file is in the plugin directory and the plugin_dir_path function does return the correct path.
Thanks for the help.
Share Improve this question asked May 15, 2019 at 21:01 JohnJohn 1 1- What is main.php and how is it used? Have you tried echoing in main.php directly, to see if the issue is just with reviews.php? – Jacob Peattie Commented May 16, 2019 at 6:46
1 Answer
Reset to default 0Without seeing your complete code, it's a bit difficult to answer. Also it's a big vague when you say that it's not calling the function (are you getting any errors / warnings?) If you've got error reporting turned off, please turn it on.
Also, try this:
require_once('reviews.php');
reviewsPanel();
If the file is not included, "require" will throw a Fatal Error.
One other thing I see is that the echo "test" in the reviewPanel() function is outside the PHP tags. So that will not be executed as PHP code.
本文标签: WordPress Plugin PHP Not Calling Function
版权声明:本文标题:WordPress Plugin PHP Not Calling Function 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745488658a2660501.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论