WordPress.org

Making WordPress.org

Changeset 7714


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

developer.wordpress.org: Add DevHub_Parser::cache_source_code() for pre-caching source code.

File:
1 edited

Legend:

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

    r7713 r7714  
    2626    }
    2727
     28    /**
     29     * Pre-caches source for parsed post types that support showing source code.
     30     *
     31     * By default, source code gets imported and cached as needed.
     32     *
     33     * Primarily intended to be run as a commandline convenience script.
     34     *
     35     * @return bool True on sucess, false on failure.
     36     */
     37    public static function cache_source_code() {
     38        // Ensure the parsed code source directory exists.
     39        $import_dir = get_option( 'wp_parser_root_import_dir' );
     40        if ( ! $import_dir || ! file_exists( $import_dir ) ) {
     41            echo "Unable to cache source code; import directory does not exist: {$import_dir}\n";
     42            return false;
     43        }
     44
     45        foreach ( \DevHub\get_post_types_with_source_code() as $post_type ) {
     46            $posts = get_posts( array( 'fields' => 'ids', 'post_type' => $post_type, 'posts_per_page' => '-1' ) );
     47            foreach ( $posts as $post ) {
     48                echo '.';
     49                \DevHub\get_source_code( $post, true );
     50            }
     51        }
     52        echo "\n";
     53
     54        return true;
     55    }
     56
    2857} // DevHub_Parser
    2958
Note: See TracChangeset for help on using the changeset viewer.