WordPress.org

Making WordPress.org

Changeset 7715


Ignore:
Timestamp:
10/04/2018 08:41:02 PM (6 months ago)
Author:
coffee2code
Message:

developer.wordpress.org: Specify files and directories that should be skipped when parsing.

File:
1 edited

Legend:

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

    r7714 r7715  
    1010 */
    1111class DevHub_Parser {
     12
     13    // Files and directories to skip from parsing.
     14    const SKIP_FROM_PARSING = [
     15        'wp-admin/css/',
     16        'wp-admin/includes/class-ftp',
     17        'wp-admin/includes/class-pclzip.php',
     18        'wp-admin/js/',
     19        'wp-content/',
     20        'wp-includes/ID3/',
     21        'wp-includes/IXR/',
     22        'wp-includes/SimplePie/',
     23        'wp-includes/Text/',
     24        'wp-includes/certificates/',
     25        'wp-includes/class-IXR.php',
     26        'wp-includes/class-json.php',
     27        'wp-includes/class-phpass.php',
     28        'wp-includes/class-phpmailer.php',
     29        'wp-includes/class-pop3.php ',
     30        'wp-includes/class-simplepie.php',
     31        'wp-includes/class-smtp.php',
     32        'wp-includes/class-snoopy.php',
     33        'wp-includes/js/',
     34    ];
     35
    1236
    1337    /**
     
    2448        // Skip duplicate hooks.
    2549        add_filter( 'wp_parser_skip_duplicate_hooks', '__return_true' );
     50
     51        // Skip parsing of certain files.
     52        add_filter( 'wp_parser_pre_import_file',      [ __CLASS__, 'should_file_be_imported' ], 10, 2 );
     53    }
     54
     55    /**
     56     * Indicates if the given file should be imported for parsing or not.
     57     *
     58     * @param  bool  $import Should the file be imported?
     59     * @param  array $file   File data.
     60     * @return bool  True if file should be imported, else false.
     61     */
     62    public static function should_file_be_imported( $import, $file ) {
     63        // Bail early if file is already being skipped.
     64        if ( ! $import ) {
     65            return $import;
     66        }
     67
     68        // Skip file if it matches anything in the list.
     69        foreach ( self::SKIP_FROM_PARSING as $skip ) {
     70            if ( 0 === strpos( $file['path'], $skip ) ) {
     71                $import = false;
     72                break;
     73            }
     74        }
     75
     76        return $import;
    2677    }
    2778
Note: See TracChangeset for help on using the changeset viewer.