Making WordPress.org


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

Handbooks, Admin Notices: Output error notice atop import handbook post listing if misconfigured.

At the moment, only shows if configured cron interval is invalid.

File:
1 edited

Legend:

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

    r10776 r10777  
    1616        add_action( 'admin_notices', [ __CLASS__, 'show_new_handbook_message' ] );
    1717        add_action( 'admin_notices', [ __CLASS__, 'show_imported_handbook_notice' ] );
     18        add_action( 'admin_notices', [ __CLASS__, 'show_imported_handbook_config_errors' ] );
    1819    }
    1920
     
    109110    }
    110111
     112    /**
     113     * Outputs admin error notice(s) for any misconfigured imported handbooks.
     114     *
     115     * @access public
     116     */
     117    public static function show_imported_handbook_config_errors() {
     118        global $wp_query;
     119
     120        // Bail if handbook importer is not available.
     121        if ( ! class_exists( 'WPorg_Handbook_Importer' ) ) {
     122            return;
     123        }
     124
     125        $current_screen = get_current_screen();
     126
     127        // Only show message in listing of handbook posts when no posts are present yet.
     128        if (
     129            $current_screen
     130        &&
     131            'edit' === $current_screen->base
     132        &&
     133            in_array( $current_screen->post_type, wporg_get_handbook_post_types() )
     134        &&
     135            WPorg_Handbook_Importer::is_handbook_imported( $current_screen->post_type )
     136        ) {
     137            $handbook_config = WPorg_Handbook_Init::get_handbooks_config( $current_screen->post_type );
     138
     139            $handbook = WPorg_Handbook_Init::get_handbook( $current_screen->post_type );
     140            if ( ! $handbook ) {
     141                return;
     142            }
     143
     144            $handbook_config = $handbook->get_config();
     145            $cron_intervals = wp_get_schedules();
     146            $interval_display = $handbook_config[ 'cron_interval' ] ?? '';
     147
     148            if ( ! empty( $cron_intervals[ $interval_display ] ) ) {
     149                return;
     150            }
     151
     152            echo '<div class="notice notice-warning"><p>';
     153            printf(
     154                /* translators: %s: cron interval. */
     155                __( '<strong>Misconfigured cron interval!</strong> This imported handbook has a misconfigured cron interval. The config defines an interval of <strong>%s</strong>, which has not been defined. The fallback import interval shown in a notice above includes the default cron interval currently in use.', 'wporg' ),
     156                $interval_display
     157            );
     158            echo "</p></div>\n";
     159        }
     160    }
    111161}
    112162
Note: See TracChangeset for help on using the changeset viewer.