delete_network_option

The timeline below displays how wordpress function delete_network_option has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 5.5

/**
 * Removes a network option by name.
 *
 * @since 4.4.0
 *
 * @see delete_option()
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param int    $network_id ID of the network. Can be null to default to the current network ID.
 * @param string $option     Name of the option to delete. Expected to not be SQL-escaped.
 * @return bool True if the option was deleted, false otherwise.
 */
function delete_network_option($network_id, $option)
{
    global $wpdb;
    if ($network_id && !is_numeric($network_id)) {
        return false;
    }
    $network_id = (int) $network_id;
    // Fallback to the current network if a network ID is not specified.
    if (!$network_id) {
        $network_id = get_current_network_id();
    }
    /**
     * Fires immediately before a specific network option is deleted.
     *
     * The dynamic portion of the hook name, `$option`, refers to the option name.
     *
     * @since 3.0.0
     * @since 4.4.0 The `$option` parameter was added.
     * @since 4.7.0 The `$network_id` parameter was added.
     *
     * @param string $option     Option name.
     * @param int    $network_id ID of the network.
     */
    do_action("pre_delete_site_option_{$option}", $option, $network_id);
    if (!is_multisite()) {
        $result = delete_option($option);
    } else {
        $row = $wpdb->get_row($wpdb->prepare("SELECT meta_id FROM {$wpdb->sitemeta} WHERE meta_key = %s AND site_id = %d", $option, $network_id));
        if (is_null($row) || !$row->meta_id) {
            return false;
        }
        $cache_key = "{$network_id}:{$option}";
        wp_cache_delete($cache_key, 'site-options');
        $result = $wpdb->delete($wpdb->sitemeta, array('meta_key' => $option, 'site_id' => $network_id));
    }
    if ($result) {
        /**
         * Fires after a specific network option has been deleted.
         *
         * The dynamic portion of the hook name, `$option`, refers to the option name.
         *
         * @since 2.9.0 As "delete_site_option_{$key}"
         * @since 3.0.0
         * @since 4.7.0 The `$network_id` parameter was added.
         *
         * @param string $option     Name of the network option.
         * @param int    $network_id ID of the network.
         */
        do_action("delete_site_option_{$option}", $option, $network_id);
        /**
         * Fires after a network option has been deleted.
         *
         * @since 3.0.0
         * @since 4.7.0 The `$network_id` parameter was added.
         *
         * @param string $option     Name of the network option.
         * @param int    $network_id ID of the network.
         */
        do_action('delete_site_option', $option, $network_id);
        return true;
    }
    return false;
}

WordPress Version: 5.1

/**
 * Removes a network option by name.
 *
 * @since 4.4.0
 *
 * @see delete_option()
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param int    $network_id ID of the network. Can be null to default to the current network ID.
 * @param string $option     Name of option to remove. Expected to not be SQL-escaped.
 * @return bool True, if succeed. False, if failure.
 */
function delete_network_option($network_id, $option)
{
    global $wpdb;
    if ($network_id && !is_numeric($network_id)) {
        return false;
    }
    $network_id = (int) $network_id;
    // Fallback to the current network if a network ID is not specified.
    if (!$network_id) {
        $network_id = get_current_network_id();
    }
    /**
     * Fires immediately before a specific network option is deleted.
     *
     * The dynamic portion of the hook name, `$option`, refers to the option name.
     *
     * @since 3.0.0
     * @since 4.4.0 The `$option` parameter was added.
     * @since 4.7.0 The `$network_id` parameter was added.
     *
     * @param string $option     Option name.
     * @param int    $network_id ID of the network.
     */
    do_action("pre_delete_site_option_{$option}", $option, $network_id);
    if (!is_multisite()) {
        $result = delete_option($option);
    } else {
        $row = $wpdb->get_row($wpdb->prepare("SELECT meta_id FROM {$wpdb->sitemeta} WHERE meta_key = %s AND site_id = %d", $option, $network_id));
        if (is_null($row) || !$row->meta_id) {
            return false;
        }
        $cache_key = "{$network_id}:{$option}";
        wp_cache_delete($cache_key, 'site-options');
        $result = $wpdb->delete($wpdb->sitemeta, array('meta_key' => $option, 'site_id' => $network_id));
    }
    if ($result) {
        /**
         * Fires after a specific network option has been deleted.
         *
         * The dynamic portion of the hook name, `$option`, refers to the option name.
         *
         * @since 2.9.0 As "delete_site_option_{$key}"
         * @since 3.0.0
         * @since 4.7.0 The `$network_id` parameter was added.
         *
         * @param string $option     Name of the network option.
         * @param int    $network_id ID of the network.
         */
        do_action("delete_site_option_{$option}", $option, $network_id);
        /**
         * Fires after a network option has been deleted.
         *
         * @since 3.0.0
         * @since 4.7.0 The `$network_id` parameter was added.
         *
         * @param string $option     Name of the network option.
         * @param int    $network_id ID of the network.
         */
        do_action('delete_site_option', $option, $network_id);
        return true;
    }
    return false;
}

