Commit b46a2440 authored by Reinhold Kainhofer's avatar Reinhold Kainhofer

Some fixes for the settings page, etc.

parent 3c37894d
<div class="wrap"> <div class="wrap">
<h2>OpenTools Advanced ordernumbers</h2> <h2>OpenTools Advanced Ordernumbers</h2>
<form method="post" action="options.php"> <form method="post" action="options.php">
<?php @settings_fields('create_ordernumber-group'); ?> <?php @settings_fields('create_ordernumbers-group'); ?>
<?php @do_settings_fields('create_ordernumber-group'); ?> <?php @do_settings_fields('create_ordernumbers-group'); ?>
<table class="form-table"> <table class="form-table">
<tr valign="top"> <tr valign="top">
<th scope="row"><label for="customize_ordernumber">Customize Order Numbers</label></th> <th scope="row"><label for="customize_ordernumbers">Customize Order Numbers</label></th>
<td><input type="text" name="customize_ordernumber" id="customize_ordernumber" value="<?php echo get_option('customize_ordernumber'); ?>" /></td> <td><input type="text" name="customize_ordernumbers" id="customize_ordernumbers" value="<?php echo get_option('customize_ordernumbers'); ?>" /></td>
</tr> </tr>
<tr valign="top"> <tr valign="top">
<th scope="row"><label for="ordernumber_format">Order Number Format</label></th> <th scope="row"><label for="ordernumber_format">Order Number Format</label></th>
......
...@@ -27,7 +27,7 @@ if ( ! defined( 'ABSPATH' ) ) { ...@@ -27,7 +27,7 @@ if ( ! defined( 'ABSPATH' ) ) {
if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) { if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
// Put your plugin code here // Put your plugin code here
// Load the language files // Load the language files
load_plugin_textdomain('your-unique-name', false, basename( dirname( __FILE__ ) ) . '/languages' ); load_plugin_textdomain('opentools-ordernumbers', false, basename( dirname( __FILE__ ) ) . '/languages' );
if (!class_exists("OpenToolsOrdernumbers")) { if (!class_exists("OpenToolsOrdernumbers")) {
class OpenToolsOrdernumbers { class OpenToolsOrdernumbers {
...@@ -36,10 +36,13 @@ if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', g ...@@ -36,10 +36,13 @@ if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', g
*/ */
public function __construct() public function __construct()
{ {
add_action ('woocommerce_order_number', array(&$this, 'get_ordernumber')); $plugin = plugin_basename(__FILE__);
add_action( 'admin_init', array(&$this, 'admin_init'));
add_action( 'admin_menu', array(&$this, 'admin_menu'));
// register actions // register actions
add_action( 'admin_init', array(&$this, 'admin_init'));
add_action( 'admin_menu', array(&$this, 'add_menu'));
// register filters
add_filter("plugin_action_links_$plugin", array(&$this, 'plugin_settings_link'));
add_filter ('woocommerce_order_number', array(&$this, 'get_ordernumber'), 10, 2/*<= Also get the order object! */);
} }
/** /**
...@@ -74,9 +77,10 @@ if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', g ...@@ -74,9 +77,10 @@ if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', g
public function init_settings() public function init_settings()
{ {
// register the settings for this plugin // register the settings for this plugin
register_setting('opentools-ordernumber-group', 'customize_ordernumber'); // TODO: Properly design the set of options needed
register_setting('opentools-ordernumber-group', 'ordernumber_format'); register_setting('opentools-ordernumbers-group', 'customize_ordernumbers');
register_setting('opentools-ordernumber-group', 'ordernumber_counter_scope'); register_setting('opentools-ordernumbers-group', 'ordernumber_format');
register_setting('opentools-ordernumbers-group', 'ordernumber_counter_scope');
} }
/** /**
...@@ -84,19 +88,27 @@ if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', g ...@@ -84,19 +88,27 @@ if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', g
*/ */
public function add_menu() public function add_menu()
{ {
// TODO: Move this inside the WooCommerce configuration!
add_options_page('Advanced Ordernumber Plugin Settings', 'OpenTools Advanced Ordernumbers', add_options_page('Advanced Ordernumber Plugin Settings', 'OpenTools Advanced Ordernumbers',
'manage_options', 'opentools-ordernumbers', array(&$this, 'plugin_settings_page')); 'manage_options', 'opentools-ordernumbers', array(&$this, 'plugin_settings_page'));
} // END public function add_menu() } // END public function add_menu()
function plugin_settings_link($links)
{
$settings_link = '<a href="options-general.php?page=opentools-ordernumbers">Settings</a>';
array_unshift($links, $settings_link);
return $links;
}
/** /**
* Menu Callback * Menu Callback
*/ */
public function plugin_settings_page() public function plugin_settings_page()
{ {
// if(!current_user_can('manage_options')) if(!current_user_can('manage_options'))
// { {
// wp_die(__('You do not have sufficient permissions to access this page.')); wp_die(__('You do not have sufficient permissions to access this page.'));
// } }
// Render the settings template // Render the settings template
include(sprintf("%s/templates/settings.php", dirname(__FILE__))); include(sprintf("%s/templates/settings.php", dirname(__FILE__)));
...@@ -108,13 +120,13 @@ if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', g ...@@ -108,13 +120,13 @@ if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', g
* The hook to customize order numbers (requests the order number from the database; creates a new ordernumber if no entry exists in the database) * The hook to customize order numbers (requests the order number from the database; creates a new ordernumber if no entry exists in the database)
*/ */
function get_ordernumber($orderid, $order) { function get_ordernumber($orderid, $order) {
$stored_number = get_post_meta( $orderid, 'ordernumber', 'true'); $stored_number = get_post_meta( $orderid, 'Order Number', 'true');
if (!empty($stored_number)) { if (!empty($stored_number)) {
return $stored_number; return $stored_number;
} else { } else {
// create a new one (if this is a new order, otherwise we don't have/generate a number!) // create a new one (if this is a new order, otherwise we don't have/generate a number!)
$number = $this->create_ordernumber($orderid, $order); $number = $this->create_ordernumber($orderid, $order);
update_post_meta( $orderid, 'ordernumber', $number ); update_post_meta( $orderid, 'Order Number', $number );
return $number; return $number;
} }
} }
...@@ -134,20 +146,6 @@ if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', g ...@@ -134,20 +146,6 @@ if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', g
// instantiate the plugin class // instantiate the plugin class
$ordernumber_plugin = new OpenToolsOrdernumbers(); $ordernumber_plugin = new OpenToolsOrdernumbers();
// Add a link to the settings page onto the plugin page
if(isset($ordernumber_plugin)) {
// Add the settings link to the plugins page
function plugin_settings_link($links)
{
$settings_link = '<a href="options-general.php?page=wp_plugin_template">Settings</a>';
array_unshift($links, $settings_link);
return $links;
}
$plugin = plugin_basename(__FILE__);
add_filter("plugin_action_links_$plugin", 'plugin_settings_link');
}
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment