Skip to content

Commit

Permalink
[debug-page] [code] Enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
fajardoleo committed Dec 5, 2024
1 parent 5a8a3de commit 0857469
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 22 deletions.
2 changes: 1 addition & 1 deletion assets/css/admin/debug.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions includes/class-fs-logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,10 @@ private static function write_csv_to_filesystem( $file_path, $query_results ) {
WP_Filesystem();
global $wp_filesystem;

if ( ! $wp_filesystem->is_writable( dirname( $file_path ) ) ) {
return false;
}

$content = '';

foreach ( $query_results as $row ) {
Expand Down
32 changes: 12 additions & 20 deletions templates/debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,8 @@

$auto_off_timestamp = wp_next_scheduled( 'fs_debug_turn_off_logging_hook' ) * 1000;

function fs_get_debug_table_toggle_button( $open = false ) {
return '
<button class="fs-debug-table-toggle-button" aria-expanded="' . ( $open ? 'true' : 'false' ) . '">
<span class="fs-debug-table-toggle-icon">' . ( $open ? '' : '' ) . '</span>
</button>';
}
$debug_table_toggle_button_template_vars = array( 'is_open' => true );
$debug_table_toggle_button = fs_get_template( 'debug/partials/toggle-button.php', $debug_table_toggle_button_template_vars );
?>
<h1><?php echo fs_text_inline( 'Freemius Debug' ) . ' - ' . fs_text_inline( 'SDK' ) . ' v.' . $fs_active_plugins->newest->version ?></h1>
<div>
Expand Down Expand Up @@ -296,7 +292,7 @@ function stopCountdownManually() {
</tbody>
</table>
<h2>
<?php echo fs_get_debug_table_toggle_button( true ) ?>
<?php echo $debug_table_toggle_button ?>
<?php fs_esc_html_echo_x_inline( 'SDK Versions', 'as software development kit versions', 'sdk-versions' ) ?>
</h2>
<table id="fs_sdks" class="widefat">
Expand Down Expand Up @@ -334,7 +330,7 @@ function stopCountdownManually() {
<?php $modules = fs_get_entities( $fs_options->get_option( $module_type . 's' ), FS_Plugin::get_class_name() ) ?>
<?php if ( is_array( $modules ) && count( $modules ) > 0 ) : ?>
<h2>
<?php echo fs_get_debug_table_toggle_button( true ) ?>
<?php echo $debug_table_toggle_button ?>
<?php echo esc_html( ( WP_FS__MODULE_TYPE_PLUGIN == $module_type ) ? fs_text_inline( 'Plugins',
'plugins' ) : fs_text_inline( 'Themes', 'themes' ) ) ?>
</h2>
Expand Down Expand Up @@ -471,7 +467,7 @@ function stopCountdownManually() {
?>
<?php if ( is_array( $sites_map ) && count( $sites_map ) > 0 ) : ?>
<h2>
<?php echo fs_get_debug_table_toggle_button( true ) ?>
<?php echo $debug_table_toggle_button ?>
<?php echo esc_html( sprintf(
/* translators: %s: 'plugin' or 'theme' */
fs_text_inline( '%s Installs', 'module-installs' ),
Expand Down Expand Up @@ -589,7 +585,7 @@ function stopCountdownManually() {
?>
<?php foreach ( $addons as $plugin_id => $plugin_addons ) : ?>
<h2>
<?php echo fs_get_debug_table_toggle_button( true ) ?>
<?php echo $debug_table_toggle_button ?>
<?php echo esc_html( sprintf( fs_text_inline( 'Add Ons of module %s', 'addons-of-x' ), $plugin_id ) ) ?>
</h2>
<table id="fs_addons" class="widefat">
Expand Down Expand Up @@ -651,7 +647,7 @@ function stopCountdownManually() {
?>
<?php if ( is_array( $users ) && 0 < count( $users ) ) : ?>
<h2>
<?php echo fs_get_debug_table_toggle_button( true ) ?>
<?php echo $debug_table_toggle_button ?>
<?php fs_esc_html_echo_inline( 'Users' ) ?>
</h2>
<table id="fs_users" class="widefat">
Expand Down Expand Up @@ -703,7 +699,7 @@ function stopCountdownManually() {
$licenses = $VARS[ $module_type . '_licenses' ] ?>
<?php if ( is_array( $licenses ) && count( $licenses ) > 0 ) : ?>
<h2>
<?php echo fs_get_debug_table_toggle_button( true ) ?>
<?php echo $debug_table_toggle_button ?>
<?php echo esc_html( sprintf( fs_text_inline( '%s Licenses', 'module-licenses' ), ( WP_FS__MODULE_TYPE_PLUGIN === $module_type ? fs_text_inline( 'Plugin', 'plugin' ) : fs_text_inline( 'Theme', 'theme' ) ) ) ) ?>
</h2>
<table id="fs_<?php echo $module_type ?>_licenses" class="widefat">
Expand Down Expand Up @@ -745,11 +741,7 @@ function stopCountdownManually() {
<?php endif ?>
<?php endforeach ?>
<?php
$page_params = array(
'title_tag' => 'h2',
'toggle_button' => fs_get_debug_table_toggle_button(),
);

$page_params = array( 'title_tag' => 'h2' );
fs_require_template( 'debug/scheduled-crons.php', $page_params );
?>
<?php if ( FS_Logger::is_storage_logging_on() ) : ?>
Expand Down Expand Up @@ -938,9 +930,9 @@ class="dashicons dashicons-download"></i> <?php fs_esc_html_echo_inline( 'Downlo
button.attr( 'aria-expanded', isExpanded );
button.find( '.fs-debug-table-toggle-icon' ).text( isExpanded ? '▼' : '▶' );
table.css( {
display : isExpanded ? 'table' : 'block',
borderWidth: isExpanded ? '1px' : '0',
maxHeight : isExpanded ? 'auto' : '0'
display : isExpanded ? 'table' : 'block',
borderBottomWidth: isExpanded ? '1px' : '0',
maxHeight : isExpanded ? 'auto' : '0',
} );
};

Expand Down
21 changes: 21 additions & 0 deletions templates/debug/partials/toggle-button.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
/**
* @package Freemius
* @copyright Copyright (c) 2015, Freemius, Inc.
* @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
* @since 2.10.1
*/

if ( ! defined( 'ABSPATH' ) ) {
exit;
}

/**
* @var array $VARS
* @var bool $is_open
*/
$is_open = $VARS['is_open'];
?>
<button class="fs-debug-table-toggle-button" aria-expanded="<?php echo $is_open ? 'true' : 'false' ?>">
<span class="fs-debug-table-toggle-icon"><?php echo $is_open ? '' : '' ?></span>
</button>
5 changes: 4 additions & 1 deletion templates/debug/scheduled-crons.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@
$sec_text = fs_text_x_inline( 'sec', 'seconds' );
?>
<?php echo $title_tag_open; ?>
<?php echo $toggle_button; ?>
<?php
$debug_table_toggle_button_template_vars = array( 'is_open' => false );
$debug_table_toggle_button = fs_require_template( 'debug/partials/toggle-button.php', $debug_table_toggle_button_template_vars );
?>
<?php fs_esc_html_echo_inline('Scheduled Crons') ?>
<?php echo $title_tag_close; ?>
<table class="widefat">
Expand Down

0 comments on commit 0857469

Please sign in to comment.