Split style and css code

This commit is contained in:
2026-01-29 22:00:24 +01:00
parent 3b943a4a72
commit 87da77584f
3 changed files with 152 additions and 37 deletions
+39
View File
@@ -0,0 +1,39 @@
/* Styles for WordPress Activity Stats Plugin - Admin Area */
/* Infografika */
.mystat-infographic-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 20px;
}
.mystat-infographic-card {
background: #fff;
border: 1px solid #e0e0e0;
border-radius: 5px;
padding: 15px;
text-align: center;
box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}
.mystat-infographic-card h3 {
margin-top: 0;
color: #555;
font-size: 1.1em;
}
.mystat-infographic-card p {
font-size: 1.8em;
font-weight: bold;
color: #333;
margin-bottom: 0;
}
/* Kontener dla szczegółów aktywności */
#mystat-details-container {
display: flex;
flex-wrap: wrap;
gap: 2%;
}
/* Szczegóły aktywności */
.mystat-details-col {
flex: 1 1 48%; /* Pozwala na elastyczne dopasowanie, z bazową szerokością 48% */
min-width: 300px; /* Zapobiega zbytniemu ściskaniu kolumn na mniejszych ekranach */
}
+64
View File
@@ -0,0 +1,64 @@
/* Styles for WordPress Activity Stats Plugin - Frontend Shortcodes */
/* Shortcode [moje_statystyki] */
.mystats-shortcode-container table {
width: 100%;
border-collapse: collapse;
margin-bottom: 2em;
}
.mystats-shortcode-container th,
.mystats-shortcode-container td {
padding: 8px 12px;
border: 1px solid #ddd;
text-align: left;
}
.mystats-shortcode-container th {
background-color: #f4f4f4;
}
.mystats-activity-table td:nth-child(4),
.mystats-activity-table td:nth-child(5) {
text-align: right;
}
/* Shortcode [moje_statystyki_wpis] */
.mystat-single-activity-shortcode {
border: 1px solid #eee;
padding: 15px;
margin-bottom: 1.5em;
border-radius: 5px;
background: #f9f9f9;
}
.mystat-single-activity-shortcode h4 {
margin-top: 0;
}
.mystat-single-activity-shortcode p em {
color: #777;
font-size: 0.9em;
}
.mystat-single-columns-container {
display: flex;
flex-wrap: wrap;
gap: 30px;
margin-bottom: 15px;
}
.mystat-single-col {
flex: 1;
min-width: 240px;
}
.mystat-single-summary-table {
width: 100%;
border-collapse: collapse;
}
.mystat-single-summary-table th,
.mystat-single-summary-table td {
padding: 4px 0;
border: none;
text-align: left;
vertical-align: top;
}
.mystat-single-summary-table th {
font-weight: bold;
padding-right: 1em;
white-space: nowrap;
width: 1%;
}
+49 -37
View File
@@ -107,6 +107,9 @@ function mystat_activate() {
} }
// --- 2. MENU ADMINA I DASHBOARD --- // --- 2. MENU ADMINA I DASHBOARD ---
$mystat_plugin_hooks = [];
add_action( 'admin_menu', 'mystat_add_admin_menu' ); add_action( 'admin_menu', 'mystat_add_admin_menu' );
/** /**
@@ -118,6 +121,21 @@ function mystat_admin_init_setup() {
} }
add_action( 'admin_init', 'mystat_admin_init_setup' ); add_action( 'admin_init', 'mystat_admin_init_setup' );
/**
* Enqueue admin-specific CSS.
*
* @param string $hook The current admin page hook.
*/
function mystat_enqueue_admin_styles( $hook ) {
global $mystat_plugin_hooks;
if ( in_array( $hook, $mystat_plugin_hooks, true ) ) {
$plugin_version = '1.0'; // You can use filemtime() for cache-busting in development
wp_enqueue_style( 'mystat-admin-styles', plugin_dir_url( __FILE__ ) . 'assets/css/admin.css', [], $plugin_version );
}
}
add_action( 'admin_enqueue_scripts', 'mystat_enqueue_admin_styles' );
/** /**
* Add GPX support to WordPress Media Library. * Add GPX support to WordPress Media Library.
* *
@@ -148,7 +166,9 @@ function mystat_fix_gpx_upload_permission( $data, $file, $filename, $mimes ) {
} }
function mystat_add_admin_menu() { function mystat_add_admin_menu() {
add_menu_page( global $mystat_plugin_hooks;
$mystat_plugin_hooks[] = add_menu_page(
'Moje Statystyki', // Tytuł strony 'Moje Statystyki', // Tytuł strony
'Statystyki', // Tytuł w menu 'Statystyki', // Tytuł w menu
'manage_options', // Wymagane uprawnienia 'manage_options', // Wymagane uprawnienia
@@ -158,7 +178,7 @@ function mystat_add_admin_menu() {
6 // Pozycja 6 // Pozycja
); );
add_submenu_page( $mystat_plugin_hooks[] = add_submenu_page(
'moje-statystyki', // Slug rodzica 'moje-statystyki', // Slug rodzica
'Dodaj Nowy Trening', // Tytuł strony 'Dodaj Nowy Trening', // Tytuł strony
'Nowy trening', // Tytuł w podmenu 'Nowy trening', // Tytuł w podmenu
@@ -167,7 +187,7 @@ function mystat_add_admin_menu() {
'mystat_add_new_page' // Funkcja renderująca stronę dodawania 'mystat_add_new_page' // Funkcja renderująca stronę dodawania
); );
add_submenu_page( $mystat_plugin_hooks[] = add_submenu_page(
'moje-statystyki', 'moje-statystyki',
'Typy Wydarzeń', 'Typy Wydarzeń',
'Typy wydarzeń', 'Typy wydarzeń',
@@ -176,7 +196,7 @@ function mystat_add_admin_menu() {
'mystat_event_types_page' 'mystat_event_types_page'
); );
add_submenu_page( $mystat_plugin_hooks[] = add_submenu_page(
'moje-statystyki', 'moje-statystyki',
'Sprzęt', 'Sprzęt',
'Sprzęt', 'Sprzęt',
@@ -185,7 +205,7 @@ function mystat_add_admin_menu() {
'mystat_equipment_page' 'mystat_equipment_page'
); );
add_submenu_page( $mystat_plugin_hooks[] = add_submenu_page(
null, // Ukryta strona, nie pojawia się w menu null, // Ukryta strona, nie pojawia się w menu
'Szczegóły Treningu', // Tytuł strony 'Szczegóły Treningu', // Tytuł strony
'Szczegóły Treningu', // Tytuł w menu (nieistotny) 'Szczegóły Treningu', // Tytuł w menu (nieistotny)
@@ -194,7 +214,7 @@ function mystat_add_admin_menu() {
'mystat_view_activity_page' // Funkcja renderująca 'mystat_view_activity_page' // Funkcja renderująca
); );
add_submenu_page( $mystat_plugin_hooks[] = add_submenu_page(
null, // Ukryta strona null, // Ukryta strona
'Edytuj Trening', // Tytuł strony 'Edytuj Trening', // Tytuł strony
'Edytuj Trening', // Tytuł w menu (nieistotny) 'Edytuj Trening', // Tytuł w menu (nieistotny)
@@ -203,7 +223,7 @@ function mystat_add_admin_menu() {
'mystat_edit_activity_page' // Funkcja renderująca 'mystat_edit_activity_page' // Funkcja renderująca
); );
add_submenu_page( $mystat_plugin_hooks[] = add_submenu_page(
'moje-statystyki', // Slug rodzica 'moje-statystyki', // Slug rodzica
'Podsumowanie Roczne', // Tytuł strony 'Podsumowanie Roczne', // Tytuł strony
'Podsumowanie Roczne', // Tytuł w podmenu 'Podsumowanie Roczne', // Tytuł w podmenu
@@ -212,7 +232,7 @@ function mystat_add_admin_menu() {
'mystat_yearly_summary_page'// Funkcja renderująca 'mystat_yearly_summary_page'// Funkcja renderująca
); );
add_submenu_page( $mystat_plugin_hooks[] = add_submenu_page(
'moje-statystyki', // Slug rodzica 'moje-statystyki', // Slug rodzica
'Infografika', // Tytuł strony 'Infografika', // Tytuł strony
'Infografika', // Tytuł w podmenu 'Infografika', // Tytuł w podmenu
@@ -221,7 +241,7 @@ function mystat_add_admin_menu() {
'mystat_infographic_page' // Funkcja renderująca 'mystat_infographic_page' // Funkcja renderująca
); );
add_submenu_page( $mystat_plugin_hooks[] = add_submenu_page(
'moje-statystyki', // Slug rodzica 'moje-statystyki', // Slug rodzica
'Import CSV', // Tytuł strony 'Import CSV', // Tytuł strony
'Import CSV', // Tytuł w podmenu 'Import CSV', // Tytuł w podmenu
@@ -877,12 +897,6 @@ function mystat_infographic_page() {
</div> </div>
</div> </div>
</div> </div>
<style>
.mystat-infographic-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 20px; }
.mystat-infographic-card { background: #fff; border: 1px solid #e0e0e0; border-radius: 5px; padding: 15px; text-align: center; box-shadow: 0 2px 4px rgba(0,0,0,0.05); }
.mystat-infographic-card h3 { margin-top: 0; color: #555; font-size: 1.1em; }
.mystat-infographic-card p { font-size: 1.8em; font-weight: bold; color: #333; margin-bottom: 0; }
</style>
<?php <?php
} }
@@ -1320,7 +1334,7 @@ function mystat_view_activity_page() {
<div class="postbox" style="margin-top: 20px;"> <div class="postbox" style="margin-top: 20px;">
<div class="postbox-header"><h2 class="hndle">Podsumowanie</h2></div> <div class="postbox-header"><h2 class="hndle">Podsumowanie</h2></div>
<div class="inside"> <div class="inside">
<div id="mystat-details-container" class="wp-clearfix"> <div id="mystat-details-container">
<div class="mystat-details-col"> <div class="mystat-details-col">
<h3>Główne dane</h3> <h3>Główne dane</h3>
<table class="form-table"> <table class="form-table">
@@ -1384,11 +1398,6 @@ function mystat_view_activity_page() {
</div> </div>
</div> </div>
</div> </div>
<style>
.mystat-details-col { float: left; width: 49%; }
.mystat-details-col:first-child { margin-right: 2%; }
@media screen and (max-width: 782px) { .mystat-details-col { float: none; width: 100%; margin-right: 0; } }
</style>
<?php <?php
} }
@@ -1808,6 +1817,21 @@ function mystat_render_history_table() {
<?php <?php
// --- 3. SHORTCODE DO WYŚWIETLANIA NA FRONCIE --- // --- 3. SHORTCODE DO WYŚWIETLANIA NA FRONCIE ---
/**
* Registers styles for frontend and enqueues them when shortcodes are used.
*/
function mystat_enqueue_frontend_assets() {
// Register the stylesheet. It will be enqueued by the shortcodes when needed.
$plugin_version = '1.0';
wp_register_style(
'mystat-frontend-styles',
plugin_dir_url( __FILE__ ) . 'assets/css/frontend.css',
[],
$plugin_version
);
}
add_action( 'wp_enqueue_scripts', 'mystat_enqueue_frontend_assets' );
/** /**
* Rejestruje shortcode [moje_statystyki]. * Rejestruje shortcode [moje_statystyki].
*/ */
@@ -1823,6 +1847,8 @@ add_action( 'init', 'mystat_register_shortcode' );
* @return string HTML do wyświetlenia. * @return string HTML do wyświetlenia.
*/ */
function mystat_shortcode_handler( $atts ) { function mystat_shortcode_handler( $atts ) {
wp_enqueue_style( 'mystat-frontend-styles' );
global $wpdb; global $wpdb;
// Ustawienie domyślnych atrybutów (bieżący rok i miesiąc) // Ustawienie domyślnych atrybutów (bieżący rok i miesiąc)
@@ -1914,12 +1940,6 @@ function mystat_shortcode_handler( $atts ) {
</tbody> </tbody>
</table> </table>
</div> </div>
<style>
.mystats-shortcode-container table { width: 100%; border-collapse: collapse; margin-bottom: 2em; }
.mystats-shortcode-container th, .mystats-shortcode-container td { padding: 8px 12px; border: 1px solid #ddd; text-align: left; }
.mystats-shortcode-container th { background-color: #f4f4f4; }
.mystats-activity-table td:nth-child(4), .mystats-activity-table td:nth-child(5) { text-align: right; }
</style>
<?php <?php
// Zwrócenie zawartości bufora // Zwrócenie zawartości bufora
return ob_get_clean(); return ob_get_clean();
@@ -1933,6 +1953,8 @@ function mystat_shortcode_handler( $atts ) {
* @return string HTML do wyświetlenia. * @return string HTML do wyświetlenia.
*/ */
function mystat_single_activity_shortcode_handler( $atts ) { function mystat_single_activity_shortcode_handler( $atts ) {
wp_enqueue_style( 'mystat-frontend-styles' );
global $wpdb; global $wpdb;
$atts = shortcode_atts( array( $atts = shortcode_atts( array(
@@ -2089,16 +2111,6 @@ function mystat_single_activity_shortcode_handler( $atts ) {
</div> </div>
<?php endif; ?> <?php endif; ?>
</div> </div>
<style>
.mystat-single-activity-shortcode { border: 1px solid #eee; padding: 15px; margin-bottom: 1.5em; border-radius: 5px; background: #f9f9f9; }
.mystat-single-activity-shortcode h4 { margin-top: 0; }
.mystat-single-activity-shortcode p em { color: #777; font-size: 0.9em; }
.mystat-single-columns-container { display: flex; flex-wrap: wrap; gap: 30px; margin-bottom: 15px; }
.mystat-single-col { flex: 1; min-width: 240px; }
.mystat-single-summary-table { width: 100%; border-collapse: collapse; }
.mystat-single-summary-table th, .mystat-single-summary-table td { padding: 4px 0; border: none; text-align: left; vertical-align: top; }
.mystat-single-summary-table th { font-weight: bold; padding-right: 1em; white-space: nowrap; width: 1%; }
</style>
<?php <?php
return ob_get_clean(); return ob_get_clean();
} }