I came to add this feature request and I’m glad I found someone else who wants this. I have been using Sliced Invoices for years and I have always wished that the charts from the Reports page on Sliced could be visible on the Admin Home Dashboard.
I was debating whether or not to share this code snippet since I paid to have it written but someone else shared a snippet that really helped me out so this feels like paying it forward. This will add the widgets from the Sliced Invoices > Reports to the WordPress Dashboard as a custom widget if you add it to your functions.php
/*Sliced Invoices – Dashboard Widget*/
function enqueue_scripts_only_on_dashboard() {
// Get the current screen
$screen = get_current_screen();
// Check if the current screen is the dashboard
if ($screen && $screen->id === ‘dashboard’) {
// Enqueue your scripts here
$SlicedAdmin = new Sliced_Admin(‘sliced-invoices’, SLICED_VERSION);
wp_enqueue_script( ‘sliced-invoices-chart’, WP_PLUGIN_URL . ‘/sliced-invoices/admin/js/Chart.min.js’, array( ‘jquery’ ), SLICED_VERSION, false );
2 Comments. Leave new
I came to add this feature request and I’m glad I found someone else who wants this. I have been using Sliced Invoices for years and I have always wished that the charts from the Reports page on Sliced could be visible on the Admin Home Dashboard.
I was debating whether or not to share this code snippet since I paid to have it written but someone else shared a snippet that really helped me out so this feels like paying it forward. This will add the widgets from the Sliced Invoices > Reports to the WordPress Dashboard as a custom widget if you add it to your functions.php
/*Sliced Invoices – Dashboard Widget*/
function enqueue_scripts_only_on_dashboard() {
// Get the current screen
$screen = get_current_screen();
// Check if the current screen is the dashboard
if ($screen && $screen->id === ‘dashboard’) {
// Enqueue your scripts here
$SlicedAdmin = new Sliced_Admin(‘sliced-invoices’, SLICED_VERSION);
wp_enqueue_script( ‘sliced-invoices-chart’, WP_PLUGIN_URL . ‘/sliced-invoices/admin/js/Chart.min.js’, array( ‘jquery’ ), SLICED_VERSION, false );
$SlicedAdmin->enqueue_styles();
$SlicedAdmin->enqueue_scripts();
}
}
add_action(‘admin_enqueue_scripts’, ‘enqueue_scripts_only_on_dashboard’);
function custom_dashboard_invoice_report($slicedReports) {
echo ”;
$slicedReports->invoice_report();
echo ”;
}
function custom_dashboard_quote_report($slicedReports) {
echo ”;
$slicedReports->quote_report();
echo ”;
}
function custom_dashboard_quotes_and_invoices($slicedReports) {
echo ”;
$slicedReports->invoice_quote_chart();
echo ”;
}
function custom_dashboard_current_quote_statuses($slicedReports) {
echo ”;
$slicedReports->quote_status();
echo ”;
}
function custom_dashboard_current_invoice_statuses($slicedReports) {
echo ”;
$slicedReports->invoice_status();
echo ”;
}
function add_custom_dashboard_widget() {
$slicedReports = new Sliced_Reports();
wp_add_dashboard_widget(‘custom_dashboard_invoice_report’, ‘Invoice Report’, function() use ($slicedReports) {
custom_dashboard_invoice_report($slicedReports);
});
wp_add_dashboard_widget(‘custom_dashboard_quote_report’, ‘Quote Report’, function() use ($slicedReports) {
custom_dashboard_quote_report($slicedReports);
});
wp_add_dashboard_widget(‘custom_dashboard_quotes_and_invoices’, ‘Quotes and Invoices’, function() use ($slicedReports) {
custom_dashboard_quotes_and_invoices($slicedReports);
});
wp_add_dashboard_widget(‘custom_dashboard_current_quote_statuses’, ‘Current Quote Statuses’, function() use ($slicedReports) {
custom_dashboard_current_quote_statuses($slicedReports);
});
wp_add_dashboard_widget(‘custom_dashboard_current_invoice_statuses’, ‘Current Invoice Statuses’, function() use ($slicedReports) {
custom_dashboard_current_invoice_statuses($slicedReports);
});
}
add_action(‘wp_dashboard_setup’, ‘add_custom_dashboard_widget’);
add_filter(“admin_body_class”, function($classes) {
$current_screen = get_current_screen();
if($current_screen->base == “dashboard”) {
$classes .= ” sliced sliced-invoices_page_sliced_reports “;
}
return $classes;
});