我正在试图保存一个数组以在wordpress中获取\\u选项,我知道我不必因为获取选项而序列化数组。
目前,点击提交按钮后,我没有收到任何失败消息的成功消息。
是否使用get\\u选项和update\\u选项将输入数据正确添加到数据库中。如果没有,我的代码如何调整才能实现这一点。
添加操作(“admin\\u菜单”、“dw\\u quotes\\u create\\u菜单”);
function dw_quotes_create_menu() {
//create custom top-level menu
add_menu_page(\'Quotes Settings\', \'Quotes Styling\', \'manage_options\', \'dw_quotes\', \'dw_styling_quotes_settings\');
}
//generating the random quote
function dw_get_random_quote() {
}
function validate_dw_quote() {
//validation here
if (isset($_POST[\'submit\'] ) ) {
//checking that $_POST[\'adding_quote\'] is set
if( isset( $_POST[\'adding_quote\'] ) ) {
//retrieve the stored values
if( get_option( \'list_of_quotes\' ) )
$list_of_quotes = get_option(\'list_of_quotes\');
else
$list_of_quotes = array();
//add the new quote to the end of the array
$list_of_quotes[] = $_POST[\'adding_quote\'];
//store the updated quote
if ( update_option( \'list_of_quotes\', $list_of_quotes ) ) {
echo "Success your quote was added!";
} else {
echo "Failed to add quote!";
}
}
}
}
//styling the admin menu
function dw_styling_quotes_settings() { ?>
<h2>Quote Setting</h2>
<form action="admin.php?page=dw_quotes" method="post">
<label for="add">Enter your quote</label>
<input type="textarea" name="adding_quote" />
<input type="submit" name="submit" value="add the new quote" />
<?php //test the output
var_dump($list_of_quotes);
?>
最合适的回答,由SO网友:Steven Jones 整理而成
为了保存数据,您需要挂接validate_dw_quote()
转到操作,例如admin\\u init或init。
add_action(\'admin_init\', \'validate_dw_quote\');