Making WordPress.org


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

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.