<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[53584] trunk/src/wp-includes/wp-db.php: Docs: Adjust some DocBlocks in `wpdb` per the documentation standards.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/53584">53584</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/53584","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>SergeyBiryukov</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2022-06-28 11:25:21 +0000 (Tue, 28 Jun 2022)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Docs: Adjust some DocBlocks in `wpdb` per the documentation standards.
Includes:
* Wrapping long single-line comments to multi-line for better readability.
* Formatting code blocks to display correctly on the Code Reference.
* Other minor edits for consistency.
This applies to:
* `wpdb::$allow_unsafe_unquoted_parameters`
* `wpdb::escape_identifier()`
* `wpdb::_escape_identifier_value()`
* `wpdb::prepare()`
* `wpdb::has_cap()`
Follow-up to <a href="https://core.trac.wordpress.org/changeset/53575">[53575]</a>.
See <a href="https://core.trac.wordpress.org/ticket/52506">#52506</a>, <a href="https://core.trac.wordpress.org/ticket/55646">#55646</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludeswpdbphp">trunk/src/wp-includes/wp-db.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludeswpdbphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/wp-db.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/wp-db.php 2022-06-27 19:34:38 UTC (rev 53583)
+++ trunk/src/wp-includes/wp-db.php 2022-06-28 11:25:21 UTC (rev 53584)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -645,28 +645,35 @@
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Backwards compatibility, where wpdb::prepare() has not quoted formatted/argnum placeholders.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Backward compatibility, where wpdb::prepare() has not quoted formatted/argnum placeholders.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * Historically this could be used for table/field names, or for some string formatting, e.g.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * $wpdb->prepare( 'WHERE `%1s` = "%1s something %1s" OR %1$s = "%-10s"', 'field_1', 'a', 'b', 'c' );
</del><span class="cx" style="display: block; padding: 0 10px"> *
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * $wpdb->prepare( 'WHERE `%1s` = "%1s something %1s" OR %1$s = "%-10s"', 'field_1', 'a', 'b', 'c' );
+ *
</ins><span class="cx" style="display: block; padding: 0 10px"> * But it's risky, e.g. forgetting to add quotes, resulting in SQL Injection vulnerabilities:
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * $wpdb->prepare( 'WHERE (id = %1s) OR (id = %2$s)', $_GET['id'], $_GET['id'] ); // ?id=id
</del><span class="cx" style="display: block; padding: 0 10px"> *
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * $wpdb->prepare( 'WHERE (id = %1s) OR (id = %2$s)', $_GET['id'], $_GET['id'] ); // ?id=id
+ *
</ins><span class="cx" style="display: block; padding: 0 10px"> * This feature is preserved while plugin authors update their code to use safer approaches:
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * $wpdb->prepare( 'WHERE %1s = %s', $_GET['key'], $_GET['value'] );
- * $wpdb->prepare( 'WHERE %i = %s', $_GET['key'], $_GET['value'] );
</del><span class="cx" style="display: block; padding: 0 10px"> *
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * $wpdb->prepare( 'WHERE %1s = %s', $_GET['key'], $_GET['value'] );
+ * $wpdb->prepare( 'WHERE %i = %s', $_GET['key'], $_GET['value'] );
+ *
</ins><span class="cx" style="display: block; padding: 0 10px"> * While changing to false will be fine for queries not using formatted/argnum placeholders,
</span><span class="cx" style="display: block; padding: 0 10px"> * any remaining cases are most likely going to result in SQL errors (good, in a way):
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * $wpdb->prepare( 'WHERE %1s = "%-10s"', 'my_field', 'my_value' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ *
+ * $wpdb->prepare( 'WHERE %1s = "%-10s"', 'my_field', 'my_value' );
</ins><span class="cx" style="display: block; padding: 0 10px"> * true = WHERE my_field = "my_value "
</span><span class="cx" style="display: block; padding: 0 10px"> * false = WHERE 'my_field' = "'my_value '"
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ *
</ins><span class="cx" style="display: block; padding: 0 10px"> * But there may be some queries that result in an SQL Injection vulnerability:
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * $wpdb->prepare( 'WHERE id = %1s', $_GET['id'] ); // ?id=id
- * So there may need to be a `_doing_it_wrong()` phase, after we know everyone can use Identifier
- * placeholders (%i), but before this feature is disabled or removed.
</del><span class="cx" style="display: block; padding: 0 10px"> *
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * $wpdb->prepare( 'WHERE id = %1s', $_GET['id'] ); // ?id=id
+ *
+ * So there may need to be a `_doing_it_wrong()` phase, after we know everyone can use
+ * identifier placeholders (%i), but before this feature is disabled or removed.
+ *
</ins><span class="cx" style="display: block; padding: 0 10px"> * @since 6.1.0
</span><span class="cx" style="display: block; padding: 0 10px"> * @var bool
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1376,12 +1383,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Escapes an identifier for a MySQL database (e.g. table/field names).
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Escapes an identifier for a MySQL database, e.g. table/field names.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 6.1.0
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $identifier Identifier to escape.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return string Escaped Identifier
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return string Escaped identifier.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function escape_identifier( $identifier ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return '`' . $this->_escape_identifier_value( $identifier ) . '`';
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1388,19 +1395,19 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Escapes an identifier value.
- *
</del><span class="cx" style="display: block; padding: 0 10px"> * Escapes an identifier value without adding the surrounding quotes.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * - Permitted characters in quoted identifiers include the full Unicode Basic Multilingual Plane (BMP), except U+0000
- * - To quote the identifier itself, then you need to double the character, e.g. `a``b`
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * - Permitted characters in quoted identifiers include the full Unicode
+ * Basic Multilingual Plane (BMP), except U+0000.
+ * - To quote the identifier itself, you need to double the character, e.g. `a``b`.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @link https://dev.mysql.com/doc/refman/8.0/en/identifiers.html
</del><span class="cx" style="display: block; padding: 0 10px"> * @since 6.1.0
</span><span class="cx" style="display: block; padding: 0 10px"> * @access private
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @link https://dev.mysql.com/doc/refman/8.0/en/identifiers.html
+ *
</ins><span class="cx" style="display: block; padding: 0 10px"> * @param string $identifier Identifier to escape.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return string Escaped Identifier
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return string Escaped identifier.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> private function _escape_identifier_value( $identifier ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return str_replace( '`', '``', $identifier );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1433,17 +1440,24 @@
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * Examples:
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * $wpdb->prepare( "SELECT * FROM `table` WHERE `column` = %s AND `field` = %d OR `other_field` LIKE %s", array( 'foo', 1337, '%bar' ) );
- * $wpdb->prepare( "SELECT DATE_FORMAT(`field`, '%%c') FROM `table` WHERE `column` = %s", 'foo' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * $wpdb->prepare(
+ * "SELECT * FROM `table` WHERE `column` = %s AND `field` = %d OR `other_field` LIKE %s",
+ * array( 'foo', 1337, '%bar' )
+ * );
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * $wpdb->prepare(
+ * "SELECT DATE_FORMAT(`field`, '%%c') FROM `table` WHERE `column` = %s",
+ * 'foo'
+ * );
+ *
</ins><span class="cx" style="display: block; padding: 0 10px"> * @since 2.3.0
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 5.3.0 Formalized the existing and already documented `...$args` parameter
</span><span class="cx" style="display: block; padding: 0 10px"> * by updating the function signature. The second parameter was changed
</span><span class="cx" style="display: block; padding: 0 10px"> * from `$args` to `...$args`.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @since 6.1.0 Added '%i' for Identifiers, e.g. table or field names.
- * Check support via `wpdb::has_cap( 'identifier_placeholders' )`
- * This preserves compatibility with sprinf, as the C version uses %d and $i
- * as a signed integer, whereas PHP only supports %d.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 6.1.0 Added `%i` for identifiers, e.g. table or field names.
+ * Check support via `wpdb::has_cap( 'identifier_placeholders' )`.
+ * This preserves compatibility with sprintf(), as the C version uses
+ * `%d` and `$i` as a signed integer, whereas PHP only supports `%d`.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @link https://www.php.net/sprintf Description of syntax.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1478,33 +1492,38 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /*
</span><span class="cx" style="display: block; padding: 0 10px"> * Specify the formatting allowed in a placeholder. The following are allowed:
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * - Sign specifier. eg, $+d
- * - Numbered placeholders. eg, %1$s
- * - Padding specifier, including custom padding characters. eg, %05s, %'#5s
- * - Alignment specifier. eg, %05-s
- * - Precision specifier. eg, %.2f
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * - Sign specifier, e.g. $+d
+ * - Numbered placeholders, e.g. %1$s
+ * - Padding specifier, including custom padding characters, e.g. %05s, %'#5s
+ * - Alignment specifier, e.g. %05-s
+ * - Precision specifier, e.g. %.2f
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> $allowed_format = '(?:[1-9][0-9]*[$])?[-+0-9]*(?: |0|\'.)?[-+0-9]*(?:\.[0-9]+)?';
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /*
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * If a %s placeholder already has quotes around it, removing the existing quotes and re-inserting them
- * ensures the quotes are consistent.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * If a %s placeholder already has quotes around it, removing the existing quotes
+ * and re-inserting them ensures the quotes are consistent.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * For backward compatibility, this is only applied to %s, and not to placeholders like %1$s, which are frequently
- * used in the middle of longer strings, or as table name placeholders.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * For backward compatibility, this is only applied to %s, and not to placeholders like %1$s,
+ * which are frequently used in the middle of longer strings, or as table name placeholders.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> $query = str_replace( "'%s'", '%s', $query ); // Strip any existing single quotes.
</span><span class="cx" style="display: block; padding: 0 10px"> $query = str_replace( '"%s"', '%s', $query ); // Strip any existing double quotes.
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $query = preg_replace( "/%(?:%|$|(?!($allowed_format)?[sdfFi]))/", '%%\\1', $query ); // Escape any unescaped percents (i.e. anything unrecognised).
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Escape any unescaped percents (i.e. anything unrecognised).
+ $query = preg_replace( "/%(?:%|$|(?!($allowed_format)?[sdfFi]))/", '%%\\1', $query );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Extract placeholders from the query.
</span><span class="cx" style="display: block; padding: 0 10px"> $split_query = preg_split( "/(^|[^%]|(?:%%)+)(%(?:$allowed_format)?[sdfFi])/", $query, -1, PREG_SPLIT_DELIM_CAPTURE );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $split_query_count = count( $split_query );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $placeholder_count = ( ( $split_query_count - 1 ) / 3 ); // Split always returns with 1 value before the first placeholder (even with $query = "%s"), then 3 additional values per placeholder.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /*
+ * Split always returns with 1 value before the first placeholder (even with $query = "%s"),
+ * then 3 additional values per placeholder.
+ */
+ $placeholder_count = ( ( $split_query_count - 1 ) / 3 );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // If args were passed as an array (as in vsprintf), move them up.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // If args were passed as an array, as in vsprintf(), move them up.
</ins><span class="cx" style="display: block; padding: 0 10px"> $passed_as_array = ( isset( $args[0] ) && is_array( $args[0] ) && 1 === count( $args ) );
</span><span class="cx" style="display: block; padding: 0 10px"> if ( $passed_as_array ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $args = $args[0];
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1511,10 +1530,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $new_query = '';
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $key = 2; // keys 0 and 1 in $split_query contain values before the first placeholder.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $key = 2; // Keys 0 and 1 in $split_query contain values before the first placeholder.
</ins><span class="cx" style="display: block; padding: 0 10px"> $arg_id = 0;
</span><span class="cx" style="display: block; padding: 0 10px"> $arg_identifiers = array();
</span><span class="cx" style="display: block; padding: 0 10px"> $arg_strings = array();
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> while ( $key < $split_query_count ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $placeholder = $split_query[ $key ];
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1528,30 +1548,44 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( 'i' === $type ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $placeholder = '`%' . $format . 's`';
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $argnum_pos = strpos( $format, '$' ); // Using a simple strpos() due to previous checking (e.g. $allowed_format).
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Using a simple strpos() due to previous checking (e.g. $allowed_format).
+ $argnum_pos = strpos( $format, '$' );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( false !== $argnum_pos ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $arg_identifiers[] = ( intval( substr( $format, 0, $argnum_pos ) ) - 1 ); // sprintf argnum starts at 1, $arg_id from 0.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // sprintf() argnum starts at 1, $arg_id from 0.
+ $arg_identifiers[] = ( intval( substr( $format, 0, $argnum_pos ) ) - 1 );
</ins><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><span class="cx" style="display: block; padding: 0 10px"> $arg_identifiers[] = $arg_id;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- } elseif ( 'd' !== $type && 'F' !== $type ) { // i.e. ('s' === $type), where 'd' and 'F' keeps $placeholder unchanged, and we ensure string escaping is used as a safe default (e.g. even if 'x').
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ } elseif ( 'd' !== $type && 'F' !== $type ) {
+ /*
+ * i.e. ( 's' === $type ), where 'd' and 'F' keeps $placeholder unchanged,
+ * and we ensure string escaping is used as a safe default (e.g. even if 'x').
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> $argnum_pos = strpos( $format, '$' );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( false !== $argnum_pos ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $arg_strings[] = ( intval( substr( $format, 0, $argnum_pos ) ) - 1 );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( true !== $this->allow_unsafe_unquoted_parameters || '' === $format ) { // Unquoted strings for backwards compatibility (dangerous).
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ // Unquoted strings for backward compatibility (dangerous).
+ if ( true !== $this->allow_unsafe_unquoted_parameters || '' === $format ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $placeholder = "'%" . $format . "s'";
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $new_query .= $split_query[ $key - 2 ] . $split_query[ $key - 1 ] . $placeholder; // Glue (-2), any leading characters (-1), then the new $placeholder.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Glue (-2), any leading characters (-1), then the new $placeholder.
+ $new_query .= $split_query[ $key - 2 ] . $split_query[ $key - 1 ] . $placeholder;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $key += 3;
</span><span class="cx" style="display: block; padding: 0 10px"> $arg_id++;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $query = $new_query . $split_query[ $key - 2 ]; // Replace $query; and add remaining $query characters, or index 0 if there were no placeholders.
</del><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Replace $query; and add remaining $query characters, or index 0 if there were no placeholders.
+ $query = $new_query . $split_query[ $key - 2 ];
+
</ins><span class="cx" style="display: block; padding: 0 10px"> $dual_use = array_intersect( $arg_identifiers, $arg_strings );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( count( $dual_use ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> wp_load_translations_early();
</span><span class="cx" style="display: block; padding: 0 10px"> _doing_it_wrong(
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1571,7 +1605,10 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( $args_count !== $placeholder_count ) {
</span><span class="cx" style="display: block; padding: 0 10px"> if ( 1 === $placeholder_count && $passed_as_array ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // If the passed query only expected one argument, but the wrong number of arguments were sent as an array, bail.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /*
+ * If the passed query only expected one argument,
+ * but the wrong number of arguments was sent as an array, bail.
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> wp_load_translations_early();
</span><span class="cx" style="display: block; padding: 0 10px"> _doing_it_wrong(
</span><span class="cx" style="display: block; padding: 0 10px"> 'wpdb::prepare',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1582,7 +1619,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return;
</span><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><span class="cx" style="display: block; padding: 0 10px"> /*
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * If we don't have the right number of placeholders, but they were passed as individual arguments,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * If we don't have the right number of placeholders,
+ * but they were passed as individual arguments,
</ins><span class="cx" style="display: block; padding: 0 10px"> * or we were expecting multiple arguments in an array, throw a warning.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> wp_load_translations_early();
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1603,12 +1641,16 @@
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> if ( $args_count < $placeholder_count ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $max_numbered_placeholder = 0;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> for ( $i = 2, $l = $split_query_count; $i < $l; $i += 3 ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $argnum = intval( substr( $split_query[ $i ], 1 ) ); // Assume a leading number is for a numbered placeholder, e.g. '%3$s'.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Assume a leading number is for a numbered placeholder, e.g. '%3$s'.
+ $argnum = intval( substr( $split_query[ $i ], 1 ) );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( $max_numbered_placeholder < $argnum ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $max_numbered_placeholder = $argnum;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( ! $max_numbered_placeholder || $args_count < $max_numbered_placeholder ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return '';
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1635,8 +1677,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> '4.8.2'
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $value = ''; // Preserving old behaviour, where values are escaped as strings.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ // Preserving old behavior, where values are escaped as strings.
+ $value = '';
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> $args_escaped[] = $this->_real_escape( $value );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3872,11 +3917,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Determine DB or WPDB support for a particular feature.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Determines whether the database or WPDB supports a particular feature.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Capability sniffs for the database server and current version of wpdb.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Capability sniffs for the database server and current version of WPDB.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Database sniffs test based on the version of MySQL the site is using.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Database sniffs are based on the version of MySQL the site is using.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * WPDB sniffs are added as new features are introduced to allow theme and plugin
</span><span class="cx" style="display: block; padding: 0 10px"> * developers to determine feature support. This is to account for drop-ins which may
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3926,7 +3971,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> case 'utf8mb4_520': // @since 4.6.0
</span><span class="cx" style="display: block; padding: 0 10px"> return version_compare( $version, '5.6', '>=' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- case 'identifier_placeholders': // @since 6.1.0, wpdb::prepare() supports identifiers via '%i' - e.g. table/field names.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ case 'identifier_placeholders': // @since 6.1.0
+ /*
+ * As of WordPress 6.1, wpdb::prepare() supports identifiers via '%i',
+ * e.g. table/field names.
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> return true;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span></span></pre>
</div>
</div>
</body>
</html>