Making WordPress.org

Changeset 2290


Ignore:
Timestamp:
01/12/2016 10:59:50 PM (7 years ago)
Author:
coffee2code
Message:

developer.wordpress.org: Add hook type "action" or "filter" to archive and search result pages.

  • Prepend "Action Hook" or "Filter Hook" to archive and search results, as appropriate.
  • Add get_hook_type() to return type of hook.

Props keesiemeijer.
Fixes #1506.

Location:
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc
Files:
2 edited

Legend:

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

    r2041 r2290  
    9393 * Prefixes excerpts for archive view with content type label.
    9494 *
    95  * @param  string $excerpt The excerpt.
     95 * @param string $excerpt The excerpt.
    9696 * @return string
    9797 */
    9898function wporg_filter_archive_excerpt( $excerpt ) {
    9999    if ( ! is_single() ) {
    100         $excerpt = '<b>' . get_post_type_object( get_post_type( get_the_ID() ) )->labels->singular_name . ': </b>' . $excerpt;
     100
     101        $post_id = get_the_ID();
     102        $type    = get_post_type_object( get_post_type( $post_id ) )->labels->singular_name;
     103
     104        if ( 'hook' === strtolower( $type ) ) {
     105            $hook_type = \DevHub\get_hook_type( $post_id );
     106
     107            if ( isset( $hook_type ) ) {
     108                switch ( $hook_type ) {
     109                    case 'action':
     110                        $type = __( 'Action Hook', 'wporg' );
     111                        break;
     112                    case 'filter':
     113                        $type = __( 'Filter Hook', 'wporg' );
     114                        break;
     115                }
     116            }
     117        }
     118        $excerpt = '<b>' . $type . ': </b>' . $excerpt;
    101119    }
    102120
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/template-tags.php

    r2282 r2290  
    440440
    441441        return in_array( $post_type, get_parsed_post_types() );
     442    }
     443
     444    /**
     445     * Get the specific type of hook.
     446     *
     447     * @param int|WP_Post|null $post Optional. Post ID or post object. Default is global $post.
     448     * @return string          Either 'action', 'filter', or an empty string if not a hook post type.
     449     */
     450    function get_hook_type( $post = null ) {
     451        $hook = '';
     452
     453        if ( 'wp-parser-hook' === get_post_type( $post ) ) {
     454            $hook = get_post_meta( get_post_field( 'ID', $post ), '_wp-parser_hook_type', true );
     455        }
     456
     457        return $hook;
    442458    }
    443459
Note: See TracChangeset for help on using the changeset viewer.