PHPackages                             lin3s/wp-foundation - 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. lin3s/wp-foundation

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

lin3s/wp-foundation
===================

Helper classes for building WordPress theme in the LIN3S way

v1.7.1(7y ago)615.7k2[2 PRs](https://github.com/LIN3S/WPFoundation/pulls)1MITPHPPHP ^5.5 || ^7.0

Since Jul 22Pushed 5y ago1 watchersCompare

[ Source](https://github.com/LIN3S/WPFoundation)[ Packagist](https://packagist.org/packages/lin3s/wp-foundation)[ RSS](/packages/lin3s-wp-foundation/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (3)Versions (48)Used By (1)

WordPress Foundation
====================

[](#wordpress-foundation)

> Helper classes for building WordPress theme in the LIN3S way

[![SensioLabsInsight](https://camo.githubusercontent.com/4ff862212a47b7010cb9c160e18f51c7eb1c060ab98a7c6a9a00aec333d2a70e/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f39643937346637362d336635332d343837622d623665642d3932643362333238613435302f6d696e692e706e67)](https://insight.sensiolabs.com/projects/9d974f76-3f53-487b-b6ed-92d3b328a450)[![Build Status](https://camo.githubusercontent.com/439a751c3ea07763d75d20a48715f08cc583ac9f9e32633c91cb5a633b81a99d/68747470733a2f2f7472617669732d63692e6f72672f4c494e33532f5750466f756e646174696f6e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/LIN3S/WPFoundation)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/068438744caf32504534df0f7e5ada141e02196544040ccae5c50e0f4727c5d7/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f4c494e33532f5750466f756e646174696f6e2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/LIN3S/WPFoundation/?branch=master)[![Total Downloads](https://camo.githubusercontent.com/cea3ddbc56c893b53de3e1677851efac2c121551d1ab3dc5cf69bc99e90ad55b/68747470733a2f2f706f7365722e707567782e6f72672f6c696e33732f77702d666f756e646174696f6e2f646f776e6c6f616473)](https://packagist.org/packages/lin3s/wp-foundation) [![Latest Stable Version](https://camo.githubusercontent.com/b096300cc670c8657d7fe50e90a5a8aeb95ec94957082ac5ff7522967783b686/68747470733a2f2f706f7365722e707567782e6f72672f6c696e33732f77702d666f756e646174696f6e2f762f737461626c652e737667)](https://packagist.org/packages/lin3s/wp-foundation)[![Latest Unstable Version](https://camo.githubusercontent.com/e214fd3b82d656d6d1989a51b58910182b59866afee2f6b78b0de244fd794674/68747470733a2f2f706f7365722e707567782e6f72672f6c696e33732f77702d666f756e646174696f6e2f762f756e737461626c652e737667)](https://packagist.org/packages/lin3s/wp-foundation)

Why?
----

[](#why)

After implementing several WordPress themes, we built what we think can be considered as best practices building this kind of projects in a clean, consistent and fast way: thus was born [LIN3S](http://lin3s.com)'s [WordPress Standard Edition](https://github.com/LIN3S/WordpressStandard). We are really happy with it, but there are some tasks that are very repetitive and tedious, furthermore each developer usually implements in a different way so, with this library we try to avoid these kind of troubles. At this moment, WPFoundation only contains a set of **interfaces** and **abstract classes** (in the future who knows :)) to force all developers to follow the same way becoming our code more consistent.

Installation
------------

[](#installation)

The recommended and the most suitable way to install is through [Composer](https://getcomposer.org/download/). Be sure that the tool is installed in your system and execute the following command:

```
$ composer require lin3s/wp-foundation

```

Usage examples
--------------

[](#usage-examples)

The following code snippets are representative code samples of how can it use this library:

1. Ajax

- [Ajax](#ajax)

2. Configuration

- [ACF](#acf)
- [Assets](#assets)
- [Mailer](#mailer)
- [Menus](#menus)
- [Theme](#theme)
- [Translations](#translations)

3. PostTypes

- [PostType](#posttype)
- [Fields](#fields)
- [RewriteRules](#rewriterules)

4. Twig

- [TagManagerTwig](#tagmanagertwig)
- [TranslationTwig](#translationtwig)

5. Widgets

- [Widget](#widget)
- [Widget Areas](#widget-areas)

### Ajax

[](#ajax)

```
(...)

use LIN3S\WPFoundation\Ajax\Ajax;

final class MyAwesomeAjax extends Ajax
{
    /**
     * {@inheritdoc}
     */
    protected $action = 'my_awesome_ajax';

    /**
     * {@inheritdoc}
     */
    public function ajax()
    {
        (...)

        die('returning data');
    }
}
```

### ACF

[](#acf)

ACF configuration class, this class is responsible for all the logic about this WordPress plugin. A this moment this API only has one method that allows to have seamlessly multiple WYSWYG configuration for this type field used by ACF.

```
(...)

use LIN3S\WPFoundation\Configuration\Acf\Acf;

final class Acf extends BaseAcf
{
    /**
     * {@inheritdoc}
     */
    public function wyswygToolbars()
    {
        return [
            'basic' => [1 => ['bold', 'italic']],
            'lin3s' => [1 => ['bold', 'italic', 'bullist', 'numlist', 'link', 'unlink']],
        ];
    }
}
```

### Assets

[](#assets)

```
(...)

use LIN3S\WPFoundation\Configuration\Assets\Assets as BaseAssets;

final class Assets extends BaseAssets
{
    /**
     * {@inheritdoc}
     */
    public function productionAssets()
    {
        $this
            ->addScript('app.min', self::BUILD_JS, ['jquery', 'jquery.counterup', 'sidr']);
    }

    /**
     * {@inheritdoc}
     */
    public function developmentAssets()
    {
            $this
                ->addScript('jquery.sidr.min', self::VENDOR . '/sidr')
                ->addScript('waypoints', self::VENDOR . '/jquery-waypoints')
                ->addScript('jquery.counterup', self::VENDOR . '/Counter-Up')

                ->addScript('counter', self::ASSETS_JS, ['jquery', 'jquery.sidr.min', 'waypoints', 'jquery.counterup'])
                ->addScript('typekit', self::ASSETS_JS, [], '1.0.0', false)

                ->addScript('menu')
                ->addScript('accordion')

                ->addScript('post-ajax', self::ASSETS_JS, [], '1.0.0', false, 'postsAjax')
    }

    /**
     * {@inheritdoc}
     */
    public function adminAssets()
    {
        $this->addStylesheet('adminCss');
        $this->addScript('adminScript');
    }
}
```

### Mailer

[](#mailer)

`Mailer` class configures the way that emails are sent using `wp_mail()`. You should configure the mailer parameters editing the WordPress config file. Default parameters are given for the localhost smtp delivery.

You can define your own custom mailer that implements `MailInterface` and uses `wp_mail()` configuration selected creating an instance of one of the two strategies above.

```
(...)

use LIN3S\WPFoundation\Configuration\Mailer\MailInterface;
use Timber;

final class ContactMail implements MailInterface
{
    /**
     * {@inheritdoc}
     */
    public static function mail($request)
    {
        wp_mail(
            MAILER_TO,
            'Contact'
            Timber::compile('mail/mail.twig', ['request' => $request]),
            ['Content-Type: text/html; charset=UTF-8']
        );
    }
}
```

> `MailerInterface` is deprecated and will be removed in v2.0.0. Use wp\_mail() directly to send the emails

### Menus

[](#menus)

```
// src/App/App.php

use LIN3S\WPFoundation\Configuration\Menus\Menus

class App extends Theme {
    public function classes() {
        (...)
        new Menus([
            self::MENU_AWESOME => 'Awesome menu'
        ]
    }
}
```

### Theme

[](#theme)

```
(...)

use LIN3S\WPFoundation\Configuration\Theme\Theme;

final class AwesomeTheme extends Theme
{
    /**
     * {@inheritdoc}
     */
    public function classes()
    {
        new Assets();
        new Acf();
        new Mailer();
        new Menus();

        new CustomPostType();
    }

    /**
     * {@inheritdoc}
     */
    public function templates($templates)
    {
        return array_merge($templates, [
            'index'    => 'Index',
            'customs' => 'Customs',
        ]);
    }

    /**
     * {@inheritdoc}
     */
    public function context(array $context)
    {
        $context['mainMenu'] = new TimberMenu('main-menu');
        $data['lang'] = ICL_LANGUAGE_CODE;

        return $context;
    }
}
```

### Translations

[](#translations)

```
\LIN3S\WPFoundation\Configuration\Translations\Translations::trans('Your awesome string');
```

### PostType

[](#posttype)

Declaring a post type is as easy as creating a new instance of `PostType`.

```
// src/App/App.php

class App extends Theme {
    public function classes() {
        (...)
        new PostType(
            PostTypes::CUSTOM_POST_TYPE,
            [
                'labels'             => [
                    'name'          => Translations::trans('Exhibitions'),
                    'singular_name' => Translations::trans('Exhibition'),
                ],
                'has_archive'        => true,
                'public'             => true,
                'publicly_queryable' => true,
                'query_var'          => true,
                'show_in_rest'       => true,
                'show_ui'            => true,
                'supports'           => ['title', 'editor', 'thumbnail'],
            ]
        )
    }
}
```

To add custom fields to a custom post type just create a `Fields` instance:

```
// src/App/App.php

class App extends Theme {
    public function classes() {
        (...)
        new Fields(
            PostTypes::CUSTOM_POST_TYPE,
            [
                Fully\Qualified\Namespace\Components\CustomFieldComponent::class,
            ],
            new PostTypeFieldConnector(PostTypes::CUSTOM_POST_TYPE)
            ['editor'],
            ['comments']
        );
    }
}
```

### Fields

[](#fields)

```
(...)

use LIN3S\WPFoundation\PostTypes\Field\FieldComponent;

final class CustomFieldComponent extends FieldComponent
{
    /**
     * {@inheritdoc}
     */
    public static function definition($aName)
    {
        return [
            'key' => sprintf('field_%s_component', $aName),

            (...)
        ]);
    }
}
```

```
(...)

use LIN3S\WPFoundation\PostTypes\Fields\PageFields as BasePageFields;

final class PageFields extends BasePageFields
{
    /**
     * {@inheritdoc}
     */
    private $name = 'my_awesome_template;

    /**
     * {@inheritdoc}
     */
    public function components()
    {
        return [
            'Fully\Qualified\Namespace\Components\CustomFieldComponent',
        ];
    ];
}
```

### RewriteRules

[](#rewriterules)

```
(...)

use LIN3S\WPFoundation\PostTypes\RewriteRules\RewriteRules;

final class CustomRewriteRules extends RewriteRules
{
    /**
     * {@inheritdoc}
     */
    public function rewriteRules()
    {
        add_rewrite_rule(
            '^custom-base-url/([^/]*)/([^/]*)/([^/]*)/?$',
            'index.php?category=$matches[1]&subcategory=$matches[2]&custom=$matches[3]',
            'top'
        );

        add_rewrite_rule(
            '^custom-base-url/([^/]*)/([^/]*)/?$',
            'index.php?category=$matches[1]&subcategory=$matches[2]',
            'top'
        );
    }

    /**
     * {@inheritdoc}
     */
    public function rewriteTags()
    {
        add_rewrite_tag('%category%', '([^/]*)');
        add_rewrite_tag('%subcategory%', '([^/]*)');
        add_rewrite_tag('%custom%', '([^/]*)');
    }

    /**
     * {@inheritdoc}
     */
    public function templateInclude($template)
    {
        $controller = new CustomController();

        $method = '';
        if (get_query_var('category') !== ''
            && get_query_var('subcategory') !== ''
            && get_query_var('custom') != ''
        ) {
            $method = 'showAction';
        } elseif (get_query_var('category') !== ''
            && get_query_var('subcategory') !== ''
        ) {
            $method = 'listAction';
        }

        return $method === '' ? $template : $controller->$method();
    }
}
```

### TagManagerTwig

[](#tagmanagertwig)

After instantiate the the `TagManagerTwig` in your theme, you can just call as following:

```
(...)
{% block tagManager %}
    {{ tagManager('GTM-XXXXXX') }}
{% endblock %}
```

### TranslationTwig

[](#translationtwig)

After instantiate the the `TranslationTwig` in your theme, you can just call as following:

```
(...)
{{ trans('Your awesome string') }}
```

### Widget

[](#widget)

```
(...)

use LIN3S\WPFoundation\Widgets\Widget;

final class SocialNetworksWidget extends Widget
{
    /**
     * {@inheritdoc}
     */
    public function widget($args, $instance)
    {
        $data = [
            'beforeWidget' => $args['before_widget'],
            'afterWidget'  => $args['after_widget'],
            'beforeTitle'  => $args['before_title'],
            'afterTitle'   => $args['after_title'],
            'twitterUrl'   => (!empty($instance['twitterUrl'])) ? strip_tags($instance['twitterUrl']) : '',
            'facebookUrl'  => (!empty($instance['facebookUrl'])) ? strip_tags($instance['facebookUrl']) : '',
            'pinterestUrl' => (!empty($instance['pinterestUrl'])) ? strip_tags($instance['pinterestUrl']) : '',
            'youtubeUrl'   => (!empty($instance['youtubeUrl'])) ? strip_tags($instance['youtubeUrl']) : '',
            'rssUrl'       => (!empty($instance['rssUrl'])) ? strip_tags($instance['rssUrl']) : '',
        ];

        return Timber::render('widgets/front/socialNetworks.twig', $data);
    }

    /**
     * {@inheritdoc}
     */
    public function form($instance)
    {
        $instance['widgetNumber'] = $this->number();
        $instance['widgetName'] = $this->name();

        return Timber::render('widgets/admin/socialNetworks.twig', $instance);
    }

    /**
     * {@inheritdoc}
     */
    public function update($newInstance)
    {
        $instance = [
            'twitterUrl'   => (!empty($newInstance['twitterUrl'])) ? strip_tags($newInstance['twitterUrl']) : '',
            'facebookUrl'  => (!empty($newInstance['facebookUrl'])) ? strip_tags($newInstance['facebookUrl']) : '',
            'pinterestUrl' => (!empty($newInstance['pinterestUrl'])) ? strip_tags($newInstance['pinterestUrl']) : '',
            'youtubeUrl'   => (!empty($newInstance['youtubeUrl'])) ? strip_tags($newInstance['youtubeUrl']) : '',
            'rssUrl'       => (!empty($newInstance['rssUrl'])) ? strip_tags($newInstance['rssUrl']) : '',
        ];

        return $instance;
    }
}
```

### Widget Areas

[](#widget-areas)

```
(...)

use LIN3S\WPFoundation\Widgets\Areas\WidgetArea;

final class CustomWidgetArea extends WidgetArea
{
    /**
     * {@inheritdoc}
     */
    public function widgetArea()
    {
        register_sidebar([
            'name'          => 'Custom widgets',
            'id'            => 'custom-widgets',
            'before_widget' => '',
            'after_widget'  => '',
            'before_title'  => '',
            'after_title'   => '',
        ]);
    }
}
```

\##Licensing Options [![License](https://camo.githubusercontent.com/0c765684c796af14b3f1ac267a1ec00a4106993825fe825b5eecb114c7e2e419/68747470733a2f2f706f7365722e707567782e6f72672f6c696e33732f77702d666f756e646174696f6e2f6c6963656e73652e737667)](https://github.com/LIN3S/WPFoundation/blob/master/LICENSE)

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity71

Established project with proven stability

 Bus Factor1

Top contributor holds 64.8% 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 ~33 days

Recently: every ~192 days

Total

37

Last Release

2758d ago

PHP version history (3 changes)v1.0.0PHP &gt;=5.4

v1.4.1PHP &gt;=5.5

v1.5.0PHP ^5.5 || ^7.0

### Community

Maintainers

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

![](https://www.gravatar.com/avatar/06308bfc15d8774c16d36d727f852c2d29ed8d0d6153637384439747776dc658?d=identicon)[benatespina](/maintainers/benatespina)

---

Top Contributors

[![benatespina](https://avatars.githubusercontent.com/u/3951376?v=4)](https://github.com/benatespina "benatespina (70 commits)")[![gorkalaucirica](https://avatars.githubusercontent.com/u/1749891?v=4)](https://github.com/gorkalaucirica "gorkalaucirica (37 commits)")[![jontorrado](https://avatars.githubusercontent.com/u/6916591?v=4)](https://github.com/jontorrado "jontorrado (1 commits)")

---

Tags

lin3sphpwordpresswordpresshelpersfoundationlin3s

###  Code Quality

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/lin3s-wp-foundation/health.svg)

```
[![Health](https://phpackages.com/badges/lin3s-wp-foundation/health.svg)](https://phpackages.com/packages/lin3s-wp-foundation)
```

###  Alternatives

[php-stubs/wordpress-stubs

WordPress function and class declaration stubs for static analysis.

19013.0M263](/packages/php-stubs-wordpress-stubs)[wpsitecare/carelib

A collection of helpful functions to make creating an awesome theme more enjoyable.

164.6k](/packages/wpsitecare-carelib)

PHPackages © 2026

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