<!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>[1057] sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer: developer.wordpress.org: Reintroduce Explanations, with editorial flow.</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/1057">1057</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/1057","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-12-19 21:57:26 +0000 (Fri, 19 Dec 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'>developer.wordpress.org: Reintroduce Explanations, with editorial flow.
* Add explanations as an associated post type
* Add metabox to create, unpublish, and link to edit explanation for a parsed post type
* Add template tags: `get_explanation()` and `get_explanation_field()`
* Re-enable display of Explanations on the frontend
props DrewAPicture.
fixes <a href="http://meta.trac.wordpress.org/ticket/786">#786</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgdevelopercontentreferencephp">sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/content-reference.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgdevelopercontentwpparserhookphp">sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/content-wp-parser-hook.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgdeveloperfunctionsphp">sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/functions.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgdeveloperincparsedcontentphp">sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/parsed-content.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgdeveloperinctemplatetagsphp">sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/template-tags.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgdeveloperscssadminscss">sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/scss/admin.scss</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgdeveloperstylesheetsadmincss">sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/stylesheets/admin.css</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgdeveloperincexplanationsphp">sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/explanations.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgdeveloperjsexplanationsjs">sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/js/explanations.js</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgdevelopercontentreferencephp"></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/content-reference.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/content-reference.php 2014-12-19 18:31:36 UTC (rev 1056)
+++ sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/content-reference.php 2014-12-19 21:57:26 UTC (rev 1057)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -45,13 +45,13 @@
</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"> <?php
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $explanation = '';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $explanation = get_explanation_field( 'post_content', get_the_ID() );
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( $explanation ) :
</span><span class="cx" style="display: block; padding: 0 10px"> ?>
</span><span class="cx" style="display: block; padding: 0 10px"> <hr/>
</span><span class="cx" style="display: block; padding: 0 10px"> <section class="explanation">
</span><span class="cx" style="display: block; padding: 0 10px"> <h2><?php _e( 'Explanation', 'wporg' ); ?></h2>
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- <?php the_content(); ?>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ <?php echo apply_filters( 'the_content', apply_filters( 'get_the_content', $explanation ) ); ?>
</ins><span class="cx" style="display: block; padding: 0 10px"> </section>
</span><span class="cx" style="display: block; padding: 0 10px"> <?php endif; ?>
</span><span class="cx" style="display: block; padding: 0 10px">
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgdevelopercontentwpparserhookphp"></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/content-wp-parser-hook.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/content-wp-parser-hook.php 2014-12-19 18:31:36 UTC (rev 1056)
+++ sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/content-wp-parser-hook.php 2014-12-19 21:57:26 UTC (rev 1057)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -43,13 +43,13 @@
</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"> <?php
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $explanation = '';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $explanation = get_explanation_field( 'post_content', get_the_ID() );
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( $explanation ) :
</span><span class="cx" style="display: block; padding: 0 10px"> ?>
</span><span class="cx" style="display: block; padding: 0 10px"> <hr/>
</span><span class="cx" style="display: block; padding: 0 10px"> <section class="explanation">
</span><span class="cx" style="display: block; padding: 0 10px"> <h2><?php _e( 'Explanation', 'wporg' ); ?></h2>
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- <?php the_content(); ?>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ <?php echo apply_filters( 'the_content', apply_filters( 'get_the_content', $explanation ) ); ?>
</ins><span class="cx" style="display: block; padding: 0 10px"> </section>
</span><span class="cx" style="display: block; padding: 0 10px"> <?php endif; ?>
</span><span class="cx" style="display: block; padding: 0 10px">
</span></span></pre></div>
<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-12-19 18:31:36 UTC (rev 1056)
+++ sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/functions.php 2014-12-19 21:57:26 UTC (rev 1057)
</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">+ * Explanations for functions. hooks, classes, and methods.
+ */
+require( __DIR__ . '/inc/explanations.php' );
+
+/**
</ins><span class="cx" style="display: block; padding: 0 10px"> * Handbooks.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> require __DIR__ . '/inc/handbooks.php';
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -79,9 +84,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> add_action( 'after_switch_theme', __NAMESPACE__ . '\\add_roles' );
</span><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><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'post_type_link', __NAMESPACE__ . '\\method_permalink', 10, 2 );
</span><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'term_link', __NAMESPACE__ . '\\taxonomy_permalink', 10, 3 );
</span><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'the_posts', __NAMESPACE__ . '\\rerun_empty_exact_search', 10, 2 );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> add_theme_support( 'automatic-feed-links' );
</span><span class="cx" style="display: block; padding: 0 10px"> add_theme_support( 'post-thumbnails' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgdeveloperincexplanationsphp"></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/explanations.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/explanations.php (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/explanations.php 2014-12-19 21:57:26 UTC (rev 1057)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,321 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+/**
+ * Explanations functionality
+ *
+ * @package wporg-developer
+ */
+
+/**
+ * Class to handle creating, editing, managing, and retrieving explanations
+ * for various Code Reference post types.
+ */
+class WPORG_Explanations {
+
+ /**
+ * List of Code Reference post types.
+ *
+ * @access public
+ * @var array
+ */
+ public $post_types = array();
+
+ /**
+ * Explanations post type slug.
+ *
+ * @access public
+ * @var string
+ */
+ public $exp_post_type = 'wporg_explanations';
+
+ /**
+ * Constructor.
+ *
+ * @access public
+ */
+ public function __construct() {
+ $this->post_types = array( 'wp-parser-function', 'wp-parser-class', 'wp-parser-hook', 'wp-parser-method' );
+
+ // Setup.
+ add_action( 'init', array( $this, 'register_post_type' ), 0 );
+ add_action( 'init', array( $this, 'remove_editor_support' ), 100 );
+ add_action( 'edit_form_after_title', array( $this, 'post_to_expl_controls' ) );
+ add_action( 'edit_form_top', array( $this, 'expl_to_post_controls' ) );
+
+ // Script and styles.
+ add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
+
+ // AJAX.
+ add_action( 'wp_ajax_new_explanation', array( $this, 'new_explanation' ) );
+ add_action( 'wp_ajax_un_publish', array( $this, 'un_publish_explanation' ) );
+ }
+
+ /**
+ * Register the Explanations post type.
+ *
+ * @access public
+ */
+ public function register_post_type() {
+ register_post_type( $this->exp_post_type, array(
+ 'labels' => array(
+ 'name' => __( 'Explanations', 'wporg' ),
+ 'singular_name' => __( 'Explanation', 'wporg' ),
+ 'all_items' => __( 'Explanations', 'wporg' ),
+ 'edit_item' => __( 'Edit Explanation', 'wporg' ),
+ 'view_item' => __( 'View Explanation', 'wporg' ),
+ 'search_items' => __( 'Search Explanations', 'wporg' ),
+ 'not_found' => __( 'No Explanations found', 'wporg' ),
+ 'not_found_in_trash' => __( 'No Explanations found in trash', 'wporg' ),
+ ),
+ 'public' => false,
+ 'hierarchical' => false,
+ 'show_ui' => false,
+ 'show_in_nav_menus' => false,
+ 'supports' => array( 'editor', 'revisions' ),
+ 'rewrite' => false,
+ 'query_var' => false,
+ ) );
+ }
+
+ /**
+ * Remove 'editor' support for the function, hook, class, and method post types.
+ *
+ * @access public
+ */
+ public function remove_editor_support() {
+ foreach ( $this->post_types as $type ) {
+ remove_post_type_support( $type, 'editor' );
+ }
+ }
+
+ /**
+ * Output the Post-to-Explanation controls in the post editor for functions,
+ * hooks, classes, and methods.
+ *
+ * @access public
+ *
+ * @param WP_Post $post Current post object.
+ */
+ public function post_to_expl_controls( $post ) {
+ if ( ! in_array( $post->post_type, $this->post_types ) ) {
+ return;
+ }
+
+ $explanation = DevHub\get_explanation( $post );
+ $date_format = get_option( 'date_format' ) . ', ' . get_option( 'time_format' );
+ ?>
+ <div class="postbox-container" style="margin-top:20px;">
+ <div class="postbox">
+ <h3 class="hndle"><?php _e( 'Explanation', 'wporg' ); ?></h3>
+ <div class="inside">
+ <table class="form-table explanation-meta">
+ <tbody>
+ <tr valign="top">
+ <th scope="row">
+ <label for="explanation-status"><?php _e( 'Status:', 'wporg' ); ?></label>
+ </th>
+ <td class="explanation-status" name="explanation-status">
+ <div class="status-links">
+ <?php $this->status_controls( $post ); ?>
+ </div><!-- .status-links -->
+ </td><!-- .explanation-status -->
+ </tr>
+ <?php if ( $explanation ) : ?>
+ <tr valign="top">
+ <th scope="row">
+ <label for="expl-modified"><?php _e( 'Last Modified:', 'wporg' ); ?></label>
+ </th>
+ <td name="expl-modified">
+ <p><?php echo get_post_modified_time( $date_format, false, $post->ID ); ?></p>
+ </td>
+ </tr>
+ <?php endif; // $has_explanation ?>
+ </tbody>
+ </table>
+ </div>
+ </div>
+ </div>
+ <?php
+ }
+
+ /**
+ * Output the Explanation-to-Post controls in the Explanation post editor.
+ *
+ * @access public
+ *
+ * @param WP_Post $post Current post object.
+ */
+ public function expl_to_post_controls( $post ) {
+ if ( $this->exp_post_type !== $post->post_type ) {
+ return;
+ }
+
+ $parent = is_a( $post, 'WP_Post' ) ? $post->post_parent : get_post( $post )->post_parent;
+
+ if ( 0 !== $parent ) :
+ $prefix = '<strong>' . __( 'Associated with: ', 'wporg' ) . '</strong>';
+ ?>
+ <div class="postbox-container" style="margin-top:20px;width:100%;">
+ <div class="postbox">
+ <div class="inside" style="padding-bottom:0;">
+ <?php edit_post_link( get_the_title( $parent ), $prefix, '', $parent ); ?>
+ </div>
+ </div>
+ </div>
+ <?php
+ endif;
+ }
+
+ /**
+ * Output the Explanation status controls.
+ *
+ * @access public
+ *
+ * @param int|WP_Post Post ID or WP_Post object.
+ */
+ public function status_controls( $post ) {
+ $explanation = DevHub\get_explanation( $post );
+
+ if ( $explanation ) :
+ echo $this->get_status_label( $explanation->ID );
+ ?>
+ <span id="expl-row-actions" class="expl-row-actions">
+ <a id="edit-expl" href="<?php echo get_edit_post_link( $explanation->ID ); ?>">
+ <?php _e( 'Edit Content', 'wporg' ); ?>
+ </a>
+ <?php if ( 'publish' == get_post_status( $explanation ) ) : ?>
+ <a href="#unpublish" id="unpublish-expl" data-nonce="<?php echo wp_create_nonce( 'unpublish-expl' ); ?>" data-id="<?php the_ID(); ?>">
+ <?php _e( 'Un-publish', 'wporg' ); ?>
+ </a>
+ <?php endif; ?>
+ </span><!-- .expl-row-actions -->
+ <?php else : ?>
+ <p class="status" id="status-label"><?php _e( 'None', 'wporg' ); ?></p>
+ <span id="expl-row-actions" class="expl-row-actions">
+ <a id="create-expl" href="" data-nonce="<?php echo wp_create_nonce( 'create-expl' ); ?>" data-id="<?php the_ID(); ?>">
+ <?php _e( 'Add Explanation', 'wporg' ); ?>
+ </a><!-- #create-explanation -->
+ </span><!-- expl-row-actions -->
+ <?php
+ endif;
+ }
+
+ /**
+ * Retrieve status label for the given post.
+ *
+ * @access public
+ *
+ * @param int|WP_Post $post Post ID or WP_Post object.
+ * @return string
+ */
+ public function get_status_label( $post ) {
+ if ( ! $post = get_post( $post ) ) {
+ return '';
+ }
+
+ switch( $status = $post->post_status ) {
+ case 'draft' :
+ $label = __( 'Drafted', 'wporg' );
+ break;
+ case 'pending' :
+ $label = __( 'Pending Review', 'wporg' );
+ break;
+ case 'publish' :
+ $label = __( 'Published', 'wporg' );
+ break;
+ default :
+ $status = '';
+ $label = __( 'None', 'wporg' );
+ break;
+ }
+
+ return '<p class="status ' . $status . '" id="status-label">' . $label . '</p>';
+ }
+
+ /**
+ * Enqueue JS and CSS for all parsed post types and explanation pages.
+ *
+ * @access public
+ */
+ public function admin_enqueue_scripts() {
+
+ if ( in_array( get_current_screen()->id, array(
+ 'wp-parser-function', 'wp-parser-class', 'wp-parser-hook', 'wp-parser-method',
+ 'wporg_explanations', 'edit-wporg_explanations',
+ ) ) ) {
+ wp_enqueue_style( 'wporg-admin', get_template_directory_uri() . '/stylesheets/admin.css', array(), '20141218' );
+ wp_enqueue_script( 'wporg-explanations', get_template_directory_uri() . '/js/explanations.js', array( 'jquery', 'wp-util' ), '20141218', true );
+
+ wp_localize_script( 'wporg-explanations', 'wporg', array(
+ 'editContentLabel' => __( 'Edit Content', 'wporg' ),
+ 'statusLabel' => array(
+ 'draft' => __( 'Drafted', 'wporg' ),
+ 'pending' => __( 'Pending Review', 'wporg' ),
+ 'publish' => __( 'Published', 'wporg' ),
+ ),
+ ) );
+ }
+ }
+
+ /**
+ * AJAX handler for creating and associating a new explanation.
+ *
+ * @access public
+ */
+ public function new_explanation() {
+ check_ajax_referer( 'create-expl', 'nonce' );
+
+ $post_id = empty( $_REQUEST['post_id'] ) ? 0 : absint( $_REQUEST['post_id'] );
+
+ if ( DevHub\get_explanation( $post_id ) ) {
+ wp_send_json_error( new WP_Error( 'post_exists', __( 'Explanation already exists.', 'wporg' ) ) );
+ } else {
+ $title = get_post_field( 'post_title', $post_id );
+
+ $explanation = wp_insert_post( array(
+ 'post_type' => 'wporg_explanations',
+ 'post_title' => "Explanation: $title",
+ 'ping_status' => false,
+ 'post_parent' => $post_id,
+ ) );
+
+ if ( ! is_wp_error( $explanation ) && 0 !== $explanation ) {
+ wp_send_json_success( array(
+ 'post_id' => $explanation
+ ) );
+ } else {
+ wp_send_json_error(
+ new WP_Error( 'post_error', __( 'Explanation could not be created.', 'wporg' ) )
+ );
+ }
+
+ }
+ }
+
+ /**
+ * AJAX handler for un-publishing an explanation.
+ *
+ * @access public
+ */
+ public function un_publish_explanation() {
+ check_ajax_referer( 'unpublish-expl', 'nonce' );
+
+ $post_id = empty( $_REQUEST['post_id'] ) ? 0 : absint( $_REQUEST['post_id'] );
+
+ if ( $explanation = \DevHub\get_explanation( $post_id ) ) {
+ $update = wp_update_post( array(
+ 'ID' => $explanation->ID,
+ 'post_status' => 'draft'
+ ) );
+
+ if ( ! is_wp_error( $update ) && 0 !== $update ) {
+ wp_send_json_success( array( 'post_id' => $update ) );
+ } else {
+ wp_send_json_error(
+ new WP_Error( 'unpublish_error', __( 'Explanation could not be un-published.', 'wporg' ) )
+ );
+ }
+ }
+ }
+}
+
+$explanations = new WPORG_Explanations();
</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/explanations.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><a id="sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgdeveloperincparsedcontentphp"></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/inc/parsed-content.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/parsed-content.php 2014-12-19 18:31:36 UTC (rev 1056)
+++ sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/parsed-content.php 2014-12-19 21:57:26 UTC (rev 1057)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -69,7 +69,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $ticket = get_post_meta( $post->ID, 'wporg_ticket_number', true );
</span><span class="cx" style="display: block; padding: 0 10px"> $ticket_label = get_post_meta( $post->ID, 'wporg_ticket_title', true );
</span><span class="cx" style="display: block; padding: 0 10px"> $ticket_info = get_post_meta( $post->ID, 'wporg_parsed_ticket_info', true );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $content = get_post_meta( $post->ID, 'wporg_parsed_content', true );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $content = $post->post_content;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( $ticket ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $src = "https://core.trac.wordpress.org/ticket/{$ticket}";
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -98,12 +98,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> <td>
</span><span class="cx" style="display: block; padding: 0 10px"> <div class="wporg_parsed_readonly <?php echo $ticket ? 'hidden' : ''; ?>"><?php echo apply_filters( 'the_content', $content ); ?></div>
</span><span class="cx" style="display: block; padding: 0 10px"> <div class="wporg_parsed_content <?php echo $ticket ? '' : 'hidden'; ?>">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- <?php wp_editor( $content, 'wporg_parsed_content_editor', array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ <?php wp_editor( $content, 'content', array(
</ins><span class="cx" style="display: block; padding: 0 10px"> 'media_buttons' => false,
</span><span class="cx" style="display: block; padding: 0 10px"> 'tinymce' => false,
</span><span class="cx" style="display: block; padding: 0 10px"> 'quicktags' => true,
</span><span class="cx" style="display: block; padding: 0 10px"> 'textarea_rows' => 10,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'textarea_name' => 'wporg_parsed_content',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'textarea_name' => 'content',
</ins><span class="cx" style="display: block; padding: 0 10px"> ) ); ?>
</span><span class="cx" style="display: block; padding: 0 10px"> </div>
</span><span class="cx" style="display: block; padding: 0 10px"> </td>
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -163,7 +163,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> public function admin_enqueue_scripts() {
</span><span class="cx" style="display: block; padding: 0 10px"> // Only enqueue 'wporg-parsed-content' script and styles on Code Reference post type screens.
</span><span class="cx" style="display: block; padding: 0 10px"> if ( in_array( get_current_screen()->id, $this->post_types ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- wp_enqueue_style( 'wporg-parsed-content', get_template_directory_uri() . '/stylesheets/admin.css', array(), '20140826' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ wp_enqueue_style( 'wporg-admin', get_template_directory_uri() . '/stylesheets/admin.css', array(), '20140826' );
</ins><span class="cx" style="display: block; padding: 0 10px"> wp_enqueue_script( 'wporg-parsed-content', get_template_directory_uri() . '/js/parsed-content.js', array( 'jquery', 'utils' ), '20140826', true );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> wp_localize_script( 'wporg-parsed-content', 'wporg', array(
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgdeveloperinctemplatetagsphp"></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/inc/template-tags.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/template-tags.php 2014-12-19 18:31:36 UTC (rev 1056)
+++ sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/template-tags.php 2014-12-19 21:57:26 UTC (rev 1057)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1103,4 +1103,62 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return ( is_singular( $post_types ) || is_post_type_archive( $post_types ) || is_tax( $taxonomies ) );
</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">\ No newline at end of file
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Retrieve an explanation for the given post.
+ *
+ * @param int|WP_Post $post Post ID or WP_Post object.
+ * @param bool $published Optional. Whether to only retrieve the explanation if it's published.
+ * Default false.
+ * @return WP_Post|null WP_Post object for the Explanation, null otherwise.
+ */
+ function get_explanation( $post, $published = false ) {
+ if ( ! $post = get_post( $post ) ) {
+ return null;
+ }
+
+ $args = array(
+ 'post_type' => 'wporg_explanations',
+ 'post_parent' => $post->ID,
+ 'no_found_rows' => true,
+ 'posts_per_page' => 1,
+ );
+
+ if ( true === $published ) {
+ $args['post_status'] = 'publish';
+ }
+
+ $explanation = get_children( $args, OBJECT );
+
+ if ( empty( $explanation ) ) {
+ return null;
+ }
+
+ $explanation = reset( $explanation );
+
+ if ( ! $explanation ) {
+ return null;
+ }
+ return $explanation;
+ }
+
+ /**
+ * Retrieve data from an explanation post field.
+ *
+ * Works only for published explanations.
+ *
+ * @see get_post_field()
+ *
+ * @param string $field Post field name.
+ * @param int|WP_Post $post Post ID or object for the function, hook, class, or method post
+ * to retrieve an explanation field for.
+ * @param string $context Optional. How to filter the field. Accepts 'raw', 'edit', 'db',
+ * or 'display'. Default 'display'.
+ * @return string The value of the post field on success, empty string on failure.
+ */
+ function get_explanation_field( $field, $post, $context = 'display' ) {
+ if ( ! $explanation = get_explanation( $post, $published = true ) ) {
+ return '';
+ }
+ return get_post_field( $field, $explanation, $context );
+ }
+}
</ins></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgdeveloperjsexplanationsjs"></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/js/explanations.js</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/js/explanations.js (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/js/explanations.js 2014-12-19 21:57:26 UTC (rev 1057)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,93 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+/**
+ * Explanations JS.
+ */
+
+( function( $ ) {
+
+ //
+ // Explanations AJAX handlers.
+ //
+
+ var statusLabel = $( '#status-label' ),
+ createLink = $( '#create-expl' ),
+ unPublishLink = $( '#unpublish-expl' ),
+ rowActions = $( '#expl-row-actions' );
+
+ /**
+ * AJAX handler for creating and associating a new explanation post.
+ *
+ * @param {object} event Event object.
+ */
+ function createExplanation( event ) {
+ event.preventDefault();
+
+ wp.ajax.send( 'new_explanation', {
+ success: createExplSuccess,
+ error: createExplError,
+ data: {
+ nonce: $( this ).data( 'nonce' ),
+ post_id: $( this ).data( 'id' )
+ }
+ } );
+ }
+
+ /**
+ * Success callback for creating a new explanation via AJAX.
+ *
+ * @param {object} data Data response object.
+ */
+ function createExplSuccess( data ) {
+ createLink.hide();
+ rowActions.html( '<a href="post.php?post=' + data.post_id + '&action=edit">' + wporg.editContentLabel + '</a>' );
+ statusLabel.text( wporg.statusLabel.draft );
+ }
+
+ /**
+ * Error callback for creating a new explanation via AJAX.
+ *
+ * @param {object} data Data response object.
+ */
+ function createExplError( data ) {}
+
+ /**
+ * Handler for un-publishing an existing Explanation.
+ *
+ * @param {object} event Event object.
+ */
+ function unPublishExplantaion( event ) {
+ event.preventDefault();
+
+ wp.ajax.send( 'un_publish', {
+ success: unPublishSuccess,
+ error: unPublishError,
+ data: {
+ nonce: $( this ).data( 'nonce' ),
+ post_id: $( this ).data( 'id' )
+ }
+ } );
+ }
+
+ /**
+ * Success callback for un-publishing an explanation via AJAX.
+ *
+ * @param {object} data Data response object.
+ */
+ function unPublishSuccess( data ) {
+ if ( statusLabel.hasClass( 'pending' ) || statusLabel.hasClass( 'publish' ) ) {
+ statusLabel.removeClass( 'pending publish' ).text( wporg.statusLabel.draft );
+ }
+ unPublishLink.hide();
+ }
+
+ /**
+ * Error callback for un-publishing an explanation via AJAX.
+ *
+ * @param {object} data Data response object.
+ */
+ function unPublishError( data ) {}
+
+ // Events.
+ $( '#create-expl' ).on( 'click', createExplanation );
+ $( '#unpublish-expl' ).on( 'click', unPublishExplantaion );
+
+} )( jQuery );
</ins></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgdeveloperscssadminscss"></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/scss/admin.scss</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/scss/admin.scss 2014-12-19 18:31:36 UTC (rev 1056)
+++ sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/scss/admin.scss 2014-12-19 21:57:26 UTC (rev 1057)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -20,3 +20,57 @@
</span><span class="cx" style="display: block; padding: 0 10px"> margin-bottom: 10px;
</span><span class="cx" style="display: block; padding: 0 10px"> display: block;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+
+/* Explanations */
+
+.post-type-wporg_explanations .add-new-h2 {
+ display: none;
+}
+
+.expl-row-actions {
+ display: block;
+
+ a {
+ display: inline-block;
+
+ &:first-child {
+ padding-right: 6px;
+ padding-left: 0;
+ }
+ &:nth-child(n+2) {
+ padding-left: 8px;
+ border-left: 1px solid #ccc;
+ }
+ }
+}
+
+.status {
+ font-weight: bold;
+
+ &.pending {
+ color: red;
+ }
+
+ &.publish {
+ color: green;
+ }
+}
+.post-type-wp-parser-function,
+.post-type-wp-parser-class,
+.post-type-wp-parser-method,
+.post-type-wp-parser-hook {
+ .form-table {
+ th {
+ padding-top: 10px;
+ padding-bottom: 10px;
+ }
+ td {
+ padding: 10px;
+
+ p {
+ margin-top: 0;
+ }
+ }
+ }
+}
</ins></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgdeveloperstylesheetsadmincss"></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/stylesheets/admin.css</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/stylesheets/admin.css 2014-12-19 18:31:36 UTC (rev 1056)
+++ sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/stylesheets/admin.css 2014-12-19 21:57:26 UTC (rev 1057)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -19,3 +19,53 @@
</span><span class="cx" style="display: block; padding: 0 10px"> margin-bottom: 10px;
</span><span class="cx" style="display: block; padding: 0 10px"> display: block;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+/* Explanations */
+.post-type-wporg_explanations .add-new-h2 {
+ display: none;
+}
+
+.expl-row-actions {
+ display: block;
+}
+.expl-row-actions a {
+ display: inline-block;
+}
+.expl-row-actions a:first-child {
+ padding-right: 6px;
+ padding-left: 0;
+}
+.expl-row-actions a:nth-child(n+2) {
+ padding-left: 8px;
+ border-left: 1px solid #ccc;
+}
+
+.status {
+ font-weight: bold;
+}
+.status.pending {
+ color: red;
+}
+.status.publish {
+ color: green;
+}
+
+.post-type-wp-parser-function .form-table th,
+.post-type-wp-parser-class .form-table th,
+.post-type-wp-parser-method .form-table th,
+.post-type-wp-parser-hook .form-table th {
+ padding-top: 10px;
+ padding-bottom: 10px;
+}
+.post-type-wp-parser-function .form-table td,
+.post-type-wp-parser-class .form-table td,
+.post-type-wp-parser-method .form-table td,
+.post-type-wp-parser-hook .form-table td {
+ padding: 10px;
+}
+.post-type-wp-parser-function .form-table td p,
+.post-type-wp-parser-class .form-table td p,
+.post-type-wp-parser-method .form-table td p,
+.post-type-wp-parser-hook .form-table td p {
+ margin-top: 0;
+}
</ins></span></pre>
</div>
</div>
</body>
</html>