From bcfd04e2e300682e3b6a93f5494502535252ec2c Mon Sep 17 00:00:00 2001 From: Andreas Brain Date: Sat, 2 Nov 2024 20:13:41 +0100 Subject: [PATCH] Add more recommended WP phpcs rules --- .phpcs.xml | 34 +++++++++++++++++++ src/includes/Admin/Initializer.php | 11 +++--- src/includes/Export/Page.php | 3 +- src/includes/Frontend.php | 2 +- src/includes/Settings/MainPage.php | 4 +-- src/includes/Types/IncidentType.php | 2 +- src/includes/Types/Vehicle.php | 23 ------------- src/includes/Widgets/RecentIncidents.php | 6 ++-- .../Widgets/RecentIncidentsFormatted.php | 6 ++-- tests/unit/Admin/InitializerTest.php | 6 ++-- 10 files changed, 56 insertions(+), 41 deletions(-) diff --git a/.phpcs.xml b/.phpcs.xml index f1b309a5..b55e986b 100644 --- a/.phpcs.xml +++ b/.phpcs.xml @@ -124,4 +124,38 @@ + + + + + + + + + + + + + + tests/ + + + + + + + + + + + + + + + + + + + + diff --git a/src/includes/Admin/Initializer.php b/src/includes/Admin/Initializer.php index 2e83dc87..59b9d5b4 100644 --- a/src/includes/Admin/Initializer.php +++ b/src/includes/Admin/Initializer.php @@ -107,7 +107,8 @@ public function enqueueEditScripts($hook) 'einsatzverwaltung-edit-script', Core::$scriptUrl . 'einsatzverwaltung-edit.js', array('jquery', 'jquery-ui-autocomplete', 'wp-i18n'), - Core::VERSION + Core::VERSION, + true ); wp_localize_script( 'einsatzverwaltung-edit-script', @@ -126,7 +127,8 @@ public function enqueueEditScripts($hook) 'einsatzverwaltung-settings-script', Core::$scriptUrl . 'einsatzverwaltung-settings.js', array('jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-ui-sortable'), - Core::VERSION + Core::VERSION, + true ); } elseif ('edit.php' == $hook) { $screen = get_current_screen(); @@ -135,7 +137,7 @@ public function enqueueEditScripts($hook) 'einsatzverwaltung-report-list-table', Core::$scriptUrl . 'report-list-table.js', false, - null, + Core::VERSION, true ); } @@ -169,7 +171,8 @@ public function enqueueEditScripts($hook) 'einsatzverwaltung-admin-script', Core::$scriptUrl . 'einsatzverwaltung-admin.js', array('wp-color-picker'), - Core::VERSION + Core::VERSION, + true ); wp_enqueue_style('wp-color-picker'); } diff --git a/src/includes/Export/Page.php b/src/includes/Export/Page.php index 1fe848e1..d4685d0f 100644 --- a/src/includes/Export/Page.php +++ b/src/includes/Export/Page.php @@ -48,7 +48,8 @@ public function enqueueAdminScripts($hook) 'einsatzverwaltung-export', Core::$scriptUrl . 'export.js', array('jquery'), - Core::VERSION + Core::VERSION, + true ); } diff --git a/src/includes/Frontend.php b/src/includes/Frontend.php index 65de4c31..7ece1402 100644 --- a/src/includes/Frontend.php +++ b/src/includes/Frontend.php @@ -100,7 +100,7 @@ public function enqueueStyleAndScripts() Core::VERSION ); wp_add_inline_style('einsatzverwaltung-frontend', ReportListRenderer::getDynamicCss()); - wp_enqueue_script('einsatzverwaltung-reportlist', Core::$scriptUrl . 'reportlist.js'); + wp_enqueue_script('einsatzverwaltung-reportlist', Core::$scriptUrl . 'reportlist.js', [], Core::VERSION, true); } /** diff --git a/src/includes/Settings/MainPage.php b/src/includes/Settings/MainPage.php index 1bc91682..1fdab15b 100644 --- a/src/includes/Settings/MainPage.php +++ b/src/includes/Settings/MainPage.php @@ -20,9 +20,9 @@ use function get_permalink; use function get_post_type_archive_link; use function home_url; -use function parse_url; use function str_replace; use function strpos; +use function wp_parse_url; use const PHP_URL_PATH; /** @@ -165,7 +165,7 @@ private function getConflictingPage(): ?WP_Post if (strpos($reportArchiveUrl, $homeUrl) === 0) { $reportArchivePath = str_replace($homeUrl, '', $reportArchiveUrl); } else { - $reportArchivePath = parse_url($reportArchiveUrl, PHP_URL_PATH); + $reportArchivePath = wp_parse_url($reportArchiveUrl, PHP_URL_PATH); } return get_page_by_path($reportArchivePath); diff --git a/src/includes/Types/IncidentType.php b/src/includes/Types/IncidentType.php index 088c5bc0..16299230 100644 --- a/src/includes/Types/IncidentType.php +++ b/src/includes/Types/IncidentType.php @@ -129,7 +129,7 @@ public function registerHooks() // Enqueue the scripts to handle media upload and selection if ($screen->taxonomy === self::getSlug() && in_array($screen->base, array('edit-tags', 'term'))) { wp_enqueue_media(); - wp_enqueue_script('einsatzverwaltung-media-selector', Core::$scriptUrl . 'media-selector.js'); + wp_enqueue_script('einsatzverwaltung-media-selector', Core::$scriptUrl . 'media-selector.js', [], Core::VERSION, true); } }); diff --git a/src/includes/Types/Vehicle.php b/src/includes/Types/Vehicle.php index 65b90c2d..9802c579 100644 --- a/src/includes/Types/Vehicle.php +++ b/src/includes/Types/Vehicle.php @@ -166,7 +166,6 @@ public function registerHooks() { $taxonomySlug = self::getSlug(); add_action("{$taxonomySlug}_pre_add_form", array($this, 'deprectatedHierarchyNotice')); - add_action('admin_menu', array($this, 'addBadgeToMenu')); /** * Prevent the Gutenberg Editor from creating a UI for this taxonomy, so we can use our own @@ -205,28 +204,6 @@ public function deprectatedHierarchyNotice() } } - public function addBadgeToMenu() - { - global $submenu; - $termsWithParentCount = $this->getTermsWithParentCount(); - if ($termsWithParentCount > 0) { - $submenuKey = 'edit.php?post_type=' . Report::getSlug(); - if (array_key_exists($submenuKey, $submenu)) { - $vehicleEntry = array_filter($submenu[$submenuKey], function ($entry) { - return $entry[2] === 'edit-tags.php?taxonomy=fahrzeug&post_type=einsatz'; - }); - - foreach ($vehicleEntry as $id => $entry) { - $entry[0] .= sprintf( - ' %d', - esc_html($termsWithParentCount) - ); - $submenu[$submenuKey][$id] = $entry; - } - } - } - } - /** * @return int Returns the number of terms in this taxonomy that have a parent term. */ diff --git a/src/includes/Widgets/RecentIncidents.php b/src/includes/Widgets/RecentIncidents.php index 52579563..58305c8e 100644 --- a/src/includes/Widgets/RecentIncidents.php +++ b/src/includes/Widgets/RecentIncidents.php @@ -16,8 +16,8 @@ use function get_queried_object_id; use function get_taxonomy; use function printf; -use function strip_tags; use function trim; +use function wp_strip_all_tags; /** * WordPress-Widget für die letzten X Einsätze @@ -116,7 +116,7 @@ private function echoReports(array $instance, string $title) // Add a nav element for accessibility if (current_theme_supports('html5', 'navigation-widgets')) { - $title = trim(strip_tags($title)); + $title = trim(wp_strip_all_tags($title)); $ariaLabel = !empty($title) ? $title : $this->defaultTitle; printf('