Index: /sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/content-reference-archive.php
===================================================================
--- /sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/content-reference-archive.php (revision 1195)
+++ /sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/content-reference-archive.php (revision 1196)
@@ -18,3 +18,20 @@
+ post_count;
+ $uses = get_uses()->post_count;
+ ?>
+
Index: /sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/content-reference.php
===================================================================
--- /sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/content-reference.php (revision 1195)
+++ /sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/content-reference.php (revision 1196)
@@ -44,10 +44,4 @@
-
-
-
-
- */ ?>
@@ -130,4 +124,48 @@
endif; ?>
+
+
+
+
+
Index: /sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/template-tags.php
===================================================================
--- /sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/template-tags.php (revision 1195)
+++ /sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/template-tags.php (revision 1196)
@@ -898,4 +898,94 @@
}
+ function show_usage_info() {
+ $p2p_enabled = function_exists( 'p2p_register_connection_type' );
+
+ return $p2p_enabled && post_type_has_usage_info( get_post_type() );
+ }
+
+ /**
+ * Does the post type support usage information?
+ *
+ * @param string $post_type Optional. The post type name. If blank, assumes current post type.
+ *
+ * @return boolean
+ */
+ function post_type_has_usage_info( $post_type = null ) {
+ $post_type = $post_type ? $post_type : get_post_type();
+ $post_types_with_usage = array( 'wp-parser-function', 'wp-parser-method', 'wp-parser-hook' );
+
+ return in_array( $post_type, $post_types_with_usage );
+ }
+
+ /**
+ * Does the post type support uses information?
+ *
+ * @param string $post_type Optional. The post type name. If blank, assumes current post type.
+ *
+ * @return boolean
+ */
+ function post_type_has_uses_info( $post_type = null ) {
+ $post_type = $post_type ? $post_type : get_post_type();
+ $post_types_with_uses = array( 'wp-parser-function', 'wp-parser-method' );
+
+ return in_array( $post_type, $post_types_with_uses );
+ }
+
+ /**
+ * Retrieve a WP_Query object for the posts that the current post uses
+ *
+ * @return WP_Query A WP_Query object for the posts the current post uses
+ */
+ function get_uses() {
+
+ if ( 'wp-parser-function' === get_post_type() ) {
+ $connection_types = array( 'functions_to_functions', 'functions_to_methods', 'functions_to_hooks' );
+ } else {
+ $connection_types = array( 'methods_to_functions', 'methods_to_methods', 'methods_to_hooks' );
+ }
+
+ $connected = new \WP_Query( array(
+ 'post_type' => array( 'wp-parser-function', 'wp-parser-method', 'wp-parser-hook' ),
+ 'connected_type' => $connection_types,
+ 'connected_direction' => array( 'from', 'from', 'from' ),
+ 'connected_items' => get_the_ID(),
+ 'nopaging' => true,
+ ) );
+
+ return $connected;
+ }
+
+ function get_used_by( $post_id = null ) {
+
+ if ( empty( $post_id ) ) {
+ $post_id = get_the_ID();
+ }
+
+ switch ( get_post_type() ) {
+
+ case 'wp-parser-function':
+ $connection_types = array( 'functions_to_functions', 'methods_to_functions' );
+ break;
+
+ case 'wp-parser-method':
+ $connection_types = array( 'functions_to_methods', 'methods_to_methods', );
+ break;
+
+ case 'wp-parser-hook':
+ $connection_types = array( 'functions_to_hooks', 'methods_to_hooks' );
+ break;
+ }
+
+ $connected = new \WP_Query( array(
+ 'post_type' => array( 'wp-parser-function', 'wp-parser-method' ),
+ 'connected_type' => $connection_types,
+ 'connected_direction' => array( 'to', 'to' ),
+ 'connected_items' => $post_id,
+ 'nopaging' => true,
+ ) );
+
+ return $connected;
+ }
+
/**
* Does the post type have source code?
Index: /sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/js/function-reference.js
===================================================================
--- /sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/js/function-reference.js (revision 1195)
+++ /sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/js/function-reference.js (revision 1196)
@@ -5,23 +5,22 @@
*/
( function( $ ) {
+ 'use strict';
+
var $sourceContent, $sourceCodeContainer, $sourceCodeTable, $showCompleteSource, $lessCompleteSource, sourceCollapsedHeight;
- function toggleCompleteSource( e ) {
- e.preventDefault();
+ var $usesList, $usedByList, $showMoreUses, $hideMoreUses, $showMoreUsedBy, $hideMoreUsedBy;
- if ( $showCompleteSource.is(':visible') ) {
- var heightGoal = $sourceCodeTable.height() + 45; // takes into consideration potential x-scrollbar
- } else {
- var heightGoal = sourceCollapsedHeight;
- }
+ function onLoad() {
+ sourceCodeHighlightInit();
- $sourceCodeContainer.animate( { height: heightGoal + 'px' } );
-
- $showCompleteSource.toggle();
- $lessCompleteSource.toggle();
-
+ toggleUsageListInit();
}
- function onLoad() {
+ function sourceCodeHighlightInit() {
+
+ // We require the SyntaxHighlighter javascript library
+ if ( undefined === window.SyntaxHighlighter ) {
+ return;
+ }
// We only expect one source-content per document
@@ -50,5 +49,59 @@
$lessCompleteSource.on( 'click', toggleCompleteSource );
}
+ }
+ function toggleCompleteSource( e ) {
+ e.preventDefault();
+
+ if ( $showCompleteSource.is(':visible') ) {
+ var heightGoal = $sourceCodeTable.height() + 45; // takes into consideration potential x-scrollbar
+ } else {
+ var heightGoal = sourceCollapsedHeight;
+ }
+
+ $sourceCodeContainer.animate( { height: heightGoal + 'px' } );
+
+ $showCompleteSource.toggle();
+ $lessCompleteSource.toggle();
+
+ }
+
+ function toggleUsageListInit() {
+
+ // We only expect one used_by and uses per document
+ $usedByList = $( '.used-by' ).find( 'li' );
+ $usesList = $( '.uses' ).find( 'li' );
+
+ if ( $usedByList.length > 5 ) {
+ $usedByList = $usedByList.slice( 5 ).hide();
+
+ $showMoreUsedBy = $( '.used-by .show-more' ).show().on( 'click', toggleMoreUsedBy );
+ $hideMoreUsedBy = $( '.used-by .hide-more' ).on( 'click', toggleMoreUsedBy );
+ }
+
+ if ( $usesList.length > 5 ) {
+ $usesList = $usesList.slice( 5 ).hide();
+
+ $showMoreUses = $( '.uses .show-more' ).show().on( 'click', toggleMoreUses );
+ $hideMoreUses = $( '.uses .hide-more' ).on( 'click', toggleMoreUses );
+ }
+ }
+
+ function toggleMoreUses( e ) {
+ e.preventDefault();
+
+ $usesList.toggle();
+
+ $showMoreUses.toggle();
+ $hideMoreUses.toggle();
+ }
+
+ function toggleMoreUsedBy( e ) {
+ e.preventDefault();
+
+ $usedByList.toggle();
+
+ $showMoreUsedBy.toggle();
+ $hideMoreUsedBy.toggle();
}
Index: /sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/scss/main.scss
===================================================================
--- /sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/scss/main.scss (revision 1195)
+++ /sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/scss/main.scss (revision 1196)
@@ -466,4 +466,8 @@
* section styles
*/
+
+ section {
+ overflow: auto;
+ }
.home-landing .section {
@@ -923,4 +927,5 @@
.wp-parser-class, .wp-parser-function, .wp-parser-hook, .wp-parser-method {
border-bottom: 1px solid #dfdfdf;
+
h1 {
margin: 24px 0;
@@ -1013,4 +1018,32 @@
}
+ /* = Usage
+ ----------------------------------------------- */
+ .usage {
+ article {
+ float: left;
+ width: 50%;
+ }
+
+ .used-by {
+ padding-right: 30px;
+ }
+
+ .uses {
+ padding-left: 30px;
+ }
+
+ ul {
+ line-height: 1.7; /* Slightly increase the line height for more readability */
+ list-style-type: none;
+ margin: 0;
+ }
+
+ .show-more, .hide-more {
+ display: none;
+ }
+ }
+
+
.source-content {
overflow: auto;
@@ -1303,4 +1336,30 @@
padding-left: 0;
}
+
+ &.archive, &.search {
+ .meta {
+ font-size: 100%;
+ margin-bottom: 1.5em;
+
+ a {
+ color: #21759b;
+ }
+ }
+ }
+ }
+
+}
+
+@media ( min-width: 43em ) {
+ .devhub-wrap {
+ &.archive, &.search {
+ .meta {
+ float: right;
+ }
+
+ .sourcefile {
+ float: left;
+ }
+ }
}
}
@@ -1390,4 +1449,10 @@
width: 99%;
}
+
+ .usage {
+ article {
+ width: 100%;
+ }
+ }
}
}
Index: /sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/stylesheets/main.css
===================================================================
--- /sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/stylesheets/main.css (revision 1195)
+++ /sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/stylesheets/main.css (revision 1196)
@@ -299,4 +299,6 @@
* section styles
*/
+ /* = Usage
+ ----------------------------------------------- */
/* Comments */
/*
@@ -727,4 +729,7 @@
color: #606060;
}
+.devhub-wrap section {
+ overflow: auto;
+}
.devhub-wrap .home-landing .section {
padding: 30px 0%;
@@ -1203,4 +1208,23 @@
border-bottom-style: none;
}
+.devhub-wrap .usage article {
+ float: left;
+ width: 50%;
+}
+.devhub-wrap .usage .used-by {
+ padding-right: 30px;
+}
+.devhub-wrap .usage .uses {
+ padding-left: 30px;
+}
+.devhub-wrap .usage ul {
+ line-height: 1.7;
+ /* Slightly increase the line height for more readability */
+ list-style-type: none;
+ margin: 0;
+}
+.devhub-wrap .usage .show-more, .devhub-wrap .usage .hide-more {
+ display: none;
+}
.devhub-wrap .source-content {
overflow: auto;
@@ -1425,4 +1449,19 @@
padding-left: 0;
}
+ .devhub-wrap.archive .meta, .devhub-wrap.search .meta {
+ font-size: 100%;
+ margin-bottom: 1.5em;
+ }
+ .devhub-wrap.archive .meta a, .devhub-wrap.search .meta a {
+ color: #21759b;
+ }
+}
+@media (min-width: 43em) {
+ .devhub-wrap.archive .meta, .devhub-wrap.search .meta {
+ float: right;
+ }
+ .devhub-wrap.archive .sourcefile, .devhub-wrap.search .sourcefile {
+ float: left;
+ }
}
@media (max-width: 43em) {
@@ -1498,3 +1537,6 @@
width: 99%;
}
-}
+ .devhub-wrap .usage article {
+ width: 100%;
+ }
+}