我不是php或wordpress的完全新手,但我想以最有效的方式解决这个问题,所以相信在这里提问会有所帮助。
我有一个插件,可以随机生成一个引号-我需要将引号保存到mysql数据库中。
我想知道保存数据的最佳方法,无论是使用设置api还是简单地将其保存到数组。
我还想实现删除报价的选项。
使用输入文本字段,我想知道如何在文本框中添加新引号,并将数据传递给包含引号的数组。
我的代码far(引号目前存储在一个数组中)
<?php
/*idea to develop further would be, add a text box that the user can input the quote in
this then gets added to the DB and passed to the $quotes array. From here the results get
output the same way*/
/*
Plugin Name: Random Quotes
Plugin URI: xxx
Description: This Plugin randomly generates Quotes input by the user.
Version: 0.0.1
Author: xxx
Author URI: xxx
License: GPL2
*/
add_action(\'admin_menu\', \'dw_quotes_create_menu\');
function dw_quotes_create_menu() {
//create custom top-level menu
add_menu_page(\'Quotes Settings\', \'Quotes Styling\', \'manage_options\', __FILE__, \'dw_styling_quotes_settings\');
}
function dw_styling_quotes_settings() { ?>
<div class="wrap">
<?php screen_icon( \'plugins\' ); ?>
<h2>Quotes Page</h2>
<table class="form-table">
<tr valign="top">
<th scope="row">Input Quotes in the textbox</th>
<td><input type="textarea" name="random_quote" value="" /></td>
</tr>
</table>
</div>
<?php }
// add quotes to this list
$quotes = array(
"one" => "The weak can never forgive. Forgiveness is the attribute of the strong",
"two" => "Be strong when you are weak, Be brave when you are scared, Be humble when you are victorious",
"three" => "Our success is achieved by uniting our strength, not by gathering our weaknesses",
"four" => "One of the most common causes of failure is the habit of of quitting when one is overtaken by temporary defeat",
"five" => "The struggles make you stronger and the changes make you wise! Happiness has its own way of taking its sweet time"
);
// uses array_rand to randomly pick a quote
$rand_quotes = array_rand( $quotes);
// pass\'s the result of $array_rand to $result_quotes
$result_quote = $quotes[$rand_quotes];
// outputs the result
//echo $result_quote;
?>