我是插件开发新手,我对新插件的设置页面有问题。
我的页面似乎将正确的设置数据保存到wordpress数据库中,但几小时/几天后,存储在数据库中的值就会消失。
插件主页的代码为:
//security
defined( \'ABSPATH\' ) or die( \'No script kiddies please!\' );
//define path
define(\'ffita_gads_DIR\', plugin_dir_path(__FILE__));
require_once(ffita_gads_DIR.\'inc/settings.php\');
//add shortcode
add_shortcode(\'ffita_gads\', \'ffita_view_ads\');
/* Runs on plugin deactivation*/
register_deactivation_hook( __FILE__, \'ffita_gads_remove\' );
function ffita_gads_remove() {
/* Deletes shortcodes */
remove_shortcode (\'ffita_gads\');
}
//add menu
add_action(\'admin_menu\', \'ffita_gads_admin_menu\');
function ffita_gads_admin_menu () {
// richiama la funzione ffi_gads_setting_page definita nel file settings.php
add_menu_page( \'Impostazioni\', \'FFI G Ads settings\', \'manage_options\', \'ffita_gads_option\', \'ffi_gads_setting_page\', \'dashicons-images-alt\' );
}
设置页面代码为:
function ffi_gads_setting_page() {
// security
defined(\'ABSPATH\') or die(\'No script kiddies please!\');
// verifica che l\'utente possa gestire le impostazioni
if (!current_user_can(\'manage_options\')) {
wp_die(__(\'You do not have sufficient permissions to access this page.\', \'FFita G Ads\'));
}
// form wordpress
?>
<div class="wrap">
<h1 class="dashicons-before dashicons-admin-settings">FFItalia Options</h1>
<form name="ffiset_gads_form" method="post" action="options.php">
<?php
// add_settings_section callback is displayed here. For every new section we need to call settings_fields.
settings_fields("ffita_gads_settings");
// all the add_settings_field callbacks is displayed here
do_settings_sections("ffita_gads_settings");
?>
<table class="widefat" style="margin-top: 10px;">
<tr>
<td colspan="3"><h2>Connection parameters</h2></td>
</tr>
<tr>
<th scope="row" style="width: 15%;">ID VALUE</th>
<td style="vertical-align: middle; width: 45%;"><input type="text"
name="ffita_gads_capub"
value="<?php echo esc_attr( get_option(\'ffita_gads_capub\') ); ?>"
style="width: 90%" required /></td>
<td>ID value" .</td>
</tr>
<tr>
<th scope="row" style="width: 15%;">IP debug</th>
<td style="vertical-align: middle; width: 45%;"><input type="text"
name="ffita_gads_ipdebug"
value="<?php echo esc_attr( get_option(\'ffita_gads_ipdebug\') ); ?>"
style="width: 90%"></td>
<td>Ip for debug....</td>
</tr>
</table>
<table class="widefat Product" style="margin-top: 10px;">
<tr>
<td colspan="3"><h2>Parameter</h2></td>
</tr>
<tr>
<th scope="row" style="width: 10%;">ID</th>
<td style="width: 20%;">Product id</td>
<td>Product description</td>
<td>Shortcode</td>
</tr>
<?php
$Product_options = get_option(\'ffita_gads_option\');
$num_Product = 0;
if (empty($Product_options)) {
$codice_html = "<tr><td colspan=4 bgcolor=red>Imposta i dettagli di almeno un Product</td></tr>";
$codice_html .= \'<tr><td><input type="text" size="2" name="listaProduct[1][Product1][id_shortcode_Product]" value="1" readonly></td>\';
$codice_html .= \'<td><input type="text" name="listaProduct[1][Product1][id_Product]]" value="" required/></td>\';
$codice_html .= \'<td><input type="text" name="listaProduct[1][Product1][desc_Product]]" value="" size="60"/></td>\';
$codice_html .= \'<td>[ffita_gads id="1" ] </td></tr>\';
echo $codice_html;
$num_Product++;
} else {
foreach ($Product_options as $dati_Product) {
$html = \'<tr><td><input type="text" size="2" name="listaProduct[\' . $dati_Product[id_shortcode_Product] . \'][Product\' . $dati_Product[id_shortcode_Product] . \'][id_shortcode_Product]" value="\' . $dati_Product[id_shortcode_Product] . \'" readonly></td>\';
$html .= \'<td><input type="text" name="listaProduct[\' . $dati_Product[id_shortcode_Product] . \'][Product\' . $dati_Product[id_shortcode_Product] . \'][id_Product]]" value="\' . $dati_Product[id_Product] . \'" required/></td>\';
$html .= \'<td><input type="text" name="listaProduct[\' . $dati_Product[id_shortcode_Product] . \'][Product\' . $dati_Product[id_shortcode_Product] . \'][desc_Product]]" value="\' . $dati_Product[desc_Product] . \'" size="60"/></td>\';
$html .= \'<td> [ffita_gads id="\' . $dati_Product[id_shortcode_Product] . \'" ]</td></tr>\';
echo $html;
$num_Product++;
}
}
?>
</table>
<div align="right">
<input type="button" value="Add Product" id="add_ban_but"
data-value="<?php echo $num_Product ?>" /> <input type="button"
value="Remove last Product" id="remove_ban_but" />
</div>
<input type="text" id="n_tot" name="ffita_n_tot"
value="<?php echo $num_Product; ?>" />
<?php
// Add the submit button to serialize the options
submit_button();
?>
</form>
</div>
<?php
}
if (isset($_POST[\'submit\'])) {
// registra i dati dei Product
$nuovi_Product = $_POST[\'listaProduct\'];
$array_Product = array();
// print_r ($nuovi_Product);
foreach ($nuovi_Product as $key) {
$nuovo_Product = $key;
$array_Product = array_merge($array_Product, $nuovo_Product);
}
update_option(\'ffita_gads_option\', $array_Product);
// registra i dati ca-pub-xxxx
$nuovo_ca = $_POST[\'ffita_gads_capub\'];
update_option(\'ffita_gads_capub\', $nuovo_ca);
// registra i dati ipdebug
$nuovo_ipdeb = $_POST[\'ffita_gads_ipdebug\'];
update_option(\'ffita_gads_ipdebug\', $nuovo_ipdeb);
}
function ffita_gads_option_init() {
// registra il codice publisher ca-pub xxxx
register_setting("ffita_gads_settings", "ffita_gads_capub");
// delete_option("ffita_gads_capub");
}
add_action("admin_init", "ffita_gads_option_init");
你知道这个问题吗?非常感谢