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

[PR] Stats / Charts broken when disk_total_space and/or disk_free_space are disabled via PHP #312

Merged
merged 3 commits into from
Apr 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .gitchange
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
1460135613
49dd4154d8f5d3b70691c8e3f52a063a49137fb7:57be33556df067.43016776
853d9120b42cf4f2eabe2f35ea18a6ace7170ea6:588bb5682f4739.12912408
1491589996
12 changes: 7 additions & 5 deletions src/includes/classes/MenuPageStats.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,13 @@ public function __construct()
echo ' <div class="-dir">'.esc_html(basename(WP_CONTENT_DIR).'/'.$this->plugin->options['base_dir'].'/*').'</div>'."\n";
echo ' </div>'."\n";

echo ' <div class="-disk">'."\n";
echo ' <div class="-heading">'.__('Current Disk Health', SLUG_TD).'</div>'."\n";
echo ' <div class="-size"><span class="-value">&nbsp;</span> '.__('total capacity', SLUG_TD).'</div>'."\n";
echo ' <div class="-free"><span class="-value">&nbsp;</span> '.__('available', SLUG_TD).'</div>'."\n";
echo ' </div>'."\n";
if ($this->plugin->functionIsPossible('disk_total_space') && $this->plugin->functionIsPossible('disk_free_space')) {
echo ' <div class="-disk">' . "\n";
echo ' <div class="-heading">' . __('Current Disk Health', SLUG_TD) . '</div>' . "\n";
echo ' <div class="-size"><span class="-value">&nbsp;</span> ' . __('total capacity', SLUG_TD) . '</div>' . "\n";
echo ' <div class="-free"><span class="-value">&nbsp;</span> ' . __('available', SLUG_TD) . '</div>' . "\n";
echo ' </div>' . "\n";
}

echo ' <div class="-system">'."\n";
echo ' <div class="-heading">'.__('Current System Health', SLUG_TD).'</div>'."\n";
Expand Down
88 changes: 58 additions & 30 deletions src/includes/traits/Plugin/AdminBarUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,36 +240,64 @@ public function adminBarMenu(\WP_Admin_Bar &$wp_admin_bar)
],
]
);
$wp_admin_bar->add_menu(
[
'parent' => GLOBAL_NS.'-stats-wrapper',
'id' => GLOBAL_NS.'-stats-container',
'title' => '<div class="-refreshing"></div>'.
'<canvas class="-chart-a"></canvas>'.
// '<canvas class="-chart-b"></canvas>'.
'<div class="-totals">'.
' <div class="-heading">'.__('Current Cache Totals', SLUG_TD).'</div>'.
' <div class="-files"><span class="-value">&nbsp;</span></div>'.
' <div class="-size"><span class="-value">&nbsp;</span></div>'.
' <div class="-dir">'.esc_html(basename(WP_CONTENT_DIR).'/'.$this->options['base_dir'].'/*').'</div>'.
'</div>'.
'<div class="-disk">'.
' <div class="-heading">'.__('Current Disk Health', SLUG_TD).'</div>'.
' <div class="-size"><span class="-value">&nbsp;</span> '.__('total capacity', SLUG_TD).'</div>'.
' <div class="-free"><span class="-value">&nbsp;</span> '.__('available', SLUG_TD).'</div>'.
'</div>'.
(current_user_can($this->cap) ?
'<div class="-more-info">'.
' <a href="'.esc_attr(add_query_arg(urlencode_deep(['page' => GLOBAL_NS.'-stats']), network_admin_url('/admin.php'))).'">'.__('More Info', SLUG_TD).'</a>'.
'</div>'
: '').
'<div class="-spacer"></div>',
'meta' => [
'class' => '-container',
'tabindex' => -1,
],
]
);
if ($this->plugin->functionIsPossible('disk_total_space') && $this->plugin->functionIsPossible('disk_free_space')) {
$wp_admin_bar->add_menu(
[
'parent' => GLOBAL_NS.'-stats-wrapper',
'id' => GLOBAL_NS.'-stats-container',
'title' => '<div class="-refreshing"></div>'.
'<canvas class="-chart-a"></canvas>'.
// '<canvas class="-chart-b"></canvas>'.
'<div class="-totals">'.
' <div class="-heading">'.__('Current Cache Totals', SLUG_TD).'</div>'.
' <div class="-files"><span class="-value">&nbsp;</span></div>'.
' <div class="-size"><span class="-value">&nbsp;</span></div>'.
' <div class="-dir">'.esc_html(basename(WP_CONTENT_DIR).'/'.$this->options['base_dir'].'/*').'</div>'.
'</div>'.
'<div class="-disk">'.
' <div class="-heading">'.__('Current Disk Health', SLUG_TD).'</div>'.
' <div class="-size"><span class="-value">&nbsp;</span> '.__('total capacity', SLUG_TD).'</div>'.
' <div class="-free"><span class="-value">&nbsp;</span> '.__('available', SLUG_TD).'</div>'.
'</div>'.
(current_user_can($this->cap) ?
'<div class="-more-info">'.
' <a href="'.esc_attr(add_query_arg(urlencode_deep(['page' => GLOBAL_NS.'-stats']), network_admin_url('/admin.php'))).'">'.__('More Info', SLUG_TD).'</a>'.
'</div>'
: '').
'<div class="-spacer"></div>',
'meta' => [
'class' => '-container',
'tabindex' => -1,
],
]
);
} else {
$wp_admin_bar->add_menu(
[
'parent' => GLOBAL_NS.'-stats-wrapper',
'id' => GLOBAL_NS.'-stats-container',
'title' => '<div class="-refreshing"></div>'.
'<canvas class="-chart-a"></canvas>'.
// '<canvas class="-chart-b"></canvas>'.
'<div class="-totals">'.
' <div class="-heading">'.__('Current Cache Totals', SLUG_TD).'</div>'.
' <div class="-files"><span class="-value">&nbsp;</span></div>'.
' <div class="-size"><span class="-value">&nbsp;</span></div>'.
' <div class="-dir">'.esc_html(basename(WP_CONTENT_DIR).'/'.$this->options['base_dir'].'/*').'</div>'.
'</div>'.
(current_user_can($this->cap) ?
'<div class="-more-info">'.
' <a href="'.esc_attr(add_query_arg(urlencode_deep(['page' => GLOBAL_NS.'-stats']), network_admin_url('/admin.php'))).'">'.__('More Info', SLUG_TD).'</a>'.
'</div>'
: '').
'<div class="-spacer"></div>',
'meta' => [
'class' => '-container',
'tabindex' => -1,
],
]
);
}
}
/*[/pro]*/
}
Expand Down
9 changes: 7 additions & 2 deletions src/includes/traits/Shared/FsUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,14 @@ public function getDirRegexStats($dir, $regex = '', $include_paths = false, $che
unset($_resource, $_resource_sub_path, $_resource_basename); // Housekeeping.

if ($check_disk) { // Check disk also?
$stats['disk_total_space'] = disk_total_space($dir);
$stats['disk_free_space'] = disk_free_space($dir);
if ($this->functionIsPossible('disk_total_space')) {
$stats['disk_total_space'] = disk_total_space($dir);
}
if ($this->functionIsPossible('disk_free_space')) {
$stats['disk_free_space'] = disk_free_space($dir);
}
}

return $stats;
}

Expand Down