Making WordPress.org


Ignore:
Timestamp:
01/27/2015 12:39:51 AM (10 years ago)
Author:
coffee2code
Message:

developer.wordpress.org: Add 'Used By' and 'Uses' sections to parsed content permalink pages.

Basically the UI surfacing of the P2P relationships.

Fixes #323.
Props atimmer.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/template-tags.php

    r1173 r1196  
    898898    }
    899899
     900    function show_usage_info() {
     901        $p2p_enabled = function_exists( 'p2p_register_connection_type' );
     902
     903        return $p2p_enabled && post_type_has_usage_info( get_post_type() );
     904    }
     905
     906    /**
     907     * Does the post type support usage information?
     908     *
     909     * @param string $post_type Optional. The post type name. If blank, assumes current post type.
     910     *
     911     * @return boolean
     912     */
     913    function post_type_has_usage_info( $post_type = null ) {
     914        $post_type             = $post_type ? $post_type : get_post_type();
     915        $post_types_with_usage = array( 'wp-parser-function', 'wp-parser-method', 'wp-parser-hook' );
     916
     917        return in_array( $post_type, $post_types_with_usage );
     918    }
     919
     920    /**
     921     * Does the post type support uses information?
     922     *
     923     * @param string $post_type Optional. The post type name. If blank, assumes current post type.
     924     *
     925     * @return boolean
     926     */
     927    function post_type_has_uses_info( $post_type = null ) {
     928        $post_type             = $post_type ? $post_type : get_post_type();
     929        $post_types_with_uses  = array( 'wp-parser-function', 'wp-parser-method' );
     930
     931        return in_array( $post_type, $post_types_with_uses );
     932    }
     933
     934    /**
     935     * Retrieve a WP_Query object for the posts that the current post uses
     936     *
     937     * @return WP_Query A WP_Query object for the posts the current post uses
     938     */
     939    function get_uses() {
     940
     941        if ( 'wp-parser-function' === get_post_type() ) {
     942            $connection_types = array( 'functions_to_functions', 'functions_to_methods', 'functions_to_hooks' );
     943        } else {
     944            $connection_types = array( 'methods_to_functions', 'methods_to_methods', 'methods_to_hooks' );
     945        }
     946
     947        $connected = new \WP_Query( array(
     948            'post_type'           => array( 'wp-parser-function', 'wp-parser-method', 'wp-parser-hook' ),
     949            'connected_type'      => $connection_types,
     950            'connected_direction' => array( 'from', 'from', 'from' ),
     951            'connected_items'     => get_the_ID(),
     952            'nopaging'            => true,
     953        ) );
     954
     955        return $connected;
     956    }
     957
     958    function get_used_by( $post_id = null ) {
     959
     960        if ( empty( $post_id ) ) {
     961            $post_id = get_the_ID();
     962        }
     963
     964        switch ( get_post_type() ) {
     965
     966            case 'wp-parser-function':
     967                $connection_types = array( 'functions_to_functions', 'methods_to_functions' );
     968                break;
     969
     970            case 'wp-parser-method':
     971                $connection_types = array( 'functions_to_methods', 'methods_to_methods', );
     972                break;
     973
     974            case 'wp-parser-hook':
     975                $connection_types = array( 'functions_to_hooks', 'methods_to_hooks' );
     976                break;
     977        }
     978
     979        $connected = new \WP_Query( array(
     980            'post_type'           => array( 'wp-parser-function', 'wp-parser-method' ),
     981            'connected_type'      => $connection_types,
     982            'connected_direction' => array( 'to', 'to' ),
     983            'connected_items'     => $post_id,
     984            'nopaging'            => true,
     985        ) );
     986
     987        return $connected;
     988    }
     989
    900990    /**
    901991     * Does the post type have source code?
Note: See TracChangeset for help on using the changeset viewer.