Using WordPress ‘remove_allowed_options()’ PHP function

The remove_allowed_options() WordPress PHP function removes a list of options from the allowed options list.

Usage

remove_allowed_options( $del_options, $options = '' );

Parameters

  • $del_options (array) – The options to remove from the allowed options list.
  • $options (string|array) – The current allowed options list, can be a string or an array. Default is an empty string.

More information

See WordPress Developer Resources: remove_allowed_options

Examples

Remove a single option

Remove the ‘my_option’ from the allowed options list.

$del_options = array( 'my_option' );
$current_options = array( 'option1', 'my_option', 'option3' );

$new_options = remove_allowed_options( $del_options, $current_options );

Remove multiple options

Remove ‘option2’ and ‘option4’ from the allowed options list.

$del_options = array( 'option2', 'option4' );
$current_options = array( 'option1', 'option2', 'option3', 'option4', 'option5' );

$new_options = remove_allowed_options( $del_options, $current_options );

Remove options using a string

Remove ‘option3’ from the allowed options list, using a string for the current options.

$del_options = array( 'option3' );
$current_options = 'option1,option2,option3,option4';

$new_options = remove_allowed_options( $del_options, $current_options );

Remove options with an empty current options list

Remove ‘option1’ and ‘option2’ from the allowed options list, but the current options list is empty.

$del_options = array( 'option1', 'option2' );
$current_options = '';

$new_options = remove_allowed_options( $del_options, $current_options );

Remove options with an empty delete options list

Attempt to remove options when the delete options list is empty.

$del_options = array();
$current_options = array( 'option1', 'option2', 'option3', 'option4', 'option5' );

$new_options = remove_allowed_options( $del_options, $current_options );