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

Adding documentation to WordPress.WP.DiscouragedConstants #2493

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

RafaelFunchal
Copy link

Related to #1722

Copy link
Collaborator

@rodrigoprimo rodrigoprimo left a comment

Choose a reason for hiding this comment

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

Thanks for creating this PR, and sorry for the delay in reviewing it, @RafaelFunchal! I left some comments with points I believe need to be addressed before it can be merged.

Comment on lines +42 to +45
<em>define("TEMPLATEPATH", "foo");</em>
<img src="
<?php echo <em>$foo</em>; ?>
/img/logo.svg" />
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think it is necessary to include the <img> tag here. Including it means that this code example will trigger both sniff warnings and not just the one associated with this <standard> block. If you decide to keep the <img>, there are some fixes that need to be made. This code currently generates a syntax error due to the missing PHP closing tag after the call to define(). Also, I believe it should echo TEMPLATEPATH instead of the undefined variable $foo.

</code>
<code title="Invalid: The TEMPLATEPATH constant is set by a theme.">
<![CDATA[
<em>define("TEMPLATEPATH", "foo");</em>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe it is better to highlight just the constant name instead of the whole line as it is not any call to define() that triggers this sniff?

<code_comparison>
<code title="Valid: A function is used in the code to retrieve the theme directory.">
<![CDATA[
<img src="
Copy link
Collaborator

Choose a reason for hiding this comment

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

AFAIK, it is not common to indent an HTML tag like it is done here. Maybe instead of fixing the indentation, we can simplify the example and make it easier to understand what this sniff is about? I believe the code sample could be trimmed down to echo <em>TEMPLATEPATH</em>;.

Copy link
Collaborator

@rodrigoprimo rodrigoprimo Oct 28, 2024

Choose a reason for hiding this comment

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

Actually just echo <em>TEMPLATEPATH</em>; is not a realistic example. Maybe something like the example below is better?

$subdir = TEMPLATEPATH . '/subdir/';

And something similar for the example with get_template_directory_uri().

>
<standard>
<![CDATA[
The usage of WordPress Constants is discouraged.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
The usage of WordPress Constants is discouraged.
The usage of WordPress constants is discouraged.

</code_comparison>
<standard>
<![CDATA[
Defining WordPress Constants is discouraged.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
Defining WordPress Constants is discouraged.
Defining WordPress constants is discouraged.

>
<standard>
<![CDATA[
The usage of WordPress Constants is discouraged.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if it makes sense to list here and in the other <standard> block the discouraged constants, as this sniff triggers a warning only for a specific set of WP constants and not all constants. What do you think?

Copy link
Collaborator

Choose a reason for hiding this comment

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

On a second thought, maybe providing the whole list is too much, we could simply say something like The use of certain WordPress constants is discouraged.

]]>
</standard>
<code_comparison>
<code title="Valid: A function is used in the code to retrieve the theme directory.">
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is not explicitly mentioned in #1722, but my understanding, based on checking the documentation from other sniffs, is that the description of the valid and invalid examples should be generic and describe what constitutes a valid example for this particular check that the sniff performs instead of describing the code sample provided.

Maybe here, the valid description should mention that the code does not use one of the discouraged WP constants or something like that?

</code>
<code title="Invalid: The TEMPLATEPATH constant is set by a theme.">
<![CDATA[
<em>define("TEMPLATEPATH", "foo");</em>
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would suggest using a different discouraged constant here, so that we have two examples of constants that trigger this sniff. And possibly wrapping it with a if defined check to illustrate that the sniff is triggered even in this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants