Settings.php
3.01 KB
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
86
87
88
89
90
91
92
93
94
<?php
namespace Tz\WordPress\Tools\Auth\Settings;
use Tz\Common;
use Tz\WordPress\Tools;
use Tz\WordPress\Tools\Auth;
const OPTION_GROUP = 'auth_group'; // Grouping of options used for setting output by WP
const OPTION_SECTION = 'tz_auth_main';
const ADMIN_PAGE = 'tz-tools-auth'; // URI of options page
const CAPABILITY = 'manage_auth'; // User & Roles capability name
call_user_func(function() {
$role = get_role('administrator');
$role->add_cap(CAPABILITY);
Tools\add_actions(__NAMESPACE__ . '\Actions');
});
/**
* Loads the view for the settings page
*/
function displayPage() {
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'settings_view.php');
}
/**
* @todo Make this work
* @param {Array} $data Data provided by WP to sanatize
* @returns Array
*/
function validate($data) {
return $data;
// Validation library causing some issues with Array
$valid = new Validation((array)$data);
return $valid->valid;
}
/**
* @uses Tools\add_actions
*/
class Actions {
/**
* Creates a settings page for the WP admin
*/
public static function admin_menu() {
add_options_page('Authentication', 'Authentication', CAPABILITY, ADMIN_PAGE, __NAMESPACE__ . '\displayPage');
}
/**
* Generates variables for the module's options
*/
public static function admin_init() {
register_setting(OPTION_GROUP, Auth\OPTION_NAME, __NAMESPACE__ . '\validate');
add_settings_section(OPTION_SECTION, 'Authentication Pages', function(){}, ADMIN_PAGE);
Tools\add_settings_fields(__NAMESPACE__ . '\Fields', ADMIN_PAGE, OPTION_SECTION);
}
}
/**
* Each function is a variable stored in the WP_Option
* @uses Tools\add_settings_fields
*/
class Fields {
public static function login_page() {
_dropdown_pages(Array('name' => Auth\OPTION_NAME . '[' . __FUNCTION__ . ']', 'sort_column' => 'menu_order', 'echo' => 1, 'selected' => Auth\Vars::$options[__FUNCTION__]));
}
public static function account_page() {
_dropdown_pages(Array('name' => Auth\OPTION_NAME . '[' . __FUNCTION__ . ']', 'sort_column' => 'menu_order', 'echo' => 1, 'selected' => Auth\Vars::$options[__FUNCTION__]));
}
public static function Facebook() {
echo '<input type="checkbox" id="' . __FUNCTION__ . '" name="' . Auth\OPTION_NAME . '[third_party][' . __FUNCTION__ . ']" value="1" ' . checked('1', Auth\Vars::$options['third_party'][__FUNCTION__], false) . ' />';
}
public static function Twitter() {
echo '<input type="checkbox" id="' . __FUNCTION__ . '" name="' . Auth\OPTION_NAME . '[third_party][' . __FUNCTION__ . ']" value="1" ' . checked('1', Auth\Vars::$options['third_party'][__FUNCTION__], false) . ' />';
}
}
class Validation extends Common\Validation {
public static function login_page($val) {
// if !is page throw exception
}
public static function account_page($val) {
// if !is page throw exception
// if is same as login_page throw exception
}
}
?>