Changeset 953
- Timestamp:
- 10/29/2014 07:30:54 PM (10 years ago)
- Location:
- sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/functions.php
r951 r953 47 47 48 48 /** 49 * Handbooks. 50 */ 51 require __DIR__ . '/inc/handbooks.php'; 52 53 /** 49 54 * Redirects. 50 55 */ … … 60 65 61 66 add_action( 'init', __NAMESPACE__ . '\\init' ); 62 add_filter( 'handbook_post_types', __NAMESPACE__ . '\\filter_handbook_post_types' );63 67 add_action( 'widgets_init', __NAMESPACE__ . '\\widgets_init' ); 64 68 … … 69 73 70 74 add_action( 'after_switch_theme', __NAMESPACE__ . '\\add_roles' ); 71 add_filter( 'user_has_cap', __NAMESPACE__ . '\\adjust_handbook_editor_caps', 11 );72 75 add_action( 'pre_get_posts', __NAMESPACE__ . '\\pre_get_posts' ); 73 76 add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\\theme_scripts_styles' ); … … 80 83 add_filter( 'the_excerpt', __NAMESPACE__ . '\\lowercase_P_dangit_just_once' ); 81 84 add_filter( 'the_content', __NAMESPACE__ . '\\make_doclink_clickable', 10, 5 ); 82 add_filter( 'the_content', __NAMESPACE__ . '\\autolink_credits' );83 85 84 86 // Add the handbook's 'Watch' action link. … … 89 91 add_filter( 'breadcrumb_trail_items', __NAMESPACE__ . '\\breadcrumb_trail_items', 10, 2 ); 90 92 91 }92 93 94 /**95 * Create the handbook_editor role which can only edit handbooks.96 *97 * @access public98 *99 */100 function add_roles() {101 add_role(102 'handbook_editor',103 __( 'Handbook Editor', 'wporg' ),104 array(105 'moderate_comments' => true,106 'upload_files' => true,107 'unfiltered_html' => true,108 'read' => true,109 'edit_handbook_pages' => true,110 'edit_others_handbook_pages' => true,111 'edit_published_handbook_pages' => true,112 'edit_private_handbook_pages' => true,113 'read_private_handbook_pages' => true,114 )115 );116 }117 118 /**119 * Adjusts handbook capabilities for roles.120 *121 * Undoes some capability assignments by the handbook plugin since only122 * administrators, editors, and handbook_editors can manipulate handbooks.123 *124 * @access public125 *126 * @param array $caps Array of user capabilities.127 * @return array128 */129 function adjust_handbook_editor_caps( $caps ) {130 if ( ! is_user_member_of_blog() || ! class_exists( 'WPorg_Handbook' ) ) {131 return $caps;132 }133 134 // Get current user's role.135 $role = wp_get_current_user()->roles[0];136 137 // Unset caps set by handbook plugin.138 // Only administrators, editors, and handbook_editors can manipulate handbooks.139 if ( ! in_array( $role, array( 'administrator', 'editor', 'handbook_editor' ) ) ) {140 foreach ( \WPorg_Handbook::caps() as $cap ) {141 unset( $caps[ $cap ] );142 }143 144 foreach ( \WPorg_Handbook::editor_caps() as $cap ) {145 unset( $caps[ $cap ] );146 }147 }148 149 return $caps;150 93 } 151 94 … … 179 122 180 123 return $items; 181 }182 183 /**184 * handbook post_type filter function185 */186 function filter_handbook_post_types( $types ) {187 return array( 'theme', 'plugin' );188 124 } 189 125 … … 588 524 ); 589 525 } 590 591 /**592 * For specific credit pages, link @usernames references to their profiles on593 * profiles.wordpress.org.594 *595 * Simplistic matching. Does not verify that the @username is a legitimate596 * WP.org user.597 *598 * @param string $content Post content599 * @return string600 */601 function autolink_credits( $content ) {602 // Only apply to the 'credits' (themes handbook) and 'credits-2' (plugin603 // handbook) pages604 if ( is_single( 'credits' ) || is_single( 'credits-2' ) ) {605 $content = preg_replace_callback(606 '/\B@([\w\-]+)/i',607 function ( $matches ) {608 return sprintf(609 '<a href="https://profiles.wordpress.org/%s">@%s</a>',610 esc_attr( $matches[1] ),611 esc_html( $matches[1] )612 );613 },614 $content615 );616 }617 618 return $content;619 }
Note: See TracChangeset
for help on using the changeset viewer.