Я пишу простой плагин для Wordpress. Я добавил Metabox, но не могу получить данные формы из $ _POST. Это просто пусто. Для тестирования я выводю переменную $ _POST в файл, а $ _POST пуст. Как получить данные формы для сохранения?
<?php
/**
* Plugin Name: Test Meta
*/
function testmeta_add_custom_box() {
add_meta_box(
'testmeta', // Unique ID
'Test Meta', // Title
'testmeta_html', // Callback function
'post', // Admin page (or post type)
'normal', // Context
'default' // Priority
);
}
add_action('add_meta_boxes', 'testmeta_add_custom_box');
function testmeta_html($post) {
wp_nonce_field( basename( __FILE__ ), 'testmeta_nonce' );
$testvalue = get_post_meta($post->ID, '_testmeta_value');
?>
<input type="checkbox" name="testcheck" id="testcheck" <?php checked($testvalue, 'true'); ?> />Test<br/>
<input type="text" name="testtext" id="testtext"/>
<?php
}
function testmeta_save_postdata($post_id, $post) {
ob_start();
var_dump($_POST);
$result = ob_get_clean();
templog("post variable: " . $result);
}
add_action('save_post', 'testmeta_save_postdata', 10, 2);
function templog($msg) {
$file = fopen("log.txt", "a");
fwrite($file, $msg . "\r\n");
fclose($file);
}
log.txt
post variable: array(0) {
}