Browse Source

Add basic settings

develop
Sam Black 1 year ago
parent
commit
75cb41cea7
Signed by: samwwwblack GPG Key ID: 0FF0223994EA47D8
  1. 2
      README.txt
  2. 108
      admin/class-bespokomatic-ebs-admin.php
  3. 40
      admin/partials/bespokomatic-ebs-admin-settings.php
  4. 1
      bespokomatic-ebs.php
  5. 5
      includes/class-bespokomatic-ebs.php

2
README.txt

@ -3,7 +3,7 @@ Contributors: bespokomatic
Donate link: https://www.bespokomatic.co.uk
Tags: booking, booked-scheduler
Requires at least: 5.3
Tested up to: 5.3.2
Tested up to: 5.5
Stable tag: trunk
License: GPLv3 or later
License URI: http://www.gnu.org/licenses/gpl-3.0.html

108
admin/class-bespokomatic-ebs-admin.php

@ -39,18 +39,47 @@ class Bespokomatic_Ebs_Admin {
*/
private $version;
/**
* Settings for the plugin.
*
* @since 0.1
* @access private
* @var object $plugin_options The options for this plugin.
*/
private $plugin_options;
/**
* Settings name for the plugin.
*
* @since 0.1
* @access private
* @var string $options_name The options name for this plugin.
*/
private $options_name;
/**
* Page name for the plugin settings.
*
* @since 0.1
* @access private
* @var string $page_name The page name for the settings.
*/
private $page_name;
/**
* Initialize the class and set its properties.
*
* @since 0.1
* @param string $plugin_name The name of this plugin.
* @param string $version The version of this plugin.
* @param string $plugin_name The name of this plugin.
* @param string $version The version of this plugin.
*/
public function __construct( $plugin_name, $version ) {
$this->plugin_name = $plugin_name;
$this->version = $version;
$this->plugin_name = $plugin_name;
$this->version = $version;
$this->page_name = $plugin_name . '-settings';
$this->options_name = str_replace( '-', '_', $this->page_name );
$this->plugin_options = array();
}
/**
@ -75,6 +104,62 @@ class Bespokomatic_Ebs_Admin {
}
/**
* Add settings config
*
* @since 0.1
*/
public function settings_setup() {
// General settings
$general_settings_name = $this->options_name . '_general';
register_setting(
$general_settings_name,
$general_settings_name,
array( $this, 'general_settings_sanitizer' )
);
add_settings_section(
$general_settings_name,
'General',
null,
$this->page_name
);
add_settings_field(
'delete_data0',
'Delete data',
array( $this, 'settings_general_delete_cb' ),
$this->page_name,
$general_settings_name
);
}
/**
* Sanitize any incoming settings.
*
* @since 0.1
*/
public function general_settings_sanitizer( $input ) {
$sanitary_values = array();
$sanitary_values['delete_data_0'] = isset( $input['delete_data_0'] ) ? $input['delete_data_0'] : false;
return $sanitary_values;
}
/**
* Delete data callback.
*
* @since 0.1
*/
public function settings_general_delete_cb() {
vprintf(
'<input type="checkbox" name="%s[delete_data_0]" id="delete_data_0" value="delete_data_0" %s> <label for="delete_data_0">Delete data on plugin deactivation</label>',
array( $this->options_name . '_general', ( isset( $this->plugin_options['general']['delete_data_0'] ) && $this->plugin_options['general']['delete_data_0'] === 'delete_data_0' ) ? 'checked' : '' )
);
}
/**
* Add menu links
*
@ -85,23 +170,23 @@ class Bespokomatic_Ebs_Admin {
'Booked Scheduler',
'Booked Scheduler',
'manage_options',
'booked-scheduler'
$this->plugin_name
);
add_submenu_page(
'booked-scheduler',
$this->plugin_name,
'Booked Scheduler',
'Booked Scheduler',
'manage_options',
'booked-scheduler',
$this->plugin_name,
array( $this, 'admin_main' )
);
add_submenu_page(
'booked-scheduler',
'Settings',
$this->plugin_name,
'Booked Scheduler Settings',
'Settings',
'manage_options',
'booked-scheduler-settings',
$this->options_name,
array( $this, 'admin_settings' )
);
}
@ -117,6 +202,7 @@ class Bespokomatic_Ebs_Admin {
* Admin settings page
*/
public function admin_settings() {
$this->plugin_options['general'] = get_option( $this->options_name . '_general' );
require_once plugin_dir_path( __FILE__ ) . 'partials/bespokomatic-ebs-admin-settings.php';
}

40
admin/partials/bespokomatic-ebs-admin-settings.php

@ -9,6 +9,44 @@
* @subpackage Bespokomatic_Ebs/admin/partials
*/
global $wp_settings_sections;
$settings_page = $this->plugin_name . '-settings';
$active_tab = 'general';
?>
<!-- Settings HTML -->
<div class="wrap">
<h2><?php echo esc_html( get_admin_page_title() ); ?></h2>
<?php
settings_errors();
if ( isset( $_GET['tab'] ) ) {
$active_tab = isset( $_GET['tab'] ) ? $_GET['tab'] : 'general';
}
?>
<h2 class="nav-tab-wrapper">
<a href="?page=<?php echo $settings_page ?>&tab=general" class="nav-tab <?php echo $active_tab == 'general' ? 'nav-tab-active' : ''; ?>">General</a>
</h2>
<form action="options.php" method="post">
<?php
$page_section_name = $this->options_name . '_' . $active_tab;
$page_section = $wp_settings_sections[ $settings_page ][ $page_section_name ];
settings_fields( $page_section_name );
if ( $page_section[ 'callback' ] ) {
call_user_func( $page_section['callback'], $page_section );
}
?>
<table class="form-table" role="presentation">
<?php
do_settings_fields( $settings_page, $page_section_name );
?>
</table>
<?php
submit_button();
?>
</form>
</div>

1
bespokomatic-ebs.php

@ -29,6 +29,7 @@ if ( ! defined( 'WPINC' ) ) {
die;
}
define( 'BESPOKOMATIC_EBS_NAME', 'bespokomatic-ebs' );
define( 'BESPOKOMATIC_EBS_VERSION', '0.1' );
define( 'BESPOKOMATIC_EBS_BOOKED_VERSION', '2.8.4' );
define( 'BESPOKOMATIC_EBS_BOOKED_MAJOR_VERSION', '2.8' );

5
includes/class-bespokomatic-ebs.php

@ -71,7 +71,7 @@ class Bespokomatic_Ebs {
} else {
$this->version = '0.1';
}
$this->plugin_name = 'bespokomatic-ebs';
$this->plugin_name = BESPOKOMATIC_EBS_NAME;
$this->load_dependencies();
$this->set_locale();
@ -156,6 +156,9 @@ class Bespokomatic_Ebs {
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
// Add settings.
$this->loader->add_action( 'admin_init', $plugin_admin, 'settings_setup' );
// Add menu items.
$this->loader->add_action( 'admin_menu', $plugin_admin, 'admin_menu' );

Loading…
Cancel
Save