<!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>[42379] trunk/tests/phpunit/includes/testcase.php: Build/Test tools: Add inline documentation to undocumented methods in the `WP_UnitTestCase` class.</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 { 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/42379">42379</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/42379","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>johnbillion</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2017-12-08 21:00:08 +0000 (Fri, 08 Dec 2017)</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'>Build/Test tools: Add inline documentation to undocumented methods in the `WP_UnitTestCase` class.
Props Frank Klein
Fixes <a href="https://core.trac.wordpress.org/ticket/42731">#42731</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunktestsphpunitincludestestcasephp">trunk/tests/phpunit/includes/testcase.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunktestsphpunitincludestestcasephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/includes/testcase.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/includes/testcase.php 2017-12-07 14:49:10 UTC (rev 42378)
+++ trunk/tests/phpunit/includes/testcase.php 2017-12-08 21:00:08 UTC (rev 42379)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -519,12 +519,28 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( preg_replace( '/\s*/', '', $expected ), preg_replace( '/\s*/', '', $actual ) );
</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">+ /**
+ * Asserts that the contents of two un-keyed, single arrays are equal, without accounting for the order of elements.
+ *
+ * @since 3.5.0
+ *
+ * @param array $expected Expected array.
+ * @param array $actual Array to check.
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> function assertEqualSets( $expected, $actual ) {
</span><span class="cx" style="display: block; padding: 0 10px"> sort( $expected );
</span><span class="cx" style="display: block; padding: 0 10px"> sort( $actual );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( $expected, $actual );
</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">+ /**
+ * Asserts that the contents of two keyed, single arrays are equal, without accounting for the order of elements.
+ *
+ * @since 4.1.0
+ *
+ * @param array $expected Expected array.
+ * @param array $actual Array to check.
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> function assertEqualSetsWithIndex( $expected, $actual ) {
</span><span class="cx" style="display: block; padding: 0 10px"> ksort( $expected );
</span><span class="cx" style="display: block; padding: 0 10px"> ksort( $actual );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -534,7 +550,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Asserts that the given variable is a multidimensional array, and that all arrays are non-empty.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param array $array
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 4.8.0
+ *
+ * @param array $array Array to check.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function assertNonEmptyMultidimensionalArray( $array ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertTrue( is_array( $array ) );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -549,9 +567,14 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Asserts that a condition is not false.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param bool $condition
- * @param string $message
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * This method has been backported from a more recent PHPUnit version, as tests running on PHP 5.2 use
+ * PHPUnit 3.6.x.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 4.7.4
+ *
+ * @param bool $condition Condition to check.
+ * @param string $message Optional. Message to display when the assertion fails.
+ *
</ins><span class="cx" style="display: block; padding: 0 10px"> * @throws PHPUnit_Framework_AssertionFailedError
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public static function assertNotFalse( $condition, $message = '' ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -559,8 +582,16 @@
</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">- * Modify WordPress's query internals as if a given URL has been requested.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Sets the global state to as if a given URL has been requested.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * This sets:
+ * - The super globals.
+ * - The globals.
+ * - The query variables.
+ * - The main query.
+ *
+ * @since 3.5.0
+ *
</ins><span class="cx" style="display: block; padding: 0 10px"> * @param string $url The URL for the request.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function go_to( $url ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -608,6 +639,16 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $GLOBALS['wp']->main( $parts['query'] );
</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">+ /**
+ * Allows tests to be skipped on single or multisite installs by using @group annotations.
+ *
+ * This is a custom extension of the PHPUnit requirements handling.
+ *
+ * Contains legacy code for skipping tests that are associated with an open Trac ticket. Core tests no longer
+ * support this behaviour.
+ *
+ * @since 3.5.0
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> protected function checkRequirements() {
</span><span class="cx" style="display: block; padding: 0 10px"> parent::checkRequirements();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -644,7 +685,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">- * Skips the current test if there is an open WordPress ticket with id $ticket_id
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Skips the current test if there is an open Trac ticket associated with it.
+ *
+ * @since 3.5.0
+ *
+ * @param int $ticket_id Ticket number.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function knownWPBug( $ticket_id ) {
</span><span class="cx" style="display: block; padding: 0 10px"> if ( WP_TESTS_FORCE_KNOWN_BUGS || in_array( $ticket_id, self::$forced_tickets ) ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -656,14 +701,24 @@
</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">- * @deprecated No longer used since the unit test Trac was merged into Core's.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Skips the current test if there is an open Unit Test Trac ticket associated with it.
+ *
+ * @since 3.5.0
+ *
+ * @deprecated No longer used since the Unit Test Trac was merged into the Core Trac.
+ *
+ * @param int $ticket_id Ticket number.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function knownUTBug( $ticket_id ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return;
</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">- * Skips the current test if there is an open plugin ticket with id $ticket_id
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Skips the current test if there is an open Plugin Trac ticket associated with it.
+ *
+ * @since 3.5.0
+ *
+ * @param int $ticket_id Ticket number.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function knownPluginBug( $ticket_id ) {
</span><span class="cx" style="display: block; padding: 0 10px"> if ( WP_TESTS_FORCE_KNOWN_BUGS || in_array( 'Plugin' . $ticket_id, self::$forced_tickets ) ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -674,12 +729,26 @@
</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><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Adds a Trac ticket number to the `$forced_tickets` property.
+ *
+ * @since 3.5.0
+ *
+ * @param int $ticket Ticket number.
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> public static function forceTicket( $ticket ) {
</span><span class="cx" style="display: block; padding: 0 10px"> self::$forced_tickets[] = $ticket;
</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">- * Define constants after including files.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Custom preparations for the PHPUnit process isolation template.
+ *
+ * When restoring global state between tests, PHPUnit defines all the constants that were already defined, and then
+ * includes included files. This does not work with WordPress, as the included files define the constants.
+ *
+ * This method defines the constants after including files.
+ *
+ * @param Text_Template $template
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function prepareTemplate( Text_Template $template ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $template->setVar( array( 'constants' => '' ) );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -688,7 +757,13 @@
</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">- * Returns the name of a temporary file
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Creates a unique temporary file name.
+ *
+ * The directory in which the file is created depends on the environment configuration.
+ *
+ * @since 3.5.0
+ *
+ * @return string|bool Path on success, else false.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function temp_filename() {
</span><span class="cx" style="display: block; padding: 0 10px"> $tmp_dir = '';
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -707,12 +782,15 @@
</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">- * Check each of the WP_Query is_* functions/properties against expected boolean value.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Checks each of the WP_Query is_* functions/properties against expected boolean value.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * Any properties that are listed by name as parameters will be expected to be true; all others are
</span><span class="cx" style="display: block; padding: 0 10px"> * expected to be false. For example, assertQueryTrue('is_single', 'is_feed') means is_single()
</span><span class="cx" style="display: block; padding: 0 10px"> * and is_feed() must be true and everything else must be false to pass.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 2.5.0
+ * @since 3.8.0 Moved from `Tests_Query_Conditionals` to `WP_UnitTestCase`.
+ *
</ins><span class="cx" style="display: block; padding: 0 10px"> * @param string $prop,... Any number of WP_Query properties that are expected to be true for the current request.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function assertQueryTrue() {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -775,6 +853,13 @@
</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><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Selectively deletes a file.
+ *
+ * Does not delete a file if its path is set in the `$ignore_files` property.
+ *
+ * @param string $file File path.
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> function unlink( $file ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $exists = is_file( $file );
</span><span class="cx" style="display: block; padding: 0 10px"> if ( $exists && ! in_array( $file, self::$ignore_files ) ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -785,6 +870,13 @@
</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><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Selectively deletes files from a directory.
+ *
+ * Does not delete files if their paths are set in the `$ignore_files` property.
+ *
+ * @param string $path Directory path.
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> function rmdir( $path ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $files = $this->files_in_dir( $path );
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( $files as $file ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -794,12 +886,29 @@
</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><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Deletes files added to the `uploads` directory during tests.
+ *
+ * This method works in tandem with the `setUp()` and `rmdir()` methods:
+ * - `setUp()` scans the `uploads` directory before every test, and stores its contents inside of the
+ * `$ignore_files` property.
+ * - `rmdir()` and its helper methods only delete files that are not listed in the `$ignore_files` property. If
+ * called during `tearDown()` in tests, this will only delete files added during the previously run test.
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> function remove_added_uploads() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // Remove all uploads.
</del><span class="cx" style="display: block; padding: 0 10px"> $uploads = wp_upload_dir();
</span><span class="cx" style="display: block; padding: 0 10px"> $this->rmdir( $uploads['basedir'] );
</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">+ /**
+ * Returns a list of all files contained inside a directory.
+ *
+ * @since 4.0.0
+ *
+ * @param string $dir Path to the directory to scan.
+ *
+ * @return array List of file paths.
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> function files_in_dir( $dir ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $files = array();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -814,6 +923,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return $files;
</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">+ /**
+ * Returns a list of all files contained inside the `uploads` directory.
+ *
+ * @since 4.0.0
+ *
+ * @return array List of file paths.
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> function scan_user_uploads() {
</span><span class="cx" style="display: block; padding: 0 10px"> static $files = array();
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! empty( $files ) ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -825,6 +941,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return $files;
</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">+ /**
+ * Deletes all directories contained inside a directory.
+ *
+ * @since 4.1.0
+ *
+ * @param string $path Path to the directory to scan.
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> function delete_folders( $path ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $this->matched_dirs = array();
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! is_dir( $path ) ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -838,6 +961,16 @@
</span><span class="cx" style="display: block; padding: 0 10px"> rmdir( $path );
</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">+ /**
+ * Retrieves all directories contained inside a directory and stores them in the `$matched_dirs` property. Hidden
+ * directories are ignored.
+ *
+ * This is a helper for the `delete_folders()` method.
+ *
+ * @since 4.1.0
+ *
+ * @param string $dir Path to the directory to scan.
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> function scandir( $dir ) {
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( scandir( $dir ) as $path ) {
</span><span class="cx" style="display: block; padding: 0 10px"> if ( 0 !== strpos( $path, '.' ) && is_dir( $dir . '/' . $path ) ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -848,7 +981,13 @@
</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">- * Helper to Convert a microtime string into a float
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Converts a microtime string into a float.
+ *
+ * @since 4.1.0
+ *
+ * @param string $microtime Time string generated by `microtime()`.
+ *
+ * @return float `microtime()` output as a float.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> protected function _microtime_to_float( $microtime ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $time_array = explode( ' ', $microtime );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -856,9 +995,13 @@
</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">- * Multisite-agnostic way to delete a user from the database.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Deletes a user from the database in a Multisite-agnostic way.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 4.3.0
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ *
+ * @param int $user_id User ID.
+ *
+ * @return bool True if the user was deleted.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public static function delete_user( $user_id ) {
</span><span class="cx" style="display: block; padding: 0 10px"> if ( is_multisite() ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -869,7 +1012,7 @@
</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">- * Utility method that resets permalinks and flushes rewrites.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Resets permalinks and flushes rewrites.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 4.4.0
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -885,6 +1028,16 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $wp_rewrite->flush_rules();
</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">+ /**
+ * Creates an attachment post from an uploaded file.
+ *
+ * @since 4.4.0
+ *
+ * @param array $upload Array of information about the uploaded file, provided by wp_upload_bits().
+ * @param int $parent_post_id Optional. Parent post ID.
+ *
+ * @return int|WP_Error The attachment ID on success. The value 0 or WP_Error on failure.
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> function _make_attachment( $upload, $parent_post_id = 0 ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $type = '';
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! empty( $upload['type'] ) ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -905,14 +1058,22 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'guid' => $upload['url'],
</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">- // Save the data
</del><span class="cx" style="display: block; padding: 0 10px"> $id = wp_insert_attachment( $attachment, $upload['file'], $parent_post_id );
</span><span class="cx" style="display: block; padding: 0 10px"> wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $upload['file'] ) );
</span><span class="cx" style="display: block; padding: 0 10px"> return $id;
</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">- * There's no way to change post_modified through WP functions.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Updates the modified and modified GMT date of a post in the database.
+ *
+ * @since 4.8.0
+ *
+ * @global wpdb $wpdb WordPress database abstraction object.
+ *
+ * @param int $post_id Post ID.
+ * @param string $date Post date, in the format YYYY-MM-DD HH:MM:SS.
+ *
+ * @return int|false 1 on success, or false on error.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> protected function update_post_modified( $post_id, $date ) {
</span><span class="cx" style="display: block; padding: 0 10px"> global $wpdb;
</span></span></pre>
</div>
</div>
</body>
</html>