-
Notifications
You must be signed in to change notification settings - Fork 1
/
wpsf-test.php
85 lines (70 loc) · 1.86 KB
/
wpsf-test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
/**
* Plugin Name: WP Settings Framework Example
* Description: An example of the WP Settings Framework in action.
* Version: 1.0.0
* Author: Sharaz
* Author URI: https://github.com/sharazghouri
*
* @package sbsa
*/
defined( 'ABSPATH' ) || exit;
// require_once __DIR__ . '/src/SettingsAPI.php';
// autoloader.
// if ( ! class_exists( \Solution_Box_Settings\SettingsAPI::class ) ) {
require __DIR__ . '/vendor/autoload.php';
// }
/**
* SBSATest Class.
*/
class SBSATest {
/**
* Plugin path.
*
* @var string
*/
private $plugin_path;
/**
* WordPress Settings Framework instance.
*
* @var WordPressSettingsFramework
*/
private $sbsa;
/**
* Solution Box Settings Test constructor.
*/
public function __construct() {
$this->plugin_path = plugin_dir_path( __FILE__ );
$this->sbsa = new Solution_Box_Settings\SettingsAPI( $this->plugin_path . 'src/settings/example-settings.php', 'my_example_settings' );
// Add admin menu.
add_action( 'admin_menu', array( $this, 'add_settings_page' ), 20 );
// Add an optional settings validation filter (recommended).
add_filter( $this->sbsa->get_option_group() . '_settings_validate', array( &$this, 'validate_settings' ) );
}
/**
* Add settings page.
*/
public function add_settings_page() {
$this->sbsa->add_settings_page(
array(
'parent_slug' => 'woocommerce',
'page_title' => esc_html__( 'Page Title', 'text-domain' ),
'menu_title' => esc_html__( 'menu Title', 'text-domain' ),
'capability' => 'manage_woocommerce',
)
);
}
/**
* Validate settings.
*
* @param mixed $input Input data.
*
* @return mixed $input
*/
public function validate_settings( $input ) {
// Do your settings validation here
// Same as $sanitize_callback from http://codex.wordpress.org/Function_Reference/register_setting.
return $input;
}
}
$sbsa_test = new SBSATest();