Skip to content

Commit

Permalink
Fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdevalk committed Feb 29, 2024
1 parent 08fb6c8 commit 1a7bf75
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ composer.lock export-ignore
phpunit.xml.dist export-ignore
/README.md export-ignore
/tests export-ignore
/.wordpress-org export-ignore

#
# Auto detect text files and perform LF normalization
Expand Down
File renamed without changes
5 changes: 3 additions & 2 deletions aaa-option-optimizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@
function aaa_option_optimizer_activation() {
global $wpdb;
//phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- one time query, no caching needed.
$autoload_size = $wpdb->get_var( "SELECT SUM(LENGTH(option_value)) as autoload_size FROM {$wpdb->options} WHERE autoload='yes'" );
$result = $wpdb->get_row( "SELECT count(*) AS count, SUM(LENGTH(option_value)) as autoload_size FROM {$wpdb->options} WHERE autoload='yes'" );
update_option(
'option_optimizer',
[
'starting_point_kb' => $autoload_size / 1024,
'starting_point_kb' => ( $result->autoload_size / 1024 ),
'starting_point_num' => $result->count,
'starting_point_date' => current_time( 'mysql' ),
'used_options' => [],
],
Expand Down
19 changes: 14 additions & 5 deletions src/class-admin-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,22 @@ function ( $value, $key ) {
</style>';
echo '<div class="wrap"><h1>' . esc_html__( 'AAA Option Optimizer', 'aaa-option-optimizer' ) . '</h1>';

// translators: %1$s is the date, %2$s is the size in KB.
echo '<p>' . sprintf( esc_html__( 'When you started on %1$s you had %2$sMB of autoloaded options. Now you have: ', 'aaa-option-optimizer' ), esc_html( gmdate( 'Y-m-d', strtotime( $option_optimizer['starting_point_date'] ) ) ), number_format( ( $option_optimizer['starting_point_kb'] / 1024 ), 2 ) );
global $wpdb;
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.DirectQuery
$autoload_size = $wpdb->get_var( "SELECT SUM(LENGTH(option_value)) as autoload_size FROM {$wpdb->options} WHERE autoload='yes'" );
echo number_format( ( $autoload_size / 1024 / 1024 ), 2 ) . 'MB.';
// Render differences.
$result = $wpdb->get_row( "SELECT count(*) AS count, SUM(LENGTH(option_value)) as autoload_size FROM {$wpdb->options} WHERE autoload='yes'" );

// translators: %1$s is the date, %2$s is the number of options at stat, %3$s is the size at start in KB, %4$s is the number of options now, %5$s is the size in KB now.
echo '<p>' .

Check failure on line 86 in src/class-admin-page.php

View workflow job for this annotation

GitHub Actions / Check code style

Whitespace found at end of line
sprintf(

Check failure on line 87 in src/class-admin-page.php

View workflow job for this annotation

GitHub Actions / Check code style

Whitespace found at end of line
esc_html__( 'When you started on %1$s you had %2$s autoloaded options, for %3$sKB of memory. Now you have %4$s options, for %5$sKB of memory.', 'aaa-option-optimizer' ),

Check failure on line 88 in src/class-admin-page.php

View workflow job for this annotation

GitHub Actions / Check code style

A function call to esc_html__() with texts containing placeholders was found, but was not accompanied by a "translators:" comment on the line above to clarify the meaning of the placeholders.
esc_html( gmdate( 'Y-m-d', strtotime( $option_optimizer['starting_point_date'] ) ) ),

Check failure on line 89 in src/class-admin-page.php

View workflow job for this annotation

GitHub Actions / Check code style

Whitespace found at end of line
$option_optimizer['starting_point_num'],

Check failure on line 90 in src/class-admin-page.php

View workflow job for this annotation

GitHub Actions / Check code style

All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '$option_optimizer['starting_point_num']'.
number_format( ( $option_optimizer['starting_point_kb'] ), 1 ),
$result->count,

Check failure on line 92 in src/class-admin-page.php

View workflow job for this annotation

GitHub Actions / Check code style

All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '$result'.
number_format( ( $result->autoload_size / 1024 ), 1 )
) . '</p>';

// Render differences.
echo '<h2>' . esc_html__( 'Unused Autoloaded Options', 'aaa-option-optimizer' ) . '</h2>';
if ( ! empty( $unused_options ) ) {
echo '<table class="aaa_option_table">';
Expand Down

0 comments on commit 1a7bf75

Please sign in to comment.