基础代码
This commit is contained in:
@@ -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>
|
||||
Reference in New Issue
Block a user