Skip to content

Commit

Permalink
Merge pull request #3 from wp-oop/task/allow-current-blog-options
Browse files Browse the repository at this point in the history
  • Loading branch information
XedinUnknown authored Jan 6, 2022
2 parents 4373a12 + f53ad32 commit ddfbaed
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 80 deletions.
146 changes: 72 additions & 74 deletions .idea/containers.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [[*next-version*]] - YYYY-MM-DD
### Added
- `BlogOptions` now accepts a `null` blog ID,
which causes it to use the current site's options every time, regardless (#3).

## [0.1.1-alpha1] - 2022-01-05
### Changed
Expand Down
11 changes: 6 additions & 5 deletions src/Options/BlogOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,21 @@ class BlogOptions implements MutableContainerInterface
{
use StringTranslatingTrait;

/**
* @var int
*/
/** @var int|null */
protected $blogId;
/** @var string */
protected $default;

/**
* @param int $blogId The ID of the blog to represent the options for.
* @param int|null $blogId The ID of the blog to represent the options for, or null for current blog.
* @param string $default The value to return if an option is not found.
* This is necessary because WP will otherwise return `false`, which
* is indistinguishable from a real option value.
* Therefore, this should be set to something that is unlikely to be a
* valid option value.
*/
public function __construct(
int $blogId,
?int $blogId,
string $default
) {
$this->blogId = $blogId;
Expand Down Expand Up @@ -115,6 +113,7 @@ public function set(string $key, $value): void
public function unset(string $key): void
{
$blogId = $this->blogId;
/** @psalm-suppress PossiblyNullArgument */
$result = delete_blog_option($blogId, $key);

if ($result === false) {
Expand Down Expand Up @@ -142,6 +141,7 @@ protected function getOption(string $name)
{
$blogId = $this->blogId;
$default = $this->default;
/** @psalm-suppress PossiblyNullArgument */
$value = get_blog_option($blogId, $name, $default);

if ($value === $default) {
Expand Down Expand Up @@ -170,6 +170,7 @@ protected function setOption(string $name, $value): void
{
$blogId = $this->blogId;

/** @psalm-suppress PossiblyNullArgument */
$isSuccessful = update_blog_option($blogId, $name, $value);
if (!$isSuccessful) {
$newValue = $this->getOption($name);
Expand Down
3 changes: 2 additions & 1 deletion src/Util/StringTranslatingTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ trait StringTranslatingTrait
* The translation itself is delegated to another method.
*
* @param string $string The format string to translate.
* @param scalar[] $args Placeholder values to replace in the string.
* @param array $args Placeholder values to replace in the string.
* @psalm-param array<array-key, ?scalar>
* @param mixed $context The context for translation.
* @return string The translated string.
*@see sprintf()
Expand Down

0 comments on commit ddfbaed

Please sign in to comment.