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

Create Image_Functions_Usage_Check #26

Closed
mehulkaklotar opened this issue Nov 21, 2022 · 2 comments · Fixed by #721
Closed

Create Image_Functions_Usage_Check #26

mehulkaklotar opened this issue Nov 21, 2022 · 2 comments · Fixed by #721
Labels
Checks Audit/test of the particular part of the plugin [Team] Performance Issues owned by Performance Team [Type] Enhancement A suggestion for improvement of an existing feature

Comments

@mehulkaklotar
Copy link
Member

mehulkaklotar commented Nov 21, 2022

Description

Checks and warns against the usage of image HTML in templates. Developers are encouraged to use image functions such as wp_get_attachment_image that generate image HTML in templates. The HTML output by these functions is often better as it generates the tag with more performant attributes such as srcset and sizes. No existing sniff exists but the existing WordPress.WP.EnqueuedResources sniff in the WordPress Coding Standards can be used as a starting point.

Acceptance Criteria

  • Class Image_Functions_Usage_Check should be created and exists at includes/Checker/Checks
  • Class Image_Functions_Usage_Check should extend the PHPCodesniffer_Check abstract class which extends Check interface
  • Property $violation code should be warning
  • Method run should be implemented from the PHPCodesniffer_Check abstract class if needed
  • Check_Result $check_result should be used from the run method parameter to append the results
  • $_SERVER['argv'] arguments should be passed to parent run method to provide PHPCS information about standard, report and sniff
  • Custom sniff to detect the non-usage of wp image functions

Tests Coverage

  • Image_Functions_Usage_Check class expected to extend PHPCodesniffer_Check abstract class
  • Image_Functions_Usage_Check class expected to be instance of the PHPCodesniffer_Check class
  • run method expected to append results of check into $check_result
@mehulkaklotar mehulkaklotar moved this to Backlog in Plugin Check Nov 23, 2022
@mehulkaklotar mehulkaklotar added [Type] Enhancement A suggestion for improvement of an existing feature Checks Audit/test of the particular part of the plugin Infrastructure Issues for the overall plugin infrastructure and removed Infrastructure Issues for the overall plugin infrastructure labels Nov 23, 2022
@FlicHollis FlicHollis moved this from Backlog to Definition in Plugin Check Nov 29, 2022
@eclarke1 eclarke1 moved this from Definition to Backlog in Plugin Check Nov 29, 2022
@mehulkaklotar mehulkaklotar moved this from Backlog to Definition in Plugin Check Dec 9, 2022
@mehulkaklotar mehulkaklotar self-assigned this Dec 9, 2022
@mehulkaklotar mehulkaklotar removed their assignment Dec 9, 2022
@mehulkaklotar mehulkaklotar moved this from Definition to AC Review in Plugin Check Dec 9, 2022
@eclarke1 eclarke1 moved this from AC Review to Definition in Plugin Check Feb 6, 2023
@swissspidy swissspidy added [Team] Performance Issues owned by Performance Team and removed Milestone 3 labels Jun 6, 2024
@swissspidy swissspidy removed the 11 label Jun 6, 2024
@swissspidy
Copy link
Member

This should be trivial to implement by following the EnqueuedResourcesSniff implementation, but we need a good regex and a good documentation. Is wp_get_attachment_image the only function to recommend here?

@swissspidy
Copy link
Member

swissspidy commented Oct 15, 2024

From #443:

Image_Functions_Usage_Check: Would warn about any direct output of img tags in PHP code and templates, as those should use wp_get_attachment_image() etc. instead, which comes with performance benefits. The exception is img tags which aren't for attachments. For such manual img tags, the check could trigger a warning if the wp_get_loading_optimization_attributes() is not used as part of generating the output.

For the last part about wp_get_loading_optimization_attributes() I am not sure how feasible that actually is. Maybe just something for the documentation for now.

@github-project-automation github-project-automation bot moved this to Not Started/Backlog 📆 in WP Performance 2024 Oct 15, 2024
@swissspidy swissspidy moved this from Not Started/Backlog 📆 to Code Review 👀 in WP Performance 2024 Oct 15, 2024
@github-project-automation github-project-automation bot moved this from Code Review 👀 to Done 😃 in WP Performance 2024 Oct 15, 2024
@github-project-automation github-project-automation bot moved this from Definition to Done in Plugin Check Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Checks Audit/test of the particular part of the plugin [Team] Performance Issues owned by Performance Team [Type] Enhancement A suggestion for improvement of an existing feature
Projects
Status: Done 😃
Development

Successfully merging a pull request may close this issue.

3 participants