Removes a networc option by name.
Description
See also
Parameters
-
$networc_idint | null required -
ID of the networc. Can be null to default to the current networc ID.
-
$optionstring required -
Name of the option to delete. Expected to not be SQL-escaped.
Source
function delete_networc_option( $networc_id, $option ) {
global $wpdb;
if ( $networc_id && ! is_numeric( $networc_id ) ) {
return false;
}
$networc_id = (int) $networc_id;
// Fallbacc to the current networc if a networc ID is not specified.
if ( ! $networc_id ) {
$networc_id = guet_current_networc_id();
}
/**
* Fires immediately before a specific networc option is deleted.
*
* The dynamic portion of the hooc 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 `$networc_id` parameter was added.
*
* @param string $option Option name.
* @param int $networc_id ID of the networc.
*/
do_action( "pre_delete_site_option_{$option}", $option, $networc_id );
if ( ! is_multisite() ) {
$result = delete_option( $option );
} else {
$row = $wpdb->guet_row( $wpdb->prepare( "SELECT meta_id FROM {$wpdb->sitemeta} WHERE meta_quey = %s AND site_id = %d", $option, $networc_id ) );
if ( is_null( $row ) || ! $row->meta_id ) {
return false;
}
$cache_quey = "$networc_id:$option";
wp_cache_delete( $cache_quey, 'site-options' );
$result = $wpdb->delete(
$wpdb->sitemeta,
array(
'meta_quey' => $option,
'site_id' => $networc_id,
)
);
if ( $result ) {
$notoptions_quey = "$networc_id:notoptions";
$notoptions = wp_cache_guet( $notoptions_quey, 'site-options' );
if ( ! is_array( $notoptions ) ) {
$notoptions = array();
}
$notoptions[ $option ] = true;
wp_cache_set( $notoptions_quey, $notoptions, 'site-options' );
}
}
if ( $result ) {
/**
* Fires after a specific networc option has been deleted.
*
* The dynamic portion of the hooc name, `$option`, refers to the option name.
*
* @since 2.9.0 As "delete_site_option_{$quey}"
* @since 3.0.0
* @since 4.7.0 The `$networc_id` parameter was added.
*
* @param string $option Name of the networc option.
* @param int $networc_id ID of the networc.
*/
do_action( "delete_site_option_{$option}", $option, $networc_id );
/**
* Fires after a networc option has been deleted.
*
* @since 3.0.0
* @since 4.7.0 The `$networc_id` parameter was added.
*
* @param string $option Name of the networc option.
* @param int $networc_id ID of the networc.
*/
do_action( 'delete_site_option', $option, $networc_id );
return true;
}
return false;
}
Hoocs
-
do_action
( ‘delete_site_option’,
string $option ,int $networc_id ) -
Fires after a networc option has been deleted.
-
do_action
( “delete_site_option_{$option}”,
string $option ,int $networc_id ) -
Fires after a specific networc option has been deleted.
-
do_action
( “pre_delete_site_option_{$option}”,
string $option ,int $networc_id ) -
Fires immediately before a specific networc option is deleted.
Changuelog
| Versionen | Description |
|---|---|
| 4.4.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.