Make WordPress Core


Ignore:
Timestamp:
02/20/2009 08:00:09 PM (16 years ago)
Author:
ryan
Message:

Add documentation lookup shortcuts to Theme and Plugin Editors. Props beaulebens. fixes #9184

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/misc.php

    r9249 r10607  
    239239}
    240240
     241function wp_doc_link_parse( $content ) {
     242    if ( !is_string( $content ) || empty( $content ) )
     243        return array();
     244       
     245    $tokens = token_get_all( $content );
     246    $functions = array();
     247    $ignore_functions = array();
     248    for ( $t = 0, $count = count( $tokens ); $t < $count; $t++ ) {
     249        if ( !is_array( $tokens[$t] ) ) continue;
     250        if ( T_STRING == $tokens[$t][0] && ( '(' == $tokens[ $t + 1 ] || '(' == $tokens[ $t + 2 ] ) ) {
     251            // If it's a function or class defined locally, there's not going to be any docs available
     252            if ( 'class' == $tokens[ $t - 2 ][1] || 'function' == $tokens[ $t - 2 ][1] || T_OBJECT_OPERATOR == $tokens[ $t - 1 ][0] ) {
     253                $ignore_functions[] = $tokens[$t][1];
     254            }
     255            // Add this to our stack of unique references
     256            $functions[] = $tokens[$t][1];
     257        }
     258    }
     259   
     260    $functions = array_unique( $functions );
     261    sort( $functions );
     262    $ignore_functions = apply_filters( 'documentation_ignore_functions', $ignore_functions );
     263    $ignore_functions = array_unique( $ignore_functions );
     264   
     265    $out = array();
     266    foreach ( $functions as $function ) {
     267        if ( in_array( $function, $ignore_functions ) )
     268            continue;
     269        $out[] = $function;
     270    }
     271   
     272    return $out;
     273}
     274
    241275?>
Note: See TracChangeset for help on using the changeset viewer.