Making WordPress.org

Changeset 10776


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

Handbooks, Admin Notices: Outputs notice atop imported handbook listing indicating that handbook is imported.

Also links to manifest and states import interval.

File:
1 edited

Legend:

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

    r10771 r10776  
    1515    public static function init() {
    1616        add_action( 'admin_notices', [ __CLASS__, 'show_new_handbook_message' ] );
     17        add_action( 'admin_notices', [ __CLASS__, 'show_imported_handbook_notice' ] );
    1718    }
    1819
     
    6162    }
    6263
     64    /**
     65     * Outputs admin notice indicating the handbook is an imported handbook, if applicable.
     66     *
     67     * @access public
     68     */
     69    public static function show_imported_handbook_notice() {
     70        global $wp_query;
     71
     72        // Bail if handbook importer is not available.
     73        if ( ! class_exists( 'WPorg_Handbook_Importer' ) ) {
     74            return;
     75        }
     76
     77        $current_screen = get_current_screen();
     78
     79        // Only show message in listing of handbook posts when no posts are present yet.
     80        if (
     81            $current_screen
     82        &&
     83            'edit' === $current_screen->base
     84        &&
     85            in_array( $current_screen->post_type, wporg_get_handbook_post_types() )
     86        &&
     87            WPorg_Handbook_Importer::is_handbook_imported( $current_screen->post_type )
     88        ) {
     89            $handbook_config = WPorg_Handbook_Init::get_handbooks_config( $current_screen->post_type );
     90
     91            $handbook = WPorg_Handbook_Init::get_handbook( $current_screen->post_type );
     92            if ( ! $handbook ) {
     93                return;
     94            }
     95
     96            $importer = $handbook->get_importer();
     97            $interval = $importer ? $importer->get_cron_interval() : false;
     98            $interval_display = ! empty( $interval['display'] ) ? strtolower( $interval['display'] ) : __( 'DISABLED', 'wporg' );
     99
     100            echo '<div class="notice notice-info"><p>';
     101            printf(
     102                /* translators: 1: URL to remote manifest. 2: cron interval. */
     103                __( '<strong>This is an imported handbook!</strong> This handbook is imported according to a <a href="%1$s">remote manifest</a>. Any local changes will be overwritten during the next import, so make any changes at the remote location. Import interval: <strong>%2$s</strong>.', 'wporg' ),
     104                $handbook_config['manifest'],
     105                $interval_display
     106            );
     107            echo "</p></div>\n";
     108        }
     109    }
     110
    63111}
    64112
Note: See TracChangeset for help on using the changeset viewer.