基础代码
This commit is contained in:
+112
@@ -0,0 +1,112 @@
|
||||
<documentation title="Array Indentation">
|
||||
<standard>
|
||||
<![CDATA[
|
||||
The array closing bracket indentation should line up with the start of the content on the line containing the array opener.
|
||||
]]>
|
||||
</standard>
|
||||
<code_comparison>
|
||||
<code title="Valid: Closing bracket lined up correctly">
|
||||
<![CDATA[
|
||||
$args = array(
|
||||
'post_id' => 22,
|
||||
<em>);</em>
|
||||
]]>
|
||||
</code>
|
||||
<code title="Invalid: Closing bracket lined up incorrectly">
|
||||
<![CDATA[
|
||||
$args = array(
|
||||
'post_id' => 22,
|
||||
<em>);</em>
|
||||
]]>
|
||||
</code>
|
||||
</code_comparison>
|
||||
<standard>
|
||||
<![CDATA[
|
||||
In multi-line arrays, array items should be indented by a 4-space tab for each level of nested array, so that the array visually matches its structure.
|
||||
]]>
|
||||
</standard>
|
||||
<code_comparison>
|
||||
<code title="Valid: Correctly indented array">
|
||||
<![CDATA[
|
||||
$args = array(
|
||||
'post_id' => 22,
|
||||
'comment_count' => array(
|
||||
<em>'value' => 25,
|
||||
'compare' => '>=',</em>
|
||||
),
|
||||
'post_type' => array(
|
||||
'post',
|
||||
'page',
|
||||
),
|
||||
);
|
||||
]]>
|
||||
</code>
|
||||
<code title="Invalid: Indented incorrectly; harder to read.">
|
||||
<![CDATA[
|
||||
$args = array(
|
||||
'post_id' => 22,
|
||||
'comment_count' => array(
|
||||
<em>'value' => 25,
|
||||
'compare' => '>=',</em>
|
||||
),
|
||||
'post_type' => array(
|
||||
<em>'post',
|
||||
'page',</em>
|
||||
),
|
||||
);
|
||||
]]>
|
||||
</code>
|
||||
</code_comparison>
|
||||
<standard>
|
||||
<![CDATA[
|
||||
Subsequent lines in multiline array items should be indented at least as much as the first line of the array item.
|
||||
For heredocs/nowdocs, this does not apply to the content of the heredoc/nowdoc or the closer, but it does apply to the comma separating the item from the next.
|
||||
]]>
|
||||
</standard>
|
||||
<code_comparison>
|
||||
<code title="Valid: Subsequent lines are indented correctly.">
|
||||
<![CDATA[
|
||||
$args = array(
|
||||
'phrase' => 'start of phrase'
|
||||
. 'concatented additional phrase'
|
||||
. 'more text',
|
||||
);
|
||||
]]>
|
||||
</code>
|
||||
<code title="Invalid: Subsequent items are indented before the first line item.">
|
||||
<![CDATA[
|
||||
$args = array(
|
||||
'phrase' => 'start of phrase'
|
||||
. 'concatented additional phrase'
|
||||
. 'more text',
|
||||
);
|
||||
]]>
|
||||
</code>
|
||||
</code_comparison>
|
||||
<code_comparison>
|
||||
<code title="Valid: Opener and comma after closer are indented correctly">
|
||||
<![CDATA[
|
||||
$text = array(
|
||||
<<<EOD
|
||||
start of phrase
|
||||
concatented additional phrase
|
||||
more text
|
||||
EOD
|
||||
,
|
||||
);
|
||||
]]>
|
||||
</code>
|
||||
<code title="Invalid: Opener is aligned incorrectly to match the closer. The comma does not align correctly with the array indentation.">
|
||||
<![CDATA[
|
||||
$text = array(
|
||||
<em><<<EOD</em>
|
||||
start of phrase
|
||||
concatented additional phrase
|
||||
more text
|
||||
EOD
|
||||
<em>,</em>
|
||||
);
|
||||
]]>
|
||||
</code>
|
||||
</code_comparison>
|
||||
</documentation>
|
||||
Vendored
+27
@@ -0,0 +1,27 @@
|
||||
<documentation title="Array Key Spacing Restrictions">
|
||||
<standard>
|
||||
<![CDATA[
|
||||
When referring to array items, only include a space around the index if it is a variable or the key is concatenated.
|
||||
]]>
|
||||
</standard>
|
||||
<code_comparison>
|
||||
<code title="Valid: Correct spacing around the index keys">
|
||||
<![CDATA[
|
||||
$post = $posts<em>[ </em>$post_id<em> ]</em>;
|
||||
$post_title = $post<em>[ </em>'concatenated' . $title<em> ]</em>;
|
||||
$post = $posts<em>[ </em>HOME_PAGE<em> ]</em>;
|
||||
$post = $posts<em>[</em>123<em>]</em>;
|
||||
$post_title = $post<em>[</em>'post_title'<em>]</em>;
|
||||
]]>
|
||||
</code>
|
||||
<code title="Invalid: Incorrect spacing around the index keys">
|
||||
<![CDATA[
|
||||
$post = $posts<em>[</em>$post_id<em>]</em>;
|
||||
$post_title = $post<em>[</em>'concatenated' . $title<em> ]</em>;
|
||||
$post = $posts<em>[</em>HOME_PAGE<em>]</em>;
|
||||
$post = $posts<em>[ </em>123<em> ]</em>;
|
||||
$post_title = $post<em>[ </em>'post_title'<em> ]</em>;
|
||||
]]>
|
||||
</code>
|
||||
</code_comparison>
|
||||
</documentation>
|
||||
Vendored
+46
@@ -0,0 +1,46 @@
|
||||
<documentation title="Multiple Statement Alignment">
|
||||
<standard>
|
||||
<![CDATA[
|
||||
When declaring arrays, there should be one space on either side of a double arrow operator used to assign a value to a key.
|
||||
]]>
|
||||
</standard>
|
||||
<code_comparison>
|
||||
<code title="Valid: correct spacing between the key and value.">
|
||||
<![CDATA[
|
||||
$foo = array( 'cat'<em> => </em>22 );
|
||||
$bar = array( 'year'<em> => </em>$current_year );
|
||||
]]>
|
||||
</code>
|
||||
<code title="Invalid: No or incorrect spacing between the key and value.">
|
||||
<![CDATA[
|
||||
$foo = array( 'cat'<em>=></em>22 );
|
||||
$bar = array( 'year'<em>=> </em>$current_year );
|
||||
]]>
|
||||
</code>
|
||||
</code_comparison>
|
||||
<standard>
|
||||
<![CDATA[
|
||||
In the case of a block of related assignments, it is recommended to align the arrows to promote readability.
|
||||
]]>
|
||||
</standard>
|
||||
<code_comparison>
|
||||
<code title="Valid: Double arrow operators aligned">
|
||||
<![CDATA[
|
||||
$args = array(
|
||||
'cat'<em> => </em>22,
|
||||
'year'<em> => </em>$current_year,
|
||||
'monthnum'<em> => </em>$current_month,
|
||||
);
|
||||
]]>
|
||||
</code>
|
||||
<code title="Invalid: Not aligned; harder to read">
|
||||
<![CDATA[
|
||||
$args = array(
|
||||
'cat' <em>=></em> 22,
|
||||
'year' <em>=></em> $current_year,
|
||||
'monthnum' <em>=></em> $current_month,
|
||||
);
|
||||
]]>
|
||||
</code>
|
||||
</code_comparison>
|
||||
</documentation>
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
<documentation title="Class Instantiation">
|
||||
<standard>
|
||||
<![CDATA[
|
||||
Instantiation of an object should be done with parenthesis.
|
||||
]]>
|
||||
</standard>
|
||||
<code_comparison>
|
||||
<code title="Valid: with parenthesis.">
|
||||
<![CDATA[
|
||||
$a = new Foobar<em>()</em>;
|
||||
]]>
|
||||
</code>
|
||||
<code title="Invalid: without parenthesis.">
|
||||
<![CDATA[
|
||||
$a = new Foobar;
|
||||
]]>
|
||||
</code>
|
||||
</code_comparison>
|
||||
<standard>
|
||||
<![CDATA[
|
||||
Don't use spaces between the object name and the open parenthesis when instantiating new object.
|
||||
]]>
|
||||
</standard>
|
||||
<code_comparison>
|
||||
<code title="Valid: no whitespace between the object name and the parenthesis.">
|
||||
<![CDATA[
|
||||
$a = new Foobar();
|
||||
]]>
|
||||
</code>
|
||||
<code title="Invalid: a space between the object name and the parenthesis.">
|
||||
<![CDATA[
|
||||
$a = new Foobar<em> </em>();
|
||||
]]>
|
||||
</code>
|
||||
</code_comparison>
|
||||
<standard>
|
||||
<![CDATA[
|
||||
Assigning the return value of "new" by reference was deprecated in PHP 5.3 and removed in PHP 7.0. New by reference should no longer be used.
|
||||
]]>
|
||||
</standard>
|
||||
<code_comparison>
|
||||
<code title="Valid: object instantiation without reference.">
|
||||
<![CDATA[
|
||||
$a = <em>new</em> Foobar();
|
||||
]]>
|
||||
</code>
|
||||
<code title="Invalid: object instantiation by reference.">
|
||||
<![CDATA[
|
||||
$a = <em>& new</em> Foobar();
|
||||
]]>
|
||||
</code>
|
||||
</code_comparison>
|
||||
</documentation>
|
||||
Vendored
+20
@@ -0,0 +1,20 @@
|
||||
<documentation title="Escaped Not Translated Text">
|
||||
<standard>
|
||||
<![CDATA[
|
||||
Text intended for translation needs to be wrapped in a localization function call.
|
||||
This sniff will help you find instances where text is escaped for output, but no localization function is called, even though an (unexpected) text domain argument is passed to the escape function.
|
||||
]]>
|
||||
</standard>
|
||||
<code_comparison>
|
||||
<code title="Valid: esc_html__() used to translate and escape.">
|
||||
<![CDATA[
|
||||
echo <em>esc_html__</em>( 'text', 'domain' );
|
||||
]]>
|
||||
</code>
|
||||
<code title="Invalid: esc_html() used to only escape a string intended to be translated as well.">
|
||||
<![CDATA[
|
||||
echo <em>esc_html</em>( 'text', 'domain' );
|
||||
]]>
|
||||
</code>
|
||||
</code_comparison>
|
||||
</documentation>
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
<documentation title="Current Time Timestamp">
|
||||
<standard>
|
||||
<![CDATA[
|
||||
Don't use current_time() to get a timestamp as it doesn't produce a Unix (UTC) timestamp, but a "WordPress timestamp", i.e. a Unix timestamp with current timezone offset.
|
||||
]]>
|
||||
</standard>
|
||||
<code_comparison>
|
||||
<code title="Valid: using time() to get a Unix (UTC) timestamp.">
|
||||
<![CDATA[
|
||||
$timestamp = <em>time()</em>;
|
||||
]]>
|
||||
</code>
|
||||
<code title="Invalid: using current_time() to get a Unix (UTC) timestamp.">
|
||||
<![CDATA[
|
||||
$timestamp = <em>current_time( 'timestamp', true )</em>;
|
||||
]]>
|
||||
</code>
|
||||
</code_comparison>
|
||||
<code_comparison>
|
||||
<code title="Valid: using current_time() with a non-timestamp format.">
|
||||
<![CDATA[
|
||||
$timestamp = current_time( <em>'Y-m-d'</em> );
|
||||
]]>
|
||||
</code>
|
||||
<code title="Invalid: using current_time() to get a timezone corrected timestamp.">
|
||||
<![CDATA[
|
||||
$timestamp = <em>current_time( 'U', false )</em>;
|
||||
]]>
|
||||
</code>
|
||||
</code_comparison>
|
||||
</documentation>
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
<?xml version="1.0"?>
|
||||
<documentation title="Valid Hook Name">
|
||||
<standard>
|
||||
<![CDATA[
|
||||
Use lowercase letters in action and filter names. Separate words using underscores.
|
||||
]]>
|
||||
</standard>
|
||||
<code_comparison>
|
||||
<code title="Valid: lowercase hook name.">
|
||||
<![CDATA[
|
||||
do_action( <em>'prefix_hook_name'</em>, $var );
|
||||
]]>
|
||||
</code>
|
||||
<code title="Invalid: mixed case hook name.">
|
||||
<![CDATA[
|
||||
do_action( <em>'Prefix_Hook_NAME'</em>, $var );
|
||||
]]>
|
||||
</code>
|
||||
</code_comparison>
|
||||
<code_comparison>
|
||||
<code title="Valid: words separated by underscores.">
|
||||
<![CDATA[
|
||||
apply_filters( <em>'prefix_hook_name'</em>, $var );
|
||||
]]>
|
||||
</code>
|
||||
<code title="Invalid: using non-underscore characters to separate words.">
|
||||
<![CDATA[
|
||||
apply_filters( <em>'prefix\hook-name'</em>, $var );
|
||||
]]>
|
||||
</code>
|
||||
</code_comparison>
|
||||
</documentation>
|
||||
Vendored
+117
@@ -0,0 +1,117 @@
|
||||
<documentation title="Validate post type slugs">
|
||||
<standard>
|
||||
<![CDATA[
|
||||
The post type slug used in register_post_type() must be between 1 and 20 characters.
|
||||
]]>
|
||||
</standard>
|
||||
<code_comparison>
|
||||
<code title="Valid: short post type slug.">
|
||||
<![CDATA[
|
||||
register_post_type(
|
||||
<em>'my_short_slug'</em>,
|
||||
array()
|
||||
);
|
||||
]]>
|
||||
</code>
|
||||
<code title="Invalid: too long post type slug.">
|
||||
<![CDATA[
|
||||
register_post_type(
|
||||
<em>'my_own_post_type_too_long'</em>,
|
||||
array()
|
||||
);
|
||||
]]>
|
||||
</code>
|
||||
</code_comparison>
|
||||
<standard>
|
||||
<![CDATA[
|
||||
The post type slug used in register_post_type() can only contain lowercase alphanumeric characters, dashes and underscores.
|
||||
]]>
|
||||
</standard>
|
||||
<code_comparison>
|
||||
<code title="Valid: no special characters in post type slug.">
|
||||
<![CDATA[
|
||||
register_post_type(
|
||||
<em>'my_post_type_slug'</em>,
|
||||
array()
|
||||
);
|
||||
]]>
|
||||
</code>
|
||||
<code title="Invalid: invalid characters in post type slug.">
|
||||
<![CDATA[
|
||||
register_post_type(
|
||||
<em>'my/post/type/slug'</em>,
|
||||
array()
|
||||
);
|
||||
]]>
|
||||
</code>
|
||||
</code_comparison>
|
||||
<standard>
|
||||
<![CDATA[
|
||||
One should be careful with passing dynamic slug names to "register_post_type()", as the slug may become too long and could contain invalid characters.
|
||||
]]>
|
||||
</standard>
|
||||
<code_comparison>
|
||||
<code title="Valid: static post type slug.">
|
||||
<![CDATA[
|
||||
register_post_type(
|
||||
<em>'my_post_active'</em>,
|
||||
array()
|
||||
);
|
||||
]]>
|
||||
</code>
|
||||
<code title="Invalid: dynamic post type slug.">
|
||||
<![CDATA[
|
||||
register_post_type(
|
||||
<em>"my_post_{$status}"</em>,
|
||||
array()
|
||||
);
|
||||
]]>
|
||||
</code>
|
||||
</code_comparison>
|
||||
<standard>
|
||||
<![CDATA[
|
||||
The post type slug used in register_post_type() can not use reserved keywords, such as the ones used by WordPress itself.
|
||||
]]>
|
||||
</standard>
|
||||
<code_comparison>
|
||||
<code title="Valid: prefixed post slug.">
|
||||
<![CDATA[
|
||||
register_post_type(
|
||||
<em>'prefixed_author'</em>,
|
||||
array()
|
||||
);
|
||||
]]>
|
||||
</code>
|
||||
<code title="Invalid: using a reserved keyword as slug.">
|
||||
<![CDATA[
|
||||
register_post_type(
|
||||
<em>'author'</em>,
|
||||
array()
|
||||
);
|
||||
]]>
|
||||
</code>
|
||||
</code_comparison>
|
||||
<standard>
|
||||
<![CDATA[
|
||||
The post type slug used in register_post_type() can not use reserved prefixes, such as 'wp_', which is used by WordPress itself.
|
||||
]]>
|
||||
</standard>
|
||||
<code_comparison>
|
||||
<code title="Valid: custom prefix post slug.">
|
||||
<![CDATA[
|
||||
register_post_type(
|
||||
<em>'prefixed_author'</em>,
|
||||
array()
|
||||
);
|
||||
]]>
|
||||
</code>
|
||||
<code title="Invalid: using a reserved prefix.">
|
||||
<![CDATA[
|
||||
register_post_type(
|
||||
<em>'wp_author'</em>,
|
||||
array()
|
||||
);
|
||||
]]>
|
||||
</code>
|
||||
</code_comparison>
|
||||
</documentation>
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
<documentation title="Disallow Short Ternaries">
|
||||
<standard>
|
||||
<![CDATA[
|
||||
The short ternary operator must not be used.
|
||||
]]>
|
||||
</standard>
|
||||
<code_comparison>
|
||||
<code title="Valid: long ternary.">
|
||||
<![CDATA[
|
||||
$height = ! empty( $data['height'] ) <em>?</em>
|
||||
$data['height'] <em>:</em> 0;
|
||||
]]>
|
||||
</code>
|
||||
<code title="Invalid: short ternary.">
|
||||
<![CDATA[
|
||||
$height = $data['height'] <em>? :</em> 0;
|
||||
]]>
|
||||
</code>
|
||||
</code_comparison>
|
||||
</documentation>
|
||||
@@ -0,0 +1,36 @@
|
||||
<documentation title="Detect use of `ini_set()`">
|
||||
<standard>
|
||||
<![CDATA[
|
||||
Using ini_set() and similar functions for altering PHP settings at runtime is discouraged. Changing runtime configuration might break other plugins and themes, and even WordPress itself.
|
||||
]]>
|
||||
</standard>
|
||||
<code_comparison>
|
||||
<code title="Valid: ini_set() for a possibly breaking setting.">
|
||||
<![CDATA[
|
||||
// ini_set() should not be used.
|
||||
]]>
|
||||
</code>
|
||||
<code title="Invalid: ini_set() for a possibly breaking setting.">
|
||||
<![CDATA[
|
||||
ini_set( <em>'short_open_tag'</em>, 'off' );
|
||||
]]>
|
||||
</code>
|
||||
</code_comparison>
|
||||
<standard>
|
||||
<![CDATA[
|
||||
For some configuration values there are alternative ways available - either via WordPress native functionality of via standard PHP - to achieve the same without the risk of breaking interoperability. These alternatives are preferred.
|
||||
]]>
|
||||
</standard>
|
||||
<code_comparison>
|
||||
<code title="Valid: WordPress functional alternative.">
|
||||
<![CDATA[
|
||||
<em>wp_raise_memory_limit();</em>
|
||||
]]>
|
||||
</code>
|
||||
<code title="Invalid: ini_set() to alter memory limits.">
|
||||
<![CDATA[
|
||||
ini_set( <em>'memory_limit'</em>, '256M' );
|
||||
]]>
|
||||
</code>
|
||||
</code_comparison>
|
||||
</documentation>
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
<documentation title="Safe Redirect">
|
||||
<standard>
|
||||
<![CDATA[
|
||||
wp_safe_redirect() should be used whenever possible to prevent open redirect vulnerabilities. One of the main uses of an open redirect vulnerability is to make phishing attacks more credible. In this case the user sees your (trusted) domain and might get redirected to an attacker controlled website aimed at stealing private information.
|
||||
]]>
|
||||
</standard>
|
||||
<code_comparison>
|
||||
<code title="Valid: Redirect can only go to allowed domains.">
|
||||
<![CDATA[
|
||||
<em>wp_safe_redirect</em>( $location );
|
||||
]]>
|
||||
</code>
|
||||
<code title="Invalid: Unsafe redirect, can be abused.">
|
||||
<![CDATA[
|
||||
<em>wp_redirect</em>( $location );
|
||||
]]>
|
||||
</code>
|
||||
</code_comparison>
|
||||
</documentation>
|
||||
@@ -0,0 +1,41 @@
|
||||
<documentation title="Cron interval">
|
||||
<standard>
|
||||
<![CDATA[
|
||||
Cron schedules running more often than once every 15 minutes are discouraged. Crons running that frequently can negatively impact the performance of a site.
|
||||
]]>
|
||||
</standard>
|
||||
<code_comparison>
|
||||
<code title="Valid: Cron schedule is created to run once every hour.">
|
||||
<![CDATA[
|
||||
function adjust_schedules( $schedules ) {
|
||||
$schedules['every_hour'] = array(
|
||||
'interval' => <em>HOUR_IN_SECONDS</em>,
|
||||
'display' => __( 'Every hour' )
|
||||
);
|
||||
return $schedules;
|
||||
}
|
||||
|
||||
add_filter(
|
||||
'cron_schedules',
|
||||
'adjust_schedules'
|
||||
);
|
||||
]]>
|
||||
</code>
|
||||
<code title="Invalid: Cron schedule is added to run more than once per 15 minutes.">
|
||||
<![CDATA[
|
||||
function adjust_schedules( $schedules ) {
|
||||
$schedules['every_9_mins'] = array(
|
||||
'interval' => <em>9 * 60</em>,
|
||||
'display' => __( 'Every 9 minutes' )
|
||||
);
|
||||
return $schedules;
|
||||
}
|
||||
|
||||
add_filter(
|
||||
'cron_schedules',
|
||||
'adjust_schedules'
|
||||
);
|
||||
]]>
|
||||
</code>
|
||||
</code_comparison>
|
||||
</documentation>
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
<documentation title="Deprecated Classes">
|
||||
<standard>
|
||||
<![CDATA[
|
||||
Please refrain from using deprecated WordPress classes.
|
||||
]]>
|
||||
</standard>
|
||||
<code_comparison>
|
||||
<code title="Valid: use of a current (non-deprecated) class.">
|
||||
<![CDATA[
|
||||
$a = new <em>WP_User_Query</em>();
|
||||
]]>
|
||||
</code>
|
||||
<code title="Invalid: use of a deprecated class.">
|
||||
<![CDATA[
|
||||
$a = new <em>WP_User_Search</em>(); // Deprecated WP 3.1.
|
||||
]]>
|
||||
</code>
|
||||
</code_comparison>
|
||||
</documentation>
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
<documentation title="Deprecated Functions">
|
||||
<standard>
|
||||
<![CDATA[
|
||||
Please refrain from using deprecated WordPress functions.
|
||||
]]>
|
||||
</standard>
|
||||
<code_comparison>
|
||||
<code title="Valid: use of a current (non-deprecated) function.">
|
||||
<![CDATA[
|
||||
$sites = <em>get_sites</em>();
|
||||
]]>
|
||||
</code>
|
||||
<code title="Invalid: use of a deprecated function.">
|
||||
<![CDATA[
|
||||
$sites = <em>wp_get_sites</em>(); // Deprecated WP 4.6.
|
||||
]]>
|
||||
</code>
|
||||
</code_comparison>
|
||||
</documentation>
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
<documentation title="Deprecated Function Parameter Values">
|
||||
<standard>
|
||||
<![CDATA[
|
||||
Please refrain from using deprecated WordPress function parameter values.
|
||||
]]>
|
||||
</standard>
|
||||
<code_comparison>
|
||||
<code title="Valid: passing a valid function parameter value.">
|
||||
<![CDATA[
|
||||
bloginfo( <em>'url'</em> );
|
||||
]]>
|
||||
</code>
|
||||
<code title="Invalid: passing a deprecated function parameter value.">
|
||||
<![CDATA[
|
||||
bloginfo ( <em>'home'</em> ); // Deprecated WP 2.2.0.
|
||||
]]>
|
||||
</code>
|
||||
</code_comparison>
|
||||
</documentation>
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
<documentation title="Deprecated Function Parameters">
|
||||
<standard>
|
||||
<![CDATA[
|
||||
Please refrain from passing deprecated WordPress function parameters.
|
||||
In case, you need to pass an optional parameter positioned <em>after</em> the deprecated parameter, only ever pass the default value.
|
||||
]]>
|
||||
</standard>
|
||||
<code_comparison>
|
||||
<code title="Valid: not passing a deprecated parameter.">
|
||||
<![CDATA[
|
||||
// First - and only - parameter deprecated.
|
||||
get_the_author();
|
||||
]]>
|
||||
</code>
|
||||
<code title="Invalid: passing a deprecated parameter.">
|
||||
<![CDATA[
|
||||
// First - and only - parameter deprecated.
|
||||
get_the_author( <em>$string</em> );
|
||||
]]>
|
||||
</code>
|
||||
</code_comparison>
|
||||
<code_comparison>
|
||||
<code title="Valid: passing default value for a deprecated parameter.">
|
||||
<![CDATA[
|
||||
// Third parameter deprecated in WP 2.3.0.
|
||||
add_option( 'option_name', 123, <em>''</em>, 'yes' );
|
||||
]]>
|
||||
</code>
|
||||
<code title="Invalid: not passing the default value for a deprecated parameter.">
|
||||
<![CDATA[
|
||||
// Third parameter deprecated in WP 2.3.0.
|
||||
add_option( 'my_name', 123, <em>'oops'</em>, 'yes' );
|
||||
]]>
|
||||
</code>
|
||||
</code_comparison>
|
||||
</documentation>
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
<documentation title="Enqueued Resources">
|
||||
<standard>
|
||||
<![CDATA[
|
||||
Scripts must be registered/enqueued via wp_enqueue_script().
|
||||
]]>
|
||||
</standard>
|
||||
<code_comparison>
|
||||
<code title="Valid: Script registered and enqueued correctly.">
|
||||
<![CDATA[
|
||||
<em>wp_enqueue_script</em>(
|
||||
'someScript-js',
|
||||
$path_to_file,
|
||||
array( 'jquery' ),
|
||||
'1.0.0',
|
||||
true
|
||||
);
|
||||
]]>
|
||||
</code>
|
||||
<code title="Invalid: Script is directly embedded in HTML.">
|
||||
<![CDATA[
|
||||
printf(
|
||||
'<em><script src="%s"></script></em>',
|
||||
esc_url( $path_to_file )
|
||||
);
|
||||
]]>
|
||||
</code>
|
||||
</code_comparison>
|
||||
<standard>
|
||||
<![CDATA[
|
||||
Stylesheets must be registered/enqueued via wp_enqueue_style().
|
||||
]]>
|
||||
</standard>
|
||||
<code_comparison>
|
||||
<code title="Valid: Stylesheet registered and enqueued correctly.">
|
||||
<![CDATA[
|
||||
<em>wp_enqueue_style</em>(
|
||||
'style-name',
|
||||
$path_to_file,
|
||||
array(),
|
||||
'1.0.0'
|
||||
);
|
||||
]]>
|
||||
</code>
|
||||
<code title="Invalid: Stylesheet is directly embedded in HTML.">
|
||||
<![CDATA[
|
||||
printf(
|
||||
'<em><link rel="stylesheet" href="%s" /></em>',
|
||||
esc_url( $path_to_file )
|
||||
);
|
||||
]]>
|
||||
</code>
|
||||
</code_comparison>
|
||||
</documentation>
|
||||
@@ -0,0 +1,69 @@
|
||||
<documentation title="High Posts Per Page Limit">
|
||||
<standard>
|
||||
<![CDATA[
|
||||
Using "posts_per_page" or "numberposts" with the value set to an high number opens up the potential for making requests slow if the query ends up querying thousands of posts.
|
||||
|
||||
You should always fetch the lowest number possible that still gives you the number of results you find acceptable.
|
||||
]]>
|
||||
</standard>
|
||||
<code_comparison>
|
||||
<code title="Valid: posts_per_page is not over limit (default 100).">
|
||||
<![CDATA[
|
||||
$args = array(
|
||||
'posts_per_page' => <em>-1</em>,
|
||||
);
|
||||
$args = array(
|
||||
'posts_per_page' => <em>100</em>,
|
||||
);
|
||||
$args = array(
|
||||
'posts_per_page' => <em>'10'</em>,
|
||||
);
|
||||
|
||||
$query_args['posts_per_page'] = <em>100</em>;
|
||||
|
||||
_query_posts( 'nopaging=1&posts_per_page=<em>50</em>' );
|
||||
]]>
|
||||
</code>
|
||||
<code title="Invalid: posts_per_page is over limit (default 100).">
|
||||
<![CDATA[
|
||||
$args = array(
|
||||
'posts_per_page' => <em>101</em>,
|
||||
);
|
||||
|
||||
$query_args['posts_per_page'] = <em>200</em>;
|
||||
|
||||
_query_posts( 'nopaging=1&posts_per_page=<em>999</em>' );
|
||||
]]>
|
||||
</code>
|
||||
</code_comparison>
|
||||
<code_comparison>
|
||||
<code title="Valid: numberposts is not over limit (default 100).">
|
||||
<![CDATA[
|
||||
$args = array(
|
||||
'numberposts' => <em>-1</em>,
|
||||
);
|
||||
$args = array(
|
||||
'numberposts' => <em>100</em>,
|
||||
);
|
||||
$args = array(
|
||||
'numberposts' => <em>'10'</em>,
|
||||
);
|
||||
|
||||
$query_args['numberposts'] = <em>'-1'<em>;
|
||||
|
||||
_query_posts( 'numberposts=<em>50</em>' );
|
||||
]]>
|
||||
</code>
|
||||
<code title="Invalid: numberposts is over limit (default 100).">
|
||||
<![CDATA[
|
||||
$args = array(
|
||||
'numberposts' => <em>101</em>,
|
||||
);
|
||||
|
||||
$query_args['numberposts'] = <em>'200'</em>;
|
||||
|
||||
_query_posts( 'numberposts=<em>999</em>' );
|
||||
]]>
|
||||
</code>
|
||||
</code_comparison>
|
||||
</documentation>
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
<documentation title="Cast Structure Spacing">
|
||||
<standard>
|
||||
<![CDATA[
|
||||
A type cast should be preceded by whitespace.
|
||||
There is only one exception to this rule: when the cast is preceded by the spread operator there should be no space between the spread operator and the cast.
|
||||
]]>
|
||||
</standard>
|
||||
<code_comparison>
|
||||
<code title="Valid: space before typecast.">
|
||||
<![CDATA[
|
||||
$a =<em> </em>(int) '420';
|
||||
|
||||
// No space between spread operator and cast.
|
||||
$a = function_call( <em>...(array)</em> $mixed );
|
||||
]]>
|
||||
</code>
|
||||
<code title="Invalid: no space before typecast.">
|
||||
<![CDATA[
|
||||
$a <em>=(</em>int) '420';
|
||||
]]>
|
||||
</code>
|
||||
</code_comparison>
|
||||
</documentation>
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
<documentation title="Disallow Inline Tabs">
|
||||
<standard>
|
||||
<![CDATA[
|
||||
Use spaces for inline alignment.
|
||||
]]>
|
||||
</standard>
|
||||
<code_comparison>
|
||||
<code title="Valid: spaces used for inline alignment.">
|
||||
<![CDATA[
|
||||
$a = array(
|
||||
'abc'<em>[space]</em>=> 'lor',
|
||||
'b'<em>[space][space][space]</em>=> 'em',
|
||||
);
|
||||
]]>
|
||||
</code>
|
||||
<code title="Invalid: tabs used for inline alignment.">
|
||||
<![CDATA[
|
||||
$a = array(
|
||||
'abc'<em>[tab]</em>=> 'lor',
|
||||
'b'<em>[tab]</em>=> 'em',
|
||||
);
|
||||
]]>
|
||||
</code>
|
||||
</code_comparison>
|
||||
</documentation>
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
<documentation title="Precision Alignment">
|
||||
<standard>
|
||||
<![CDATA[
|
||||
Line indentation should only use tabs. Precision alignment with spaces after the tabs is strongly discouraged.
|
||||
]]>
|
||||
</standard>
|
||||
<code_comparison>
|
||||
<code title="Valid: only tabstops used for indentation.">
|
||||
<![CDATA[
|
||||
<em>[tab]</em>$var = true;
|
||||
]]>
|
||||
</code>
|
||||
<code title="Invalid: precision alignment of 2 spaces.">
|
||||
<![CDATA[
|
||||
<em>[space][space]</em>$var = true;
|
||||
]]>
|
||||
</code>
|
||||
</code_comparison>
|
||||
<code_comparison>
|
||||
<code title="Valid: four spaces counts as a tab, the replacement of these will be handled by another sniff.">
|
||||
<![CDATA[
|
||||
<em>[tab][space][space][space][space]</em>$var = true;
|
||||
]]>
|
||||
</code>
|
||||
<code title="Invalid: precision alignment of 3 spaces.">
|
||||
<![CDATA[
|
||||
<em>[tab][space][space][space]</em>$var = true;
|
||||
]]>
|
||||
</code>
|
||||
</code_comparison>
|
||||
</documentation>
|
||||
Reference in New Issue
Block a user