前言
插件越来越复杂,原先一个插件只包括一个功能。最近把各个小功能集成到一起。需要一个插件设置页面。本文记录设置过程。
设置
主文件设置
//设置
require_once(plugin_dir_path(__FILE__) . 'settings.php');
settings.php
目录菜单函数
add_action('admin_menu', 'woo_bbpay_gateway_add_settings_page');
function woo_bbpay_gateway_add_settings_page()
{
add_submenu_page(
'options-general.php',
__('BbPay GateWay', 'woo-bbpay-gateway'),
__('BbPay', 'woo-bbpay-gateway'),
'manage_options',
'woo-bbpay-gateway-settings',
'woo_bbpay_gateway_render_settings_page'
);
}
页面函数
function woo_bbpay_gateway_render_settings_page()
{
// Check if user has sufficient permissions
if (!current_user_can('manage_options')) {
return;
}
// Save settings
if (isset($_POST['woo_bbpay_gateway_settings'])) {
update_option('woo_bbpay_gateway_abpaymerno', sanitize_text_field($_POST['woo_bbpay_gateway_abpaymerno']));
update_option('woo_bbpay_gateway_abpaykey', sanitize_text_field($_POST['woo_bbpay_gateway_abpaykey']));
echo '<div class="updated"><p>' . __('Settings saved.', 'woo-bbpay-gateway') . '</p></div>';
}
// Retrieve current settings
$abpaymerno = get_option('woo_bbpay_gateway_abpaymerno');
$abpaykey = get_option('woo_bbpay_gateway_abpaykey');
?>
<div class="wrap">
<h1><?php echo esc_html(get_admin_page_title()); ?></h1>
<form method="post" action="">
<table class="form-table">
<tr valign="top">
<th scope="row"><?php _e('Merchant ID.', 'woo-bbpay-gateway') ?></th>
<td>
<input type="text" name="woo_bbpay_gateway_abpaymerno" value="<?php echo esc_attr($abpaymerno) ?>" class="regular-text" />
<p class="description"><?php printf(__('If you don\'t have a BBPay account, <a href="%s" target="_blank">click here</a> to sign up for one.', 'woo-bbpay-gateway'), 'https://abmanger.webzhan.xyz/sign/'); ?></p>
</td>
</tr>
<tr valign="top">
<th scope="row"><?php _e('Secret Key', 'woo-bbpay-gateway') ?></th>
<td>
<input type="password" name="woo_bbpay_gateway_abpaykey" value="<?php echo esc_attr($abpaykey) ?>" class="regular-text" />
<p class="description"><?php printf(__('You can find your BBPay Secret Key by logging into your BBPay account and going to the Integration Settings page. <a href="%s" target="_blank">Click here</a> to go there now.', 'woo-bbpay-gateway'), 'http://abmanger.webzhan.xyz/login/'); ?></p>
</td>
</tr>
</table>
<?php submit_button(__('Save Settings', 'woo-bbpay-gateway')) ?>
<input type="hidden" name="woo_bbpay_gateway_settings" value="1" />
</form>
</div>
<?php
}
评论 (0)