<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[953] sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer: Code Reference: extract handbook related code into dedicated include file</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="http://meta.trac.wordpress.org/changeset/953">953</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"http://meta.trac.wordpress.org/changeset/953","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>coffee2code</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2014-10-29 19:30:54 +0000 (Wed, 29 Oct 2014)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Code Reference: extract handbook related code into dedicated include file</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgdeveloperfunctionsphp">sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/functions.php</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgdeveloperinchandbooksphp">sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/handbooks.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgdeveloperfunctionsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/functions.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/functions.php 2014-10-29 19:05:40 UTC (rev 952)
+++ sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/functions.php 2014-10-29 19:30:54 UTC (rev 953)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -46,6 +46,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> require __DIR__ . '/inc/user-content-voting.php';
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Handbooks.
+ */
+require __DIR__ . '/inc/handbooks.php';
+
+/**
</ins><span class="cx" style="display: block; padding: 0 10px"> * Redirects.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> require __DIR__ . '/inc/redirects.php';
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -59,7 +64,6 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> add_action( 'init', __NAMESPACE__ . '\\init' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-add_filter( 'handbook_post_types', __NAMESPACE__ . '\\filter_handbook_post_types' );
</del><span class="cx" style="display: block; padding: 0 10px"> add_action( 'widgets_init', __NAMESPACE__ . '\\widgets_init' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> function init() {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -68,7 +72,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> register_taxonomies();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> add_action( 'after_switch_theme', __NAMESPACE__ . '\\add_roles' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- add_filter( 'user_has_cap', __NAMESPACE__ . '\\adjust_handbook_editor_caps', 11 );
</del><span class="cx" style="display: block; padding: 0 10px"> add_action( 'pre_get_posts', __NAMESPACE__ . '\\pre_get_posts' );
</span><span class="cx" style="display: block; padding: 0 10px"> add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\\theme_scripts_styles' );
</span><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'post_type_link', __NAMESPACE__ . '\\method_permalink', 10, 2 );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -79,7 +82,6 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'the_excerpt', __NAMESPACE__ . '\\lowercase_P_dangit_just_once' );
</span><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'the_content', __NAMESPACE__ . '\\make_doclink_clickable', 10, 5 );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- add_filter( 'the_content', __NAMESPACE__ . '\\autolink_credits' );
</del><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Add the handbook's 'Watch' action link.
</span><span class="cx" style="display: block; padding: 0 10px"> if ( class_exists( 'WPorg_Handbook_Watchlist' ) && method_exists( 'WPorg_Handbook_Watchlist', 'display_action_link' ) ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -90,66 +92,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
</del><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Create the handbook_editor role which can only edit handbooks.
- *
- * @access public
- *
- */
-function add_roles() {
- add_role(
- 'handbook_editor',
- __( 'Handbook Editor', 'wporg' ),
- array(
- 'moderate_comments' => true,
- 'upload_files' => true,
- 'unfiltered_html' => true,
- 'read' => true,
- 'edit_handbook_pages' => true,
- 'edit_others_handbook_pages' => true,
- 'edit_published_handbook_pages' => true,
- 'edit_private_handbook_pages' => true,
- 'read_private_handbook_pages' => true,
- )
- );
-}
-
-/**
- * Adjusts handbook capabilities for roles.
- *
- * Undoes some capability assignments by the handbook plugin since only
- * administrators, editors, and handbook_editors can manipulate handbooks.
- *
- * @access public
- *
- * @param array $caps Array of user capabilities.
- * @return array
- */
-function adjust_handbook_editor_caps( $caps ) {
- if ( ! is_user_member_of_blog() || ! class_exists( 'WPorg_Handbook' ) ) {
- return $caps;
- }
-
- // Get current user's role.
- $role = wp_get_current_user()->roles[0];
-
- // Unset caps set by handbook plugin.
- // Only administrators, editors, and handbook_editors can manipulate handbooks.
- if ( ! in_array( $role, array( 'administrator', 'editor', 'handbook_editor' ) ) ) {
- foreach ( \WPorg_Handbook::caps() as $cap ) {
- unset( $caps[ $cap ] );
- }
-
- foreach ( \WPorg_Handbook::editor_caps() as $cap ) {
- unset( $caps[ $cap ] );
- }
- }
-
- return $caps;
-}
-
-/**
</del><span class="cx" style="display: block; padding: 0 10px"> * Fix breadcrumb for hooks.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * A hook has a parent (the function containing it), which causes the Breadcrumb
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -181,13 +124,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-* handbook post_type filter function
-*/
-function filter_handbook_post_types( $types ) {
- return array( 'theme', 'plugin' );
-}
-
-/**
</del><span class="cx" style="display: block; padding: 0 10px"> * widgets_init function.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @access public
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -587,33 +523,3 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $content
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
-/**
- * For specific credit pages, link @usernames references to their profiles on
- * profiles.wordpress.org.
- *
- * Simplistic matching. Does not verify that the @username is a legitimate
- * WP.org user.
- *
- * @param string $content Post content
- * @return string
- */
-function autolink_credits( $content ) {
- // Only apply to the 'credits' (themes handbook) and 'credits-2' (plugin
- // handbook) pages
- if ( is_single( 'credits' ) || is_single( 'credits-2' ) ) {
- $content = preg_replace_callback(
- '/\B@([\w\-]+)/i',
- function ( $matches ) {
- return sprintf(
- '<a href="https://profiles.wordpress.org/%s">@%s</a>',
- esc_attr( $matches[1] ),
- esc_html( $matches[1] )
- );
- },
- $content
- );
- }
-
- return $content;
-}
</del></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgdeveloperinchandbooksphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/handbooks.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/handbooks.php (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/handbooks.php 2014-10-29 19:30:54 UTC (rev 953)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,149 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+/**
+ * Code Reference configuration and customization of the Handbook plugin.
+ *
+ * @package wporg-developer
+ */
+
+/**
+ * Class to handle handbook configuration and behavior.
+ */
+class Devhub_Handbooks {
+
+ /**
+ * Handbook names.
+ *
+ * @var array
+ * @access public
+ */
+ public static $post_types = array( 'plugin', 'theme' );
+
+ /**
+ * Initializer
+ *
+ * @access public
+ */
+ public static function init() {
+ add_filter( 'handbook_post_types', array( __CLASS__, 'filter_handbook_post_types' ) );
+ add_action( 'init', array( __CLASS__, 'do_init' ) );
+ }
+
+ /**
+ * Initialization
+ *
+ * @access public
+ */
+ public static function do_init() {
+ add_filter( 'user_has_cap', array( __CLASS__, 'adjust_handbook_editor_caps' ), 11 );
+
+ add_filter( 'the_content', array( __CLASS__, 'autolink_credits' ) );
+
+ // Add the handbook's 'Watch' action link.
+ if ( class_exists( 'WPorg_Handbook_Watchlist' ) && method_exists( 'WPorg_Handbook_Watchlist', 'display_action_link' ) ) {
+ add_action( 'wporg_action_links', array( 'WPorg_Handbook_Watchlist', 'display_action_link' ) );
+ }
+ }
+
+ /**
+ * Filter handbook post types to create handbooks for: plugins, themes.
+ *
+ * @access public
+ *
+ * @param array $types The default handbook types.
+ * @return array
+ */
+ public static function filter_handbook_post_types( $types ) {
+ return self::$post_types;
+ }
+
+ /**
+ * Create the handbook_editor role which can only edit handbooks.
+ *
+ * @access public
+ *
+ */
+ public static function add_roles() {
+ add_role(
+ 'handbook_editor',
+ __( 'Handbook Editor', 'wporg' ),
+ array(
+ 'moderate_comments' => true,
+ 'upload_files' => true,
+ 'unfiltered_html' => true,
+ 'read' => true,
+ 'edit_handbook_pages' => true,
+ 'edit_others_handbook_pages' => true,
+ 'edit_published_handbook_pages' => true,
+ 'edit_private_handbook_pages' => true,
+ 'read_private_handbook_pages' => true,
+ )
+ );
+ }
+
+ /**
+ * Adjusts handbook capabilities for roles.
+ *
+ * Undoes some capability assignments by the handbook plugin since only
+ * administrators, editors, and handbook_editors can manipulate handbooks.
+ *
+ * @access public
+ *
+ * @param array $caps Array of user capabilities.
+ * @return array
+ */
+ public static function adjust_handbook_editor_caps( $caps ) {
+ if ( ! is_user_member_of_blog() || ! class_exists( 'WPorg_Handbook' ) ) {
+ return $caps;
+ }
+
+ // Get current user's role.
+ $role = wp_get_current_user()->roles[0];
+
+ // Unset caps set by handbook plugin.
+ // Only administrators, editors, and handbook_editors can manipulate handbooks.
+ if ( ! in_array( $role, array( 'administrator', 'editor', 'handbook_editor' ) ) ) {
+ foreach ( \WPorg_Handbook::caps() as $cap ) {
+ unset( $caps[ $cap ] );
+ }
+
+ foreach ( \WPorg_Handbook::editor_caps() as $cap ) {
+ unset( $caps[ $cap ] );
+ }
+ }
+
+ return $caps;
+ }
+
+ /**
+ * For specific credit pages, link @usernames references to their profiles on
+ * profiles.wordpress.org.
+ *
+ * Simplistic matching. Does not verify that the @username is a legitimate
+ * WP.org user.
+ *
+ * @param string $content Post content
+ * @return string
+ */
+ public static function autolink_credits( $content ) {
+ // Only apply to the 'credits' (themes handbook) and 'credits-2' (plugin
+ // handbook) pages
+ if ( is_single( 'credits' ) || is_single( 'credits-2' ) ) {
+ $content = preg_replace_callback(
+ '/\B@([\w\-]+)/i',
+ function ( $matches ) {
+ return sprintf(
+ '<a href="https://profiles.wordpress.org/%s">@%s</a>',
+ esc_attr( $matches[1] ),
+ esc_html( $matches[1] )
+ );
+ },
+ $content
+ );
+ }
+
+ return $content;
+ }
+
+} // Devhub_Handbooks
+
+Devhub_Handbooks::init();
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/handbooks.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span></div>
</body>
</html>