PluginProbe
Private groups / 2.5
Private groups v2.5
trunk 1.5 1.6 1.7 1.8 1.8.1 1.9.1 1.9.2 2.0 2.0.1 2.2 2.3 2.4 2.5 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 All 116 releases
bbp-private-groups / includes / meta-box.php

meta-box.php in Private groups 2.5, at includes/meta-box.php

116 lines 3.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * This adds the meta box for the permissions component. This allows restriction to bbpress groups
4 */
5 /**
6 */
7
8
9
10 add_action( 'admin_menu', 'private_groups_create_meta_box' );
11
12 /* Saves the content permissions metabox data to a custom field. */
13 add_action( 'save_post', 'private_groups_save_meta', 1, 2 );
14
15
16 function private_groups_create_meta_box() {
17 add_meta_box( 'forum-group-meta-box', __( 'Forum Groups' , 'bbp-private-groups') , 'private_groups_meta_box', 'forum', 'normal', 'high' );
18 //add_meta_box( 'forum-group-meta-box', 'Forum Groups', 'private_groups_meta_box', 'topic', 'normal', 'high' );
19 //add_meta_box( 'forum-group-meta-box', 'Forum Groups', 'private_groups_meta_box', 'reply', 'normal', 'high' );
20 }
21
22 /**
23 * Controls the display of the content permissions meta box. This allows users
24 * to select groups that should have access to an individual post/page.
25 */
26
27 function private_groups_meta_box( $object, $box ) {
28 global $post ?>
29
30 <input type="hidden" name="private_groups_meta_nonce" value="<?php echo wp_create_nonce(plugin_basename(__FILE__)); ?>" />
31
32 <p>
33 <label for="groups"><?php _e('<strong>Groups:</strong> Restrict the content to these groups on the front end of the site. If all boxes are left unchecked, everyone can view the content.', 'bbp-private_groups'); ?></label>
34 </p>
35
36 <div style="overflow: hidden;">
37
38 <?php
39
40 /* Get the meta*/
41
42 $meta = get_post_meta( $post->ID, '_private_group', false );
43 global $rpg_groups ;
44
45 /* Loop through each of the available roles. */
46 if(empty($rpg_groups)) {
47 echo _e('<b>No groups have yet been set up - go to Dashboard>Settings>bbp Private Groups to set</b>', 'bbp-private_groups') ;
48 }
49 else {
50 foreach ( $rpg_groups as $group => $details ) {
51 $checked = false;
52
53 /* If the role has been selected, make sure it's checked. */
54 if ( is_array( $meta ) && in_array( $group, $meta ) )
55 $checked = ' checked="checked" '; ?>
56
57 <p style="width: 32%; float: left; margin-right: 0;">
58 <label for="group-<?php echo $group; ?>">
59 <?php $groupname=__('Group','bbp-private-groups').substr($group,5,strlen($group)) ; ?>
60 <input type="checkbox" name=<?php echo $group ; ?> id=<?php echo $group ; ?> <?php echo $checked; ?> value="<?php echo $group; ?>" />
61 <?php echo $groupname." ".$details ; ?>
62 </label>
63 </p>
64
65 <?php }} ?>
66
67 </div><?php
68 }
69
70 /**
71 * Saves the content permissions metabox data to a custom field.
72 *
73 */
74 function private_groups_save_meta( $post_id, $post ) {
75 global $rpg_groups ;
76
77 /* Only allow users that can edit the current post to submit data. */
78 if ( 'post' == $post->post_type && !current_user_can( 'edit_posts', $post_id ) )
79 return;
80
81 /* Only allow users that can edit the current page to submit data. */
82 elseif ( 'page' == $post->post_type && !current_user_can( 'edit_pages', $post_id ) )
83 return;
84
85 /* Don't save if the post is only a revision. */
86 if ( 'revision' == $post->post_type )
87 return;
88
89 /* Loop through each of the site's available roles. */
90 if(!empty($rpg_groups)) {
91 foreach ( $rpg_groups as $group => $details ){
92
93
94 /* Get post metadata for the custom field key 'group'. */
95 $meta = (array)get_post_meta( $post_id, '_private_group', false );
96
97 /* Check if the group was selected. */
98 if ( $_POST[$group] ) {
99
100 /* If selected and already saved, continue looping through the roles and do nothing for this role. */
101 if ( in_array( $group, $meta ) )
102 continue;
103
104 /* If the group was selected and not already saved, add the group as a new value to the 'group' custom field. */
105 else
106 add_post_meta( $post_id, '_private_group', $group, false );
107 }
108
109 /* If role not selected, delete. */
110 else
111 delete_post_meta( $post_id, '_private_group', $group );
112
113 } // End loop through site's groups.
114 }
115 }
116 ?>