Edit File by line
/home/zeestwma/ceyloniy.../wp-admin/includes
File: template.php
$page = $screen->id;
[1500] Fix | Delete
[1501] Fix | Delete
if ( ! isset( $wp_meta_boxes ) ) {
[1502] Fix | Delete
$wp_meta_boxes = array();
[1503] Fix | Delete
}
[1504] Fix | Delete
if ( ! isset( $wp_meta_boxes[ $page ] ) ) {
[1505] Fix | Delete
$wp_meta_boxes[ $page ] = array();
[1506] Fix | Delete
}
[1507] Fix | Delete
if ( ! isset( $wp_meta_boxes[ $page ][ $context ] ) ) {
[1508] Fix | Delete
$wp_meta_boxes[ $page ][ $context ] = array();
[1509] Fix | Delete
}
[1510] Fix | Delete
[1511] Fix | Delete
foreach ( array( 'high', 'core', 'default', 'low' ) as $priority ) {
[1512] Fix | Delete
$wp_meta_boxes[ $page ][ $context ][ $priority ][ $id ] = false;
[1513] Fix | Delete
}
[1514] Fix | Delete
}
[1515] Fix | Delete
[1516] Fix | Delete
/**
[1517] Fix | Delete
* Meta Box Accordion Template Function.
[1518] Fix | Delete
*
[1519] Fix | Delete
* Largely made up of abstracted code from do_meta_boxes(), this
[1520] Fix | Delete
* function serves to build meta boxes as list items for display as
[1521] Fix | Delete
* a collapsible accordion.
[1522] Fix | Delete
*
[1523] Fix | Delete
* @since 3.6.0
[1524] Fix | Delete
*
[1525] Fix | Delete
* @uses global $wp_meta_boxes Used to retrieve registered meta boxes.
[1526] Fix | Delete
*
[1527] Fix | Delete
* @param string|object $screen The screen identifier.
[1528] Fix | Delete
* @param string $context The screen context for which to display accordion sections.
[1529] Fix | Delete
* @param mixed $data_object Gets passed to the section callback function as the first parameter.
[1530] Fix | Delete
* @return int Number of meta boxes as accordion sections.
[1531] Fix | Delete
*/
[1532] Fix | Delete
function do_accordion_sections( $screen, $context, $data_object ) {
[1533] Fix | Delete
global $wp_meta_boxes;
[1534] Fix | Delete
[1535] Fix | Delete
wp_enqueue_script( 'accordion' );
[1536] Fix | Delete
[1537] Fix | Delete
if ( empty( $screen ) ) {
[1538] Fix | Delete
$screen = get_current_screen();
[1539] Fix | Delete
} elseif ( is_string( $screen ) ) {
[1540] Fix | Delete
$screen = convert_to_screen( $screen );
[1541] Fix | Delete
}
[1542] Fix | Delete
[1543] Fix | Delete
$page = $screen->id;
[1544] Fix | Delete
[1545] Fix | Delete
$hidden = get_hidden_meta_boxes( $screen );
[1546] Fix | Delete
?>
[1547] Fix | Delete
<div id="side-sortables" class="accordion-container">
[1548] Fix | Delete
<ul class="outer-border">
[1549] Fix | Delete
<?php
[1550] Fix | Delete
$i = 0;
[1551] Fix | Delete
$first_open = false;
[1552] Fix | Delete
[1553] Fix | Delete
if ( isset( $wp_meta_boxes[ $page ][ $context ] ) ) {
[1554] Fix | Delete
foreach ( array( 'high', 'core', 'default', 'low' ) as $priority ) {
[1555] Fix | Delete
if ( isset( $wp_meta_boxes[ $page ][ $context ][ $priority ] ) ) {
[1556] Fix | Delete
foreach ( $wp_meta_boxes[ $page ][ $context ][ $priority ] as $box ) {
[1557] Fix | Delete
if ( false === $box || ! $box['title'] ) {
[1558] Fix | Delete
continue;
[1559] Fix | Delete
}
[1560] Fix | Delete
[1561] Fix | Delete
++$i;
[1562] Fix | Delete
$hidden_class = in_array( $box['id'], $hidden, true ) ? 'hide-if-js' : '';
[1563] Fix | Delete
[1564] Fix | Delete
$open_class = '';
[1565] Fix | Delete
$aria_expanded = 'false';
[1566] Fix | Delete
if ( ! $first_open && empty( $hidden_class ) ) {
[1567] Fix | Delete
$first_open = true;
[1568] Fix | Delete
$open_class = 'open';
[1569] Fix | Delete
$aria_expanded = 'true';
[1570] Fix | Delete
}
[1571] Fix | Delete
?>
[1572] Fix | Delete
<li class="control-section accordion-section <?php echo $hidden_class; ?> <?php echo $open_class; ?> <?php echo esc_attr( $box['id'] ); ?>" id="<?php echo esc_attr( $box['id'] ); ?>">
[1573] Fix | Delete
<h3 class="accordion-section-title hndle">
[1574] Fix | Delete
<button type="button" class="accordion-trigger" aria-expanded="<?php echo $aria_expanded; ?>" aria-controls="<?php echo esc_attr( $box['id'] ); ?>-content">
[1575] Fix | Delete
<span class="accordion-title">
[1576] Fix | Delete
<?php echo esc_html( $box['title'] ); ?>
[1577] Fix | Delete
<span class="dashicons dashicons-arrow-down" aria-hidden="true"></span>
[1578] Fix | Delete
</span>
[1579] Fix | Delete
</button>
[1580] Fix | Delete
</h3>
[1581] Fix | Delete
<div class="accordion-section-content <?php postbox_classes( $box['id'], $page ); ?>" id="<?php echo esc_attr( $box['id'] ); ?>-content">
[1582] Fix | Delete
<div class="inside">
[1583] Fix | Delete
<?php call_user_func( $box['callback'], $data_object, $box ); ?>
[1584] Fix | Delete
</div><!-- .inside -->
[1585] Fix | Delete
</div><!-- .accordion-section-content -->
[1586] Fix | Delete
</li><!-- .accordion-section -->
[1587] Fix | Delete
<?php
[1588] Fix | Delete
}
[1589] Fix | Delete
}
[1590] Fix | Delete
}
[1591] Fix | Delete
}
[1592] Fix | Delete
?>
[1593] Fix | Delete
</ul><!-- .outer-border -->
[1594] Fix | Delete
</div><!-- .accordion-container -->
[1595] Fix | Delete
<?php
[1596] Fix | Delete
return $i;
[1597] Fix | Delete
}
[1598] Fix | Delete
[1599] Fix | Delete
/**
[1600] Fix | Delete
* Adds a new section to a settings page.
[1601] Fix | Delete
*
[1602] Fix | Delete
* Part of the Settings API. Use this to define new settings sections for an admin page.
[1603] Fix | Delete
* Show settings sections in your admin page callback function with do_settings_sections().
[1604] Fix | Delete
* Add settings fields to your section with add_settings_field().
[1605] Fix | Delete
*
[1606] Fix | Delete
* The $callback argument should be the name of a function that echoes out any
[1607] Fix | Delete
* content you want to show at the top of the settings section before the actual
[1608] Fix | Delete
* fields. It can output nothing if you want.
[1609] Fix | Delete
*
[1610] Fix | Delete
* @since 2.7.0
[1611] Fix | Delete
* @since 6.1.0 Added an `$args` parameter for the section's HTML wrapper and class name.
[1612] Fix | Delete
*
[1613] Fix | Delete
* @global array $wp_settings_sections Storage array of all settings sections added to admin pages.
[1614] Fix | Delete
*
[1615] Fix | Delete
* @param string $id Slug-name to identify the section. Used in the 'id' attribute of tags.
[1616] Fix | Delete
* @param string $title Formatted title of the section. Shown as the heading for the section.
[1617] Fix | Delete
* @param callable $callback Function that echos out any content at the top of the section (between heading and fields).
[1618] Fix | Delete
* @param string $page The slug-name of the settings page on which to show the section. Built-in pages include
[1619] Fix | Delete
* 'general', 'reading', 'writing', 'discussion', 'media', etc. Create your own using
[1620] Fix | Delete
* add_options_page();
[1621] Fix | Delete
* @param array $args {
[1622] Fix | Delete
* Arguments used to create the settings section.
[1623] Fix | Delete
*
[1624] Fix | Delete
* @type string $before_section HTML content to prepend to the section's HTML output.
[1625] Fix | Delete
* Receives the section's class name as `%s`. Default empty.
[1626] Fix | Delete
* @type string $after_section HTML content to append to the section's HTML output. Default empty.
[1627] Fix | Delete
* @type string $section_class The class name to use for the section. Default empty.
[1628] Fix | Delete
* }
[1629] Fix | Delete
*/
[1630] Fix | Delete
function add_settings_section( $id, $title, $callback, $page, $args = array() ) {
[1631] Fix | Delete
global $wp_settings_sections;
[1632] Fix | Delete
[1633] Fix | Delete
$defaults = array(
[1634] Fix | Delete
'id' => $id,
[1635] Fix | Delete
'title' => $title,
[1636] Fix | Delete
'callback' => $callback,
[1637] Fix | Delete
'before_section' => '',
[1638] Fix | Delete
'after_section' => '',
[1639] Fix | Delete
'section_class' => '',
[1640] Fix | Delete
);
[1641] Fix | Delete
[1642] Fix | Delete
$section = wp_parse_args( $args, $defaults );
[1643] Fix | Delete
[1644] Fix | Delete
if ( 'misc' === $page ) {
[1645] Fix | Delete
_deprecated_argument(
[1646] Fix | Delete
__FUNCTION__,
[1647] Fix | Delete
'3.0.0',
[1648] Fix | Delete
sprintf(
[1649] Fix | Delete
/* translators: %s: misc */
[1650] Fix | Delete
__( 'The "%s" options group has been removed. Use another settings group.' ),
[1651] Fix | Delete
'misc'
[1652] Fix | Delete
)
[1653] Fix | Delete
);
[1654] Fix | Delete
$page = 'general';
[1655] Fix | Delete
}
[1656] Fix | Delete
[1657] Fix | Delete
if ( 'privacy' === $page ) {
[1658] Fix | Delete
_deprecated_argument(
[1659] Fix | Delete
__FUNCTION__,
[1660] Fix | Delete
'3.5.0',
[1661] Fix | Delete
sprintf(
[1662] Fix | Delete
/* translators: %s: privacy */
[1663] Fix | Delete
__( 'The "%s" options group has been removed. Use another settings group.' ),
[1664] Fix | Delete
'privacy'
[1665] Fix | Delete
)
[1666] Fix | Delete
);
[1667] Fix | Delete
$page = 'reading';
[1668] Fix | Delete
}
[1669] Fix | Delete
[1670] Fix | Delete
$wp_settings_sections[ $page ][ $id ] = $section;
[1671] Fix | Delete
}
[1672] Fix | Delete
[1673] Fix | Delete
/**
[1674] Fix | Delete
* Adds a new field to a section of a settings page.
[1675] Fix | Delete
*
[1676] Fix | Delete
* Part of the Settings API. Use this to define a settings field that will show
[1677] Fix | Delete
* as part of a settings section inside a settings page. The fields are shown using
[1678] Fix | Delete
* do_settings_fields() in do_settings_sections().
[1679] Fix | Delete
*
[1680] Fix | Delete
* The $callback argument should be the name of a function that echoes out the
[1681] Fix | Delete
* HTML input tags for this setting field. Use get_option() to retrieve existing
[1682] Fix | Delete
* values to show.
[1683] Fix | Delete
*
[1684] Fix | Delete
* @since 2.7.0
[1685] Fix | Delete
* @since 4.2.0 The `$class` argument was added.
[1686] Fix | Delete
*
[1687] Fix | Delete
* @global array $wp_settings_fields Storage array of settings fields and info about their pages/sections.
[1688] Fix | Delete
*
[1689] Fix | Delete
* @param string $id Slug-name to identify the field. Used in the 'id' attribute of tags.
[1690] Fix | Delete
* @param string $title Formatted title of the field. Shown as the label for the field
[1691] Fix | Delete
* during output.
[1692] Fix | Delete
* @param callable $callback Function that fills the field with the desired form inputs. The
[1693] Fix | Delete
* function should echo its output.
[1694] Fix | Delete
* @param string $page The slug-name of the settings page on which to show the section
[1695] Fix | Delete
* (general, reading, writing, ...).
[1696] Fix | Delete
* @param string $section Optional. The slug-name of the section of the settings page
[1697] Fix | Delete
* in which to show the box. Default 'default'.
[1698] Fix | Delete
* @param array $args {
[1699] Fix | Delete
* Optional. Extra arguments that get passed to the callback function.
[1700] Fix | Delete
*
[1701] Fix | Delete
* @type string $label_for When supplied, the setting title will be wrapped
[1702] Fix | Delete
* in a `<label>` element, its `for` attribute populated
[1703] Fix | Delete
* with this value.
[1704] Fix | Delete
* @type string $class CSS Class to be added to the `<tr>` element when the
[1705] Fix | Delete
* field is output.
[1706] Fix | Delete
* }
[1707] Fix | Delete
*/
[1708] Fix | Delete
function add_settings_field( $id, $title, $callback, $page, $section = 'default', $args = array() ) {
[1709] Fix | Delete
global $wp_settings_fields;
[1710] Fix | Delete
[1711] Fix | Delete
if ( 'misc' === $page ) {
[1712] Fix | Delete
_deprecated_argument(
[1713] Fix | Delete
__FUNCTION__,
[1714] Fix | Delete
'3.0.0',
[1715] Fix | Delete
sprintf(
[1716] Fix | Delete
/* translators: %s: misc */
[1717] Fix | Delete
__( 'The "%s" options group has been removed. Use another settings group.' ),
[1718] Fix | Delete
'misc'
[1719] Fix | Delete
)
[1720] Fix | Delete
);
[1721] Fix | Delete
$page = 'general';
[1722] Fix | Delete
}
[1723] Fix | Delete
[1724] Fix | Delete
if ( 'privacy' === $page ) {
[1725] Fix | Delete
_deprecated_argument(
[1726] Fix | Delete
__FUNCTION__,
[1727] Fix | Delete
'3.5.0',
[1728] Fix | Delete
sprintf(
[1729] Fix | Delete
/* translators: %s: privacy */
[1730] Fix | Delete
__( 'The "%s" options group has been removed. Use another settings group.' ),
[1731] Fix | Delete
'privacy'
[1732] Fix | Delete
)
[1733] Fix | Delete
);
[1734] Fix | Delete
$page = 'reading';
[1735] Fix | Delete
}
[1736] Fix | Delete
[1737] Fix | Delete
$wp_settings_fields[ $page ][ $section ][ $id ] = array(
[1738] Fix | Delete
'id' => $id,
[1739] Fix | Delete
'title' => $title,
[1740] Fix | Delete
'callback' => $callback,
[1741] Fix | Delete
'args' => $args,
[1742] Fix | Delete
);
[1743] Fix | Delete
}
[1744] Fix | Delete
[1745] Fix | Delete
/**
[1746] Fix | Delete
* Prints out all settings sections added to a particular settings page.
[1747] Fix | Delete
*
[1748] Fix | Delete
* Part of the Settings API. Use this in a settings page callback function
[1749] Fix | Delete
* to output all the sections and fields that were added to that $page with
[1750] Fix | Delete
* add_settings_section() and add_settings_field()
[1751] Fix | Delete
*
[1752] Fix | Delete
* @since 2.7.0
[1753] Fix | Delete
*
[1754] Fix | Delete
* @global array $wp_settings_sections Storage array of all settings sections added to admin pages.
[1755] Fix | Delete
* @global array $wp_settings_fields Storage array of settings fields and info about their pages/sections.
[1756] Fix | Delete
*
[1757] Fix | Delete
* @param string $page The slug name of the page whose settings sections you want to output.
[1758] Fix | Delete
*/
[1759] Fix | Delete
function do_settings_sections( $page ) {
[1760] Fix | Delete
global $wp_settings_sections, $wp_settings_fields;
[1761] Fix | Delete
[1762] Fix | Delete
if ( ! isset( $wp_settings_sections[ $page ] ) ) {
[1763] Fix | Delete
return;
[1764] Fix | Delete
}
[1765] Fix | Delete
[1766] Fix | Delete
foreach ( (array) $wp_settings_sections[ $page ] as $section ) {
[1767] Fix | Delete
if ( '' !== $section['before_section'] ) {
[1768] Fix | Delete
if ( '' !== $section['section_class'] ) {
[1769] Fix | Delete
echo wp_kses_post( sprintf( $section['before_section'], esc_attr( $section['section_class'] ) ) );
[1770] Fix | Delete
} else {
[1771] Fix | Delete
echo wp_kses_post( $section['before_section'] );
[1772] Fix | Delete
}
[1773] Fix | Delete
}
[1774] Fix | Delete
[1775] Fix | Delete
if ( $section['title'] ) {
[1776] Fix | Delete
echo "<h2>{$section['title']}</h2>\n";
[1777] Fix | Delete
}
[1778] Fix | Delete
[1779] Fix | Delete
if ( $section['callback'] ) {
[1780] Fix | Delete
call_user_func( $section['callback'], $section );
[1781] Fix | Delete
}
[1782] Fix | Delete
[1783] Fix | Delete
if ( isset( $wp_settings_fields[ $page ][ $section['id'] ] ) ) {
[1784] Fix | Delete
echo '<table class="form-table" role="presentation">';
[1785] Fix | Delete
do_settings_fields( $page, $section['id'] );
[1786] Fix | Delete
echo '</table>';
[1787] Fix | Delete
}
[1788] Fix | Delete
[1789] Fix | Delete
if ( '' !== $section['after_section'] ) {
[1790] Fix | Delete
echo wp_kses_post( $section['after_section'] );
[1791] Fix | Delete
}
[1792] Fix | Delete
}
[1793] Fix | Delete
}
[1794] Fix | Delete
[1795] Fix | Delete
/**
[1796] Fix | Delete
* Prints out the settings fields for a particular settings section.
[1797] Fix | Delete
*
[1798] Fix | Delete
* Part of the Settings API. Use this in a settings page to output
[1799] Fix | Delete
* a specific section. Should normally be called by do_settings_sections()
[1800] Fix | Delete
* rather than directly.
[1801] Fix | Delete
*
[1802] Fix | Delete
* @since 2.7.0
[1803] Fix | Delete
*
[1804] Fix | Delete
* @global array $wp_settings_fields Storage array of settings fields and their pages/sections.
[1805] Fix | Delete
*
[1806] Fix | Delete
* @param string $page Slug title of the admin page whose settings fields you want to show.
[1807] Fix | Delete
* @param string $section Slug title of the settings section whose fields you want to show.
[1808] Fix | Delete
*/
[1809] Fix | Delete
function do_settings_fields( $page, $section ) {
[1810] Fix | Delete
global $wp_settings_fields;
[1811] Fix | Delete
[1812] Fix | Delete
if ( ! isset( $wp_settings_fields[ $page ][ $section ] ) ) {
[1813] Fix | Delete
return;
[1814] Fix | Delete
}
[1815] Fix | Delete
[1816] Fix | Delete
foreach ( (array) $wp_settings_fields[ $page ][ $section ] as $field ) {
[1817] Fix | Delete
$class = '';
[1818] Fix | Delete
[1819] Fix | Delete
if ( ! empty( $field['args']['class'] ) ) {
[1820] Fix | Delete
$class = ' class="' . esc_attr( $field['args']['class'] ) . '"';
[1821] Fix | Delete
}
[1822] Fix | Delete
[1823] Fix | Delete
echo "<tr{$class}>";
[1824] Fix | Delete
[1825] Fix | Delete
if ( ! empty( $field['args']['label_for'] ) ) {
[1826] Fix | Delete
echo '<th scope="row"><label for="' . esc_attr( $field['args']['label_for'] ) . '">' . $field['title'] . '</label></th>';
[1827] Fix | Delete
} else {
[1828] Fix | Delete
echo '<th scope="row">' . $field['title'] . '</th>';
[1829] Fix | Delete
}
[1830] Fix | Delete
[1831] Fix | Delete
echo '<td>';
[1832] Fix | Delete
call_user_func( $field['callback'], $field['args'] );
[1833] Fix | Delete
echo '</td>';
[1834] Fix | Delete
echo '</tr>';
[1835] Fix | Delete
}
[1836] Fix | Delete
}
[1837] Fix | Delete
[1838] Fix | Delete
/**
[1839] Fix | Delete
* Registers a settings error to be displayed to the user.
[1840] Fix | Delete
*
[1841] Fix | Delete
* Part of the Settings API. Use this to show messages to users about settings validation
[1842] Fix | Delete
* problems, missing settings or anything else.
[1843] Fix | Delete
*
[1844] Fix | Delete
* Settings errors should be added inside the $sanitize_callback function defined in
[1845] Fix | Delete
* register_setting() for a given setting to give feedback about the submission.
[1846] Fix | Delete
*
[1847] Fix | Delete
* By default messages will show immediately after the submission that generated the error.
[1848] Fix | Delete
* Additional calls to settings_errors() can be used to show errors even when the settings
[1849] Fix | Delete
* page is first accessed.
[1850] Fix | Delete
*
[1851] Fix | Delete
* @since 3.0.0
[1852] Fix | Delete
* @since 5.3.0 Added `warning` and `info` as possible values for `$type`.
[1853] Fix | Delete
*
[1854] Fix | Delete
* @global array[] $wp_settings_errors Storage array of errors registered during this pageload
[1855] Fix | Delete
*
[1856] Fix | Delete
* @param string $setting Slug title of the setting to which this error applies.
[1857] Fix | Delete
* @param string $code Slug-name to identify the error. Used as part of 'id' attribute in HTML output.
[1858] Fix | Delete
* @param string $message The formatted message text to display to the user (will be shown inside styled
[1859] Fix | Delete
* `<div>` and `<p>` tags).
[1860] Fix | Delete
* @param string $type Optional. Message type, controls HTML class. Possible values include 'error',
[1861] Fix | Delete
* 'success', 'warning', 'info'. Default 'error'.
[1862] Fix | Delete
*/
[1863] Fix | Delete
function add_settings_error( $setting, $code, $message, $type = 'error' ) {
[1864] Fix | Delete
global $wp_settings_errors;
[1865] Fix | Delete
[1866] Fix | Delete
$wp_settings_errors[] = array(
[1867] Fix | Delete
'setting' => $setting,
[1868] Fix | Delete
'code' => $code,
[1869] Fix | Delete
'message' => $message,
[1870] Fix | Delete
'type' => $type,
[1871] Fix | Delete
);
[1872] Fix | Delete
}
[1873] Fix | Delete
[1874] Fix | Delete
/**
[1875] Fix | Delete
* Fetches settings errors registered by add_settings_error().
[1876] Fix | Delete
*
[1877] Fix | Delete
* Checks the $wp_settings_errors array for any errors declared during the current
[1878] Fix | Delete
* pageload and returns them.
[1879] Fix | Delete
*
[1880] Fix | Delete
* If changes were just submitted ($_GET['settings-updated']) and settings errors were saved
[1881] Fix | Delete
* to the 'settings_errors' transient then those errors will be returned instead. This
[1882] Fix | Delete
* is used to pass errors back across pageloads.
[1883] Fix | Delete
*
[1884] Fix | Delete
* Use the $sanitize argument to manually re-sanitize the option before returning errors.
[1885] Fix | Delete
* This is useful if you have errors or notices you want to show even when the user
[1886] Fix | Delete
* hasn't submitted data (i.e. when they first load an options page, or in the {@see 'admin_notices'}
[1887] Fix | Delete
* action hook).
[1888] Fix | Delete
*
[1889] Fix | Delete
* @since 3.0.0
[1890] Fix | Delete
*
[1891] Fix | Delete
* @global array[] $wp_settings_errors Storage array of errors registered during this pageload
[1892] Fix | Delete
*
[1893] Fix | Delete
* @param string $setting Optional. Slug title of a specific setting whose errors you want.
[1894] Fix | Delete
* @param bool $sanitize Optional. Whether to re-sanitize the setting value before returning errors.
[1895] Fix | Delete
* @return array[] {
[1896] Fix | Delete
* Array of settings error arrays.
[1897] Fix | Delete
*
[1898] Fix | Delete
* @type array ...$0 {
[1899] Fix | Delete
* Associative array of setting error data.
[1900] Fix | Delete
*
[1901] Fix | Delete
* @type string $setting Slug title of the setting to which this error applies.
[1902] Fix | Delete
* @type string $code Slug-name to identify the error. Used as part of 'id' attribute in HTML output.
[1903] Fix | Delete
* @type string $message The formatted message text to display to the user (will be shown inside styled
[1904] Fix | Delete
* `<div>` and `<p>` tags).
[1905] Fix | Delete
* @type string $type Optional. Message type, controls HTML class. Possible values include 'error',
[1906] Fix | Delete
* 'success', 'warning', 'info'. Default 'error'.
[1907] Fix | Delete
* }
[1908] Fix | Delete
* }
[1909] Fix | Delete
*/
[1910] Fix | Delete
function get_settings_errors( $setting = '', $sanitize = false ) {
[1911] Fix | Delete
global $wp_settings_errors;
[1912] Fix | Delete
[1913] Fix | Delete
/*
[1914] Fix | Delete
* If $sanitize is true, manually re-run the sanitization for this option
[1915] Fix | Delete
* This allows the $sanitize_callback from register_setting() to run, adding
[1916] Fix | Delete
* any settings errors you want to show by default.
[1917] Fix | Delete
*/
[1918] Fix | Delete
if ( $sanitize ) {
[1919] Fix | Delete
sanitize_option( $setting, get_option( $setting ) );
[1920] Fix | Delete
}
[1921] Fix | Delete
[1922] Fix | Delete
// If settings were passed back from options.php then use them.
[1923] Fix | Delete
if ( isset( $_GET['settings-updated'] ) && $_GET['settings-updated'] && get_transient( 'settings_errors' ) ) {
[1924] Fix | Delete
$wp_settings_errors = array_merge( (array) $wp_settings_errors, get_transient( 'settings_errors' ) );
[1925] Fix | Delete
delete_transient( 'settings_errors' );
[1926] Fix | Delete
}
[1927] Fix | Delete
[1928] Fix | Delete
// Check global in case errors have been added on this pageload.
[1929] Fix | Delete
if ( empty( $wp_settings_errors ) ) {
[1930] Fix | Delete
return array();
[1931] Fix | Delete
}
[1932] Fix | Delete
[1933] Fix | Delete
// Filter the results to those of a specific setting if one was set.
[1934] Fix | Delete
if ( $setting ) {
[1935] Fix | Delete
$setting_errors = array();
[1936] Fix | Delete
[1937] Fix | Delete
foreach ( (array) $wp_settings_errors as $key => $details ) {
[1938] Fix | Delete
if ( $setting === $details['setting'] ) {
[1939] Fix | Delete
$setting_errors[] = $wp_settings_errors[ $key ];
[1940] Fix | Delete
}
[1941] Fix | Delete
}
[1942] Fix | Delete
[1943] Fix | Delete
return $setting_errors;
[1944] Fix | Delete
}
[1945] Fix | Delete
[1946] Fix | Delete
return $wp_settings_errors;
[1947] Fix | Delete
}
[1948] Fix | Delete
[1949] Fix | Delete
/**
[1950] Fix | Delete
* Displays settings errors registered by add_settings_error().
[1951] Fix | Delete
*
[1952] Fix | Delete
* Part of the Settings API. Outputs a div for each error retrieved by
[1953] Fix | Delete
* get_settings_errors().
[1954] Fix | Delete
*
[1955] Fix | Delete
* This is called automatically after a settings page based on the
[1956] Fix | Delete
* Settings API is submitted. Errors should be added during the validation
[1957] Fix | Delete
* callback function for a setting defined in register_setting().
[1958] Fix | Delete
*
[1959] Fix | Delete
* The $sanitize option is passed into get_settings_errors() and will
[1960] Fix | Delete
* re-run the setting sanitization
[1961] Fix | Delete
* on its current value.
[1962] Fix | Delete
*
[1963] Fix | Delete
* The $hide_on_update option will cause errors to only show when the settings
[1964] Fix | Delete
* page is first loaded. if the user has already saved new values it will be
[1965] Fix | Delete
* hidden to avoid repeating messages already shown in the default error
[1966] Fix | Delete
* reporting after submission. This is useful to show general errors like
[1967] Fix | Delete
* missing settings when the user arrives at the settings page.
[1968] Fix | Delete
*
[1969] Fix | Delete
* @since 3.0.0
[1970] Fix | Delete
* @since 5.3.0 Legacy `error` and `updated` CSS classes are mapped to
[1971] Fix | Delete
* `notice-error` and `notice-success`.
[1972] Fix | Delete
*
[1973] Fix | Delete
* @param string $setting Optional slug title of a specific setting whose errors you want.
[1974] Fix | Delete
* @param bool $sanitize Whether to re-sanitize the setting value before returning errors.
[1975] Fix | Delete
* @param bool $hide_on_update If set to true errors will not be shown if the settings page has
[1976] Fix | Delete
* already been submitted.
[1977] Fix | Delete
*/
[1978] Fix | Delete
function settings_errors( $setting = '', $sanitize = false, $hide_on_update = false ) {
[1979] Fix | Delete
[1980] Fix | Delete
if ( $hide_on_update && ! empty( $_GET['settings-updated'] ) ) {
[1981] Fix | Delete
return;
[1982] Fix | Delete
}
[1983] Fix | Delete
[1984] Fix | Delete
$settings_errors = get_settings_errors( $setting, $sanitize );
[1985] Fix | Delete
[1986] Fix | Delete
if ( empty( $settings_errors ) ) {
[1987] Fix | Delete
return;
[1988] Fix | Delete
}
[1989] Fix | Delete
[1990] Fix | Delete
$output = '';
[1991] Fix | Delete
[1992] Fix | Delete
foreach ( $settings_errors as $key => $details ) {
[1993] Fix | Delete
if ( 'updated' === $details['type'] ) {
[1994] Fix | Delete
$details['type'] = 'success';
[1995] Fix | Delete
}
[1996] Fix | Delete
[1997] Fix | Delete
if ( in_array( $details['type'], array( 'error', 'success', 'warning', 'info' ), true ) ) {
[1998] Fix | Delete
$details['type'] = 'notice-' . $details['type'];
[1999] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function