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

Settings page updates #33

Merged
merged 9 commits into from
May 19, 2022
30 changes: 20 additions & 10 deletions includes/classes/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ public function __construct() {
public function fields() {
add_settings_section(
'debug',
__( 'Debug', 'debug-bar-for-sophi' ),
__( 'Debug Bar Settings', 'debug-bar-for-sophi' ),
'',
SETTINGS_GROUP
);

add_settings_field(
'enable_debug_log',
__( 'Debug log', 'debug-bar-for-sophi' ),
__( 'Debug logging', 'debug-bar-for-sophi' ),
array( $this, 'render_debug_log_field' ),
SETTINGS_GROUP,
'debug'
Expand All @@ -65,9 +65,17 @@ public function fields() {
* @return void
*/
public function logs_menu() {
$settings = $this->get_settings();
$is_writable = wp_is_writable( SOPHI_DEBUG_BAR_LOG_PATH );

// Don't add link if logs are disabled or directory not writable.
if ( 'yes' !== $settings['enable_debug_log'] || ! $is_writable ) {
return;
}

add_management_page(
__( 'Sophi Logs', 'debug-bar-for-sophi' ),
__( 'Sophi Logs', 'debug-bar-for-sophi' ),
__( 'Sophi.io Logs', 'debug-bar-for-sophi' ),
__( 'Sophi.io Logs', 'debug-bar-for-sophi' ),
'manage_options',
'sophi-logs',
array( $this, 'logs_page' )
Expand Down Expand Up @@ -110,7 +118,7 @@ public function logs_page() {

?>
<div class="wrap">
<h1><?php esc_html_e( 'Sophi Logs' ); ?></h1>
<h1><?php esc_html_e( 'Sophi.io Logs', 'debug-bar-for-sophi' ); ?></h1>
<form method="post" action="">
<select name="date" id="sophi_logs_date">
<?php foreach ( $dates as $date ) : ?>
Expand Down Expand Up @@ -169,10 +177,16 @@ public function render_debug_log_field() {
<?php checked( $is_writable && 'yes' === $settings['enable_debug_log'] ); ?>
<?php disabled( ! $is_writable ); ?>
/>
<?php esc_html_e( 'Enable debug log', 'debug-bar-for-sophi' ); ?>
<?php esc_html_e( 'Display verbose logging output from Sophi Authentication, Sophi API requests, and CMS publishing events', 'debug-bar-for-sophi' ); ?>
</label>
<?php

if ( $is_writable && 'yes' === $settings['enable_debug_log'] ) {
echo '<p class="description">';
echo '<a href="tools.php?page=sophi-logs">' . esc_html__( 'View Logs', 'debug-bar-for-sophi' ) . '</a>';
echo '</p>';
}

if ( ! $is_writable ) {
echo '<p class="description">';
echo wp_kses_post(
Expand All @@ -183,10 +197,6 @@ public function render_debug_log_field() {
)
);
echo '</p>';
} else {
echo '<p class="description">';
echo '<a href="tools.php?page=sophi-logs">' . esc_html__( 'View Logs', 'debug-bar-for-sophi' ) . '</a>';
echo '</p>';
}
}

Expand Down