-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.admin.php
More file actions
187 lines (157 loc) · 6.1 KB
/
functions.admin.php
File metadata and controls
187 lines (157 loc) · 6.1 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<?php
/**
* Gets an array list of editable roles excluding the defalt wordpress roles.
*
* @author James Andrews <project_support@jamesmandrews.com>
* @since 0.0.1
*/
function member_minder_admin_get_editable_roles() {
global $wp_roles;
$all_roles = $wp_roles->roles;
$editable_roles = apply_filters('editable_roles', $all_roles);
return $editable_roles;
}
/**
* Tell the admin section when to display admin meta boxes for controlling content permissions
*
* @author James Andrews <project_support@jamesmandrews.com>
* @since 0.0.1
*/
function member_minder_admin_boxes() {
add_meta_box(
'admin-content-permissoin', // id of the <div> we'll add
'Select Content Viewable Persmission', //title
'member_minder_select_content_permissions', // callback function that will echo the box content
'post', // where to add the box: on "post", "page", or "link" page
'side', // put it in the side bar
'high' // put it high on the page.
);
add_meta_box(
'admin-content-permissoin', // id of the <div> we'll add
'Select Content Viewable Persmission', //title
'member_minder_select_content_permissions', // callback function that will echo the box content
'page', // where to add the box: on "post", "page", or "link" page
'side', // put it in the side bar
'high' // put it high on the page.
);
}
/**
* Build the admin meta box for controling content permissions.
*
* @author James Andrews <project_support@jamesmandrews.com>
* @since 0.0.1
*/
function member_minder_select_content_permissions()
{
global $post_id;
// Get roles we can use.
$roles = member_minder_admin_get_editable_roles();
// Get te current meta permissions
$permissions_meta = get_post_meta($post_id, MM_PERMISIONS_META_KEY, true);
$permissions_meta = ($permissions_meta != "") ? unserialize($permissions_meta) : array();
include('views/admin/content_permissions.php');
}
/**
* Save the what roles can view the content of a post/page.
*
* @author James Andrews <project_support@jamesmandrews.com>
* @since 0.0.1
*/
function member_minder_save_content_permissions()
{
global $post_id;
// Retrieve saved permissions meta.
$current_permissions_meta = get_post_meta($post_id, MM_PERMISIONS_META_KEY, true);
// If permissions are enabled then save the content into an array.
if(isset($_POST['member_minder_protected_content']) && $_POST['member_minder_protected_content'] == true)
{
$permissions_meta = (isset($_POST['member_minder_protected_content_roles'])) ?
$_POST['member_minder_protected_content_roles'] : array();
}
else
{
// If page is viewable to everyone then set an empty array.
$permissions_meta = array();
}
// Serialize the data to save
$serialized_permissions = serialize($permissions_meta);
// If we don't have any current permissions stored then we want to add them.
if(!is_array(unserialize($current_permissions_meta)) && $current_permissions_meta =="")
{
add_post_meta($post_id, MM_PERMISIONS_META_KEY, $serialized_permissions, true);
}
// If we have current permissions update them.
else
{
update_post_meta($post_id, MM_PERMISIONS_META_KEY, $serialized_permissions, $current_permissions_meta);
}
}
/**
* Register plugin settings.
*
* @author James Andrews <project_support@jamesmandrews.com>
* @since 0.0.1
*/
function member_minder_register_settings()
{
register_setting( 'member_minder_options_group', 'member_minder_options', 'member_minder_options_validate');
add_settings_section('member_minder_main', '', 'member_minder_main_options_text', 'member_minder_options_group');
add_settings_field('member_minder_text_string', 'Unauthorized Access Message', 'member_minder_setting_string', 'member_minder_options_group', 'member_minder_main');
}
/**
* Options text currently returns an empty string.
*
* @author James Andrews <project_support@jamesmandrews.com>
* @since 0.0.1
*/
function member_minder_main_options_text()
{
return "";
}
/**
* Create the form field we'll use for settings.
*
* @author James Andrews <project_support@jamesmandrews.com>
* @since 0.0.1
*/
function member_minder_setting_string()
{
$options = get_option('member_minder_options');
echo '<textarea rows="10" cols="75" name=member_minder_options[unauthorized_access_message]>' .
((isset($options['unauthorized_access_message'])) ? $options['unauthorized_access_message'] : "") .
'</textarea><br />';
echo '(You can use the following HTML tags <p> <a> <br> <img>)';
}
/**
* options validation function. Return the input for now.
*
* @author James Andrews <project_support@jamesmandrews.com>
* @since 0.0.1
*/
function member_minder_options_validate($input)
{
return $input;
}
/**
* Display the Memberminder Admin Menu link
*
* @author James Andrews <project_support@jamesmandrews.com>
* @since 0.0.1
*/
function member_minder_admin_menu()
{
add_options_page('Member Minder', 'Member Minder', 'manage_options', 'member_minder', 'member_minder_options_page');
}
/**
* Display the Memberminder admin page.
*
* @author James Andrews <project_support@jamesmandrews.com>
* @since 0.0.1
*/
function member_minder_options_page()
{
if ( !current_user_can( 'manage_options' ) ) {
wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
}
include('views/admin/options.php');
}