WordPress Version: 4.7

/**
 * Removes a network option by name.
 *
 * @since 4.4.0
 *
 * @see delete_option()
 *
 * @global wpdb $wpdb
 *
 * @param int    $network_id ID of the network. Can be null to default to the current network ID.
 * @param string $option     Name of option to remove. Expected to not be SQL-escaped.
 * @return bool True, if succeed. False, if failure.
 */
function delete_network_option($network_id, $option)
{
    global $wpdb;
    if ($network_id && !is_numeric($network_id)) {
        return false;
    }
    $network_id = (int) $network_id;
    // Fallback to the current network if a network ID is not specified.
    if (!$network_id) {
        $network_id = get_current_network_id();
    }
    /**
     * Fires immediately before a specific network option is deleted.
     *
     * The dynamic portion of the hook name, `$option`, refers to the option name.
     *
     * @since 3.0.0
     * @since 4.4.0 The `$option` parameter was added.
     * @since 4.7.0 The `$network_id` parameter was added.
     *
     * @param string $option     Option name.
     * @param int    $network_id ID of the network.
     */
    do_action("pre_delete_site_option_{$option}", $option, $network_id);
    if (!is_multisite()) {
        $result = delete_option($option);
    } else {
        $row = $wpdb->get_row($wpdb->prepare("SELECT meta_id FROM {$wpdb->sitemeta} WHERE meta_key = %s AND site_id = %d", $option, $network_id));
        if (is_null($row) || !$row->meta_id) {
            return false;
        }
        $cache_key = "{$network_id}:{$option}";
        wp_cache_delete($cache_key, 'site-options');
        $result = $wpdb->delete($wpdb->sitemeta, array('meta_key' => $option, 'site_id' => $network_id));
    }
    if ($result) {
        /**
         * Fires after a specific network option has been deleted.
         *
         * The dynamic portion of the hook name, `$option`, refers to the option name.
         *
         * @since 2.9.0 As "delete_site_option_{$key}"
         * @since 3.0.0
         * @since 4.7.0 The `$network_id` parameter was added.
         *
         * @param string $option     Name of the network option.
         * @param int    $network_id ID of the network.
         */
        do_action("delete_site_option_{$option}", $option, $network_id);
        /**
         * Fires after a network option has been deleted.
         *
         * @since 3.0.0
         * @since 4.7.0 The `$network_id` parameter was added.
         *
         * @param string $option     Name of the network option.
         * @param int    $network_id ID of the network.
         */
        do_action('delete_site_option', $option, $network_id);
        return true;
    }
    return false;
}

WordPress Version: 4.4

/**
 * Removes a network option by name.
 *
 * @since 4.4.0
 *
 * @see delete_option()
 *
 * @global wpdb   $wpdb
 * @global object $current_site
 *
 * @param int    $network_id ID of the network. Can be null to default to the current network ID.
 * @param string $option     Name of option to remove. Expected to not be SQL-escaped.
 * @return bool True, if succeed. False, if failure.
 */
function delete_network_option($network_id, $option)
{
    global $wpdb, $current_site;
    if ($network_id && !is_numeric($network_id)) {
        return false;
    }
    $network_id = (int) $network_id;
    // Fallback to the current network if a network ID is not specified.
    if (!$network_id && is_multisite()) {
        $network_id = $current_site->id;
    }
    /**
     * Fires immediately before a specific network option is deleted.
     *
     * The dynamic portion of the hook name, `$option`, refers to the option name.
     *
     * @since 3.0.0
     * @since 4.4.0 The `$option` parameter was added
     *
     * @param string $option Option name.
     */
    do_action('pre_delete_site_option_' . $option, $option);
    if (!is_multisite()) {
        $result = delete_option($option);
    } else {
        $row = $wpdb->get_row($wpdb->prepare("SELECT meta_id FROM {$wpdb->sitemeta} WHERE meta_key = %s AND site_id = %d", $option, $network_id));
        if (is_null($row) || !$row->meta_id) {
            return false;
        }
        $cache_key = "{$network_id}:{$option}";
        wp_cache_delete($cache_key, 'site-options');
        $result = $wpdb->delete($wpdb->sitemeta, array('meta_key' => $option, 'site_id' => $network_id));
    }
    if ($result) {
        /**
         * Fires after a specific network option has been deleted.
         *
         * The dynamic portion of the hook name, `$option`, refers to the option name.
         *
         * @since 2.9.0 As "delete_site_option_{$key}"
         * @since 3.0.0
         *
         * @param string $option Name of the network option.
         */
        do_action('delete_site_option_' . $option, $option);
        /**
         * Fires after a network option has been deleted.
         *
         * @since 3.0.0
         *
         * @param string $option Name of the network option.
         */
        do_action('delete_site_option', $option);
        return true;
    }
    return false;
}