Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93

Warning: Undefined array key "page_file_edit_line" in /home/sportsfever/public_html/filemanger/edit_text_line.php on line 32
/home/sportsfe.../public_h.../wp-inclu...
File: rest-api.php
);
[1500] Fix | Delete
[1501] Fix | Delete
return in_array( $maybe_bool, $valid_boolean_values, true );
[1502] Fix | Delete
}
[1503] Fix | Delete
[1504] Fix | Delete
if ( is_int( $maybe_bool ) ) {
[1505] Fix | Delete
return in_array( $maybe_bool, array( 0, 1 ), true );
[1506] Fix | Delete
}
[1507] Fix | Delete
[1508] Fix | Delete
return false;
[1509] Fix | Delete
}
[1510] Fix | Delete
[1511] Fix | Delete
/**
[1512] Fix | Delete
* Determines if a given value is integer-like.
[1513] Fix | Delete
*
[1514] Fix | Delete
* @since 5.5.0
[1515] Fix | Delete
*
[1516] Fix | Delete
* @param mixed $maybe_integer The value being evaluated.
[1517] Fix | Delete
* @return bool True if an integer, otherwise false.
[1518] Fix | Delete
*/
[1519] Fix | Delete
function rest_is_integer( $maybe_integer ) {
[1520] Fix | Delete
return is_numeric( $maybe_integer ) && round( (float) $maybe_integer ) === (float) $maybe_integer;
[1521] Fix | Delete
}
[1522] Fix | Delete
[1523] Fix | Delete
/**
[1524] Fix | Delete
* Determines if a given value is array-like.
[1525] Fix | Delete
*
[1526] Fix | Delete
* @since 5.5.0
[1527] Fix | Delete
*
[1528] Fix | Delete
* @param mixed $maybe_array The value being evaluated.
[1529] Fix | Delete
* @return bool
[1530] Fix | Delete
*/
[1531] Fix | Delete
function rest_is_array( $maybe_array ) {
[1532] Fix | Delete
if ( is_scalar( $maybe_array ) ) {
[1533] Fix | Delete
$maybe_array = wp_parse_list( $maybe_array );
[1534] Fix | Delete
}
[1535] Fix | Delete
[1536] Fix | Delete
return wp_is_numeric_array( $maybe_array );
[1537] Fix | Delete
}
[1538] Fix | Delete
[1539] Fix | Delete
/**
[1540] Fix | Delete
* Converts an array-like value to an array.
[1541] Fix | Delete
*
[1542] Fix | Delete
* @since 5.5.0
[1543] Fix | Delete
*
[1544] Fix | Delete
* @param mixed $maybe_array The value being evaluated.
[1545] Fix | Delete
* @return array Returns the array extracted from the value.
[1546] Fix | Delete
*/
[1547] Fix | Delete
function rest_sanitize_array( $maybe_array ) {
[1548] Fix | Delete
if ( is_scalar( $maybe_array ) ) {
[1549] Fix | Delete
return wp_parse_list( $maybe_array );
[1550] Fix | Delete
}
[1551] Fix | Delete
[1552] Fix | Delete
if ( ! is_array( $maybe_array ) ) {
[1553] Fix | Delete
return array();
[1554] Fix | Delete
}
[1555] Fix | Delete
[1556] Fix | Delete
// Normalize to numeric array so nothing unexpected is in the keys.
[1557] Fix | Delete
return array_values( $maybe_array );
[1558] Fix | Delete
}
[1559] Fix | Delete
[1560] Fix | Delete
/**
[1561] Fix | Delete
* Determines if a given value is object-like.
[1562] Fix | Delete
*
[1563] Fix | Delete
* @since 5.5.0
[1564] Fix | Delete
*
[1565] Fix | Delete
* @param mixed $maybe_object The value being evaluated.
[1566] Fix | Delete
* @return bool True if object like, otherwise false.
[1567] Fix | Delete
*/
[1568] Fix | Delete
function rest_is_object( $maybe_object ) {
[1569] Fix | Delete
if ( '' === $maybe_object ) {
[1570] Fix | Delete
return true;
[1571] Fix | Delete
}
[1572] Fix | Delete
[1573] Fix | Delete
if ( $maybe_object instanceof stdClass ) {
[1574] Fix | Delete
return true;
[1575] Fix | Delete
}
[1576] Fix | Delete
[1577] Fix | Delete
if ( $maybe_object instanceof JsonSerializable ) {
[1578] Fix | Delete
$maybe_object = $maybe_object->jsonSerialize();
[1579] Fix | Delete
}
[1580] Fix | Delete
[1581] Fix | Delete
return is_array( $maybe_object );
[1582] Fix | Delete
}
[1583] Fix | Delete
[1584] Fix | Delete
/**
[1585] Fix | Delete
* Converts an object-like value to an array.
[1586] Fix | Delete
*
[1587] Fix | Delete
* @since 5.5.0
[1588] Fix | Delete
*
[1589] Fix | Delete
* @param mixed $maybe_object The value being evaluated.
[1590] Fix | Delete
* @return array Returns the object extracted from the value as an associative array.
[1591] Fix | Delete
*/
[1592] Fix | Delete
function rest_sanitize_object( $maybe_object ) {
[1593] Fix | Delete
if ( '' === $maybe_object ) {
[1594] Fix | Delete
return array();
[1595] Fix | Delete
}
[1596] Fix | Delete
[1597] Fix | Delete
if ( $maybe_object instanceof stdClass ) {
[1598] Fix | Delete
return (array) $maybe_object;
[1599] Fix | Delete
}
[1600] Fix | Delete
[1601] Fix | Delete
if ( $maybe_object instanceof JsonSerializable ) {
[1602] Fix | Delete
$maybe_object = $maybe_object->jsonSerialize();
[1603] Fix | Delete
}
[1604] Fix | Delete
[1605] Fix | Delete
if ( ! is_array( $maybe_object ) ) {
[1606] Fix | Delete
return array();
[1607] Fix | Delete
}
[1608] Fix | Delete
[1609] Fix | Delete
return $maybe_object;
[1610] Fix | Delete
}
[1611] Fix | Delete
[1612] Fix | Delete
/**
[1613] Fix | Delete
* Gets the best type for a value.
[1614] Fix | Delete
*
[1615] Fix | Delete
* @since 5.5.0
[1616] Fix | Delete
*
[1617] Fix | Delete
* @param mixed $value The value to check.
[1618] Fix | Delete
* @param string[] $types The list of possible types.
[1619] Fix | Delete
* @return string The best matching type, an empty string if no types match.
[1620] Fix | Delete
*/
[1621] Fix | Delete
function rest_get_best_type_for_value( $value, $types ) {
[1622] Fix | Delete
static $checks = array(
[1623] Fix | Delete
'array' => 'rest_is_array',
[1624] Fix | Delete
'object' => 'rest_is_object',
[1625] Fix | Delete
'integer' => 'rest_is_integer',
[1626] Fix | Delete
'number' => 'is_numeric',
[1627] Fix | Delete
'boolean' => 'rest_is_boolean',
[1628] Fix | Delete
'string' => 'is_string',
[1629] Fix | Delete
'null' => 'is_null',
[1630] Fix | Delete
);
[1631] Fix | Delete
[1632] Fix | Delete
/*
[1633] Fix | Delete
* Both arrays and objects allow empty strings to be converted to their types.
[1634] Fix | Delete
* But the best answer for this type is a string.
[1635] Fix | Delete
*/
[1636] Fix | Delete
if ( '' === $value && in_array( 'string', $types, true ) ) {
[1637] Fix | Delete
return 'string';
[1638] Fix | Delete
}
[1639] Fix | Delete
[1640] Fix | Delete
foreach ( $types as $type ) {
[1641] Fix | Delete
if ( isset( $checks[ $type ] ) && $checks[ $type ]( $value ) ) {
[1642] Fix | Delete
return $type;
[1643] Fix | Delete
}
[1644] Fix | Delete
}
[1645] Fix | Delete
[1646] Fix | Delete
return '';
[1647] Fix | Delete
}
[1648] Fix | Delete
[1649] Fix | Delete
/**
[1650] Fix | Delete
* Handles getting the best type for a multi-type schema.
[1651] Fix | Delete
*
[1652] Fix | Delete
* This is a wrapper for {@see rest_get_best_type_for_value()} that handles
[1653] Fix | Delete
* backward compatibility for schemas that use invalid types.
[1654] Fix | Delete
*
[1655] Fix | Delete
* @since 5.5.0
[1656] Fix | Delete
*
[1657] Fix | Delete
* @param mixed $value The value to check.
[1658] Fix | Delete
* @param array $args The schema array to use.
[1659] Fix | Delete
* @param string $param The parameter name, used in error messages.
[1660] Fix | Delete
* @return string
[1661] Fix | Delete
*/
[1662] Fix | Delete
function rest_handle_multi_type_schema( $value, $args, $param = '' ) {
[1663] Fix | Delete
$allowed_types = array( 'array', 'object', 'string', 'number', 'integer', 'boolean', 'null' );
[1664] Fix | Delete
$invalid_types = array_diff( $args['type'], $allowed_types );
[1665] Fix | Delete
[1666] Fix | Delete
if ( $invalid_types ) {
[1667] Fix | Delete
_doing_it_wrong(
[1668] Fix | Delete
__FUNCTION__,
[1669] Fix | Delete
/* translators: 1: Parameter, 2: List of allowed types. */
[1670] Fix | Delete
wp_sprintf( __( 'The "type" schema keyword for %1$s can only contain the built-in types: %2$l.' ), $param, $allowed_types ),
[1671] Fix | Delete
'5.5.0'
[1672] Fix | Delete
);
[1673] Fix | Delete
}
[1674] Fix | Delete
[1675] Fix | Delete
$best_type = rest_get_best_type_for_value( $value, $args['type'] );
[1676] Fix | Delete
[1677] Fix | Delete
if ( ! $best_type ) {
[1678] Fix | Delete
if ( ! $invalid_types ) {
[1679] Fix | Delete
return '';
[1680] Fix | Delete
}
[1681] Fix | Delete
[1682] Fix | Delete
// Backward compatibility for previous behavior which allowed the value if there was an invalid type used.
[1683] Fix | Delete
$best_type = reset( $invalid_types );
[1684] Fix | Delete
}
[1685] Fix | Delete
[1686] Fix | Delete
return $best_type;
[1687] Fix | Delete
}
[1688] Fix | Delete
[1689] Fix | Delete
/**
[1690] Fix | Delete
* Checks if an array is made up of unique items.
[1691] Fix | Delete
*
[1692] Fix | Delete
* @since 5.5.0
[1693] Fix | Delete
*
[1694] Fix | Delete
* @param array $input_array The array to check.
[1695] Fix | Delete
* @return bool True if the array contains unique items, false otherwise.
[1696] Fix | Delete
*/
[1697] Fix | Delete
function rest_validate_array_contains_unique_items( $input_array ) {
[1698] Fix | Delete
$seen = array();
[1699] Fix | Delete
[1700] Fix | Delete
foreach ( $input_array as $item ) {
[1701] Fix | Delete
$stabilized = rest_stabilize_value( $item );
[1702] Fix | Delete
$key = serialize( $stabilized );
[1703] Fix | Delete
[1704] Fix | Delete
if ( ! isset( $seen[ $key ] ) ) {
[1705] Fix | Delete
$seen[ $key ] = true;
[1706] Fix | Delete
[1707] Fix | Delete
continue;
[1708] Fix | Delete
}
[1709] Fix | Delete
[1710] Fix | Delete
return false;
[1711] Fix | Delete
}
[1712] Fix | Delete
[1713] Fix | Delete
return true;
[1714] Fix | Delete
}
[1715] Fix | Delete
[1716] Fix | Delete
/**
[1717] Fix | Delete
* Stabilizes a value following JSON Schema semantics.
[1718] Fix | Delete
*
[1719] Fix | Delete
* For lists, order is preserved. For objects, properties are reordered alphabetically.
[1720] Fix | Delete
*
[1721] Fix | Delete
* @since 5.5.0
[1722] Fix | Delete
*
[1723] Fix | Delete
* @param mixed $value The value to stabilize. Must already be sanitized. Objects should have been converted to arrays.
[1724] Fix | Delete
* @return mixed The stabilized value.
[1725] Fix | Delete
*/
[1726] Fix | Delete
function rest_stabilize_value( $value ) {
[1727] Fix | Delete
if ( is_scalar( $value ) || is_null( $value ) ) {
[1728] Fix | Delete
return $value;
[1729] Fix | Delete
}
[1730] Fix | Delete
[1731] Fix | Delete
if ( is_object( $value ) ) {
[1732] Fix | Delete
_doing_it_wrong( __FUNCTION__, __( 'Cannot stabilize objects. Convert the object to an array first.' ), '5.5.0' );
[1733] Fix | Delete
[1734] Fix | Delete
return $value;
[1735] Fix | Delete
}
[1736] Fix | Delete
[1737] Fix | Delete
ksort( $value );
[1738] Fix | Delete
[1739] Fix | Delete
foreach ( $value as $k => $v ) {
[1740] Fix | Delete
$value[ $k ] = rest_stabilize_value( $v );
[1741] Fix | Delete
}
[1742] Fix | Delete
[1743] Fix | Delete
return $value;
[1744] Fix | Delete
}
[1745] Fix | Delete
[1746] Fix | Delete
/**
[1747] Fix | Delete
* Validates if the JSON Schema pattern matches a value.
[1748] Fix | Delete
*
[1749] Fix | Delete
* @since 5.6.0
[1750] Fix | Delete
*
[1751] Fix | Delete
* @param string $pattern The pattern to match against.
[1752] Fix | Delete
* @param string $value The value to check.
[1753] Fix | Delete
* @return bool True if the pattern matches the given value, false otherwise.
[1754] Fix | Delete
*/
[1755] Fix | Delete
function rest_validate_json_schema_pattern( $pattern, $value ) {
[1756] Fix | Delete
$escaped_pattern = str_replace( '#', '\\#', $pattern );
[1757] Fix | Delete
[1758] Fix | Delete
return 1 === preg_match( '#' . $escaped_pattern . '#u', $value );
[1759] Fix | Delete
}
[1760] Fix | Delete
[1761] Fix | Delete
/**
[1762] Fix | Delete
* Finds the schema for a property using the patternProperties keyword.
[1763] Fix | Delete
*
[1764] Fix | Delete
* @since 5.6.0
[1765] Fix | Delete
*
[1766] Fix | Delete
* @param string $property The property name to check.
[1767] Fix | Delete
* @param array $args The schema array to use.
[1768] Fix | Delete
* @return array|null The schema of matching pattern property, or null if no patterns match.
[1769] Fix | Delete
*/
[1770] Fix | Delete
function rest_find_matching_pattern_property_schema( $property, $args ) {
[1771] Fix | Delete
if ( isset( $args['patternProperties'] ) ) {
[1772] Fix | Delete
foreach ( $args['patternProperties'] as $pattern => $child_schema ) {
[1773] Fix | Delete
if ( rest_validate_json_schema_pattern( $pattern, $property ) ) {
[1774] Fix | Delete
return $child_schema;
[1775] Fix | Delete
}
[1776] Fix | Delete
}
[1777] Fix | Delete
}
[1778] Fix | Delete
[1779] Fix | Delete
return null;
[1780] Fix | Delete
}
[1781] Fix | Delete
[1782] Fix | Delete
/**
[1783] Fix | Delete
* Formats a combining operation error into a WP_Error object.
[1784] Fix | Delete
*
[1785] Fix | Delete
* @since 5.6.0
[1786] Fix | Delete
*
[1787] Fix | Delete
* @param string $param The parameter name.
[1788] Fix | Delete
* @param array $error The error details.
[1789] Fix | Delete
* @return WP_Error
[1790] Fix | Delete
*/
[1791] Fix | Delete
function rest_format_combining_operation_error( $param, $error ) {
[1792] Fix | Delete
$position = $error['index'];
[1793] Fix | Delete
$reason = $error['error_object']->get_error_message();
[1794] Fix | Delete
[1795] Fix | Delete
if ( isset( $error['schema']['title'] ) ) {
[1796] Fix | Delete
$title = $error['schema']['title'];
[1797] Fix | Delete
[1798] Fix | Delete
return new WP_Error(
[1799] Fix | Delete
'rest_no_matching_schema',
[1800] Fix | Delete
/* translators: 1: Parameter, 2: Schema title, 3: Reason. */
[1801] Fix | Delete
sprintf( __( '%1$s is not a valid %2$s. Reason: %3$s' ), $param, $title, $reason ),
[1802] Fix | Delete
array( 'position' => $position )
[1803] Fix | Delete
);
[1804] Fix | Delete
}
[1805] Fix | Delete
[1806] Fix | Delete
return new WP_Error(
[1807] Fix | Delete
'rest_no_matching_schema',
[1808] Fix | Delete
/* translators: 1: Parameter, 2: Reason. */
[1809] Fix | Delete
sprintf( __( '%1$s does not match the expected format. Reason: %2$s' ), $param, $reason ),
[1810] Fix | Delete
array( 'position' => $position )
[1811] Fix | Delete
);
[1812] Fix | Delete
}
[1813] Fix | Delete
[1814] Fix | Delete
/**
[1815] Fix | Delete
* Gets the error of combining operation.
[1816] Fix | Delete
*
[1817] Fix | Delete
* @since 5.6.0
[1818] Fix | Delete
*
[1819] Fix | Delete
* @param array $value The value to validate.
[1820] Fix | Delete
* @param string $param The parameter name, used in error messages.
[1821] Fix | Delete
* @param array $errors The errors array, to search for possible error.
[1822] Fix | Delete
* @return WP_Error The combining operation error.
[1823] Fix | Delete
*/
[1824] Fix | Delete
function rest_get_combining_operation_error( $value, $param, $errors ) {
[1825] Fix | Delete
// If there is only one error, simply return it.
[1826] Fix | Delete
if ( 1 === count( $errors ) ) {
[1827] Fix | Delete
return rest_format_combining_operation_error( $param, $errors[0] );
[1828] Fix | Delete
}
[1829] Fix | Delete
[1830] Fix | Delete
// Filter out all errors related to type validation.
[1831] Fix | Delete
$filtered_errors = array();
[1832] Fix | Delete
foreach ( $errors as $error ) {
[1833] Fix | Delete
$error_code = $error['error_object']->get_error_code();
[1834] Fix | Delete
$error_data = $error['error_object']->get_error_data();
[1835] Fix | Delete
[1836] Fix | Delete
if ( 'rest_invalid_type' !== $error_code || ( isset( $error_data['param'] ) && $param !== $error_data['param'] ) ) {
[1837] Fix | Delete
$filtered_errors[] = $error;
[1838] Fix | Delete
}
[1839] Fix | Delete
}
[1840] Fix | Delete
[1841] Fix | Delete
// If there is only one error left, simply return it.
[1842] Fix | Delete
if ( 1 === count( $filtered_errors ) ) {
[1843] Fix | Delete
return rest_format_combining_operation_error( $param, $filtered_errors[0] );
[1844] Fix | Delete
}
[1845] Fix | Delete
[1846] Fix | Delete
// If there are only errors related to object validation, try choosing the most appropriate one.
[1847] Fix | Delete
if ( count( $filtered_errors ) > 1 && 'object' === $filtered_errors[0]['schema']['type'] ) {
[1848] Fix | Delete
$result = null;
[1849] Fix | Delete
$number = 0;
[1850] Fix | Delete
[1851] Fix | Delete
foreach ( $filtered_errors as $error ) {
[1852] Fix | Delete
if ( isset( $error['schema']['properties'] ) ) {
[1853] Fix | Delete
$n = count( array_intersect_key( $error['schema']['properties'], $value ) );
[1854] Fix | Delete
if ( $n > $number ) {
[1855] Fix | Delete
$result = $error;
[1856] Fix | Delete
$number = $n;
[1857] Fix | Delete
}
[1858] Fix | Delete
}
[1859] Fix | Delete
}
[1860] Fix | Delete
[1861] Fix | Delete
if ( null !== $result ) {
[1862] Fix | Delete
return rest_format_combining_operation_error( $param, $result );
[1863] Fix | Delete
}
[1864] Fix | Delete
}
[1865] Fix | Delete
[1866] Fix | Delete
// If each schema has a title, include those titles in the error message.
[1867] Fix | Delete
$schema_titles = array();
[1868] Fix | Delete
foreach ( $errors as $error ) {
[1869] Fix | Delete
if ( isset( $error['schema']['title'] ) ) {
[1870] Fix | Delete
$schema_titles[] = $error['schema']['title'];
[1871] Fix | Delete
}
[1872] Fix | Delete
}
[1873] Fix | Delete
[1874] Fix | Delete
if ( count( $schema_titles ) === count( $errors ) ) {
[1875] Fix | Delete
/* translators: 1: Parameter, 2: Schema titles. */
[1876] Fix | Delete
return new WP_Error( 'rest_no_matching_schema', wp_sprintf( __( '%1$s is not a valid %2$l.' ), $param, $schema_titles ) );
[1877] Fix | Delete
}
[1878] Fix | Delete
[1879] Fix | Delete
/* translators: %s: Parameter. */
[1880] Fix | Delete
return new WP_Error( 'rest_no_matching_schema', sprintf( __( '%s does not match any of the expected formats.' ), $param ) );
[1881] Fix | Delete
}
[1882] Fix | Delete
[1883] Fix | Delete
/**
[1884] Fix | Delete
* Finds the matching schema among the "anyOf" schemas.
[1885] Fix | Delete
*
[1886] Fix | Delete
* @since 5.6.0
[1887] Fix | Delete
*
[1888] Fix | Delete
* @param mixed $value The value to validate.
[1889] Fix | Delete
* @param array $args The schema array to use.
[1890] Fix | Delete
* @param string $param The parameter name, used in error messages.
[1891] Fix | Delete
* @return array|WP_Error The matching schema or WP_Error instance if all schemas do not match.
[1892] Fix | Delete
*/
[1893] Fix | Delete
function rest_find_any_matching_schema( $value, $args, $param ) {
[1894] Fix | Delete
$errors = array();
[1895] Fix | Delete
[1896] Fix | Delete
foreach ( $args['anyOf'] as $index => $schema ) {
[1897] Fix | Delete
if ( ! isset( $schema['type'] ) && isset( $args['type'] ) ) {
[1898] Fix | Delete
$schema['type'] = $args['type'];
[1899] Fix | Delete
}
[1900] Fix | Delete
[1901] Fix | Delete
$is_valid = rest_validate_value_from_schema( $value, $schema, $param );
[1902] Fix | Delete
if ( ! is_wp_error( $is_valid ) ) {
[1903] Fix | Delete
return $schema;
[1904] Fix | Delete
}
[1905] Fix | Delete
[1906] Fix | Delete
$errors[] = array(
[1907] Fix | Delete
'error_object' => $is_valid,
[1908] Fix | Delete
'schema' => $schema,
[1909] Fix | Delete
'index' => $index,
[1910] Fix | Delete
);
[1911] Fix | Delete
}
[1912] Fix | Delete
[1913] Fix | Delete
return rest_get_combining_operation_error( $value, $param, $errors );
[1914] Fix | Delete
}
[1915] Fix | Delete
[1916] Fix | Delete
/**
[1917] Fix | Delete
* Finds the matching schema among the "oneOf" schemas.
[1918] Fix | Delete
*
[1919] Fix | Delete
* @since 5.6.0
[1920] Fix | Delete
*
[1921] Fix | Delete
* @param mixed $value The value to validate.
[1922] Fix | Delete
* @param array $args The schema array to use.
[1923] Fix | Delete
* @param string $param The parameter name, used in error messages.
[1924] Fix | Delete
* @param bool $stop_after_first_match Optional. Whether the process should stop after the first successful match.
[1925] Fix | Delete
* @return array|WP_Error The matching schema or WP_Error instance if the number of matching schemas is not equal to one.
[1926] Fix | Delete
*/
[1927] Fix | Delete
function rest_find_one_matching_schema( $value, $args, $param, $stop_after_first_match = false ) {
[1928] Fix | Delete
$matching_schemas = array();
[1929] Fix | Delete
$errors = array();
[1930] Fix | Delete
[1931] Fix | Delete
foreach ( $args['oneOf'] as $index => $schema ) {
[1932] Fix | Delete
if ( ! isset( $schema['type'] ) && isset( $args['type'] ) ) {
[1933] Fix | Delete
$schema['type'] = $args['type'];
[1934] Fix | Delete
}
[1935] Fix | Delete
[1936] Fix | Delete
$is_valid = rest_validate_value_from_schema( $value, $schema, $param );
[1937] Fix | Delete
if ( ! is_wp_error( $is_valid ) ) {
[1938] Fix | Delete
if ( $stop_after_first_match ) {
[1939] Fix | Delete
return $schema;
[1940] Fix | Delete
}
[1941] Fix | Delete
[1942] Fix | Delete
$matching_schemas[] = array(
[1943] Fix | Delete
'schema_object' => $schema,
[1944] Fix | Delete
'index' => $index,
[1945] Fix | Delete
);
[1946] Fix | Delete
} else {
[1947] Fix | Delete
$errors[] = array(
[1948] Fix | Delete
'error_object' => $is_valid,
[1949] Fix | Delete
'schema' => $schema,
[1950] Fix | Delete
'index' => $index,
[1951] Fix | Delete
);
[1952] Fix | Delete
}
[1953] Fix | Delete
}
[1954] Fix | Delete
[1955] Fix | Delete
if ( ! $matching_schemas ) {
[1956] Fix | Delete
return rest_get_combining_operation_error( $value, $param, $errors );
[1957] Fix | Delete
}
[1958] Fix | Delete
[1959] Fix | Delete
if ( count( $matching_schemas ) > 1 ) {
[1960] Fix | Delete
$schema_positions = array();
[1961] Fix | Delete
$schema_titles = array();
[1962] Fix | Delete
[1963] Fix | Delete
foreach ( $matching_schemas as $schema ) {
[1964] Fix | Delete
$schema_positions[] = $schema['index'];
[1965] Fix | Delete
[1966] Fix | Delete
if ( isset( $schema['schema_object']['title'] ) ) {
[1967] Fix | Delete
$schema_titles[] = $schema['schema_object']['title'];
[1968] Fix | Delete
}
[1969] Fix | Delete
}
[1970] Fix | Delete
[1971] Fix | Delete
// If each schema has a title, include those titles in the error message.
[1972] Fix | Delete
if ( count( $schema_titles ) === count( $matching_schemas ) ) {
[1973] Fix | Delete
return new WP_Error(
[1974] Fix | Delete
'rest_one_of_multiple_matches',
[1975] Fix | Delete
/* translators: 1: Parameter, 2: Schema titles. */
[1976] Fix | Delete
wp_sprintf( __( '%1$s matches %2$l, but should match only one.' ), $param, $schema_titles ),
[1977] Fix | Delete
array( 'positions' => $schema_positions )
[1978] Fix | Delete
);
[1979] Fix | Delete
}
[1980] Fix | Delete
[1981] Fix | Delete
return new WP_Error(
[1982] Fix | Delete
'rest_one_of_multiple_matches',
[1983] Fix | Delete
/* translators: %s: Parameter. */
[1984] Fix | Delete
sprintf( __( '%s matches more than one of the expected formats.' ), $param ),
[1985] Fix | Delete
array( 'positions' => $schema_positions )
[1986] Fix | Delete
);
[1987] Fix | Delete
}
[1988] Fix | Delete
[1989] Fix | Delete
return $matching_schemas[0]['schema_object'];
[1990] Fix | Delete
}
[1991] Fix | Delete
[1992] Fix | Delete
/**
[1993] Fix | Delete
* Checks the equality of two values, following JSON Schema semantics.
[1994] Fix | Delete
*
[1995] Fix | Delete
* Property order is ignored for objects.
[1996] Fix | Delete
*
[1997] Fix | Delete
* Values must have been previously sanitized/coerced to their native types.
[1998] Fix | Delete
*
[1999] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function