所以我一直在做这个。。。现在已经3天了,我已经求助于直接从wordpress codex中粘贴代码,以使其正常工作,然后再从那里开始。
但是,该代码不起作用,所以我假设问题是一些基本的问题,希望很简单。
这是我在主插件文件中调用管理页面的方式:
add_action(\'admin_menu\', \'hostel_booking_menu\');
function hostel_booking_menu() {
add_menu_page(\'Hostel Calendar Settings\', \'Hostel Booking\', \'administrator\', \'hostel-booking-settings\', \'hostel_booking_settings_page\', \'dashicons-admin-generic\');
add_submenu_page( \'hostel-booking-settings\', \'Create Delete Rooms\', \'Rooms\', \'administrator\', \'hostel-booking-settings-rooms\', \'hostel_booking_settings_page_rooms\' );
add_submenu_page( \'hostel-booking-settings\', \'Orders\', \'Orders\', \'administrator\', \'hostel-booking-settings-orders\', \'hostel_booking_settings_page_orders\' );
add_submenu_page( \'hostel-booking-settings\', \'Settings\', \'Settings\', \'administrator\', \'hostel-booking-settings-reservations\', \'hostel_booking_settings_page_reservations\' );
}
function hostel_booking_settings_page_rooms() {
include \'view-create-rooms.php\';
}
以下是视图“创建房间”顶部的相关代码。php(直接从codex复制):
<?php
add_action( \'wp_ajax_my_action\', \'my_action_callback\' );
function my_action_callback() {
global $wpdb; // this is how you get access to the database
$whatever = intval( $_POST[\'whatever\'] );
$whatever += 10;
echo $whatever;
wp_die(); // this is required to terminate immediately and return a proper response
}
?>
<script type="text/javascript" >
jQuery(document).ready(function($) {
var data = {
\'action\': \'my_action\',
\'whatever\': 1234
};
// since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
$.post(ajaxurl, data, function(response) {
alert(\'Got this from the server: \' + response);
});
});
</script>
很明显,当我得到经典的管理ajax响应“0”时,它被发送到了正确的文件中,因此每当我刷新此页面时,我都会收到一条错误消息:“从服务器获得:0”
我已经根据许多教程添加了管理菜单,只能假设它是简单而基本的。我正在本地安装上测试这个插件,但已经在两个本地安装上测试了该插件,其中一个安装了最新版本的WP,主题为2015。
任何帮助都将不胜感激。
抢劫