我创建了这个插件,现在我收到了致命的错误消息。我对这个很陌生。请告诉我哪里错了:
<?php
/*
Plugin Name: Xenon-Result
Plugin URI: https://developer.wordpress.org/plugins/the-basics/
Description: Basic result display plugin.
Version: 1.0
Author: Himanshu Gupta
Author URI: https://developer.wordpress.org/
License: GPL2
License URI: https://www.gnu.org/licenses/gpl-2.0.html
*/
function installer(){
include(\'installer.php\');
}
register_activation_hook( __file__, \'installer\' ); //executes installer php when installing plugin to create new database
add_action(\'admin_menu\',\'result_menu\'); //wordpress admin menu creation
function result_menu()
{
add_menu_page(\'Result\',\'Result\',\'administrator\',\'xenon-result\');
add_submenu_page( \'xenon-result\', \'Manage Marks\', \' Manage Marks\', \'administrator\', \'Manage-Xenon-Marks\', \'Xenon_Marks\' );
}
function Xenon_Marks()
{
include(\'new/result-add-marks.php\');
}
/*function Result_Form()
{
include(\'new/result-form.php\');
}*/
function html_form_code()
{
echo \'<form action="" method="post">\';
echo \'<fieldset>\';
echo \'<legend>Student Information</legend>\';
echo \'Roll Number: <input type="number" min="170001" max="171000" name="rollNumber"><br>\';
echo \'<input type="submit">\';
echo \'<input type ="reset">\';
echo \'</form>\';
}
function result_display(){
$wpdb;
$student_id = $_POST[\'rollNumber\'];
$query = "SELECT * FROM `wp_xenonresult` WHERE `student_id` = $student_id";
$result = $wpdb->get_row($query);
echo $result->student_name;
}
function display_shortcode() {
ob_start();
html_form_code();
result_display();
return ob_get_clean();
}
add_shortcode( \'xenon_result_display\', \'display_shortcode\' );
// Enable shortcodes in text widgets
add_filter(\'widget_text\',\'do_shortcode\');
?>
SO网友:Himanshu
我犯的错误是定义了$wpdb的范围。正确的脚本如下所示:
<?php
/*
Plugin Name: Xenon-Result
Plugin URI: https://developer.wordpress.org/plugins/the-basics/
Description: Basic result display plugin.
Version: 1.0
Author: Himanshu Gupta
Author URI: https://developer.wordpress.org/
License: GPL2
License URI: https://www.gnu.org/licenses/gpl-2.0.html
*/
function installer(){
include(\'installer.php\');
}
register_activation_hook( __file__, \'installer\' ); //executes installer php when installing plugin to create new database
add_action(\'admin_menu\',\'result_menu\'); //wordpress admin menu creation
function result_menu()
{
add_menu_page(\'Result\',\'Result\',\'administrator\',\'xenon-result\');
add_submenu_page( \'xenon-result\', \'Manage Marks\', \' Manage Marks\', \'administrator\', \'Manage-Xenon-Marks\', \'Xenon_Marks\' );
}
function Xenon_Marks()
{
include(\'new/result-add-marks.php\');
}
/*function Result_Form()
{
include(\'new/result-form.php\');
}*/
function html_form_code()
{
echo \'<form action="" method="post">\';
echo \'<fieldset>\';
echo \'<legend>Student Information</legend>\';
echo \'Roll Number: <input type="number" min="170001" max="171000" name="rollNumber"><br>\';
echo \'<input type="submit">\';
echo \'<input type ="reset">\';
echo \'</form>\';
}
function result_display(){
global $wpdb;
$student_id = $_POST[\'rollNumber\'];
$query = "SELECT * FROM `wp_xenonresult` WHERE `student_id` = $student_id";
$result = $wpdb->get_row($query);
echo $result->student_name;
}
if(isset($_POST[\'submit\']))
{
result_display();
}
function display_shortcode() {
ob_start();
result_display();
html_form_code();
return ob_get_clean();
}
add_shortcode( \'xenon_result_display\', \'display_shortcode\' );
// Enable shortcodes in text widgets
add_filter(\'widget_text\',\'do_shortcode\');
?>
SO网友:Craig
作为旁注(抱歉,由于目前还没有达到这样的特权,我无法“评论”),不要忘记改变是个好主意define(\'WP_DEBUG\', false);
到define(\'WP_DEBUG\', true);
开发/修改网站时。这可以在您的“wp配置”中找到。php文件。
这样,浏览器中会突出显示许多错误。这可能很有用,因为错误消息将详细说明错误的位置。
记住把它改回define(\'WP_DEBUG\', false);
完成开发/修改后;作为安全措施。