WordPress.org

Making WordPress.org

Changeset 953


Ignore:
Timestamp:
10/29/2014 07:30:54 PM (5 years ago)
Author:
coffee2code
Message:

Code Reference: extract handbook related code into dedicated include file

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  
    4747
    4848/**
     49 * Handbooks.
     50 */
     51require __DIR__ . '/inc/handbooks.php';
     52
     53/**
    4954 * Redirects.
    5055 */
     
    6065
    6166add_action( 'init', __NAMESPACE__ . '\\init' );
    62 add_filter( 'handbook_post_types', __NAMESPACE__ . '\\filter_handbook_post_types' );
    6367add_action( 'widgets_init', __NAMESPACE__ . '\\widgets_init' );
    6468
     
    6973
    7074    add_action( 'after_switch_theme', __NAMESPACE__ . '\\add_roles' );
    71     add_filter( 'user_has_cap', __NAMESPACE__ . '\\adjust_handbook_editor_caps', 11 );
    7275    add_action( 'pre_get_posts', __NAMESPACE__ . '\\pre_get_posts' );
    7376    add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\\theme_scripts_styles' );
     
    8083    add_filter( 'the_excerpt', __NAMESPACE__ . '\\lowercase_P_dangit_just_once' );
    8184    add_filter( 'the_content', __NAMESPACE__ . '\\make_doclink_clickable', 10, 5 );
    82     add_filter( 'the_content', __NAMESPACE__ . '\\autolink_credits' );
    8385
    8486    // Add the handbook's 'Watch' action link.
     
    8991    add_filter( 'breadcrumb_trail_items',  __NAMESPACE__ . '\\breadcrumb_trail_items', 10, 2 );
    9092
    91 }
    92 
    93 
    94 /**
    95  * Create the handbook_editor role which can only edit handbooks.
    96  *
    97  * @access public
    98  *
    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 only
    122  * administrators, editors, and handbook_editors can manipulate handbooks.
    123  *
    124  * @access public
    125  *
    126  * @param  array $caps Array of user capabilities.
    127  * @return array
    128  */
    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;
    15093}
    15194
     
    179122
    180123    return $items;
    181 }
    182 
    183 /**
    184 * handbook post_type filter function
    185 */
    186 function filter_handbook_post_types( $types ) {
    187     return array( 'theme', 'plugin' );
    188124}
    189125
     
    588524    );
    589525}
    590 
    591 /**
    592  * For specific credit pages, link @usernames references to their profiles on
    593  * profiles.wordpress.org.
    594  *
    595  * Simplistic matching. Does not verify that the @username is a legitimate
    596  * WP.org user.
    597  *
    598  * @param  string $content Post content
    599  * @return string
    600  */
    601 function autolink_credits( $content ) {
    602     // Only apply to the 'credits' (themes handbook) and 'credits-2' (plugin
    603     // handbook) pages
    604     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             $content
    615         );
    616     }
    617 
    618     return $content;
    619 }
Note: See TracChangeset for help on using the changeset viewer.