Making WordPress.org

Changeset 8688


Ignore:
Timestamp:
04/25/2019 09:34:14 PM (6 years ago)
Author:
coffee2code
Message:

Developer: Convert WP REST API handbook importer to inherit from DevHub_Docs_Importer.

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

Legend:

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

    r8686 r8688  
    7575    // Coding Standards handbook.
    7676    require __DIR__ . '/inc/import-coding-standards.php';
    77 }
    78 
    79 /**
    80  * REST API handbook.
    81  */
    82 if ( class_exists( '\\WordPressdotorg\\Markdown\\Importer' ) ) {
     77
     78    // REST API handbook.
    8379    require __DIR__ . '/inc/rest-api.php';
    8480}
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/handbooks.php

    r8684 r8688  
    2727        add_filter( 'handbook_post_type_defaults', array( __CLASS__, 'filter_handbook_post_type_defaults' ), 10, 2 );
    2828        add_filter( 'handbook_post_types', array( __CLASS__, 'filter_handbook_post_types' ) );
    29         add_filter( 'handbook_label', array( __CLASS__, 'filter_handbook_label' ), 10, 2 );
    3029        add_action( 'init', array( __CLASS__, 'do_init' ) );
    3130    }
     
    9897    public static function filter_handbook_post_types( $types ) {
    9998        if ( ! self::$post_types ) {
    100             self::$post_types = apply_filters( 'devhub_handbook_post_types', [ 'plugin', 'rest-api', 'theme' ] );
     99            self::$post_types = apply_filters( 'devhub_handbook_post_types', [ 'plugin', 'theme' ] );
    101100        }
    102101
     
    188187
    189188    /**
    190      * Overrides the default handbook label used as the base for various handbook
    191      * post type related strings.
    192      *
    193      * @param string $label     The default label, which is merely a santized
    194      *                          version of the handbook name.
    195      * @param string $post_type The handbook post type.
    196      * @return string
    197      */
    198     public static function filter_handbook_label( $label, $post_type ) {
    199         if ( 'rest-api-handbook' === $post_type ) {
    200             $label = __( 'REST API Handbook', 'wporg' );
    201         }
    202 
    203         return $label;
    204     }
    205 
    206     /**
    207189     * For specific credit pages, link @usernames references to their profiles on
    208190     * profiles.wordpress.org.
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/rest-api.php

    r5993 r8688  
    11<?php
    22
    3 use WordPressdotorg\Markdown\Editor;
    4 use WordPressdotorg\Markdown\Importer;
     3class DevHub_REST_API extends DevHub_Docs_Importer {
     4    /**
     5     * Initializes object.
     6     */
     7    public function init() {
     8        parent::do_init(
     9            'rest-api',
     10            'rest-api',
     11            'https://raw.githubusercontent.com/WP-API/docs/master/bin/manifest.json'
     12        );
    513
    6 class DevHub_REST_API extends Importer {
    7     /**
    8      * Singleton instance.
    9      *
    10      * @var static
    11      */
    12     protected static $instance;
    13 
    14     /**
    15      * Get the singleton instance, or create if needed.
    16      *
    17      * @return static
    18      */
    19     public static function instance() {
    20         if ( empty( static::$instance ) ) {
    21             static::$instance = new static();
    22         }
    23 
    24         return static::$instance;
    25     }
    26 
    27     protected function get_base() {
    28         return home_url( 'rest-api/' );
    29     }
    30 
    31     protected function get_manifest_url() {
    32         return 'https://raw.githubusercontent.com/WP-API/docs/master/bin/manifest.json';
    33     }
    34 
    35     public function get_post_type() {
    36         return 'rest-api-handbook';
    37     }
    38 
    39     public function init() {
    40         add_filter( 'cron_schedules', array( $this, 'filter_cron_schedules' ) );
    41         add_action( 'init', array( $this, 'register_cron_jobs' ) );
    42         add_action( 'devhub_restapi_import_manifest', array( $this, 'import_manifest' ) );
    43         add_action( 'devhub_restapi_import_all_markdown', array( $this, 'import_all_markdown' ) );
    44 
    45         $editor = new Editor( $this );
    46         $editor->init();
     14        add_filter( 'handbook_label', array( $this, 'change_handbook_label' ), 10, 2 );
    4715    }
    4816
    4917    /**
    50      * Filter cron schedules to add a 15 minute schedule, if there isn't one.
     18     * Overrides the default handbook label since post type name does not directly
     19     * translate to post type label.
     20     *
     21     * @param string $label     The default label, which is merely a sanitized
     22     *                          version of the handbook name.
     23     * @param string $post_type The handbook post type.
     24     * @return string
    5125     */
    52     public function filter_cron_schedules( $schedules ) {
    53         if ( empty( $schedules['15_minutes'] ) ) {
    54             $schedules['15_minutes'] = array(
    55                 'interval' => 15 * MINUTE_IN_SECONDS,
    56                 'display'  => '15 minutes'
    57             );
     26    public static function change_handbook_label( $label, $post_type ) {
     27        if ( $this->get_post_type() === $post_type ) {
     28            $label = __( 'REST API Handbook', 'wporg' );
    5829        }
    59         return $schedules;
    60     }
    6130
    62     public function register_cron_jobs() {
    63         if ( ! wp_next_scheduled( 'devhub_restapi_import_manifest' ) ) {
    64             wp_schedule_event( time(), '15_minutes', 'devhub_restapi_import_manifest' );
    65         }
    66         if ( ! wp_next_scheduled( 'devhub_restapi_import_all_markdown' ) ) {
    67             wp_schedule_event( time(), '15_minutes', 'devhub_restapi_import_all_markdown' );
    68         }
     31        return $label;
    6932    }
    7033}
Note: See TracChangeset for help on using the changeset viewer.