Skip to content

Commit 8ed6af3

Browse files
authored
Merge pull request #30 from ProgressPlanner/develop
v1.3
2 parents 8e7fd03 + 383e117 commit 8ed6af3

19 files changed

+408
-177
lines changed

.github/workflows/cs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434

3535
steps:
3636
- name: Checkout code
37-
uses: actions/checkout@v3
37+
uses: actions/checkout@v4
3838

3939
- name: Install PHP
4040
uses: shivammathur/setup-php@v2

.github/workflows/deploy.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ jobs:
99
tag:
1010
name: New tag
1111
runs-on: ubuntu-latest
12+
if: ${{ github.ref == 'refs/heads/main' }}
1213
steps:
1314
- uses: actions/checkout@main
1415
- name: WordPress Plugin Deploy
15-
uses: 10up/action-wordpress-plugin-deploy@stable
16+
uses: 10up/action-wordpress-plugin-deploy@develop
1617
env:
1718
SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }}
1819
SVN_USERNAME: ${{ secrets.SVN_USERNAME }}

.github/workflows/lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232

3333
steps:
3434
- name: Checkout code
35-
uses: actions/checkout@v3
35+
uses: actions/checkout@v4
3636

3737
- name: Install PHP for the composer install
3838
uses: shivammathur/setup-php@v2

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
[![Lint](https://github.com/emilia-capital/aaa-option-optimizer/actions/workflows/lint.yml/badge.svg)](https://github.com/emilia-capital/aaa-option-optimizer/actions/workflows/lint.yml)
44
[![Security](https://github.com/emilia-capital/aaa-option-optimizer/actions/workflows/security.yml/badge.svg)](https://github.com/emilia-capital/aaa-option-optimizer/actions/workflows/security.yml)
55

6+
[![Try this plugin on the WordPress playground](https://img.shields.io/badge/Try%20this%20plugin%20on%20the%20WordPress%20Playground-%23117AC9.svg?style=for-the-badge&logo=WordPress&logoColor=ddd)](https://playground.wordpress.net/#%7B%22landingPage%22:%22/wp-admin/tools.php?page=aaa-option-optimizer%22,%22features%22:%7B%22networking%22:true%7D,%22steps%22:%5B%7B%22step%22:%22defineWpConfigConsts%22,%22consts%22:%7B%22IS_PLAYGROUND_PREVIEW%22:true%7D%7D,%7B%22step%22:%22login%22,%22username%22:%22admin%22,%22password%22:%22password%22%7D,%7B%22step%22:%22installPlugin%22,%22pluginZipFile%22:%7B%22resource%22:%22url%22,%22url%22:%22https://bypass-cors.altha.workers.dev/https://github.com/Emilia-Capital/aaa-option-optimizer/archive/refs/heads/develop.zip%22%7D,%22options%22:%7B%22activate%22:true%7D%7D%5D%7D)
7+
68
# AAA Option Optimizer
79
This plugin tracks which of the autoloaded options are used on a page, and stores that data at the end of page render. It keeps an array of options that it has seen as being used. On the admin page, it compares all the autoloaded options to the array of stored options, and shows the autoloaded options that have not been used as you were browsing the site. If you've been to every page on your site, or you've kept the plugin around for a week or so, this means that those options probably don't need to be autoloaded.
810

aaa-option-optimizer.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Plugin Name: AAA Option Optimizer
88
* Plugin URI: https://joost.blog/plugins/aaa-option-optimizer/
99
* Description: Tracks autoloaded options usage and allows the user to optimize them.
10-
* Version: 1.2.1
10+
* Version: 1.3
1111
* License: GPL-3.0+
1212
* Author: Joost de Valk
1313
* Author URI: https://joost.blog/
@@ -24,6 +24,7 @@
2424
require_once __DIR__ . '/src/autoload.php';
2525

2626
register_activation_hook( __FILE__, 'aaa_option_optimizer_activation' );
27+
register_deactivation_hook( __FILE__, 'aaa_option_optimizer_deactivation' );
2728

2829
/**
2930
* Activation hooked function to store start stats.
@@ -32,8 +33,15 @@
3233
*/
3334
function aaa_option_optimizer_activation() {
3435
global $wpdb;
35-
//phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- one time query, no caching needed.
36-
$result = $wpdb->get_row( "SELECT count(*) AS count, SUM(LENGTH(option_value)) as autoload_size FROM {$wpdb->options} WHERE autoload='yes'" );
36+
$autoload_values = \wp_autoload_values_to_autoload();
37+
$placeholders = implode( ',', array_fill( 0, count( $autoload_values ), '%s' ) );
38+
39+
// phpcs:disable WordPress.DB
40+
$result = $wpdb->get_row(
41+
$wpdb->prepare( "SELECT count(*) AS count, SUM( LENGTH( option_value ) ) as autoload_size FROM {$wpdb->options} WHERE autoload IN ( $placeholders )", $autoload_values )
42+
);
43+
// phpcs:enable WordPress.DB
44+
3745
update_option(
3846
'option_optimizer',
3947
[
@@ -46,6 +54,16 @@ function aaa_option_optimizer_activation() {
4654
);
4755
}
4856

57+
/**
58+
* Deactivation hooked function to remove autoload from the plugin option.
59+
*
60+
* @return void
61+
*/
62+
function aaa_option_optimizer_deactivation() {
63+
$aaa_option_value = get_option( 'option_optimizer' );
64+
update_option( 'option_optimizer', $aaa_option_value, false );
65+
}
66+
4967
/**
5068
* Initializes the plugin.
5169
*

0 commit comments

Comments
 (0)