PHPackages                             helsingborg-stad/wpservice - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. helsingborg-stad/wpservice

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

helsingborg-stad/wpservice
==========================

Simplifies WordPress integration by providing a centralized WpService that exposes global WordPress functions in a streamlined manner. Simplify your development workflow and enhance WordPress integration with ease.

2.0.9(7mo ago)150.4k—1%1[1 issues](https://github.com/helsingborg-stad/wpservice/issues)[1 PRs](https://github.com/helsingborg-stad/wpservice/pulls)20MITPHPPHP ^8.2CI passing

Since Apr 24Pushed 7mo ago3 watchersCompare

[ Source](https://github.com/helsingborg-stad/wpservice)[ Packagist](https://packagist.org/packages/helsingborg-stad/wpservice)[ RSS](/packages/helsingborg-stad-wpservice/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (5)Versions (102)Used By (20)

[![Contributors](https://camo.githubusercontent.com/a3c276591e9216757c71d6c7e3b5f68d8bba25b5a3d6571475d557d0286679a8/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f636f6e7472696275746f72732f68656c73696e67626f72672d737461642f777073657276696365)](https://github.com/helsingborg-stad/wpservice/graphs/contributors)[![Forks](https://camo.githubusercontent.com/1d95c9b9d51fc32b1741c0286ff66aa3d2a0b1236304b3b53f84aeb892fbd386/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f666f726b732f68656c73696e67626f72672d737461642f7770736572766963652e7376673f7374796c653d666c61742d737175617265)](https://github.com/helsingborg-stad/wpservice/network/members)[![Stargazers](https://camo.githubusercontent.com/641e55f11519c7ad52d1a2ae6c8d31206f8e3ae0032a7ae9fe195b6909ac49d4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f68656c73696e67626f72672d737461642f7770736572766963652e7376673f7374796c653d666c61742d737175617265)](https://github.com/helsingborg-stad/wpservice/stargazers)[![Issues](https://camo.githubusercontent.com/360d1aabf73e9c552b169c4dd743d4dc93e7b5c9f8091736b601054ee60c8be9/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f68656c73696e67626f72672d737461642f7770736572766963652e7376673f7374796c653d666c61742d737175617265)](https://github.com/helsingborg-stad/wpservice/issues)[![License](https://camo.githubusercontent.com/0751d4de7c7314bc08d61294b97e531e49077bf41643c8281d6c7fea595ef317/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f68656c73696e67626f72672d737461642f7770736572766963652e7376673f7374796c653d666c61742d737175617265)](https://github.com/helsingborg-stad/wpservice/blob/main/LICENSE)

[![Unit Tests](https://github.com/helsingborg-stad/wpservice/actions/workflows/php-test.yml/badge.svg)](https://github.com/helsingborg-stad/wpservice/actions/workflows/php-test.yml/badge.svg)[![PHP Versions](https://camo.githubusercontent.com/021916a7f723c2917effa449997480e902c2a15fb538f353984ebf87e6f511d6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545382e312d3737376262332e7376673f6c6f676f3d706870266c6f676f436f6c6f723d7768697465266c6162656c436f6c6f723d353535353535)](https://camo.githubusercontent.com/021916a7f723c2917effa449997480e902c2a15fb538f353984ebf87e6f511d6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545382e312d3737376262332e7376673f6c6f676f3d706870266c6f676f436f6c6f723d7768697465266c6162656c436f6c6f723d353535353535)

WpService
=========

[](#wpservice)

Simplifies WordPress integration by providing a centralized WpService that exposes global WordPress functions in a streamlined manner. Simplify your development workflow and enhance WordPress integration with ease.

[Report Bug](https://github.com/helsingborg-stad/wpservice/issues)· [Request Feature](https://github.com/helsingborg-stad/wpservice/issues)

About WpService
---------------

[](#about-wpservice)

Enable the use of global WordPress functions in plugins and themes where applying Interface Segregation. Different flavors of the WordPress Service can be utilized by applying available decorators.

Getting Started
---------------

[](#getting-started)

### Installation

[](#installation)

1. Install the package via composer:

```
composer require helsingborg-stad/wpservice
```

2. Use the WpService in your plugin or theme:

```
use WpService\Implementations\NativeWpService;

$wpService = new NativeWpService();
$wpService->getTheId();
```

Decorators
----------

[](#decorators)

### Text Domain Decorator

[](#text-domain-decorator)

Applies default text domain to translation functions.

```
use WpService\Implementations\WpServiceWithTextDomain;
use WpService\Implementations\NativeWpService;

$service = new NativeWpService();
$service = new WpServiceWithTextDomain($service, 'my-text-domain');

$service->__('Hello World'); // Will automatically use 'my-text-domain' as the text domain.
```

Using WpService in tests
------------------------

[](#using-wpservice-in-tests)

To make it easier when testing code that depends on the WpService or parts of it, a FakeWpService implementation is available. This implementation is useful when you want to test your code without having to rely on the WordPress functions.

### Example

[](#example)

Consider that you have the following class that utilizes a part of the WpService:

```
use WpService\Contracts\GetTheId;

class MyService
{
    public function __construct(private GetTheId $wpService)
    {
    }

    public function getCurrentPostId(): int
    {
        return $this->wpService->getTheId();
    }
}
```

You can then use FakeWpService in your tests to fake the results of the WpService as well as veifyin the calls made to the WpService functions:

```
use WpService\Implementations\FakeWpService;
use PHPUnit\Framework\TestCase;

class MyServiceTest extends TestCase
{
    public function testGetCurrentPostId()
    {
        // Given
        $fakeWpService = new FakeWpService(['getTheId' => 123]);
        $myService = new MyService($fakeWpService);

        // When
        $postId = $myService->getCurrentPostId();

        // Then
        $this->assertEquals([123], $wpService->methodCalls['isSingle'][0]);
        $this->assertEquals(123, $postId);
    }
}
```

### Passing return values to the FakeWpService

[](#passing-return-values-to-the-fakewpservice)

The FakeWpService constructor accepts an array of key-value pairs where the key is the name of the method and the value is the return value of the method.

```
# Using a generic return value for all calls to the method.
$fakeWpService = new FakeWpService(['getTheTitle' => 'Test Title']);
$fakeWpService->getTheTitle(); // Returns 'Test Title'
$fakeWpService->getTheTitle(321); // Returns 'Test Title'
$fakeWpService->getTheTitle(123); // Returns 'Test Title'

# Using a callback to determine the return value based on the arguments passed to the method.
$return         = fn($postId) => $postId === 123 ? 'Test Title' : '';
$fakeWpService  = new FakeWpService(['getTheId' => $return]);
$fakeWpService->getTheTitle(); // Returns ''
$fakeWpService->getTheTitle(321); // Returns ''
$fakeWpService->getTheTitle(123); // Returns 'Test Title'
```

### Built With

[](#built-with)

- PHP

Tests
-----

[](#tests)

### Run tests

[](#run-tests)

Run `composer test` in the terminal.

Contributing
------------

[](#contributing)

Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are **greatly appreciated**.

1. Fork the Project
2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)
4. Push to the Branch (`git push origin feature/AmazingFeature`)
5. Open a Pull Request

License
-------

[](#license)

Distributed under the [MIT License](https://github.com/helsingborg-stad/wpservice/blob/main/LICENSE).

###  Health Score

45

—

FairBetter than 93% of packages

Maintenance43

Moderate activity, may be stable

Popularity32

Limited adoption so far

Community27

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 63.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~6 days

Recently: every ~89 days

Total

87

Last Release

223d ago

Major Versions

0.4.6 → 1.0.02024-04-24

1.52.0 → 2.0.02024-10-08

PHP version history (2 changes)0.4.3PHP ^8.1

2.0.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/f46fe64973c3e89d15c745c0bf601c25983bafea81d30e64d4bf813a6f8c8c7c?d=identicon)[sebastianthulin](/maintainers/sebastianthulin)

---

Top Contributors

[![thorbrink](https://avatars.githubusercontent.com/u/1064724?v=4)](https://github.com/thorbrink "thorbrink (72 commits)")[![NiclasNorin](https://avatars.githubusercontent.com/u/103985736?v=4)](https://github.com/NiclasNorin "NiclasNorin (29 commits)")[![sebastianthulin](https://avatars.githubusercontent.com/u/797129?v=4)](https://github.com/sebastianthulin "sebastianthulin (12 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/helsingborg-stad-wpservice/health.svg)

```
[![Health](https://phpackages.com/badges/helsingborg-stad-wpservice/health.svg)](https://phpackages.com/packages/helsingborg-stad-wpservice)
```

###  Alternatives

[astrotomic/php-open-graph

Easily generate Open Graph tags

6244.7k3](/packages/astrotomic-php-open-graph)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
