|
1 | 1 | <?php |
2 | | -/** |
3 | | - * Plugin Name: BenchPress |
4 | | - * Description: A tool for benchmarking PHP code snippets and WordPress queries to help developers optimize performance. |
5 | | - * Version: 1.1 |
6 | | - * Author: Your Name |
7 | | - * Text Domain: benchpress |
8 | | - * License: GPL-2.0+ |
9 | | - * License URI: https://www.gnu.org/licenses/gpl-2.0.html |
10 | | - */ |
11 | 2 |
|
12 | | -// Exit if accessed directly |
13 | | -if ( ! defined( 'ABSPATH' ) ) { |
14 | | - exit; |
| 3 | + /** |
| 4 | + * The plugin bootstrap file |
| 5 | + * |
| 6 | + * @link https://robertdevore.com |
| 7 | + * @since 1.0.0 |
| 8 | + * @package Back_In_Stock_Notifications |
| 9 | + * |
| 10 | + * @wordpress-plugin |
| 11 | + * |
| 12 | + * Plugin Name: BenchPress |
| 13 | + * Description: A tool for benchmarking PHP code snippets and WordPress® queries to help developers optimize performance. |
| 14 | + * Plugin URI: https://github.com/robertdevore/benchpress/ |
| 15 | + * Version: 1.0.0 |
| 16 | + * Author: Robert DeVore |
| 17 | + * Author URI: https://robertdevore.com/ |
| 18 | + * License: GPL-2.0+ |
| 19 | + * License URI: http://www.gnu.org/licenses/gpl-2.0.txt |
| 20 | + * Text Domain: benchpress |
| 21 | + * Domain Path: /languages |
| 22 | + * Update URI: https://github.com/robertdevore/benchpress/ |
| 23 | + */ |
| 24 | + |
| 25 | +// If this file is called directly, abort. |
| 26 | +if ( ! defined( 'WPINC' ) ) { |
| 27 | + die; |
15 | 28 | } |
16 | 29 |
|
17 | 30 | // Define constants. |
18 | 31 | define( 'BENCHPRESS_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); |
19 | 32 | define( 'BENCHPRESS_VERSION', '1.0.0' ); |
20 | 33 |
|
| 34 | +// Add the Plugin Update Checker. |
| 35 | +require 'vendor/plugin-update-checker/plugin-update-checker.php'; |
| 36 | +use YahnisElsts\PluginUpdateChecker\v5\PucFactory; |
| 37 | + |
| 38 | +$myUpdateChecker = PucFactory::buildUpdateChecker( |
| 39 | + 'https://github.com/robertdevore/benchpress/', |
| 40 | + __FILE__, |
| 41 | + 'benchpress' |
| 42 | +); |
| 43 | + |
| 44 | +// Set the branch that contains the stable release. |
| 45 | +$myUpdateChecker->setBranch( 'main' ); |
| 46 | + |
21 | 47 | /** |
22 | 48 | * Summary of benchpress_create_snapshots_table |
23 | 49 | * |
@@ -162,6 +188,7 @@ function benchpress_render_settings_page() { |
162 | 188 | update_option( 'benchpress_tax_terms', sanitize_text_field( $_POST['benchpress_tax_terms'] ) ); |
163 | 189 | update_option( 'benchpress_orderby', sanitize_text_field( $_POST['benchpress_orderby'] ) ); |
164 | 190 | update_option( 'benchpress_order', in_array( $_POST['benchpress_order'], ['ASC', 'DESC'] ) ? $_POST['benchpress_order'] : 'ASC' ); |
| 191 | + update_option( 'benchpress_enable_transient_vs_query', isset( $_POST['benchpress_enable_transient_vs_query'] ) ? 1 : 0 ); |
165 | 192 | } |
166 | 193 |
|
167 | 194 | // Retrieve saved settings. |
@@ -198,6 +225,9 @@ function benchpress_render_settings_page() { |
198 | 225 | echo '<td><input type="number" name="benchpress_loop_count" value="' . esc_attr( $loop_count ) . '" /></td></tr>'; |
199 | 226 | echo '<tr><th>' . esc_html__( 'Enable Switch vs Match Benchmark', 'benchpress' ) . '</th>'; |
200 | 227 | echo '<td><input type="checkbox" name="benchpress_enable_switch_vs_match" ' . checked( 1, $enable_switch_vs_match, false ) . ' /></td></tr>'; |
| 228 | + echo '<tr><th>' . esc_html__( 'Enable Transient vs Direct Query Benchmark', 'benchpress' ) . '</th>'; |
| 229 | + echo '<td><input type="checkbox" name="benchpress_enable_transient_vs_query" ' . checked( 1, get_option( 'benchpress_enable_transient_vs_query', 1 ), false ) . ' /></td></tr>'; |
| 230 | + |
201 | 231 | echo '</table>'; |
202 | 232 |
|
203 | 233 | // WP_Query Customization Section. |
@@ -465,17 +495,17 @@ function benchpress_download_snapshots() { |
465 | 495 | wp_die( esc_html__( 'No snapshots available to download.', 'benchpress' ) ); |
466 | 496 | } |
467 | 497 |
|
468 | | - // Set headers to initiate a file download. |
| 498 | + // Set headers to initiate file download. |
469 | 499 | header( 'Content-Type: text/csv; charset=utf-8' ); |
470 | | - header( 'Content-Disposition: attachment; filename=snapshots.csv' ); |
| 500 | + header( 'Content-Disposition: attachment; filename=' . sanitize_title( get_bloginfo( 'name' ) ) . '-benchpress-' . date( 'Y-m-d_H-i-s' ) . '.csv' ); |
471 | 501 |
|
472 | | - // Open output stream for writing CSV data. |
| 502 | + // Open output stream for CSV. |
473 | 503 | $output = fopen( 'php://output', 'w' ); |
474 | 504 |
|
475 | 505 | // Add CSV headers. |
476 | 506 | fputcsv( $output, [ 'ID', 'Date', 'Benchmark Name', 'Execution Time', 'Description' ] ); |
477 | 507 |
|
478 | | - // Populate CSV with snapshot data. |
| 508 | + // Loop through each snapshot and format data. |
479 | 509 | foreach ( $snapshots as $snapshot ) { |
480 | 510 | $snapshot_data = json_decode( $snapshot['snapshot_data'], true ); |
481 | 511 | foreach ( $snapshot_data as $benchmark ) { |
|
0 commit comments