admin管理员组文章数量:1304267
I've made a simple "test plugin" to demonstrate the issue:
my-test-plugin/
├─ includes/
│ └─ dashboard.php
└─ main.php
<?php // dashboard.php
echo '<h1>Dashboard</h1>';
<?php // main.php
/**
* Plugin Name: My Test Plugin
*/
add_action('admin_menu', 'myTestPlugin_onAdminMenu');
function myTestPlugin_onAdminMenu() {
add_menu_page('My Dashboard', 'My Test Plugin', 'manage_options', 'my-test-plugin', 'myTestPlugin_displayDashboardPage');
}
function myTestPlugin_displayDashboardPage() {
require_once 'includes/dashboard.php';
}
This plugin only adds a menu item labeled My Test Plugin
, that displays the "dashboard" page. It works perfectly on my development Windows machine; but surprisingly, it doesn't work on my online web-hosting service (LiteSpeed Web server running PHP 7.3.25, Wordpress 5.6.2)!
When I change the name of dashboard.php
to anything else (e.g. dashboard1.php
), it works with no problems at all! What could be the problem here and how may I fix it?!
I've made a simple "test plugin" to demonstrate the issue:
my-test-plugin/
├─ includes/
│ └─ dashboard.php
└─ main.php
<?php // dashboard.php
echo '<h1>Dashboard</h1>';
<?php // main.php
/**
* Plugin Name: My Test Plugin
*/
add_action('admin_menu', 'myTestPlugin_onAdminMenu');
function myTestPlugin_onAdminMenu() {
add_menu_page('My Dashboard', 'My Test Plugin', 'manage_options', 'my-test-plugin', 'myTestPlugin_displayDashboardPage');
}
function myTestPlugin_displayDashboardPage() {
require_once 'includes/dashboard.php';
}
This plugin only adds a menu item labeled My Test Plugin
, that displays the "dashboard" page. It works perfectly on my development Windows machine; but surprisingly, it doesn't work on my online web-hosting service (LiteSpeed Web server running PHP 7.3.25, Wordpress 5.6.2)!
When I change the name of dashboard.php
to anything else (e.g. dashboard1.php
), it works with no problems at all! What could be the problem here and how may I fix it?!
1 Answer
Reset to default 0WordPress has a file with the same name at wp-admin/includes/dashboard.php
. Since you are using require_once
PHP will not load a file if it already has been loaded.
The fact that your setup works locally, but not on your remote server, suggests that is has something to do with PHP server set-up. Locally require_once
recognizes the different paths to the two files, your web server does not. So, I would try explicitly including your plugin's directory in the call. Like this:
require_once (plugin_dir_path( __FILE__ ) . 'includes/dashboard.php');
本文标签: plugin developmentquotdashboardquotnamed PHP file doesn39t get included
版权声明:本文标题:plugin development - "dashboard"-named PHP file doesn't get included 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741706193a2393574.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
require_once 'includes/dashboard.php';
meaning a different dashboard? But obviously they should be different files so not conflict. – Rup Commented Mar 2, 2021 at 10:12include_path
- which could be different on the live site. – MrWhite Commented Mar 14, 2021 at 12:57