| 1 |
<?php |
| 2 |
/** |
| 3 |
* Represents the view for the administration dashboard. |
| 4 |
* |
| 5 |
* This includes the header, options, and other information that should provide |
| 6 |
* the User Interface to the end user. |
| 7 |
*/ |
| 8 |
|
| 9 |
// phpcs:disable WordPress.NamingConventions, VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable -- Variables are not global. |
| 10 |
$sidebar_tab_url = add_query_arg( |
| 11 |
[ |
| 12 |
'page' => 'wp-widget-disable', |
| 13 |
'tab' => 'sidebar', |
| 14 |
] |
| 15 |
); |
| 16 |
|
| 17 |
$dashboard_tab_url = add_query_arg( |
| 18 |
[ |
| 19 |
'page' => 'wp-widget-disable', |
| 20 |
'tab' => 'dashboard', |
| 21 |
] |
| 22 |
); |
| 23 |
|
| 24 |
$active_tab = $this->sidebar_widgets_option; |
| 25 |
|
| 26 |
// phpcs:ignore WordPress.Security.NonceVerification |
| 27 |
if ( is_network_admin() || ( isset( $_GET['tab'] ) && 'dashboard' === $_GET['tab'] ) ) { |
| 28 |
$active_tab = $this->dashboard_widgets_option; |
| 29 |
} |
| 30 |
|
| 31 |
$form_action = is_network_admin() ? network_admin_url( 'edit.php?action=wp-widget-disable' ) : admin_url( 'options.php' ); |
| 32 |
?> |
| 33 |
|
| 34 |
<div class="wrap"> |
| 35 |
<h1><?php echo esc_html( get_admin_page_title() ); ?></h1> |
| 36 |
|
| 37 |
<?php |
| 38 |
if ( ! is_network_admin() ) : |
| 39 |
?> |
| 40 |
<h2 class="nav-tab-wrapper"> |
| 41 |
<a href="<?php echo esc_url( $sidebar_tab_url ); ?>" class="nav-tab <?php echo $this->sidebar_widgets_option === $active_tab ? 'nav-tab-active' : ''; ?>"> |
| 42 |
<?php _e( 'Sidebar Widgets', 'wp-widget-disable' ); ?> |
| 43 |
</a> |
| 44 |
<a href="<?php echo esc_url( $dashboard_tab_url ); ?>" class="nav-tab <?php echo $this->dashboard_widgets_option === $active_tab ? 'nav-tab-active' : ''; ?>"> |
| 45 |
<?php _e( 'Dashboard Widgets', 'wp-widget-disable' ); ?> |
| 46 |
</a> |
| 47 |
</h2> |
| 48 |
<?php endif; ?> |
| 49 |
|
| 50 |
<form method="post" action="<?php echo esc_url( $form_action ); ?>" class="wp-widget-disable-form"> |
| 51 |
<?php |
| 52 |
settings_fields( $active_tab ); |
| 53 |
do_settings_sections( $active_tab ); |
| 54 |
submit_button(); |
| 55 |
?> |
| 56 |
</form> |
| 57 |
</div> |
| 58 |
|
| 59 |
<script> |
| 60 |
const toggleButtons = document.querySelectorAll( '#wp_widget_disable_select_all, #wp_widget_disable_deselect_all' ); |
| 61 |
toggleButtons.forEach( function( button ) { |
| 62 |
button.addEventListener( 'click', function() { |
| 63 |
const isChecked = 'wp_widget_disable_select_all' === button.id; |
| 64 |
const inputs = button.closest( 'td' ).querySelectorAll( 'input' ); |
| 65 |
inputs.forEach( function( input ) { |
| 66 |
input.checked = isChecked; |
| 67 |
} ); |
| 68 |
} ); |
| 69 |
} ); |
| 70 |
</script> |
| 71 |
|