Making WordPress.org

Changeset 10775


Ignore:
Timestamp:
03/05/2021 12:40:59 AM (3 years ago)
Author:
coffee2code
Message:

Handbooks: Add ability to import handbook content from a remote source.

  • Add WPorg_Handbook_Importer class, incorporating related functionality from DevHub theme
  • Add 'cron_interval' and 'manifest' handbook config options
  • Add get_importer() and init_importer() to handbook object
Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/handbook.php

    r9990 r10775  
    33 * Plugin Name: Handbook
    44 * Description: Features for a handbook, complete with glossary and table of contents
     5 * Version:     2.0
    56 * Author:      WordPress.org
    67 * Author URI:  https://wordpress.org/
     
    2526require_once __DIR__ . '/inc/blocks.php';
    2627
     28add_action( 'plugins_loaded', function () {
     29    if ( class_exists( 'WordPressdotorg\\Markdown\\Importer' ) ) {
     30        require_once __DIR__ . '/inc/importer.php';
     31    }
     32}, 1 );
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/inc/handbook.php

    r10772 r10775  
    3535     */
    3636    protected $label = '';
     37
     38    /**
     39     * The associated importer object, if warranted.
     40     */
     41    protected $importer;
    3742
    3843    /**
     
    7883         *     Associative array of handbook configuration.
    7984         *
     85         *     @type string $cron_interval The cron interval for which an imported handbook gets
     86         *                                 imported, e.g. 'hourly', 'daily'. If defined as an
     87         *                                 unrecognized interval, 'hourly' will be used.
     88         *                                 Default '15_minutes'.
    8089         *     @type string $label The label for the handbook. Default is the
    8190         *                         post type slug converted to titlecase (e.g.
    8291         *                         plugin-handbok => "Plugin Handbook").
     92         *     @type string manifest       The URL to the manifest JSON file for an imported
     93         *                                 handbook.
    8394         *     @type string $slug  The slug for the post type. Default is the
    8495         *                         post type.
     
    8697         */
    8798        return (array) apply_filters( 'handbook_default_handbook_config', [
     99            'cron_interval' => '15_minutes',
    88100            'label'         => '',
     101            'manifest'      => '',
    89102            'slug'          => '',
    90103        ] );
     
    142155        $this->setting_name = $this->post_type . '_name';
    143156
     157        add_action( 'after_handbooks_init',               [ $this, 'init_importer' ] );
    144158        add_filter( 'user_has_cap',                       [ $this, 'grant_handbook_caps' ] );
    145159        add_action( 'widgets_init',                       [ $this, 'register_post_type' ] );
     
    171185    public function get_config() {
    172186        return $this->config;
     187    }
     188
     189    /**
     190     * Returns the handbook's importer object, if applicable.
     191     *
     192     * @return WPorg_Handbook_Importer|null
     193     */
     194    public function get_importer() {
     195        return $this->importer;
     196    }
     197
     198    /**
     199     * Initializes the importer, if applicable.
     200     */
     201    public function init_importer() {
     202        $config = $this->get_config();
     203
     204        if ( class_exists( 'WPorg_Handbook_Importer' ) ) {
     205            if ( WPorg_Handbook_Importer::is_handbook_imported( $this->post_type ) ) {
     206                $this->importer = new WPorg_Handbook_Importer( $this );
     207            }
     208        } elseif ( is_admin() && ( $config['manifest'] ?: false ) ) {
     209            add_action( 'admin_notices', function () {
     210                echo '<div class="notice notice-error"><p>' . __( 'Error: The <strong>WPORG Markdown Importer</strong> plugin needs to be activated in order to allow importing of handbooks.', 'wporg' ) . '</p></div>';
     211            } );
     212        }
    173213    }
    174214
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/phpunit/includes/utils.php

    r10773 r10775  
    3232function dataprovider_get_default_config() {
    3333    return [
     34        [ 'cron_interval', '15_minutes' ],
    3435        [ 'label', '' ],
     36        [ 'manifest', '' ],
    3537        [ 'slug', '' ],
    3638    ];
Note: See TracChangeset for help on using the changeset viewer.