Make WordPress Core

Ticket #15865: removal-functions-03-refreshed.patch

File removal-functions-03-refreshed.patch, 4.1 KB (added by dcavins, 20 months ago)

A refereshed version of the previous patch that adds removal functions.

  • src/wp-admin/includes/template.php

    diff --git src/wp-admin/includes/template.php src/wp-admin/includes/template.php
    index 0771b7129e..8fed7a6205 100644
    function add_settings_section( $id, $title, $callback, $page, $args = array() ) 
    16621662        $wp_settings_sections[ $page ][ $id ] = $section;
    16631663}
    16641664
     1665/**
     1666 * Remove a settings section from a settings page.
     1667 *
     1668 * Part of the Settings API. Use this to remove a settings section from an admin page.
     1669 *
     1670 * @since 6.3.0
     1671 *
     1672 * @global array $wp_settings_sections Storage array of all settings sections added to admin pages.
     1673 * @global array $wp_settings_fields Storage array of settings fields and info about their pages/sections.
     1674 *
     1675 * @param string $id    Slug-name to identify the section.
     1676 * @param string $page  The slug-name of the settings page on which to remove the section.
     1677 */
     1678function remove_settings_section( $id, $page ) {
     1679        global $wp_settings_sections, $wp_settings_fields;
     1680
     1681        // Remove item from $wp_settings_sections global.
     1682        if ( isset( $wp_settings_sections[ $page ][ $id ] ) ) {
     1683                unset( $wp_settings_sections[ $page ][ $id ] );
     1684        }
     1685
     1686        // Remove containing structure that could potentially now be empty.
     1687        if ( empty( $wp_settings_sections[ $page ] ) ) {
     1688                unset( $wp_settings_sections[ $page ] );
     1689        }
     1690
     1691        // Remove related fields from the $wp_settings_fields global.
     1692        if ( isset( $wp_settings_fields[ $page ][ $id ] ) ) {
     1693                unset( $wp_settings_fields[ $page ][ $id ] );
     1694        }
     1695
     1696        // Remove containing structure that could potentially now be empty.
     1697        if ( empty( $wp_settings_fields[ $page ] ) ) {
     1698                unset( $wp_settings_fields[ $page ] );
     1699        }
     1700}
     1701
    16651702/**
    16661703 * Adds a new field to a section of a settings page.
    16671704 *
    function add_settings_field( $id, $title, $callback, $page, $section = 'default' 
    17341771        );
    17351772}
    17361773
     1774/**
     1775 * Removes field from a section of a settings page.
     1776 *
     1777 * Part of the Settings API. Use this to remove a previously
     1778 * declared settings field.
     1779 *
     1780 * @since 6.3,0
     1781 *
     1782 * @global array $wp_settings_fields Storage array of settings fields and info about their pages/sections.
     1783 *
     1784 * @param string $id       Slug-name to identify the field.
     1785 * @param string $page     The slug-name of the settings page on which to show the section
     1786 *                         (general, reading, writing, ...).
     1787 * @param string $section  Optional. The slug-name of the section of the settings page
     1788 *                         with which the field is associated. Default 'default'.
     1789 */
     1790function remove_settings_field( $id, $page, $section = 'default' ) {
     1791        global $wp_settings_fields;
     1792
     1793        if ( isset( $wp_settings_fields[ $page ][ $section ][ $id ] ) ) {
     1794                unset( $wp_settings_fields[ $page ][ $section ][ $id ] );
     1795        }
     1796
     1797        // Remove containing structure that could potentially now be empty.
     1798        if ( empty( $wp_settings_fields[ $page ][ $section ] ) ) {
     1799                unset( $wp_settings_fields[ $page ][ $section ] );
     1800        }
     1801
     1802        if ( empty( $wp_settings_fields[ $page ] ) ) {
     1803                unset( $wp_settings_fields[ $page ] );
     1804        }
     1805}
     1806
    17371807/**
    17381808 * Prints out all settings sections added to a particular settings page.
    17391809 *
    function add_settings_error( $setting, $code, $message, $type = 'error' ) { 
    18631933        );
    18641934}
    18651935
     1936/**
     1937 * Removes a settings error to be displayed to the user.
     1938 *
     1939 * Part of the Settings API. Use this to remove messages to users about settings validation
     1940 * problems, missing settings or anything else.
     1941 *
     1942 * @since 6.3.0
     1943 *
     1944 * @global array[] $wp_settings_errors Storage array of errors registered during this pageload
     1945 *
     1946 * @param string $setting Slug title of the setting to which the error
     1947 *                        we want to remove applies.
     1948 * @param string $code    Slug-name to identify the error.
     1949 */
     1950function remove_settings_error( $setting, $code ) {
     1951        global $wp_settings_errors;
     1952
     1953        if ( ! empty( $wp_settings_errors ) ) {
     1954                foreach ( $wp_settings_errors as $index => $error ) {
     1955                        if ( $error['setting'] === $setting && $error['code'] === $code ) {
     1956                                unset( $wp_settings_errors[ $index ] );
     1957                        }
     1958                }
     1959        }
     1960}
     1961
    18661962/**
    18671963 * Fetches settings errors registered by add_settings_error().
    18681964 *