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

Plugin: Fix wp translation access #1711

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

datengraben
Copy link
Contributor

@datengraben datengraben commented Dec 31, 2024

Closes #1710

Before, it unnecessarily initialized all CustomPostType classes, even when static access was sufficient.

Now uses static access on $postType variable

  • Refactors methods to use class-string based lists instead of objects of custom post types.

@datengraben datengraben added the technical Non-functional changes (refactorings or increase test coverage) label Dec 31, 2024
@datengraben datengraben added this to the 2.10.1 milestone Dec 31, 2024
@datengraben datengraben requested a review from hansmorb December 31, 2024 15:47
Copy link

codecov bot commented Jan 3, 2025

Codecov Report

Attention: Patch coverage is 38.46154% with 24 lines in your changes missing coverage. Please review.

Project coverage is 53.82%. Comparing base (7e01486) to head (60f58fb).

Files with missing lines Patch % Lines
src/Plugin.php 38.46% 24 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #1711      +/-   ##
============================================
- Coverage     54.08%   53.82%   -0.27%     
- Complexity     2628     2631       +3     
============================================
  Files            98       98              
  Lines         11655    11675      +20     
============================================
- Hits           6304     6284      -20     
- Misses         5351     5391      +40     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@datengraben
Copy link
Contributor Author

@hansmorb mit 9dde2bf jetzt fertig zum Review.

@hansmorb hansmorb modified the milestones: 2.10.1, 2.10.2 Jan 9, 2025
@datengraben datengraben modified the milestones: 2.10.2, 2.10.3 Jan 14, 2025
src/Plugin.php Outdated Show resolved Hide resolved
@@ -976,7 +1013,7 @@ public function getTheContent( $content ): string {
// Check if we're inside the main loop in a single post page.
if ( is_single() && in_the_loop() && is_main_query() ) {
global $post;
foreach ( self::getCustomPostTypes() as $customPostType ) {
foreach ( self::getCustomPostTypeClasses() as $customPostType ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hier würde ich den Call auf getCustomPostTypes beibehalten und dafür den Call in #L1017 auf getPostType rausnehmen.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wobei das geht nicht, unten wird ja noch getView aufgerufen.

src/Plugin.php Outdated
@@ -156,19 +156,56 @@ public static function addCustomUserRoles() {
* All CustomPostType classes extend the CustomPostType class and must be registered in this method.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Die Dokumentation muss jetzt auf die getCustomPostTypeClasses Methode.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mh an sich stimmt die Beschreibung ja noch für die Methode. Ich persönlich finde den den Ort im Plugin.php eher etwas unschön.

Ich habe mal noch auf die Classes Methode verwiesen.

src/Plugin.php Outdated Show resolved Hide resolved
src/Plugin.php Outdated Show resolved Hide resolved
@datengraben datengraben force-pushed the datengraben/fix-translations-plugin-init branch from 5ec121a to dd5e584 Compare February 7, 2025 00:27
@datengraben datengraben requested a review from hansmorb February 7, 2025 00:28
Uses static access on $postType variable

* Refactors methods to use class-string based lists instead of objects of custom post types.
diff --git a/tests/php/PluginTest.php b/tests/php/PluginTest.php
index e04f2329..ce7bfd02 100644
--- a/tests/php/PluginTest.php
+++ b/tests/php/PluginTest.php
@@ -18,8 +18,8 @@ class PluginTest extends CustomPostTypeTest {
 			// first, create a post of this type
 			$post = wp_insert_post(
 				[
-					'post_type' => $customPostType::getPostType(),
-					'post_title' => 'Test ' . $customPostType::getPostType(),
+					'post_type' => $customPostType,
+					'post_title' => 'Test ' . $customPostType,
 					'post_status' => 'publish',
 				]
 			);
@datengraben datengraben force-pushed the datengraben/fix-translations-plugin-init branch from dd5e584 to b46cc7d Compare February 7, 2025 12:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
technical Non-functional changes (refactorings or increase test coverage)
Projects
Status: In progress
Development

Successfully merging this pull request may close these issues.

QueryMonitor: Technischer Zugriff auf Übersetzungen zu früh
2 participants