Skip to content

Commit

Permalink
separate enabled/disabled notices
Browse files Browse the repository at this point in the history
  • Loading branch information
aristath committed Nov 8, 2022
1 parent 5072a9d commit 161daa9
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 28 deletions.
25 changes: 16 additions & 9 deletions admin/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,15 @@ function perflab_render_modules_page_field( $module_slug, $module_data, $module_
<p id="<?php echo esc_attr( "{$base_id}_description" ); ?>" class="description">
<?php echo esc_html( $module_data['description'] ); ?>
</p>
<?php if ( ! empty( $module_data['notice'] ) ) : ?>
<?php if ( $enabled && ! empty( $module_data['enabled-notice'] ) ) : ?>
<?php // Don't use the WP notice classes here, as that makes them move to the top of the page. ?>
<p style="background:#fff;border:1px solid #c3c4c7;border-left-width: 4px;border-left-color:#dba617;box-shadow: 0 1px 1px rgba(0, 0, 0, 0.04);padding:1em;max-width:50em;">
<?php echo esc_html( $module_data['notice'] ); ?>
<?php echo esc_html( $module_data['enabled-notice'] ); ?>
</p>
<?php elseif ( ! $enabled && perflab_can_load_module( $module_slug ) && ! empty( $module_data['disabled-notice'] ) ) : ?>
<?php // Don't use the WP notice classes here, as that makes them move to the top of the page. ?>
<p style="background:#fff;border:1px solid #c3c4c7;border-left-width: 4px;border-left-color:#dba617;box-shadow: 0 1px 1px rgba(0, 0, 0, 0.04);padding:1em;max-width:50em;">
<?php echo esc_html( $module_data['disabled-notice'] ); ?>
</p>
<?php endif; ?>
</fieldset>
Expand Down Expand Up @@ -317,10 +322,11 @@ function perflab_get_module_data( $module_file ) {
$module_dir = $matches[1];

$default_headers = array(
'name' => 'Module Name',
'description' => 'Description',
'experimental' => 'Experimental',
'notice' => 'Notice',
'name' => 'Module Name',
'description' => 'Description',
'experimental' => 'Experimental',
'enabled-notice' => 'Enabled Notice',
'disabled-notice' => 'Disabled Notice',
);

$module_data = get_file_data( $module_file, $default_headers, 'perflab_module' );
Expand All @@ -347,9 +353,10 @@ function perflab_get_module_data( $module_file ) {
// Translate fields using low-level function since they come from PHP comments, including the necessary context for
// `_x()`. This must match how these are translated in the generated `/module-i18n.php` file.
$translatable_fields = array(
'name' => 'module name',
'description' => 'module description',
'notice' => 'module notice',
'name' => 'module name',
'description' => 'module description',
'enabled-notice' => 'module enabled notice',
'disabled-notice' => 'module disabled notice',
);
foreach ( $translatable_fields as $field => $context ) {
// phpcs:ignore WordPress.WP.I18n.LowLevelTranslationFunction,WordPress.WP.I18n.NonSingularStringLiteralContext,WordPress.WP.I18n.NonSingularStringLiteralText
Expand Down
3 changes: 2 additions & 1 deletion modules/database/sqlite/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
/**
* Module Name: SQLite Integration
* Description: Use an SQLite database instead of MySQL.
* Notice: CAUTION: Enabling this module will bring up the WordPress installation screen. You will need to reconfigure your site, and you will lose all your data. If you then disable the module, you will get back to your previous MySQL database, with all your previous data intact.
* Disabled Notice: Enabling this module will bring up the WordPress installation screen. You will need to reconfigure your site, and start with a fresh site. Disabling the module you will get back to your previous MySQL database, with all your previous data intact.
* Enabled Notice: Your site is currently using an SQLite database. You can disable this module to get back to your previous MySQL database, with all your previous data intact.
* Experimental: Yes
*
* @package performance-lab
Expand Down
40 changes: 22 additions & 18 deletions tests/admin/load-tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,32 @@ class Admin_Load_Tests extends WP_UnitTestCase {

private static $demo_modules = array(
'js-and-css/demo-module-1' => array(
'name' => 'Demo Module 1',
'description' => 'This is the description for demo module 1.',
'experimental' => false,
'notice' => '',
'focus' => 'js-and-css',
'slug' => 'demo-module-1',
'javascript/demo-module-1' => array(
'name' => 'Demo Module 1',
'description' => 'This is the description for demo module 1.',
'experimental' => false,
'enabled-notice' => '',
'disabled-notice' => '',
'focus' => 'js-and-css',
'slug' => 'demo-module-1',
),
'something/demo-module-2' => array(
'name' => 'Demo Module 2',
'description' => 'This is the description for demo module 2.',
'experimental' => true,
'notice' => '',
'focus' => 'something',
'slug' => 'demo-module-2',
'name' => 'Demo Module 2',
'description' => 'This is the description for demo module 2.',
'experimental' => true,
'enabled-notice' => '',
'disabled-notice' => '',
'focus' => 'something',
'slug' => 'demo-module-2',
),
'images/demo-module-3' => array(
'name' => 'Demo Module 3',
'description' => 'This is the description for demo module 3.',
'experimental' => false,
'notice' => '',
'focus' => 'images',
'slug' => 'demo-module-3',
'name' => 'Demo Module 3',
'description' => 'This is the description for demo module 3.',
'experimental' => false,
'enabled-notice' => '',
'disabled-notice' => '',
'focus' => 'images',
'slug' => 'demo-module-3',
),
);

Expand Down

0 comments on commit 161daa9

Please sign in to comment.