我只是把我的职能分开了。php文件转换为较小的文件和所需的每个内部函数。php
其中一个文件是“dashboard”。php’在这里,我添加了一个小部件来更改商店中的通知。
<?php
// Store Notice Dashboard Widget
add_action(\'wp_dashboard_setup\', \'widgets_definitions\');
function widgets_definitions() {
error_log("widget_defs");
wp_add_dashboard_widget(
\'update_store_notice_widget\', // widget slug
\'Update Store Notice\', // Title
\'render_store_notice_widget\', // Display function
\'handle_store_notice_widget\' // Handle configure function
);
error_log("widget_defs 2");
}
function render_store_notice_widget() {
error_log("render");
$notice_text = get_option(\'woocommerce_demo_store_notice\');
error_log($notice_text);
if (!isset($notice_text)) {
$notice_text = "";
}
echo "<p><strong>Current Store Notice:</strong></p>";
echo "<p>" . $notice_text . "</p>";
}
function handle_store_notice_widget() {
error_log("handler");
$notice_text = get_option(\'woocommerce_demo_store_notice\');
if (\'POST\' == $_SERVER[\'REQUEST_METHOD\'] && isset($_POST[\'woocommerce_demo_store_notice\'])) {
error_log("POST");
//minor validation
$notice_text = wp_kses($_POST[\'woocommerce_demo_store_notice\']);
error_log($notice_text);
//save update
update_option(\'woocommerce_demo_store_notice\', $notice_text);
}
if (!isset($notice_text)) {
$notice_text = "";
}
error_log($notice_text);
echo "<p><strong>New Store Notice</strong></p>";
echo "<textarea name=\'woocommerce_demo_store_notice\'>" . $notice_text . "</textarea>";
}
?>
由于某些原因,它没有显示在我的仪表板中,没有错误。我在require之前和之后以及函数末尾添加了error\\u log()。php文件,我可以在日志文件中看到所有3个,但仪表板上没有一个。php’。
知道怎么回事吗?
编辑
<?php
add_action(\'wp_enqueue_scripts\', \'supro_child_enqueue_scripts\', 20);
function supro_child_enqueue_scripts() {
wp_enqueue_style(\'supro-child-style\', get_stylesheet_uri());
if (is_rtl()) {
wp_enqueue_style(\'supro-rtl\', get_template_directory_uri() . \'/rtl.css\', array(), \'20180727\');
}
}
require "includes/dashboard.php";
require \'file\';
require \'file\';
require \'file\';
[...]
这就是我的职能。php文件,唯一省略的是所有其他要求。我会将其更改为wp\\u kses\\u post(),谢谢@达维罗姆西