<!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>[10751] sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/inc/handbook.php: Handbooks, Handbook: Improve code formatting for `WPorg_Handbook`.</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 { white-space: pre-line; 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/10751">10751</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/10751","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>2021-03-04 22:43:04 +0000 (Thu, 04 Mar 2021)</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'>Handbooks, Handbook: Improve code formatting for `WPorg_Handbook`.
* Explicitly declare methods as public
* Use short array syntax
* Minor code reformatting</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginshandbookinchandbookphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/inc/handbook.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginshandbookinchandbookphp"></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/plugins/handbook/inc/handbook.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/plugins/handbook/inc/handbook.php 2021-03-04 22:18:01 UTC (rev 10750)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/inc/handbook.php 2021-03-04 22:43:04 UTC (rev 10751)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -12,20 +12,24 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> protected $label = '';
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- static function caps() {
- return array(
- 'edit_handbook_pages', 'edit_others_handbook_pages',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public static function caps() {
+ return [
+ 'edit_handbook_pages',
+ 'edit_others_handbook_pages',
</ins><span class="cx" style="display: block; padding: 0 10px"> 'edit_published_handbook_pages',
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ ];
</ins><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">- static function editor_caps() {
- return array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public static function editor_caps() {
+ return [
</ins><span class="cx" style="display: block; padding: 0 10px"> 'publish_handbook_pages',
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'delete_handbook_pages', 'delete_others_handbook_pages',
- 'delete_published_handbook_pages', 'delete_private_handbook_pages',
- 'edit_private_handbook_pages', 'read_private_handbook_pages',
- );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'delete_handbook_pages',
+ 'delete_others_handbook_pages',
+ 'delete_published_handbook_pages',
+ 'delete_private_handbook_pages',
+ 'edit_private_handbook_pages',
+ 'read_private_handbook_pages',
+ ];
</ins><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><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -37,12 +41,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param bool $raw Optional. Return only explicitly set name without attempting to generate default name?
</span><span class="cx" style="display: block; padding: 0 10px"> * @return string
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- static function get_name( $post_type = 'handbook', $raw = false ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public static function get_name( $post_type = 'handbook', $raw = false ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> // Prefer explicitly configured handbook name.
</span><span class="cx" style="display: block; padding: 0 10px"> $name = get_option( $post_type . '_name' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // If handbook name isn't set, try root relative site path.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! $raw && empty( $name ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! $raw && ! $name ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( is_multisite() ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $name = trim( get_blog_details()->path, '/' );
</span><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -50,7 +54,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"> // If no name defined yet, try handbook post type if not standard.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( empty( $name ) && ( 'handbook' != $post_type ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! $name && ( 'handbook' !== $post_type ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $name = ucfirst( substr( $post_type, 0, -9 ) );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -60,37 +64,37 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return trim( $name );
</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">- function __construct( $type ) {
- if ( 'handbook' != $type ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function __construct( $type ) {
+ if ( 'handbook' !== $type ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->post_type = $type . '-handbook';
</span><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><span class="cx" style="display: block; padding: 0 10px"> $this->post_type = $type;
</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">- $this->label = ucwords( str_replace( array( '-', '_' ), ' ', $this->post_type ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->label = ucwords( str_replace( [ '-', '_' ], ' ', $this->post_type ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->label = apply_filters( 'handbook_label', $this->label, $this->post_type );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $this->setting_name = $this->post_type . '_name';
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- add_filter( 'user_has_cap', array( $this, 'grant_handbook_caps' ) );
- add_action( 'widgets_init', array( $this, 'register_post_type' ) );
- add_filter( 'post_type_link', array( $this, 'post_type_link' ), 10, 2 );
- add_action( 'template_redirect', array( $this, 'redirect_handbook_root_page' ) );
- add_filter( 'template_include', array( $this, 'template_include' ) );
- add_filter( 'pre_get_posts', array( $this, 'pre_get_posts' ) );
- add_action( 'widgets_init', array( $this, 'handbook_sidebar' ), 11 ); // After P2
- add_action( 'wporg_email_changes_for_post_types', array( $this, 'wporg_email_changes_for_post_types' ) );
- add_action( 'p2_action_links', array( $this, 'disable_p2_resolved_posts_action_links' ) );
- add_action( 'admin_init', array( $this, 'add_name_setting' ) );
- add_filter( 'body_class', array( $this, 'add_body_class' ) );
- add_filter( 'post_class', array( $this, 'add_post_class' ) );
- add_filter( 'o2_process_the_content', array( $this, 'disable_o2_processing' ) );
- add_filter( 'o2_application_container', array( $this, 'o2_application_container' ) );
- add_filter( 'o2_view_type', array( $this, 'o2_view_type' ) );
- add_filter( 'o2_post_fragment', array( $this, 'o2_post_fragment' ) );
- add_filter( 'comments_open', array( $this, 'comments_open' ), 10, 2 );
- add_filter( 'wp_nav_menu_objects', array( $this, 'highlight_menu_handbook_link' ) );
- add_filter( 'display_post_states', array( $this, 'display_post_states' ), 10, 2 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ add_filter( 'user_has_cap', [ $this, 'grant_handbook_caps' ] );
+ add_action( 'widgets_init', [ $this, 'register_post_type' ] );
+ add_filter( 'post_type_link', [ $this, 'post_type_link' ], 10, 2 );
+ add_action( 'template_redirect', [ $this, 'redirect_handbook_root_page' ] );
+ add_filter( 'template_include', [ $this, 'template_include' ] );
+ add_filter( 'pre_get_posts', [ $this, 'pre_get_posts' ] );
+ add_action( 'widgets_init', [ $this, 'handbook_sidebar' ], 11 ); // After P2
+ add_action( 'wporg_email_changes_for_post_types', [ $this, 'wporg_email_changes_for_post_types' ] );
+ add_action( 'p2_action_links', [ $this, 'disable_p2_resolved_posts_action_links' ] );
+ add_action( 'admin_init', [ $this, 'add_name_setting' ] );
+ add_filter( 'body_class', [ $this, 'add_body_class' ] );
+ add_filter( 'post_class', [ $this, 'add_post_class' ] );
+ add_filter( 'o2_process_the_content', [ $this, 'disable_o2_processing' ] );
+ add_filter( 'o2_application_container', [ $this, 'o2_application_container' ] );
+ add_filter( 'o2_view_type', [ $this, 'o2_view_type' ] );
+ add_filter( 'o2_post_fragment', [ $this, 'o2_post_fragment' ] );
+ add_filter( 'comments_open', [ $this, 'comments_open' ], 10, 2 );
+ add_filter( 'wp_nav_menu_objects', [ $this, 'highlight_menu_handbook_link' ] );
+ add_filter( 'display_post_states', [ $this, 'display_post_states' ], 10, 2 );
</ins><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><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -100,7 +104,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param WP_Post $post The current post object.
</span><span class="cx" style="display: block; padding: 0 10px"> * @return string[]
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- function display_post_states( $post_states, $post ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function display_post_states( $post_states, $post ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( $this->post_is_landing_page( $post ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $post_states[] = __( 'Handbook Front Page', 'wporg' );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -118,7 +122,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param array $classes Array of body classes.
</span><span class="cx" style="display: block; padding: 0 10px"> * @return array
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- function add_body_class( $classes ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function add_body_class( $classes ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( is_singular() && wporg_is_handbook( $this->post_type ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $classes[] = 'single-handbook';
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -141,7 +145,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param array $classes Array of post classes.
</span><span class="cx" style="display: block; padding: 0 10px"> * @return array
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- function add_post_class( $classes ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function add_post_class( $classes ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( $this->post_type === get_post_type() ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $classes[] = 'type-handbook';
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -149,10 +153,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return $classes;
</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">- function add_name_setting() {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function add_name_setting() {
</ins><span class="cx" style="display: block; padding: 0 10px"> register_setting( 'general', $this->setting_name, 'esc_attr' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $label = ( 'handbook' == $this->post_type ) ?
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $label = ( 'handbook' === $this->post_type ) ?
</ins><span class="cx" style="display: block; padding: 0 10px"> __( 'Handbook name', 'wporg' ) :
</span><span class="cx" style="display: block; padding: 0 10px"> sprintf( __( 'Handbook name (%s)', 'wporg' ), substr( $this->post_type, 0, -9 ) );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -159,17 +163,17 @@
</span><span class="cx" style="display: block; padding: 0 10px"> add_settings_field(
</span><span class="cx" style="display: block; padding: 0 10px"> $this->setting_name,
</span><span class="cx" style="display: block; padding: 0 10px"> '<label for="' . esc_attr( $this->setting_name ) . '">' . $label . '</label>',
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- array( $this, 'name_setting_html' ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ [ $this, 'name_setting_html' ],
</ins><span class="cx" style="display: block; padding: 0 10px"> 'general'
</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">- function name_setting_html() {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function name_setting_html() {
</ins><span class="cx" style="display: block; padding: 0 10px"> $value = get_option( $this->setting_name, '' );
</span><span class="cx" style="display: block; padding: 0 10px"> echo '<input type="text" id="' . esc_attr( $this->setting_name ) . '" name="' . esc_attr( $this->setting_name ) . '" value="' . esc_attr( $value ) . '" class="regular-text ltr" />';
</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">- function grant_handbook_caps( $caps ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function grant_handbook_caps( $caps ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( ! is_user_member_of_blog() ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return $caps;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -187,7 +191,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return $caps;
</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">- function register_post_type() {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function register_post_type() {
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( 'handbook' != $this->post_type ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $slug = substr( $this->post_type, 0, -9 );
</span><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -194,13 +198,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $slug = 'handbook';
</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">- $default_config = array(
- 'labels' => array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $default_config = [
+ 'labels' => [
</ins><span class="cx" style="display: block; padding: 0 10px"> 'name' => $this->label,
</span><span class="cx" style="display: block; padding: 0 10px"> 'singular_name' => sprintf( __( '%s Page', 'wporg' ), $this->label ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'menu_name' => $this->label,
</span><span class="cx" style="display: block; padding: 0 10px"> 'all_items' => sprintf( __( '%s Pages', 'wporg' ), $this->label ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ ],
</ins><span class="cx" style="display: block; padding: 0 10px"> 'public' => true,
</span><span class="cx" style="display: block; padding: 0 10px"> 'show_ui' => true,
</span><span class="cx" style="display: block; padding: 0 10px"> 'show_in_rest' => true,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -210,17 +214,18 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'hierarchical' => true,
</span><span class="cx" style="display: block; padding: 0 10px"> 'menu_icon' => 'dashicons-book',
</span><span class="cx" style="display: block; padding: 0 10px"> 'menu_position' => 11,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'rewrite' => array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'rewrite' => [
</ins><span class="cx" style="display: block; padding: 0 10px"> 'feeds' => false,
</span><span class="cx" style="display: block; padding: 0 10px"> 'slug' => $slug,
</span><span class="cx" style="display: block; padding: 0 10px"> 'with_front' => false,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ ],
</ins><span class="cx" style="display: block; padding: 0 10px"> 'delete_with_user' => false,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'page-attributes', 'custom-fields', 'revisions', 'wpcom-markdown' ),
- );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'supports' => [ 'title', 'editor', 'author', 'thumbnail', 'page-attributes', 'custom-fields', 'revisions' , 'wpcom-markdown' ],
+ ];
</ins><span class="cx" style="display: block; padding: 0 10px"> // Allow customization of the default post type configuration via filter.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $config = apply_filters( 'handbook_post_type_defaults', $default_config, $slug );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $config = (array) apply_filters( 'handbook_post_type_defaults', $default_config, $slug );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Override the presumed label with a potentially customized value.
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->label = $config['labels']['name'];
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> register_post_type( $this->post_type, $config );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -234,7 +239,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @return bool True if the given information would make such a post the
</span><span class="cx" style="display: block; padding: 0 10px"> * handbook's landing page.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- protected function post_is_landing_page( $post = null ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function post_is_landing_page( $post = null ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $is_landing_page = false;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $post_type = get_post_type( $post );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -268,7 +273,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $post_link The post's permalink.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param WP_Post $post The post in question.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- function post_type_link( $post_link, $post ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function post_type_link( $post_link, $post ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $post_type = get_post_type( $post );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Only change links for this handbook's post type.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -283,7 +288,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * For a handbook page acting as the root page for the handbook, redirect to the
</span><span class="cx" style="display: block; padding: 0 10px"> * post type archive link for the handbook.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- function redirect_handbook_root_page() {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function redirect_handbook_root_page() {
</ins><span class="cx" style="display: block; padding: 0 10px"> global $wp_query;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( is_singular( $this->post_type )
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -308,7 +313,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $template The path of the template to include.
</span><span class="cx" style="display: block; padding: 0 10px"> * @return string
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- function template_include( $template ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function template_include( $template ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> global $wp_query;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Don't override Embeds
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -316,11 +321,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return $template;
</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_templates = array();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $handbook_templates = [];
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // For singular handbook pages not of the 'handbook' post type.
</span><span class="cx" style="display: block; padding: 0 10px"> if ( is_singular( $this->post_type ) && 'handbook' !== $this->post_type ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $handbook_templates = array( "single-{$this->post_type}.php", 'single-handbook.php' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $handbook_templates = [ "single-{$this->post_type}.php", 'single-handbook.php' ];
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> // For handbook landing page.
</span><span class="cx" style="display: block; padding: 0 10px"> elseif ( $wp_query->is_handbook_root && get_query_var( 'handbook' ) === $this->post_type ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -339,7 +344,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return $template;
</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">- function pre_get_posts( $query ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function pre_get_posts( $query ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> // Bail early if query is not for this handbook's post type.
</span><span class="cx" style="display: block; padding: 0 10px"> if ( get_query_var( 'post_type' ) !== $this->post_type ) {
</span><span class="cx" style="display: block; padding: 0 10px"> // Request is obviously not for a handbook root page. (Though if the request is
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -378,16 +383,16 @@
</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">- function handbook_sidebar() {
- $sidebar_args = array(
- 'id' => $this->post_type,
- 'name' => sprintf( __( '%s Sidebar', 'wporg' ), $this->label ),
- 'description' => sprintf( __( 'Used on %s pages', 'wporg' ), $this->label ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function handbook_sidebar() {
+ $sidebar_args = [
+ 'id' => $this->post_type,
+ 'name' => sprintf( __( '%s Sidebar', 'wporg' ), $this->label ),
+ 'description' => sprintf( __( 'Used on %s pages', 'wporg' ), $this->label ),
</ins><span class="cx" style="display: block; padding: 0 10px"> 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
</span><span class="cx" style="display: block; padding: 0 10px"> 'after_widget' => '</aside>',
</span><span class="cx" style="display: block; padding: 0 10px"> 'before_title' => '<h2 class="widget-title">',
</span><span class="cx" style="display: block; padding: 0 10px"> 'after_title' => '</h2>',
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ ];
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $sidebar_args = apply_filters( 'wporg_handbook_sidebar_args', $sidebar_args, $this );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -397,7 +402,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> register_widget( 'WPorg_Handbook_Pages_Widget' );
</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">- function wporg_email_changes_for_post_types( $post_types ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function wporg_email_changes_for_post_types( $post_types ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( ! in_array( $this->post_type, $post_types ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $post_types[] = $this->post_type;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -409,9 +414,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * Disable the P2 Resolved Posts plugin's action links (e.g. "Flag Unresolved"),
</span><span class="cx" style="display: block; padding: 0 10px"> * if that plugin is active.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- function disable_p2_resolved_posts_action_links() {
- if ( ( $this->post_type == get_post_type() ) && class_exists( 'P2_Resolved_Posts' ) && isset( $GLOBALS['p2_resolved_posts'] ) && is_object( $GLOBALS['p2_resolved_posts'] ) ) {
- remove_filter( 'p2_action_links', array( P2_Resolved_Posts::instance(), 'p2_action_links' ), 100 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function disable_p2_resolved_posts_action_links() {
+ if ( ( $this->post_type === get_post_type() ) && class_exists( 'P2_Resolved_Posts' ) && isset( $GLOBALS['p2_resolved_posts'] ) && is_object( $GLOBALS['p2_resolved_posts'] ) ) {
+ remove_filter( 'p2_action_links', [ P2_Resolved_Posts::instance(), 'p2_action_links' ], 100 );
</ins><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><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -421,7 +426,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param bool $process_with_o2 Is o2 about to process the post content?
</span><span class="cx" style="display: block; padding: 0 10px"> * @return bool
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- function disable_o2_processing( $process_with_o2 ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function disable_o2_processing( $process_with_o2 ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return ( is_singular() && $this->post_type === get_post_type() ) ? false : $process_with_o2;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -431,7 +436,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $container The container element ID.
</span><span class="cx" style="display: block; padding: 0 10px"> * @return string
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- function o2_application_container( $container ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function o2_application_container( $container ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return ( is_singular() && $this->post_type === get_post_type() ) ? '#primary' : $container;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -442,7 +447,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $view_type The o2 view type.
</span><span class="cx" style="display: block; padding: 0 10px"> * @return string
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- function o2_view_type( $view_type ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function o2_view_type( $view_type ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return ( is_singular() && $this->post_type === get_post_type() ) ? 'single' : $view_type;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -452,7 +457,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param array $post_fragment The o2 post fragment
</span><span class="cx" style="display: block; padding: 0 10px"> * @return array
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- function o2_post_fragment( $post_fragment ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function o2_post_fragment( $post_fragment ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $post = get_post( $post_fragment['id'] );
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! $post ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return $post_fragment;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -472,7 +477,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param WP_Post|int $post_id The current post.
</span><span class="cx" style="display: block; padding: 0 10px"> * @return bool
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- function comments_open( $open, $post_id ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function comments_open( $open, $post_id ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $post = get_post( $post_id );
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! $post ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return $open;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -498,26 +503,26 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param array $menu_items Array of sorted menu items.
</span><span class="cx" style="display: block; padding: 0 10px"> * @return array
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- function highlight_menu_handbook_link( $menu_items ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function highlight_menu_handbook_link( $menu_items ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> // Must be on a handbook page that isn't the handbook landing page (which will already be handled).
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! is_page( array( 'handbook', 'handbooks' ) ) && ( ! wporg_is_handbook() || wporg_is_handbook_landing_page() ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! is_page( [ 'handbook', 'handbooks' ] ) && ( ! wporg_is_handbook() || wporg_is_handbook_landing_page() ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return $menu_items;
</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"> // Menu must not have an item that is already noted as being current.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $current_menu_item = wp_filter_object_list( $menu_items, array( 'current' => true ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $current_menu_item = wp_filter_object_list( $menu_items, [ 'current' => true ] );
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( $current_menu_item ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return $menu_items;
</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"> // Menu must have an item that links to handbook home page.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $root_handbook_menu_item = wp_filter_object_list( $menu_items, array( 'url' => wporg_get_current_handbook_home_url() ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $root_handbook_menu_item = wp_filter_object_list( $menu_items, [ 'url' => wporg_get_current_handbook_home_url() ] );
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( ! $root_handbook_menu_item ) {
</span><span class="cx" style="display: block; padding: 0 10px"> // Or it must have an item that links to a 'handbook' or 'handbooks' page.
</span><span class="cx" style="display: block; padding: 0 10px"> $page_slug = is_page( 'handbooks' ) ? 'handbooks' : 'handbook';
</span><span class="cx" style="display: block; padding: 0 10px"> $page = get_page_by_path( $page_slug );
</span><span class="cx" style="display: block; padding: 0 10px"> if ( $page ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $root_handbook_menu_item = wp_filter_object_list( $menu_items, array( 'object_id' => $page->ID ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $root_handbook_menu_item = wp_filter_object_list( $menu_items, [ 'object_id' => $page->ID ] );
</ins><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"> if ( ! $root_handbook_menu_item ) {
</span></span></pre>
</div>
</div>
</body>
</html>