Skip to content

Commit 057921b

Browse files
committed
📦 NEW: Added benchpress_admin_header helper function
1 parent 9d296af commit 057921b

2 files changed

Lines changed: 39 additions & 19 deletions

File tree

benchpress.php

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,8 @@ function benchpress_admin_menu() {
127127
* @return void
128128
*/
129129
function benchpress_render_snapshots_page() {
130-
echo '<div class="wrap"><h1>' . esc_html__( 'BenchPress Snapshots', 'benchpress' );
131-
echo ' <button id="benchpress-clear-snapshots-btn" class="button" style="margin-left: 10px;"><span class="dashicons dashicons-trash"></span> ' . esc_html__( 'Clear Snapshots', 'benchpress' ) . '</button>';
132-
echo ' <button id="benchpress-download-snapshots-btn" class="button" style="margin-left: 10px;"><span class="dashicons dashicons-download"></span> ' . esc_html__( 'Download Snapshots', 'benchpress' ) . '</button>';
133-
echo '</h1><hr />';
134-
echo '<p><a href="https://robertdevore.com/articles/benchpress/" target="_blank">' . esc_html__( 'Documentation', 'benchpress' ) . '</a> &middot; <a href="https://robertdevore.com/contact/" target="_blank">' . esc_html__( 'Support', 'benchpress' ) . '</a> &middot; <a href="https://robertdevore.com/wordpress-and-woocommerce-plugins/" target="_blank">' . esc_html__( 'More Plugins', 'benchpress' ) . '</a></p>';
130+
echo '<div class="wrap">';
131+
benchpress_admin_header( esc_html__( 'BenchPress Settings', 'benchpress' ) );
135132

136133
$table = new BenchPress_Snapshots_Table();
137134
$table->prepare_items();
@@ -163,12 +160,8 @@ function benchpress_render_page() {
163160
$benchpress_execution_time = microtime( true ) - $benchpress_start_time;
164161
$formatted_execution_time = number_format( $benchpress_execution_time, 4 );
165162

166-
echo '<div class="wrap"><h1>' . esc_html__( 'BenchPress', 'benchpress' );
167-
echo ' <button id="benchpress-snapshot-btn" class="button"><span class="dashicons dashicons-camera"></span> ' . esc_html__( 'Save Snapshot', 'benchpress' ) . '</button>';
168-
echo ' <button id="benchpress-refresh-btn" class="button"><span class="dashicons dashicons-update"></span> ' . esc_html__( 'Refresh Tests', 'benchpress' ) . '</button>';
169-
echo '</h1>';
170-
echo '<hr />';
171-
echo '<p><a href="https://robertdevore.com/benchpress-documentation/" target="_blank">' . esc_html__( 'Documentation', 'benchpress' ) . '</a> &middot; <a href="https://robertdevore.com/contact/" target="_blank">' . esc_html__( 'Support', 'benchpress' ) . '</a> &middot; <a href="https://robertdevore.com/wordpress-and-woocommerce-plugins/" target="_blank">' . esc_html__( 'More Plugins', 'benchpress' ) . '</a></p>';
163+
echo '<div class="wrap">';
164+
benchpress_admin_header( esc_html__( 'BenchPress', 'benchpress' ) );
172165

173166
echo '<div id="benchpress-results">';
174167
$table = new BenchPress_Table();
@@ -221,14 +214,8 @@ function benchpress_render_settings_page() {
221214
$post_types = get_post_types( [ 'public' => true ], 'objects' );
222215
$taxonomies = get_taxonomies( [ 'public' => true ], 'objects' );
223216

224-
echo '<div class="wrap"><h1>' . esc_html__( 'BenchPress Settings', 'benchpress' ) . '
225-
<a id="benchpress-support-btn" href="https://robertdevore.com/contact/" target="_blank" class="button button-alt" style="margin-left: 10px;">
226-
<span class="dashicons dashicons-format-chat" style="vertical-align: middle;"></span> ' . esc_html__( 'Support', 'benchpress' ) . '
227-
</a>
228-
<a id="benchpress-docs-btn" href="https://robertdevore.com/articles/benchpress/" target="_blank" class="button button-alt" style="margin-left: 5px;">
229-
<span class="dashicons dashicons-media-document" style="vertical-align: middle;"></span> ' . esc_html__( 'Documentation', 'benchpress' ) . '
230-
</a>
231-
</h1><hr />';
217+
echo '<div class="wrap">';
218+
benchpress_admin_header( esc_html__( 'BenchPress Settings', 'benchpress' ) );
232219
echo '<form method="post">';
233220
wp_nonce_field( 'benchpress_save_settings', 'benchpress_settings_nonce' );
234221

includes/helper-functions.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,3 +336,36 @@ function benchpress_benchmark_post_meta_access() {
336336
'description' => $description,
337337
];
338338
}
339+
340+
/**
341+
* Outputs the BenchPress admin header with support and documentation links.
342+
*
343+
* @param string $title The page title to display.
344+
*
345+
* @since 1.1.0
346+
* @return void
347+
*/
348+
function benchpress_admin_header( $title ) {
349+
// Output the title.
350+
echo '<h1>' . esc_html( $title );
351+
// Choose which buttons to display based on which title is passed.
352+
if ( esc_html__( 'BenchPress Snapshots', 'benchpress' ) == $title ) {
353+
echo ' <button id="benchpress-clear-snapshots-btn" class="button" style="margin-left: 10px;"><span class="dashicons dashicons-trash"></span> ' . esc_html__( 'Clear Snapshots', 'benchpress' ) . '</button>';
354+
echo ' <button id="benchpress-download-snapshots-btn" class="button" style="margin-left: 10px;"><span class="dashicons dashicons-download"></span> ' . esc_html__( 'Download Snapshots', 'benchpress' ) . '</button>';
355+
echo '</h1><hr />';
356+
} elseif ( esc_html__( 'BenchPress Settings', 'benchpress' ) == $title ) {
357+
echo '<a id="benchpress-support-btn" href="https://robertdevore.com/contact/" target="_blank" class="button button-alt" style="margin-left: 10px;">
358+
<span class="dashicons dashicons-format-chat" style="vertical-align: middle;"></span> ' . esc_html__( 'Support', 'benchpress' ) . '
359+
</a>
360+
<a id="benchpress-docs-btn" href="https://robertdevore.com/articles/benchpress/" target="_blank" class="button button-alt" style="margin-left: 5px;">
361+
<span class="dashicons dashicons-media-document" style="vertical-align: middle;"></span> ' . esc_html__( 'Documentation', 'benchpress' ) . '
362+
</a>
363+
</h1><hr />';
364+
} elseif ( esc_html__( 'BenchPress', 'benchpress' ) == $title ) {
365+
echo ' <button id="benchpress-snapshot-btn" class="button"><span class="dashicons dashicons-camera"></span> ' . esc_html__( 'Save Snapshot', 'benchpress' ) . '</button>';
366+
echo ' <button id="benchpress-refresh-btn" class="button"><span class="dashicons dashicons-update"></span> ' . esc_html__( 'Refresh Tests', 'benchpress' ) . '</button>';
367+
echo '</h1><hr />';
368+
}
369+
// Output the text links that display underneath the title.
370+
echo '<p><a href="https://robertdevore.com/benchpress-documentation/" target="_blank">' . esc_html__( 'Documentation', 'benchpress' ) . '</a> &middot; <a href="https://robertdevore.com/contact/" target="_blank">' . esc_html__( 'Support', 'benchpress' ) . '</a> &middot; <a href="https://robertdevore.com/wordpress-and-woocommerce-plugins/" target="_blank">' . esc_html__( 'More Plugins', 'benchpress' ) . '</a></p>';
371+
}

0 commit comments

Comments
 (0)