function bbconnect_role_capabilities($status, $role) { // SET GLOBALS global $wp_roles; $bbconnect_user_actions = bbconnect_get_init_user_actions(); if (isset($wp_roles)) { if ('add' == $status) { $wp_roles->add_cap($role, 'list_users'); $wp_roles->add_cap($role, 'add_users'); $wp_roles->add_cap($role, 'create_users'); $wp_roles->add_cap($role, 'edit_users'); foreach ($bbconnect_user_actions as $key => $value) { $action = $value['type']; $wp_roles->add_cap($role, 'manage_' . $action); } } else { $wp_roles->remove_cap($role, 'list_users'); $wp_roles->remove_cap($role, 'add_users'); $wp_roles->remove_cap($role, 'create_users'); $wp_roles->remove_cap($role, 'edit_users'); foreach ($bbconnect_user_actions as $key => $value) { $action = $value['type']; $altaction = array(); $wp_roles->remove_cap($role, 'manage_' . $action); } } } }
/** * Instantiates a WordPress Custom Post Type (CPT) as an Action on INIT. * * @since 1.0.2 * * @param This function accepts no parameters. * * @return null If you don't see your actions, it didn't work. :) */ function bbconnect_init_user_actions() { $bbconnect_user_actions = bbconnect_get_init_user_actions(); foreach ($bbconnect_user_actions as $action) { if (isset($action['exception']) && false != $action['exception']) { continue; } $cptype = $action['type']; $cpsingle = $action['single']; $cpplural = $action['plural']; $labels = array(); $labels['name'] = $cpplural; $labels['singular_name'] = $cpsingle; $labels['add_new'] = 'New ' . $cpsingle; $labels['add_new_item'] = 'Add New ' . $cpsingle; $labels['edit_item'] = 'Edit ' . $cpsingle; $labels['new_item'] = 'New ' . $cpsingle; $labels['view_item'] = 'View ' . $cpplural; $labels['search_items'] = 'Search ' . $cpplural; $labels['not_found'] = 'No ' . $cpplural . ' found'; $labels['not_found_in_trash'] = 'No ' . $cpplural . ' found in Trash'; $labels['parent_item_colon'] = ''; // THESE WILL NEED TO BE OPTIONS // FOR NOW, WE'RE SETTING THEM $args = array(); //$args['label'] = null; $args['labels'] = $labels; $args['description'] = ''; $args['public'] = false; $args['publicly_queryable'] = false; $args['exclude_from_search'] = true; $args['show_ui'] = true; $args['show_in_menu'] = false; $args['menu_position'] = null; $args['menu_icon'] = null; $args['capability_type'] = 'post'; $args['capabilities'] = array('publish_posts' => 'manage_' . $cptype, 'edit_posts' => 'manage_' . $cptype, 'edit_others_posts' => 'manage_' . $cptype, 'delete_posts' => 'manage_' . $cptype, 'delete_others_posts' => 'manage_' . $cptype, 'read_private_posts' => 'manage_' . $cptype, 'edit_post' => 'manage_' . $cptype, 'delete_post' => 'manage_' . $cptype, 'read_post' => 'manage_' . $cptype); $args['hierarchical'] = false; $args['register_meta_box_cb'] = 'bbconnect_user_actions_meta_box_cb'; $args['has_archive'] = false; $args['rewrite'] = false; // array( 'slug' => $cploc . '/'.( $cpplural ) ); $args['query_var'] = true; $args['can_export'] = true; $args['show_in_nav_menus'] = false; $args['supports'] = array('title', 'editor'); // THESE ARE THE WP OPTIONS // 'title','editor','excerpt','trackbacks','comments','thumbnail','author' register_post_type($cptype, $args); } }
function bbconnect_post_types($args = null) { // SET THE DEFAULTS TO BE OVERRIDDEN AS DESIRED $defaults = array('fdata' => false, 'fvalue' => false, 'faction' => false, 'ftype' => false); // PARSE THE INCOMING ARGS $args = wp_parse_args($args, $defaults); // EXTRACT THE VARIABLES extract($args, EXTR_SKIP); if (defined('BBCPRO_VER')) { $pro_msg = ''; } else { $pro_msg = __('This is a Pro feature. Visit www.bbconnect.com for more information! ', 'bbconnect'); } if (!is_array($fvalue)) { $fvalue = array(); } ?> <table class="widefat option-table"> <thead> <tr> <th><?php _e('Type', 'bbconnect'); ?> </th> <th><?php _e('Admins', 'bbconnect'); ?> <a class="help" title="<?php _e('Admins can view and edit this type through the user profile history tab', 'bbconnect'); ?> "> </a></th> <th><?php _e('Users', 'bbconnect'); ?> <a class="help" title="<?php _e('Users can view this type through their profile history tab', 'bbconnect'); ?> "> </a></th> <th><?php _e('Public', 'bbconnect'); ?> <a class="help" title="<?php printf(__('%1$s This type is publicly visible in the user profile history tab', 'bbconnect'), $pro_msg); ?> "> </a></th> <th><?php _e('Reports', 'bbconnect'); ?> <a class="help" title="<?php printf(__('%1$s Admins can search for this type in the Reports section', 'bbconnect'), $pro_msg); ?> "> </a></th> </tr> </thead> <tbody class="option-body"> <?php $args = array(); $post_types = get_post_types($args, 'objects'); $exclusions = array_merge(array('attachment', 'revision', 'nav_menu_item'), bbconnect_exclude_user_actions()); $inits = bbconnect_get_init_user_actions(); foreach ($post_types as $post) { // EXCLUDE PARTICULAR POST TYPES if (in_array($post->name, $exclusions)) { continue; } $post_type = $post->name; // INTERCEPT INIT USER ACTIONS // ALWAYS PRESERVE THE NON-PUBLIC NATURE OF INIT POST TYPES if (isset($inits[$post_type])) { if (!isset($fvalue[$post_type]['options']['admin'])) { $fvalue[$post_type]['options']['admin'] = $inits[$post_type]['options']['admin']; } if (!isset($fvalue[$post_type]['options']['user'])) { $fvalue[$post_type]['options']['user'] = $inits[$post_type]['options']['user']; } $fvalue[$post_type]['options']['public'] = $inits[$post_type]['options']['public']; if (!isset($fvalue[$post_type]['options']['reports'])) { $fvalue[$post_type]['options']['reports'] = $inits[$post_type]['options']['reports']; } $ut = 'umt'; $pt = 'umtf'; } else { $ut = 'umt'; $pt = 'umt'; } $post_arr = array('source' => 'wp', 'type' => $post->name, 'single' => $post->labels->singular_name, 'plural' => $post->labels->name); ?> <tr> <td> <?php echo $post->labels->name; ?> <br /> <?php echo $post->description; ?> </td> <td> <a class="<?php echo $ut; ?> bbconnect <?php if (isset($fvalue[$post_type]) && false != $fvalue[$post_type]['options']['admin']) { echo 'on'; } else { echo 'off'; } ?> " title="bbconnect_<?php echo 'bbconnect_' . $post_type; ?> "><input type="hidden" id="bbconnect_<?php echo 'bbconnect_' . $post_type; ?> " name="_bbc_option[_bbconnect_post_types][<?php echo $post_type; ?> ][options][admin]" value="<?php if (isset($fvalue[$post_type]) && false != $fvalue[$post_type]['options']['admin']) { echo $fvalue[$post_type]['options']['admin']; } else { echo '0'; } ?> " /> </a> <?php foreach ($post_arr as $key => $val) { echo '<input type="hidden" name="_bbc_option[_bbconnect_post_types][' . $post->name . '][' . $key . ']" value="' . $val . '" />'; } ?> </td> <td> <a class="<?php echo $ut; ?> bbconnect <?php if (isset($fvalue[$post_type]) && false != $fvalue[$post_type]['options']['user']) { echo 'on'; } else { echo 'off'; } ?> " title="bbconnect_<?php echo 'bbconnect_' . $post_type . '_user'; ?> "><input type="hidden" id="bbconnect_<?php echo 'bbconnect_' . $post_type . '_user'; ?> " name="_bbc_option[_bbconnect_post_types][<?php echo $post_type; ?> ][options][user]" value="<?php if (isset($fvalue[$post_type]) && false != $fvalue[$post_type]['options']['user']) { echo $fvalue[$post_type]['options']['user']; } else { echo '0'; } ?> " /> </a> </td> <td> <a class="<?php echo $pt; ?> bbconnect <?php if (isset($fvalue[$post_type]) && false != $fvalue[$post_type]['options']['public']) { echo 'on'; } else { echo 'off'; } ?> " title="bbconnect_<?php echo 'bbconnect_' . $post_type . '_public'; ?> "><input type="hidden" id="bbconnect_<?php echo 'bbconnect_' . $post_type . '_public'; ?> " name="_bbc_option[_bbconnect_post_types][<?php echo $post_type; ?> ][options][public]" value="<?php if (isset($fvalue[$post_type]) && false != $fvalue[$post_type]['options']['public']) { echo $fvalue[$post_type]['options']['public']; } else { echo '0'; } ?> " /> </a> </td> <td> <a class="<?php echo $ut; ?> bbconnect <?php if (isset($fvalue[$post_type]) && false != $fvalue[$post_type]['options']['reports']) { echo 'on'; } else { echo 'off'; } ?> " title="bbconnect_<?php echo 'bbconnect_' . $post_type . '_reports'; ?> "><input type="hidden" id="bbconnect_<?php echo 'bbconnect_' . $post_type . '_reports'; ?> " name="_bbc_option[_bbconnect_post_types][<?php echo $post_type; ?> ][options][reports]" value="<?php if (isset($fvalue[$post_type]) && false != $fvalue[$post_type]['options']['reports']) { echo $fvalue[$post_type]['options']['reports']; } else { echo '0'; } ?> " /> </a> </td> </tr> <?php } ?> </tbody> </table> <?php }