Automattic\WooCommerce\Internal\Admin\RemoteFreeExtensions
ProcessCoreProfilerPluginInstallOptions::add_install_option
Updates an install option in the WordPress database.
Method of the class: ProcessCoreProfilerPluginInstallOptions{}
No Hooks.
Returns
null. Nothing (null).
Usage
// protected - for code of main (parent) or child class $result = $this->add_install_option( $install_option );
- $install_option(object) (required)
- Install option object.
ProcessCoreProfilerPluginInstallOptions::add_install_option() ProcessCoreProfilerPluginInstallOptions::add install option code WC 10.8.1
protected function add_install_option( object $install_option ) {
$default_options = array(
'force_array' => false,
'autoload' => false,
);
$options = isset( $install_option->options )
? (object) $install_option->options
: new \stdClass();
foreach ( $default_options as $key => $value ) {
if ( ! isset( $options->$key ) ) {
$options->$key = $value;
}
}
if ( $options->force_array ) {
$install_option->value = json_decode( wp_json_encode( $install_option->value ), true );
// In case of JSON error, return early.
if ( json_last_error() !== JSON_ERROR_NONE ) {
$this->logger && $this->logger->error( 'Failed to decode JSON for install option value for ' . $install_option->name . ': ' . json_last_error_msg() );
return;
}
}
$autoload = null;
if ( isset( $options->autoload ) ) {
if ( 'yes' === $options->autoload ) {
$autoload = true;
} elseif ( 'no' === $options->autoload ) {
$autoload = false;
} elseif ( true === $options->autoload || false === $options->autoload ) {
$autoload = $options->autoload;
}
}
$this->add_option( $install_option->name, $install_option->value, $autoload );
}