Skip to content

Commit

Permalink
Various improvements in WpOptions
Browse files Browse the repository at this point in the history
- The property `$network_option` is renamed `$is_network_option`.
- The property `$network_id` cannot be null anymore, and is defaulted to `get_current_network_id()` on class instanciation.
- Removed useless cast to boolean in `is_network_option()`.
  • Loading branch information
Screenfeed committed Feb 3, 2021
1 parent 0694f93 commit 7ecf9ac
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions src/Storage/WpOption.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class WpOption implements StorageInterface {
* @var bool
* @since 1.0.0
*/
private $network_option;
private $is_network_option;

/**
* Tells if the option should be autoloaded by WP.
Expand All @@ -45,7 +45,7 @@ class WpOption implements StorageInterface {
* The network ID.
* Null for the current network ID.
*
* @var int|null
* @var int
* @since 1.0.0
*/
private $network_id;
Expand All @@ -55,21 +55,21 @@ class WpOption implements StorageInterface {
*
* @since 1.0.0
*
* @param string $option_name Name of the option.
* @param bool $network_option True if a network option. False otherwise.
* @param array<mixed> $args {
* @param string $option_name Name of the option.
* @param bool $is_network_option True if a network option. False otherwise.
* @param array<mixed> $args {
* Optionnal arguments.
*
* @type bool $autoload True if the option must be autoloaded. False otherwise. Not used for network options. Default value is true.
* @type int $network_id ID of the network. Used only for network options. Can be `0` to default to the current network ID. Default value is the current network ID.
* }
* @return void
*/
public function __construct( $option_name, $network_option, array $args = [] ) {
$this->option_name = (string) $option_name;
$this->network_option = (bool) $network_option;
$this->autoload = ! empty( $args['autoload'] ) && 'no' !== $args['autoload'] ? 'yes' : 'no';
$this->network_id = ! empty( $args['network_id'] ) && is_numeric( $args['network_id'] ) ? absint( $args['network_id'] ) : null;
public function __construct( $option_name, $is_network_option, array $args = [] ) {
$this->option_name = (string) $option_name;
$this->is_network_option = (bool) $is_network_option;
$this->autoload = isset( $args['autoload'] ) && ( 'no' === $args['autoload'] || false === $args['autoload'] ) ? 'no' : 'yes';
$this->network_id = ! empty( $args['network_id'] ) && is_numeric( $args['network_id'] ) ? absint( $args['network_id'] ) : get_current_network_id();
}

/**
Expand Down Expand Up @@ -102,9 +102,6 @@ public function get_full_name() {
* @return int
*/
public function get_network_id() {
if ( ! isset( $this->network_id ) ) {
$this->network_id = get_current_network_id();
}
return $this->network_id;
}

Expand All @@ -116,7 +113,7 @@ public function get_network_id() {
* @return bool
*/
public function is_network_option() {
return (bool) $this->network_option;
return $this->is_network_option;
}

/**
Expand All @@ -141,9 +138,8 @@ public function get() {
*
* @since 1.0.0
*
* @param array<mixed> $values An array of option name / option value pairs.
*
* @return bool True if the value was updated, false otherwise.
* @param array<mixed> $values An array of option name / option value pairs.
* @return bool True if the value was updated, false otherwise.
*/
public function set( array $values ) {
if ( empty( $values ) ) {
Expand Down

0 comments on commit 7ecf9ac

Please sign in to comment.