Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New release #24

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
adae31c
Alphabetize known plugins
jdevalk Apr 29, 2024
310b06d
More additions from system4pc
jdevalk Apr 29, 2024
a7a8272
Run htmlentities over source to make it more easily copy pastable
jdevalk May 16, 2024
0e723ec
Fix CS
jdevalk May 16, 2024
3720a61
Left align label
jdevalk May 16, 2024
e4dcfba
Restrict deploy to main
jdevalk Jun 2, 2024
5060714
feat(plugins): more
Mte90 Jun 19, 2024
db2067c
Optimize for smaller screen sizes
jdevalk Jun 24, 2024
7df794a
Merge pull request #19 from Emilia-Capital/jdv/small-screen-size
jdevalk Aug 20, 2024
b6d7291
Tabs to spaces
jdevalk Aug 20, 2024
15b018f
Merge pull request #18 from Mte90/plugins
jdevalk Aug 20, 2024
36f176c
Merge pull request #17 from Emilia-Capital/jdv/htmlentities-value
jdevalk Aug 20, 2024
b4e341a
Increase tested up to.
jdevalk Aug 20, 2024
f867f36
Minor copy tweak
jdevalk Aug 29, 2024
53eab76
Remove autoload from the plugin option on plugin deactivation
aristath Sep 4, 2024
cda2f6b
Add deactivation hook
aristath Sep 4, 2024
3b1b7ad
CS
aristath Sep 4, 2024
d01319e
Merge pull request #23 from Emilia-Capital/add/deactivation
jdevalk Sep 6, 2024
d4a5dc6
Make plugin understand WP 6.6
jdevalk Sep 6, 2024
9571c41
Merge branch 'develop' of github.com:Emilia-Capital/aaa-option-optimi…
jdevalk Sep 6, 2024
6320c06
Add Playground button
jdevalk Sep 6, 2024
69e4936
Fix typo in filename
jdevalk Sep 6, 2024
9a420c1
Fix queries to find options
jdevalk Sep 6, 2024
14fa0e6
Fix PHPstan and get in line with new usage of add_option
jdevalk Sep 6, 2024
6b6a493
Fix more CS
jdevalk Sep 6, 2024
8cb02f3
Get ready for 1.3
jdevalk Sep 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ jobs:
tag:
name: New tag
runs-on: ubuntu-latest
if: ${{ github.ref == 'refs/heads/main' }}
steps:
- uses: actions/checkout@main
- name: WordPress Plugin Deploy
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
[![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)
[![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)

[![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)

# AAA Option Optimizer
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.

Expand Down
24 changes: 21 additions & 3 deletions aaa-option-optimizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Plugin Name: AAA Option Optimizer
* Plugin URI: https://joost.blog/plugins/aaa-option-optimizer/
* Description: Tracks autoloaded options usage and allows the user to optimize them.
* Version: 1.2.1
* Version: 1.3
* License: GPL-3.0+
* Author: Joost de Valk
* Author URI: https://joost.blog/
Expand All @@ -24,6 +24,7 @@
require_once __DIR__ . '/src/autoload.php';

register_activation_hook( __FILE__, 'aaa_option_optimizer_activation' );
register_deactivation_hook( __FILE__, 'aaa_option_optimizer_deactivation' );

/**
* Activation hooked function to store start stats.
Expand All @@ -32,8 +33,15 @@
*/
function aaa_option_optimizer_activation() {
global $wpdb;
//phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- one time query, no caching needed.
$result = $wpdb->get_row( "SELECT count(*) AS count, SUM(LENGTH(option_value)) as autoload_size FROM {$wpdb->options} WHERE autoload='yes'" );
$autoload_values = \wp_autoload_values_to_autoload();
$placeholders = implode( ',', array_fill( 0, count( $autoload_values ), '%s' ) );

// phpcs:disable WordPress.DB
$result = $wpdb->get_row(
$wpdb->prepare( "SELECT count(*) AS count, SUM( LENGTH( option_value ) ) as autoload_size FROM {$wpdb->options} WHERE autoload IN ( $placeholders )", $autoload_values )
);
// phpcs:enable WordPress.DB

update_option(
'option_optimizer',
[
Expand All @@ -46,6 +54,16 @@ function aaa_option_optimizer_activation() {
);
}

/**
* Deactivation hooked function to remove autoload from the plugin option.
*
* @return void
*/
function aaa_option_optimizer_deactivation() {
$aaa_option_value = get_option( 'option_optimizer' );
update_option( 'option_optimizer', $aaa_option_value, false );
}

/**
* Initializes the plugin.
*
Expand Down
Loading
Loading