Settings.php
4.08 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
95
96
97
98
99
100
101
102
103
104
105
106
<?php
namespace Tz\WordPress\Tools\AddThis\Settings;
use Tz\Common;
use Tz\WordPress\Tools;
use Tz\WordPress\Tools\AddThis;
const OPTION_GROUP = 'addthis_group'; // Grouping of options used for setting output by WP
const OPTION_SECTION = 'tz_addthis_main';
const ADMIN_PAGE = 'tz-tools-addthis'; // URI of options page
const CAPABILITY = 'manage_addthis_params'; // User & Roles capability name
call_user_func(function() {
$role = get_role('administrator');
$role->add_cap(CAPABILITY);
Tools\add_actions(__NAMESPACE__ . '\Actions');
});
function displayPage() {
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'views/Settings.php');
}
function validate($data) {
return $data;
}
/**
* @uses Tools\add_actions
*/
class Actions {
/**
* Creates a settings page for the WP admin
*/
public static function admin_menu() {
add_options_page('AddThis', 'AddThis', CAPABILITY, ADMIN_PAGE, __NAMESPACE__ . '\displayPage');
}
/**
* Generates variables for the module's options
*/
public static function admin_init() {
register_setting(OPTION_GROUP, AddThis\OPTION_NAME, __NAMESPACE__ . '\validate');
add_settings_section(OPTION_SECTION, 'AddThis Default Expanded Settings', 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 use_32px_icons() {
echo '<input type="checkbox" id="' . __FUNCTION__ . '" name="' . AddThis\OPTION_NAME . '[' . __FUNCTION__ . ']" value="1" ' . checked('1', AddThis\Vars::$options[__FUNCTION__], false) . ' />';
}
public static function show_share_dropdown() {
echo '<input type="checkbox" id="' . __FUNCTION__ . '" name="' . AddThis\OPTION_NAME . '[' . __FUNCTION__ . ']" value="1" ' . checked('1', AddThis\Vars::$options[__FUNCTION__], false) . ' />';
}
public static function facebook() {
echo '<input type="checkbox" id="' . __FUNCTION__ . '" name="' . AddThis\OPTION_NAME . '[' . __FUNCTION__ . ']" value="1" ' . checked('1', AddThis\Vars::$options[__FUNCTION__], false) . ' />';
}
public static function twitter() {
echo '<input type="checkbox" id="' . __FUNCTION__ . '" name="' . AddThis\OPTION_NAME . '[' . __FUNCTION__ . ']" value="1" ' . checked('1', AddThis\Vars::$options[__FUNCTION__], false) . ' />';
}
public static function googlebuzz() {
echo '<input type="checkbox" id="' . __FUNCTION__ . '" name="' . AddThis\OPTION_NAME . '[' . __FUNCTION__ . ']" value="1" ' . checked('1', AddThis\Vars::$options[__FUNCTION__], false) . ' />';
}
public static function print_button() {
echo '<input type="checkbox" id="' . __FUNCTION__ . '" name="' . AddThis\OPTION_NAME . '[' . __FUNCTION__ . ']" value="1" ' . checked('1', AddThis\Vars::$options[__FUNCTION__], false) . ' />';
}
public static function email() {
echo '<input type="checkbox" id="' . __FUNCTION__ . '" name="' . AddThis\OPTION_NAME . '[' . __FUNCTION__ . ']" value="1" ' . checked('1', AddThis\Vars::$options[__FUNCTION__], false) . ' />';
}
public static function facebook_like() {
echo '<input type="checkbox" id="' . __FUNCTION__ . '" name="' . AddThis\OPTION_NAME . '[' . __FUNCTION__ . ']" value="1" ' . checked('1', AddThis\Vars::$options[__FUNCTION__], false) . ' />';
}
public static function myspace() {
echo '<input type="checkbox" id="' . __FUNCTION__ . '" name="' . AddThis\OPTION_NAME . '[' . __FUNCTION__ . ']" value="1" ' . checked('1', AddThis\Vars::$options[__FUNCTION__], false) . ' />';
}
public static function digg() {
echo '<input type="checkbox" id="' . __FUNCTION__ . '" name="' . AddThis\OPTION_NAME . '[' . __FUNCTION__ . ']" value="1" ' . checked('1', AddThis\Vars::$options[__FUNCTION__], false) . ' />';
}
public static function stumble_upon() {
echo '<input type="checkbox" id="' . __FUNCTION__ . '" name="' . AddThis\OPTION_NAME . '[' . __FUNCTION__ . ']" value="1" ' . checked('1', AddThis\Vars::$options[__FUNCTION__], false) . ' />';
}
}
?>