Changeset 930
- Timestamp:
- 10/24/2014 07:16:04 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/functions.php
r929 r930 66 66 register_post_types(); 67 67 register_taxonomies(); 68 69 add_action( 'after_switch_theme', __NAMESPACE__ . '\\add_roles' ); 70 add_filter( 'user_has_cap', __NAMESPACE__ . '\\adjust_handbook_editor_caps', 11 ); 68 71 add_action( 'widgets_init', __NAMESPACE__ . '\\widgets_init' ); 69 72 add_action( 'pre_get_posts', __NAMESPACE__ . '\\pre_get_posts' ); … … 85 88 add_filter( 'breadcrumb_trail_items', __NAMESPACE__ . '\\breadcrumb_trail_items', 10, 2 ); 86 89 90 } 91 92 93 /** 94 * Create the handbook_editor role which can only edit handbooks. 95 * 96 * @access public 97 * 98 */ 99 function add_roles() { 100 add_role( 101 'handbook_editor', 102 __( 'Handbook Editor', 'wporg' ), 103 array( 104 'moderate_comments' => true, 105 'upload_files' => true, 106 'unfiltered_html' => true, 107 'read' => true, 108 'edit_handbook_pages' => true, 109 'edit_others_handbook_pages' => true, 110 'edit_published_handbook_pages' => true, 111 'edit_private_handbook_pages' => true, 112 'read_private_handbook_pages' => true, 113 ) 114 ); 115 } 116 117 /** 118 * Adjusts handbook capabilities for roles. 119 * 120 * Undoes some capability assignments by the handbook plugin since only 121 * administrators, editors, and handbook_editors can manipulate handbooks. 122 * 123 * @access public 124 * 125 * @param array $caps Array of user capabilities. 126 * @return array 127 */ 128 function adjust_handbook_editor_caps( $caps ) { 129 if ( ! is_user_member_of_blog() || ! class_exists( 'WPorg_Handbook' ) ) { 130 return $caps; 131 } 132 133 // Get current user's role. 134 $role = wp_get_current_user()->roles[0]; 135 136 // Unset caps set by handbook plugin. 137 // Only administrators, editors, and handbook_editors can manipulate handbooks. 138 if ( ! in_array( $role, array( 'administrator', 'editor', 'handbook_editor' ) ) ) { 139 foreach ( \WPorg_Handbook::caps() as $cap ) { 140 unset( $caps[ $cap ] ); 141 } 142 143 foreach ( \WPorg_Handbook::editor_caps() as $cap ) { 144 unset( $caps[ $cap ] ); 145 } 146 } 147 148 return $caps; 87 149 } 88 150
Note: See TracChangeset
for help on using the changeset viewer.